Example usage for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress

List of usage examples for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress

Introduction

In this page you can find the example usage for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress.

Prototype

IRunnableWithProgress

Source Link

Usage

From source file:com.nokia.carbide.cpp.internal.pi.wizards.ui.TraceHandler.java

License:Open Source License

/**
 * Start trace/*from ww w  .j av  a 2s  .  co m*/
 * 
 * @param fileName
 *            for new profiler data file
 * @param traceIDs
 *            selected plug-ins to be profiling
 */
public void startTrace(final String fileName, final int[] traceIDs) {

    try {
        IRunnableWithProgress runnableWithProgress = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(Messages.getString("TraceHandler.preparingTracing"), //$NON-NLS-1$
                        IProgressMonitor.UNKNOWN);
                try {

                    PiPlugin.getTraceProvider().startTrace(fileName, traceIDs, TraceHandler.this,
                            new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN));
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                } finally {
                    monitor.done();
                }

            }
        };
        wizardContainer.run(true, false, runnableWithProgress);

    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof CoreException) {
            updateStatus(((CoreException) e.getCause()).getStatus());
        } else {
            notifyError(e.getMessage());
        }
    } catch (InterruptedException e) {
        notifyError(e.getMessage());
    }
}

From source file:com.nokia.carbide.cpp.internal.pi.wizards.ui.TraceHandler.java

License:Open Source License

/**
 * Stop trace/*  w w w.j av a  2s .c  o  m*/
 * 
 * @return
 */
public IPath stopTrace() {
    final IPath[] path = new Path[1];
    try {
        IRunnableWithProgress runnableWithProgress = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(Messages.getString("TraceHandler.creatingProfilerDataFile"), //$NON-NLS-1$
                        IProgressMonitor.UNKNOWN);
                try {
                    path[0] = PiPlugin.getTraceProvider().stopTrace(false);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                } finally {
                    monitor.done();
                }
            }
        };
        wizardContainer.run(true, false, runnableWithProgress);
        return path[0];
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof CoreException) {
            updateStatus(((CoreException) e.getCause()).getStatus());
        } else {
            notifyError(e.getMessage());
        }

    } catch (InterruptedException e) {
        notifyError(e.getMessage());
    }
    return null;
}

From source file:com.nokia.carbide.cpp.internal.project.ui.importWizards.ProjectPropertiesPage.java

License:Open Source License

@Override
public void setVisible(boolean visible) {
    // this gets called just before the page goes in or out of view.  if it's
    // going into view then get the project name and root directory.  when
    // we do save the bld.inf file and list of build configs we parsed with so we
    // know if we need to re-parse again if either of these changes, e.g. the user
    // hits back and selects a different bld.inf or set of configs
    if (visible) {
        if (parsedBldInfFile == null || parsedWithConfigs == null
                || !parsedBldInfFile.equals(theWizard.getBldInfFile())
                || !parsedWithConfigs.equals(theWizard.getSelectedConfigs())
                || !selectedMakMakeRefs.equals(theWizard.getSelectedMakMakeReferences())) {
            parsedBldInfFile = theWizard.getBldInfFile();
            parsedWithConfigs = theWizard.getSelectedConfigs();
            selectedMakMakeRefs = theWizard.getSelectedMakMakeReferences();

            try {
                getContainer().run(true, true, new IRunnableWithProgress() {
                    public void run(IProgressMonitor monitor) {
                        List<IPath> projectRoots = EpocEngineHelper.getProjectRoots(new Path(parsedBldInfFile),
                                parsedWithConfigs, monitor);
                        rootDirectoryPath = projectRoots.get(0);
                        rootPathContainingAllProjectFiles = projectRoots.get(1);
                        rootPathContainingAllProjectAndSourceFiles = projectRoots.get(2);

                        // do not use the group directory by default if possible
                        if (rootDirectoryPath.segmentCount() > 1
                                && rootDirectoryPath.lastSegment().compareToIgnoreCase("group") == 0) { //$NON-NLS-1$
                            rootDirectoryPath = rootDirectoryPath.removeLastSegments(1);
                        }/*from  ww  w.  ja  v  a2 s. c om*/

                        // do this in the ui thread
                        getControl().getDisplay().asyncExec(new Runnable() {
                            public void run() {
                                rootDirectory.setText(rootDirectoryPath.toOSString());
                                projectName.setText(getProposedProjectName());
                                setPageComplete(validatePage());
                            }
                        });
                    }
                });
            } catch (InvocationTargetException e) {
            } catch (InterruptedException e) {
                // Nothing to do if the user interrupts.
            }
        }
    }

    super.setVisible(visible);
}

From source file:com.nokia.carbide.cpp.sdk.ui.shared.BuildTargetTreeNode.java

License:Open Source License

