List of usage examples for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress
IRunnableWithProgress
From source file:com.nokia.carbide.cdt.internal.api.builder.ui.MMPSelectionUI.java
License:Open Source License
/** * Sets the data for this UI from bld.inf file and list of build configs * @param bldInfFile IPath//from w ww .j a v a 2 s . c o m * @param buildConfigs List<ISymbianBuildContext> */ public void setBldInfFile(final IPath bldInfFile, final List<ISymbianBuildContext> buildContexts, final boolean useSBSv2Builder) { if (bldInfFile.equals(this.bldInfFile) && buildConfigs.equals(this.buildConfigs)) return; this.bldInfFile = bldInfFile; this.buildConfigs = buildContexts; this.useSBSv2Builder = useSBSv2Builder; try { runnableContext.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) { data = new ArrayList<FileInfo>(); List<IPath> normalMakMakeList = new ArrayList<IPath>(); List<IPath> testMakMakeList = new ArrayList<IPath>(); EpocEngineHelper.getMakMakeFiles(bldInfFile, buildConfigs, normalMakMakeList, testMakMakeList, monitor); int i = 0; for (IPath currPath : normalMakMakeList) { data.add(new FileInfo(currPath, ++i, false)); } for (IPath currPath : testMakMakeList) { data.add(new FileInfo(currPath, ++i, true)); } // named extensions are only supported in SBSv2 if (useSBSv2Builder) { List<IExtension> normalNamedExtensionsList = new ArrayList<IExtension>(); List<IExtension> testNamedExtensionsList = new ArrayList<IExtension>(); EpocEngineHelper.getNamedExtensions(bldInfFile, buildConfigs, normalNamedExtensionsList, testNamedExtensionsList, monitor); for (IExtension extension : normalNamedExtensionsList) { data.add(new FileInfo(new Path(extension.getName()), ++i, false)); } for (IExtension extension : testNamedExtensionsList) { data.add(new FileInfo(new Path(extension.getName()), ++i, true)); } } hasUnnamedProjectExtensions = EpocEngineHelper.hasUnnamedExtensions(bldInfFile, buildConfigs, monitor); } }); } catch (InvocationTargetException e) { } catch (InterruptedException e) { // Nothing to do if the user interrupts. } viewer.setInput(data); TableColumn[] columns = viewer.getTable().getColumns(); for (TableColumn tableColumn : columns) { tableColumn.pack(); } if (data.size() > MMP_SELECTION_THRESHOLD) { setAllChecked(false); } else { setAllChecked(true); } }
From source file:com.nokia.carbide.cpp.internal.pi.analyser.AnalyserDataProcessor.java
License:Open Source License
public void openNpiForPIPageEditor(final URI analysisFileURI, final Composite parent, final int uid) { boolean isImport = analyserDataProcessorState == STATE_IMPORTING; final String displayName = new java.io.File(analysisFileURI).getName(); if (isImport && getProgressMonitor() != null) { //import is already wrapped in runnable, and we should have progressmonitor getProgressMonitor().setTaskName(Messages.getString("AnalyserDataProcessor.5") + displayName); //$NON-NLS-1$ try {/*from w w w . j ava2 s. c o m*/ analyserDataProcessorState = STATE_OPENING; // by saying isImport true, we assume trace is set up proper in repository processTraceDrawAndResize(parent, true); analyserDataProcessorState = STATE_OK; if (false) internalOpenNPI(analysisFileURI, parent, uid); } catch (InvocationTargetException e) { analyserDataProcessorState = STATE_INVALID; String error = Messages.getString("AnalyserDataProcessor.6") + e.getTargetException().getMessage() //$NON-NLS-1$ + Messages.getString("AnalyserDataProcessor.7"); //$NON-NLS-1$ if (e.getTargetException().getStackTrace() != null) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.getTargetException().printStackTrace(pw); error += sw.toString() + "\n"; //$NON-NLS-1$ } GeneralMessages.showErrorMessage(error); } catch (InterruptedException e) { String error = Messages.getString("AnalyserDataProcessor.8") + e.getMessage() //$NON-NLS-1$ + Messages.getString("AnalyserDataProcessor.9"); //$NON-NLS-1$ analyserDataProcessorState = STATE_CANCELED; } catch (Exception e) { analyserDataProcessorState = STATE_INVALID; String error = Messages.getString("AnalyserDataProcessor.6") + e.getMessage() //$NON-NLS-1$ + Messages.getString("AnalyserDataProcessor.7"); //$NON-NLS-1$ if (e.getStackTrace() != null) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); error += sw.toString() + "\n"; //$NON-NLS-1$ } GeneralMessages.showErrorMessage(error); } } else { setUp(); //open need to be wrapped in runnable, and we should set progressmonitor IProgressService progressService = PlatformUI.getWorkbench().getProgressService(); IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor progressMonitor) throws InvocationTargetException, InterruptedException { setProgressMonitor(progressMonitor); progressMonitor.beginTask(Messages.getString("AnalyserDataProcessor.10") + displayName, //$NON-NLS-1$ AnalyserDataProcessor.TOTAL_PROGRESS_COUNT * 20 / 100); internalOpenNPI(analysisFileURI, parent, uid); } }; try { progressService.busyCursorWhile(runnable); } catch (InvocationTargetException e) { analyserDataProcessorState = STATE_INVALID; } catch (InterruptedException e) { analyserDataProcessorState = STATE_CANCELED; } } getProgressMonitor().done(); }
From source file:com.nokia.carbide.cpp.internal.pi.analyser.AnalyserDataProcessor.java
License:Open Source License
public void importSaveAndOpen(final IFile analysisFile, boolean pollTillNpiSaved, final List<ITrace> pluginsToUse) { analyserDataProcessorState = STATE_IMPORTING; setProgressMonitor(null);/*from w w w. j a v a 2 s. com*/ final int uid = NpiInstanceRepository.getInstance().register(null); setUp(); IProgressService progressService = PlatformUI.getWorkbench().getProgressService(); IRunnableWithProgress runnableImportAndSave = new IRunnableWithProgress() { public void run(IProgressMonitor progressMonitor) throws InvocationTargetException, InterruptedException { importAndSave(analysisFile, uid, pluginsToUse, null, progressMonitor); } }; IRunnableWithProgress runnableOpen = new IRunnableWithProgress() { public void run(IProgressMonitor arg0) throws InvocationTargetException, InterruptedException { // open the saved file openFile(analysisFile); } }; try { progressService.busyCursorWhile(runnableImportAndSave); final IRunnableWithProgress saveNpi = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { ProfileReader.getInstance().writeAnalysisFile(analysisFile.getLocation().toString(), monitor, null, uid); } }; progressService.busyCursorWhile(saveNpi); progressService.busyCursorWhile(runnableOpen); } catch (InvocationTargetException e) { handleRunnableException(e, uid, analysisFile); } catch (InterruptedException e) { handleRunnableException(e, uid, analysisFile); } }
From source file:com.nokia.carbide.cpp.internal.pi.analyser.AnalyserDataProcessor.java
License:Open Source License
public void saveAnalysis(final String filename, final int uid) throws InvocationTargetException, InterruptedException { IProgressService progressService = PlatformUI.getWorkbench().getProgressService(); IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor progressMonitor) throws InvocationTargetException, InterruptedException { saveAnalysisInternal(filename, uid); }/*from w ww . ja v a2s . c o m*/ }; try { progressService.busyCursorWhile(runnable); } catch (InvocationTargetException e) { analyserDataProcessorState = STATE_INVALID; } catch (InterruptedException e) { analyserDataProcessorState = STATE_CANCELED; } }
From source file:com.nokia.carbide.cpp.internal.pi.analyser.AnalyserDataProcessor.java
License:Open Source License
public void importForStrippingTimeStamp(final Composite parent) { if (SampleImporter.getInstance().isStrippingTimeStamp()) { // had to do this monkey business for pi validation because // serialization is an untestable format // read file final SampleImporter sampleImporter = SampleImporter.getInstance(); IProgressService progressService = PlatformUI.getWorkbench().getProgressService(); IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor progressMonitor) throws InvocationTargetException, InterruptedException { setProgressMonitor(progressMonitor); progressMonitor.beginTask(Messages.getString("AnalyserDataProcessor.23"), 100); //$NON-NLS-1$ try { int uid = NpiInstanceRepository.getInstance().activeUid(); loadExistingAnalysis(parent, sampleImporter.getDatFileName(), sampleImporter.getDatFileName(), uid); // time stample differs for every save, take it out AnalysisInfoHandler infoHandler = NpiInstanceRepository.getInstance() .activeUidGetAnalysisInfoHandler(); if (infoHandler != null) { infoHandler.eraseTimeStamp(); }// w w w . j av a 2 s . c o m // write file saveAnalysisInternal(sampleImporter.getPiFileName(), uid); } catch (Exception e) { e.printStackTrace(); } } }; try { progressService.busyCursorWhile(runnable); } catch (InvocationTargetException e) { analyserDataProcessorState = STATE_INVALID; e.printStackTrace(); } catch (InterruptedException e) { analyserDataProcessorState = STATE_CANCELED; e.printStackTrace(); } setProgressMonitor(null); } }
From source file:com.nokia.carbide.cpp.internal.pi.save.SaveSamplesWizard.java
License:Open Source License
/** * This method is called when 'Finish' button is pressed in * the wizard. We will create an operation and run it * using the wizard as execution context. *//*from ww w. j a va 2 s.c o m*/ public boolean performFinish() { final IPath containerName = page.getContainerName(); String fileName = page.getFileName(); int dotLoc = fileName.lastIndexOf('.'); if (dotLoc == -1) { fileName += ".csv"; //$NON-NLS-1$ } final String fileNameFinal = fileName; IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); final IResource resource = root.findMember(containerName); this.saveSamples.clear(); this.canceled = false; this.file = null; IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.worked(1); try { // find the file path in the workspace if (!resource.exists() || !(resource instanceof IContainer)) { throwCoreException(Messages.getString("SaveSamplesWizard.ProjectFolder") + containerName //$NON-NLS-1$ + Messages.getString("SaveSamplesWizard.doesNotExist")); //$NON-NLS-1$ } IContainer container = (IContainer) resource; file = container.getFile(new Path(fileNameFinal)); // save samples, several at a time, to the output file writeInProgress = true; while (writeInProgress) { if (monitor.isCanceled()) { canceled = true; return; } writeOneSampleSet(monitor); } if (monitor.isCanceled()) { canceled = true; return; } // open the output file for editing monitor.setTaskName(Messages.getString("SaveSamplesWizard.OpeningFileForEditing")); //$NON-NLS-1$ getShell().getDisplay().asyncExec(new Runnable() { public void run() { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getActivePage(); try { IDE.openEditor(page, file, true); } catch (PartInitException e) { } } }); monitor.worked(1); } catch (CoreException e) { throw new InvocationTargetException(e); } if (monitor.isCanceled()) { canceled = true; return; } } }; try { getContainer().run(true, true, op); } catch (InterruptedException e) { canceled = true; } catch (InvocationTargetException e) { Throwable realException = e.getTargetException(); MessageDialog.openError(getShell(), Messages.getString("SaveSamplesWizard.Error"), //$NON-NLS-1$ realException.getLocalizedMessage()); } if (canceled && (file != null)) { try { file.delete(true, false, new NullProgressMonitor()); } catch (CoreException coreEx) { MessageDialog.openError(getShell(), Messages.getString("SaveSamplesWizard.Error"), //$NON-NLS-1$ coreEx.getLocalizedMessage()); } } return true; }
From source file:com.nokia.carbide.cpp.internal.pi.save.SaveTableWizard.java
License:Open Source License
/** * This method is called when 'Finish' button is pressed in * the wizard. We will create an operation and run it * using wizard as execution context./*from w ww .j a v a2 s. co m*/ */ public boolean performFinish() { final IPath containerName = page.getContainerName(); final String fileName = page.getFileName(); IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException { try { doFinish(containerName, fileName, monitor); } catch (CoreException e) { throw new InvocationTargetException(e); } finally { monitor.done(); } } }; try { getContainer().run(true, false, op); } catch (InterruptedException e) { return false; } catch (InvocationTargetException e) { Throwable realException = e.getTargetException(); MessageDialog.openError(getShell(), Messages.getString("SaveTableWizard.Error"), //$NON-NLS-1$ realException.getMessage()); return false; } return true; }
From source file:com.nokia.carbide.cpp.internal.pi.wizards.ui.NewPIWizard.java
License:Open Source License
private void createNewProject() { final SampleImporter sampleImporter = SampleImporter.getInstance(); NewPIWizardSettings wizardSettings = NewPIWizardSettings.getInstance(); Map<Object, IFile> preprocessedMap = new HashMap<Object, IFile>(); sampleImporter.clear();// w w w. j ava 2s . co m String container = wizardSettings.outputContainer.getFullPath().toString(); if (container.startsWith("/")) //$NON-NLS-1$ container = container.substring(1, container.length()); sampleImporter.setProjectName(container); if (wizardSettings.haveRomOnly || wizardSettings.haveAppRom) { if (wizardSettings.romSdk != null && wizardSettings.romSdk.getEPOCROOT() != null) { sampleImporter.setRomEpocroot(wizardSettings.romSdk.getEPOCROOT()); } if (wizardSettings.romSymbolFile != null) { sampleImporter.setRomSymbolFile(wizardSettings.romSymbolFile); } if (wizardSettings.romObyFile != null) { sampleImporter.setRomObyFile(wizardSettings.romObyFile); } sampleImporter.clearRofsObyFileList(); sampleImporter.clearRofsSymbolFileList(); for (RofsObySymbolPair pair : wizardSettings.rofsObySymbolPairList) { sampleImporter.addRofsObyFile(pair.getObyFile()); sampleImporter.addRofsSymbolFile(pair.getSymbolFile()); } } if (wizardSettings.haveAppOnly || wizardSettings.haveAppRom) { for (IPkgEntry entry : wizardSettings.selectedAppFileList) { java.io.File javaFile = new java.io.File(entry.getPkgFile()); if (javaFile.exists()) { IFile tmpPkgFile = createTempPkgFile(); if (tmpPkgFile == null) { Check.reportFailure( tmpPkgFile.getLocation().toString() + Messages.getString("NewPIWizard.failed.convertFileToIFile"), //$NON-NLS-1$ new Throwable()); return; } { try { char[] pkgFileBuf = FileUtils.readFileContents(javaFile, null); String pkgFileStr = new String(pkgFileBuf); FileUtils.writeFileContents(new java.io.File(tmpPkgFile.getLocation().toString()), pkgFileStr.toCharArray(), null); } catch (CoreException e) { e.printStackTrace(); } } preprocessedMap.put(entry, tmpPkgFile); } } for (ICarbideBuildConfiguration config : wizardSettings.selectedBuildConfigList) { ISymbianBuildContext context = SymbianBuildContext .getBuildContextFromDisplayName(config.getDisplayString()); IFile tmpPkgFile; List<ISISBuilderInfo> sisBuilderInfoList = config.getSISBuilderInfoList(); for (ISISBuilderInfo sisBuildInfo : sisBuilderInfoList) { tmpPkgFile = createTempPkgFile(); if (tmpPkgFile == null) { Check.reportFailure( tmpPkgFile.getLocation().toString() + Messages.getString("NewPIWizard.failed.convertFileToIFile"), //$NON-NLS-1$ new Throwable()); return; } IPath tmpPkgPath = tmpPkgFile.getLocation(); CarbideCPPBuilder.resolvePKGFile(sisBuildInfo.getPKGFullPath(), context, tmpPkgPath); preprocessedMap.put(config, tmpPkgFile); } } } if (preprocessedMap.size() > 0) { for (Entry<Object, IFile> entry : preprocessedMap.entrySet()) { String epocroot = ""; //$NON-NLS-1$ if (entry.getKey() instanceof IPkgEntry) { epocroot = ((IPkgEntry) entry.getKey()).getSdk().getEPOCROOT(); } else if (entry.getKey() instanceof ICarbideBuildConfiguration) { epocroot = ((ICarbideBuildConfiguration) entry.getKey()).getSDK().getEPOCROOT(); } sampleImporter.addPkgObyFile(epocroot, entry.getValue().getLocation().toString()); } } if (wizardSettings.keyMapProfile != null) { //BUP key press profile sampleImporter.setBupMapProfileId(wizardSettings.keyMapProfile.getProfileId()); if (wizardSettings.keyMapProfile.getSDK() != null) { sampleImporter.setBupMapSymbianSDKId(wizardSettings.keyMapProfile.getSDK().getUniqueId()); sampleImporter.setBupMapIsBuiltIn(false); sampleImporter.setBupMapIsWorkspace(false); } if (wizardSettings.keyMapProfile.getURI().equals(BupEventMapManager.DEFAULT_PROFILE_URI)) { sampleImporter.setBupMapSymbianSDKId(""); //$NON-NLS-1$ sampleImporter.setBupMapIsBuiltIn(true); sampleImporter.setBupMapIsWorkspace(false); } else if (wizardSettings.keyMapProfile.getURI() .equals(BupEventMapManager.WORKSPACE_PREF_KEY_MAP_URI)) { sampleImporter.setBupMapSymbianSDKId(""); //$NON-NLS-1$ sampleImporter.setBupMapIsBuiltIn(false); sampleImporter.setBupMapIsWorkspace(true); } } sampleImporter.setProfilerActivator(wizardSettings.profilerActivator); if (profilerDataPlugins.size() <= 1) { for (ProfilerDataPlugins pdp : profilerDataPlugins) { sampleImporter.setDatFileName(pdp.getProfilerDataPath().toString()); // due to PI shortcomings (i.e. plugins that create pages have to come first) // the plugins have to be sorted by trace id sampleImporter.setPiFileName(""); //$NON-NLS-1$ sampleImporter.importSamples(false, PIUtilities.sortPlugins(pdp.getSelectedPlugins()), true, null, null); logImportedFile(pdp); break; } } else { final int[] i = { 1 }; final int count = profilerDataPlugins.size(); IProgressService progressService = PlatformUI.getWorkbench().getProgressService(); IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor progressMonitor) { progressMonitor.beginTask("", count * AnalyserDataProcessor.TOTAL_PROGRESS_COUNT); //$NON-NLS-1$ String suffixTaskName; for (ProfilerDataPlugins pdp : profilerDataPlugins) { if (progressMonitor.isCanceled()) { break; } suffixTaskName = MessageFormat.format(Messages.getString("NewPIWizard.suffixTaskName"), //$NON-NLS-1$ i[0]++, count); sampleImporter.setDatFileName(pdp.getProfilerDataPath().toString()); sampleImporter.setPiFileName(""); //$NON-NLS-1$ sampleImporter.importSamples(false, PIUtilities.sortPlugins(pdp.getSelectedPlugins()), false, suffixTaskName, new SubProgressMonitor(progressMonitor, AnalyserDataProcessor.TOTAL_PROGRESS_COUNT)); logImportedFile(pdp); } } }; try { progressService.busyCursorWhile(runnable); } catch (Exception e) { GeneralMessages.showErrorMessage(e.getMessage()); } } cleanTempPkgFile(); showPIViewer(); }
From source file:com.nokia.carbide.cpp.internal.pi.wizards.ui.TraceHandler.java
License:Open Source License
/** * Update current connection/*w ww .j a va 2 s.c om*/ * */ public void updateCurrenConnection() { try { IRunnableWithProgress runnableWithProgress = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(Messages.getString("TraceHandler.resolvingCurrentConnection"), //$NON-NLS-1$ IProgressMonitor.UNKNOWN); try { String currenConnection = PiPlugin.getTraceProvider() .getDisplayNameForCurrentConnection(monitor); profilerActivatorGroup.setCurrentConnection(currenConnection); } catch (CoreException e) { throw new InvocationTargetException(e); } finally { monitor.done(); } } }; wizardContainer.run(true, true, 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
/** * Fetch available plug-ins list/*from w ww .j a va2s. c o m*/ * */ public List<ITrace> fetchAvailablePlugins() { final List<ITrace> plugins = new ArrayList<ITrace>(); try { IRunnableWithProgress runnableWithProgress = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(Messages.getString("TraceHandler.fetchingPluginsList"), //$NON-NLS-1$ IProgressMonitor.UNKNOWN); try { plugins.addAll( PiPlugin.getTraceProvider().getAvailableSamplers(TraceHandler.this, monitor)); } catch (CoreException e) { throw new InvocationTargetException(e); } finally { monitor.done(); } } }; wizardContainer.run(true, false, runnableWithProgress); if (wizardPage instanceof INewPIWizardSettings) { ((INewPIWizardSettings) wizardPage).validatePage(); } return plugins; } 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; }