/**
 * Gets the list of SDK tree nodes for use in a tree viewer.  The SDK's are gathered
 * from the SDK preferences page.  Only enabled SDK's are used.  Each SDK node will
 * have build configurations for children appropriate for the SDK.  These configurations
 * are filtered based on the platform filtering preference panel.
 * @param sbsv2Project true if this is an SBSv2 project which affects how the build
 * configuration list is calculated//from  ww  w  .j a va2  s . c  o  m
 * @param IRunnableContext - a runnable context for which to update a progress monitor. Cannot be null.
 * @return array of BuildTargetTreeNode, or null
 * @since 1.4
 */
public static BuildTargetTreeNode[] getTreeViewerInput(final boolean sbsv2Project,
        IRunnableContext runnableContext) {

    final List<BuildTargetTreeNode> assembledInput = new ArrayList<BuildTargetTreeNode>();

    try {
        runnableContext.run(true, false, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

                String msgPrefix = "Building SDK/Configuration Model: "; //$NON-NLS-N$

                ISDKManager sdkMgr = SDKCorePlugin.getSDKManager();
                List<ISymbianSDK> sdkList = sdkMgr.getSDKList();
                monitor.beginTask(msgPrefix, sdkList.size() + 2);
                if (sdkList == null)
                    return;

                monitor.worked(1);
                List<ISymbianSDK> sdkListCopy = new ArrayList<ISymbianSDK>();
                // Only add SDKs that are enabled
                for (ISymbianSDK currSDK : sdkList) {
                    if (currSDK.isEnabled()) {
                        sdkListCopy.add(currSDK);
                    }
                }

                if (sbsv2Project) {
                    // filter non-SBSv2 supported SDK's
                    sdkListCopy = SBSv2Utils.getSupportedSDKs(sdkListCopy);
                }

                BuildTargetTreeNode[] input = new BuildTargetTreeNode[sdkListCopy.size()];
                int index = 0;
                monitor.worked(1);
                for (ISymbianSDK sdk : sdkListCopy) {
                    monitor.worked(1);
                    String sdkErr = ""; // If we are scanning due to errors in the SDK
                    if (!(new File(sdk.getEPOCROOT()).exists())) {
                        sdkErr = " (Building cache with bad EPOCROOT)";
                    }
                    monitor.setTaskName(msgPrefix + sdk.getUniqueId() + sdkErr);
                    BuildTargetTreeNode treeNode = new BuildTargetTreeNode(sdk, sbsv2Project);
                    if (treeNode.getChildren() != null || sbsv2Project) {
                        input[index++] = treeNode;
                    }
                }

                // Filter out any SDKs that don't have configs
                monitor.worked(1);
                for (BuildTargetTreeNode currNode : input) {
                    if (currNode != null) {
                        assembledInput.add(currNode);
                    }
                }
                monitor.done();
            }

        });
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    if (assembledInput.size() == 0) {
        return null;
    }

    return assembledInput.toArray(new BuildTargetTreeNode[assembledInput.size()]);
}

From source file:com.nokia.carbide.cpp.uiq.ui.vieweditor.ViewEditorUtils.java

License:Open Source License

/**
 * This code was taken from the EventCommands class. It saves the model.
 * @return//from ww w.  j  av a2  s . co  m
 */
public static boolean saveDataModel(IDesignerDataModelEditor modelEditor) {
    final IDesignerDataModelEditor editor = modelEditor;
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            editor.doSave(monitor);
        }
    };
    try {
        PlatformUI.getWorkbench().getProgressService()
                .runInUI(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), runnable, null);
        return true;
    } catch (InvocationTargetException e) {
        UIDesignerPlugin.getDefault().log(e);
        return false;
    } catch (InterruptedException e) {
        return false;
    }
}

From source file:com.nokia.carbide.cpp.uiq.ui.viewwizard.ViewWizardManager.java

License:Open Source License

/**
 * Find collisions between existing sources and those generated by a new model.
 * @return list of project-relative paths
 *//*from ww  w.  j  a v  a2  s . com*/
public List<IPath> getSourceCollisions() {
    WorkspaceContext wc = WorkspaceContext.getContext();
    final IProject project = (IProject) getDataStore().get(PROJECT_KEY);
    final IProjectContext pc = wc.getContextForProject(project);
    Check.checkContract(pc != null);
    final ISymbianProjectContext spc = (ISymbianProjectContext) pc.getAdapter(ISymbianProjectContext.class);
    final IDesignerDataModelSpecifier modelSpecifier = createModelSpecifier(project, spc);

    // create a separate provider so we don't disturb the existing one
    ISourceGenProvider provider;
    try {
        provider = SourceGenUtils.loadSourceGenProvider(SymbianModelUtils.SOURCEGEN_PROVIDER_ID, project);
    } catch (CoreException e) {
        UIPlugin.log(e);
        return Collections.EMPTY_LIST;
    }
    //pc.getSourceGenProvider();
    Check.checkContract(provider != null);

    final List<IPath> collisions = new ArrayList<IPath>();

    // check view model (use runnable to get busy notification)
    IDesignerDataModel model = (IDesignerDataModel) getDataStore().get(VIEW_MODEL_KEY);
    final ISourceGenSession session = SymbianModelUtils.createSourceGenSession(provider, model, modelSpecifier);
    UITaskUtils.runImmediately(new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            List<IPath> sources = session.scanForGeneratedSources(monitor);
            filterCollisions(collisions, project, sources);
        }
    });
    session.dispose();
    provider.dispose();

    return collisions;
}

From source file:com.nokia.carbide.installpackages.InstallPackages.java

License:Open Source License

public InstallPackages(IService service, IRunnableContext runnableContext) {
    Check.checkArg(service);/*from w  w  w.j  a v  a 2  s  .  com*/
    this.service = service;
    if (runnableContext == null)
        getPackageList();
    else {
        try {
            runnableContext.run(true, false, new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    monitor.beginTask(Messages.getString("InstallPackages.GettingPackagesJobLabel"), //$NON-NLS-1$
                            IProgressMonitor.UNKNOWN);
                    getPackageList();
                }
            });
        } catch (Exception e) {
            RemoteConnectionsActivator.logError(e);
        }
    }
}

From source file:com.nokia.carbide.internal.api.templatewizard.ui.ChooseTemplatePage.java

License:Open Source License

private List<ITemplate> getSortedTemplates() {
    if (templates == null) {
        if (TemplateEngine.isLoaded())
            templates = TemplateEngine.getInstance().getTemplates(getWizardId());
        else {/*from  w  ww. ja  v  a2s  .  com*/
            try {
                // blocks until returns, even if fork is true (per javadoc)
                getWizard().getContainer().run(true, false, new IRunnableWithProgress() {
                    public void run(IProgressMonitor monitor) {
                        monitor.beginTask(Messages.getString("ChooseTemplatePage.LoadingTemplatesTaskName"), 1); //$NON-NLS-1$
                        templates = TemplateEngine.getInstance().getTemplates(getWizardId());
                        monitor.worked(1);
                    }
                });
            } catch (InvocationTargetException e) {
                TemplateEngine.logError(Messages.getString("ChooseTemplatePage.CouldNotLoadTemplates"), e); //$NON-NLS-1$
            } catch (InterruptedException e) {
                TemplateEngine.logError(Messages.getString("ChooseTemplatePage.TemplateLoadingInterrupted"), e); //$NON-NLS-1$
                // Nothing to do if the user interrupts.
            }
        }

        if (templates == null) {
            Logging.log(null, Logging.newStatus(TemplateWizardPlugin.getDefault(), IStatus.ERROR,
                    Messages.getString("ChooseTemplatePage.TemplatesNotRead"))); //$NON-NLS-1$
            return Collections.emptyList();
        }

        Collections.sort(templates, new Comparator<ITemplate>() {
            public int compare(ITemplate t1, ITemplate t2) {
                String label1 = t1.getGroupLabel();
                String label2 = t2.getGroupLabel();
                if (label1.equals(label2)) {
                    return t1.getDisplayName().compareToIgnoreCase(t2.getDisplayName());
                }
                return label1.compareTo(label2);
            }
        });
    }

    return templates;
}

From source file:com.nokia.carbide.internal.bugreport.ui.wizards.NewBugReportWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    try {/*from  w  w w. j  a  v  a 2s . c  o  m*/
        getContainer().run(true, true, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) {
                monitor.beginTask(Messages.getString("NewBugReportWizard.SendingReport"), //$NON-NLS-1$
                        IProgressMonitor.UNKNOWN);
                String bugNumber = Communication.sendBugReport(fieldsHandler.getFieldsForSending(),
                        productHandler.getProduct());
                ConsoleLine line = new ConsoleLine(productHandler.getProduct(), bugNumber);
                console.addLineToConsole(line);

                monitor.done();
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
        MessageDialog.openError(this.getShell(), Messages.getString("NewBugReportWizard.BugReporting"), //$NON-NLS-1$
                e.getCause().getLocalizedMessage());
        return false;
    }

    return true;
}

From source file:com.nokia.carbide.remoteconnections.interfaces.AbstractConnectedService.java

License:Open Source License

public void testStatus() {
    if (!(isEnabled() || manualTesting))
        return;/*from  ww  w . j  a  va2s  .  c  o  m*/

    final TestResult result[] = { null };
    if (runnableContext != null && (!(runnableContext instanceof WizardDialog)
            || ((WizardDialog) runnableContext).getShell() != null)) {
        Display.getDefault().syncExec(new Runnable() {
            public void run() {
                try {
                    runnableContext.run(true, false, new IRunnableWithProgress() {
                        public void run(IProgressMonitor monitor)
                                throws InvocationTargetException, InterruptedException {
                            result[0] = runTestStatus(monitor);
                        }
                    });
                } catch (InvocationTargetException e) {
                } catch (InterruptedException e) {
                }
            }
        });
    } else {
        result[0] = runTestStatus(new NullProgressMonitor());
    }

    if (!(isEnabled() || manualTesting)) // could be waiting for response past when service testing was disabled
        return;
    if (result[0].shortDescription != null && result[0].longDescription != null) {
        currentStatus.setEStatus(result[0].estatus, result[0].shortDescription, result[0].longDescription);
    }
}