List of usage examples for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress
IRunnableWithProgress
From source file:com.bdaum.zoom.ui.internal.commands.MigrateCatalogCommand.java
License:Open Source License
@Override public void run() { IDbManager dbManager = Core.getCore().getDbManager(); File catFile = dbManager.getFile(); if (catFile != null) { Job[] criticalJobs = Job.getJobManager().find(Constants.CRITICAL); if (criticalJobs.length > 0) { AcousticMessageDialog.openInformation(getShell(), Messages.MigrateCatActionDelegate_cat_migratiion, Messages.MigrateCatActionDelegate_cannot_execute); return; }/*from w w w .j a v a2 s . c om*/ MigrateDialog dialog = new MigrateDialog(getShell(), catFile); if (dialog.open() == MigrateDialog.OK) { final MigrationPolicy policy = dialog.getResult(); File targetFile = new File(policy.getTargetCatalog()); if (targetFile.exists() && !AcousticMessageDialog.openQuestion(getShell(), Messages.MigrateCatActionDelegate_cat_migratiion, NLS.bind(Messages.MigrateCatActionDelegate_target_exists, targetFile.getName()))) return; targetFile.delete(); IDbFactory dbFactory = Core.getCore().getDbFactory(); final IDbManager newDbManager = dbFactory.createDbManager(policy.getTargetCatalog(), true, false, false); IRunnableWithProgress runnable1 = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { CoreActivator.getDefault().getFileWatchManager().setPaused(true, this.getClass().toString()); Job.getJobManager().cancel(Constants.FOLDERWATCH); Job.getJobManager().cancel(Constants.SYNCPICASA); Core.waitOnJobCanceled(Constants.FOLDERWATCH, Constants.SYNCPICASA); MigrateOperation op = new MigrateOperation(newDbManager, policy); try { status = op.execute(monitor, MigrateCatalogCommand.this); finalMessage = op.getFinalMessage(); severity = op.getSeverity(); } catch (ExecutionException e) { status = new Status(IStatus.ERROR, UiActivator.PLUGIN_ID, Messages.MigrateCatActionDelegate_internal_error, e); } } }; ZProgressMonitorDialog pm = new ZProgressMonitorDialog(getShell()); try { pm.run(true, true, runnable1); if (status.getSeverity() == IStatus.ERROR || status.getSeverity() == IStatus.CANCEL) { if (status.getSeverity() == IStatus.ERROR) { AcousticMessageDialog.openError(getShell(), Messages.MigrateCatActionDelegate_cat_migratiion, NLS.bind(Messages.MigrateCatActionDelegate_finished_with_problems, status.toString())); } targetFile.delete(); return; } if (finalMessage == null) finalMessage = ""; //$NON-NLS-1$ if (status.getSeverity() == IStatus.WARNING) { finalMessage += '\n' + status.getMessage(); severity = MessageDialog.WARNING; } AcousticMessageDialog finalDialog = new AcousticMessageDialog(getShell(), Messages.MigrateCatActionDelegate_catalog_migration, null, finalMessage, severity, new String[] { Messages.MigrateCatActionDelegate_export_preferences, Messages.MigrateCatActionDelegate_done }, 1); if (finalDialog.open() == 0) { ExportPreferencesWizard wizard = new ExportPreferencesWizard(); wizard.init(getActiveWorkbenchWindow().getWorkbench(), null); new WizardDialog(getShell(), wizard).open(); } } catch (InvocationTargetException e) { UiActivator.getDefault().logError(Messages.MigrateCatActionDelegate_error_migrating, e); targetFile.delete(); } catch (InterruptedException e) { targetFile.delete(); } catch (Exception e) { e.printStackTrace(); } finally { UiActivator.getDefault().postCatInit(false); CoreActivator.getDefault().getFileWatchManager().setPaused(false, this.getClass().toString()); } } } }
From source file:com.bdaum.zoom.ui.internal.commands.OrphansCommand.java
License:Open Source License
@Override public void run() { AcousticMessageDialog includeDialog = new AcousticMessageDialog(getShell(), Messages.FindOrphansActionDelegate_search_orphans, null, Messages.FindOrphansActionDelegate_include_off_line, AcousticMessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 1);// w ww . ja va2s . c o m final int ret = includeDialog.open(); if (ret >= 2) return; isCanceled = false; ZProgressMonitorDialog dialog = new ZProgressMonitorDialog(getShell()); IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { ICore core = Core.getCore(); IVolumeManager volumeManager = core.getVolumeManager(); List<AssetImpl> set = core.getDbManager().obtainAssets(); monitor.beginTask(Messages.FindOrphansActionDelegate_scanning_catalog, set.size()); for (AssetImpl asset : set) { URI uri = volumeManager.findExistingFile(asset, false); if (uri == null) { if (ret == 0 || !volumeManager.isOffline(asset.getVolume())) result.add(asset); else { String volume = asset.getVolume(); if (volume != null && !volume.isEmpty()) volumes.add(volume); } } if (monitor.isCanceled()) { isCanceled = true; break; } monitor.worked(1); } monitor.done(); } }; if (isCanceled) return; try { String v = null; if (!volumes.isEmpty()) { String[] vols = volumes.toArray(new String[volumes.size()]); Arrays.sort(vols); StringBuffer sb = new StringBuffer(); for (String volume : vols) { if (sb.length() > 0) sb.append(", "); //$NON-NLS-1$ sb.append(volume); } v = sb.toString(); } dialog.run(true, true, runnable); if (result.isEmpty()) { String message = Messages.FindOrphansActionDelegate_no_orphans_found; if (ret == 1 && v != null) message += NLS.bind(Messages.FindOrphansActionDelegate_entries_not_checked, v); AcousticMessageDialog.openInformation(getShell(), Messages.FindOrphansActionDelegate_orphan_search, message); } else { boolean show = true; if (v != null) { String message = NLS.bind(Messages.FindOrphansActionDelegate_n_entries_found, result.size()); if (ret == 1) message += NLS.bind(Messages.FindOrphansActionDelegate_entries_not_checked, v); show = AcousticMessageDialog.openConfirm(getShell(), Messages.FindOrphansActionDelegate_orphan_search, message); } if (show) { SmartCollectionImpl collection = new SmartCollectionImpl( Messages.FindOrphansActionDelegate_orphans, true, false, true, false, null, 0, null, 0, null, Constants.INHERIT_LABEL, null, 0, null); collection.addCriterion( new CriterionImpl(ICollectionProcessor.ORPHANS, null, result, QueryField.XREF, false)); Ui.getUi().getNavigationHistory(getActiveWorkbenchWindow()) .postSelection(new StructuredSelection(collection)); } } } catch (InvocationTargetException e) { UiActivator.getDefault().logError(Messages.FindOrphansActionDelegate_error_scanning_for_orphans, e); } catch (InterruptedException e) { // nothing to do } }
From source file:com.bdaum.zoom.ui.internal.wizards.ImportFileSelectionPage.java
License:Open Source License
private ImportNode[] createInput(final StorageObject[] files, final StorageObject[] dcims) throws InvocationTargetException, InterruptedException { nodeCount = 0;// w w w .j a v a 2s . c o m final ObjectFilter imageFilter = new FileNameExtensionFilter( ImageConstants.getSupportedImageFileExtensionsGroups(true), true); final List<ImportNode> nodes = new ArrayList<ImportNode>(); final ZProgressMonitorDialog dialog = new ZProgressMonitorDialog(getShell()); dialog.create(); dialog.getShell() .setText(Constants.APPLICATION_NAME + " - " + Messages.ImportFileSelectionPage_import_preparation); //$NON-NLS-1$ dialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { ImportFileSelectionPage.this.monitor = monitor; try { monitor.beginTask(Messages.ImportFileSelectionPage_analyzing_folder_contents, IProgressMonitor.UNKNOWN); for (int i = 0; i < dcims.length; i++) { StorageObject file = dcims[i]; ImportNode node = new ImportNode(null, file.getAbsolutePath(), -1, 0, 0, Messages.ImportFileSelectionPage_photos, Messages.ImportFileSelectionPage_photo); nodes.add(node); node.count = addChildren(node, file, null, imageFilter, monitor); if (monitor.isCanceled()) throw new InterruptedException(); } if (files != null && files.length > 0) { ImportNode node = new ImportNode(null, Messages.ImportFileSelectionPage_dropped_files, -1, 0, 0, Messages.ImportFileSelectionPage_photos, Messages.ImportFileSelectionPage_photo); nodes.add(node); node.count = addChildren(node, null, files, imageFilter, monitor); if (monitor.isCanceled()) throw new InterruptedException(); } for (IMediaSupport ms : CoreActivator.getDefault().getMediaSupport()) { ObjectFilter foreignFilter = new FileNameExtensionFilter(ms.getFileExtensions()); for (int i = 0; i < dcims.length; i++) { StorageObject file = media ? ms.getMediaFolder(dcims[i]) : dcims[i]; if (file == null) continue; ImportNode node = new ImportNode(null, file.getAbsolutePath(), -1, 0, 0, ms.getPlural(), ms.getName()); nodes.add(node); node.count = addChildren(node, file, null, foreignFilter, monitor); if (monitor.isCanceled()) throw new InterruptedException(); } if (files != null && files.length > 0) { ImportNode node = new ImportNode(null, Messages.ImportFileSelectionPage_dropped_files, -1, 0, 0, ms.getPlural(), ms.getName()); nodes.add(node); node.count = addChildren(node, null, files, foreignFilter, monitor); if (monitor.isCanceled()) throw new InterruptedException(); } } monitor.done(); } catch (IOException e) { throw new InterruptedException(Messages.ImportFileSelectionPage_io_error_while_scanning); } finally { ImportFileSelectionPage.this.monitor = null; } } }); groupedByLabel.setText(byDate ? byFilename ? Messages.ImportFileSelectionPage_grouped_by_date_or_filename : Messages.ImportFromDeviceWizard_modification_dates : Messages.ImportFileSelectionPage_grouped_by_filename); return nodes.toArray(new ImportNode[nodes.size()]); }
From source file:com.binge.workforce.app.handlers.SaveHandler.java
License:Open Source License
@Execute public void execute(IEclipseContext context, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell, @Named(IServiceConstants.ACTIVE_PART) final MContribution contribution) throws InvocationTargetException, InterruptedException { final IEclipseContext pmContext = context.createChild(); ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell); dialog.open();/*from www .ja v a 2 s . com*/ dialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { pmContext.set(IProgressMonitor.class.getName(), monitor); if (contribution != null) { Object clientObject = contribution.getObject(); // ContextInjectionFactory.invoke(clientObject, Persist.class, //$NON-NLS-1$ // pmContext, null); } } }); if (pmContext instanceof IDisposable) { ((IDisposable) pmContext).dispose(); } }
From source file:com.bluexml.side.clazz.edit.ui.actions.wizards.initializefromclass.InitializerWizard.java
License:Open Source License
@Override public boolean performFinish() { try {/*from w ww. j a va 2 s. co m*/ System.out.println("InitializerWizard.performFinish()"); //$NON-NLS-1$ InitializerPageWelcome page = (InitializerPageWelcome) getContainer().getCurrentPage(); final String alf_home = page .getFieldValueString(InitializerPageWelcome.Fields.alfresco_home.toString()); final String alf_ver = page .getFieldValueString(InitializerPageWelcome.Fields.alfresco_version.toString()); side_gene = Boolean .parseBoolean(page.getFieldValueString(InitializerPageWelcome.Fields.generate.toString())); this.ini = InitializerRegister.getInitializerRegisterFromClassModel(classModel, alf_home, alf_ver); final InitializerRegister ini = this.ini; // run as long running process IRunnableWithProgress runPro = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(Messages.InitializerWizard_2, -1); // initialize models try { //TODO use fork to run this job and use syncExec only for action than require to run in UI thread instead of do all the job in UI thread // so progress bar can be updated ... ini.initialize(); classModel.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); } catch (Exception e) { throw new InvocationTargetException(e); } monitor.done(); } }; this.getContainer().run(true, true, runPro); while (!ini.isInitialized()) { //$NON-NLS-1$ try { this.wait(1000); } catch (InterruptedException e) { e.printStackTrace(); Activator.getDefault().getLog().log(new Status(Status.ERROR, Activator.PLUGIN_ID, "Alfresco Extension project creation fail !", e)); //$NON-NLS-1$ return false; } } } catch (Exception e) { e.printStackTrace(); Activator.getDefault().getLog().log( new Status(Status.ERROR, Activator.PLUGIN_ID, "Alfresco Extension project creation fail !", e)); //$NON-NLS-1$ } System.out.println("InitializerWizard.performFinish() DONE"); //$NON-NLS-1$ return true; }
From source file:com.bluexml.side.Integration.eclipse.branding.enterprise.wizards.migration.ModelMigrationWizard.java
License:Open Source License
@Override public boolean performFinish() { System.out.println("ModelMigrationWizard.performFinish()"); final GeneralProjectMigration page = (GeneralProjectMigration) getContainer().getCurrentPage(); final String libraryId = page.getFieldValueString(GeneralProjectMigration.Fields.library.toString()); // import library if project do not exists in workspace IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { execute(page, libraryId, monitor); } catch (Exception e) { throw new InvocationTargetException(e); }//from w ww . ja v a 2 s . c om } }; try { this.getContainer().run(true, true, runnable); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); Activator.getDefault().getLog() .log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, cause.toString(), cause)); MessageDialog.openError(getShell(), "Error", NLS.bind("Internal error {0}", cause.getMessage())); //$NON-NLS-1$ } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return true; }
From source file:com.bluexml.side.Integration.eclipse.branding.enterprise.wizards.newAlfrescoModule.NewModuleWizard.java
License:Open Source License
@Override public boolean performFinish() { try {/* w w w . j ava2s .c o m*/ System.out.println("Finish called"); // get values from the unique page GeneralProjectInformationsPage page = (GeneralProjectInformationsPage) getContainer().getCurrentPage(); // execute maven goal final MavenUtil mu = new MavenUtil(); final String goal = "archetype:generate"; final File baseDir = getBaseDir(); if (!baseDir.exists()) { baseDir.mkdirs(); } String artifactId = page.getArtifactId(); final File projectFile = new File(baseDir, artifactId); if (projectFile.exists()) { // error project already exist page.setErrorMessage("artifact :" + artifactId + " already exist, use another value"); return false; } // setParameters final HashMap<String, String> params = new HashMap<String, String>(); params.put("groupId", page.getGroupId()); params.put("artifactId", artifactId); params.put("version", page.getArtifactVersion()); params.put("project-name", page.getArtifactName()); String moduleType = page.getModuleType(); Map<String, String> map = archetypes.get(moduleType); if (map != null) { params.putAll(map); } else { System.err.println("moduleType do not match"); } IRunnableWithProgress runPro = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Start creating alfresco extension project", -1); System.out.println("launch maven execution"); try { MavenExecutionResult result = mu.doMavenGoal(baseDir, new String[] { goal }, params, new String[] {}, false); if (result.getExceptions().size() > 0) { throw new Exception(result.getExceptions().get(0)); } System.out.println("refresh baseDir folder"); IFileHelper.refreshFolder(currentProject); System.out.println("import new eclipse project into workspace"); EclipseUtils.importEclipseProject(projectFile); } catch (Exception e) { e.printStackTrace(); throw new InterruptedException(e.getMessage()); } monitor.done(); } }; this.getContainer().run(false, false, runPro); } catch (Exception e) { e.printStackTrace(); MessageDialog.openError(getShell(), "Archetype fail to create project see log view for details", e.getLocalizedMessage()); Activator.getDefault().getLog().log( new Status(Status.ERROR, Activator.PLUGIN_ID, "Alfresco Extension project creation fail !", e)); //$NON-NLS-1$ } return true; }
From source file:com.bluexml.side.Requirements.modeler.views.internal.TableView.java
License:Open Source License
protected SelectionListener getHeaderListener() { return new SelectionAdapter() { /**//www. j a v a 2 s. c o m * Handles the case of user selecting the header area. */ public void widgetSelected(SelectionEvent e) { final TreeColumn column = (TreeColumn) e.widget; final IField field = (IField) column.getData(); try { IWorkbenchSiteProgressService progressService = getProgressService(); if (progressService == null) BusyIndicator.showWhile(getSite().getShell().getDisplay(), new Runnable() { /* * (non-Javadoc) * * @see java.lang.Runnable#run() */ public void run() { resortTable(column, field, new NullProgressMonitor()); } }); else getProgressService().busyCursorWhile(new IRunnableWithProgress() { /* * (non-Javadoc) * * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor) */ public void run(IProgressMonitor monitor) { resortTable(column, field, monitor); } }); } catch (InvocationTargetException e1) { IDEWorkbenchPlugin.getDefault().getLog().log(Util.errorStatus(e1)); } catch (InterruptedException e1) { return; } } /** * Resort the table based on field. * * @param column * the column being updated * @param field * @param monitor */ private void resortTable(final TreeColumn column, final IField field, IProgressMonitor monitor) { TableComparator sorter = getTableSorter(); monitor.beginTask("Sorting", 100); monitor.worked(10); if (field.equals(sorter.getTopField())) sorter.reverseTopPriority(); else sorter.setTopPriority(field); monitor.worked(15); PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { /* * (non-Javadoc) * * @see java.lang.Runnable#run() */ public void run() { viewer.refresh(); updateDirectionIndicator(column); } }); monitor.done(); } }; }
From source file:com.buildml.eclipse.actions.ActionsEditor.java
License:Open Source License
/** * Refresh the editor's content. This is typically called when some type of display * option changes (e.g. packages have been added), and the content is now * different, or if the user resizes the main Eclipse shell. We use a progress monitor, * since a redraw operation might take a while. * @param forceRedraw true if we want to force a complete redraw of the viewer. */// w w w .j a v a 2 s . c o m public void refreshView(boolean forceRedraw) { /* compute the set of option bits that have changed since we were last called */ int currentOptions = getOptions(); int changedOptions = previousEditorOptionBits ^ currentOptions; previousEditorOptionBits = currentOptions; /* * Determine whether the packages columns should be shown. Setting the * width appropriately is important, especially if the shell was recently resized. * TODO: figure out why subtracting 20 pixels is important for matching the column * size with the size of the parent composite. */ Display.getDefault().asyncExec(new Runnable() { @Override public void run() { int editorWidth = filesEditorComposite.getClientArea().width - 20; int pkgWidth = isOptionSet(EditorOptions.OPT_SHOW_PACKAGES) ? 100 : 0; treeColumn.getColumn().setWidth(editorWidth - 2 * pkgWidth); pkgColumn.getColumn().setWidth(pkgWidth); } }); /* * Has the content of the tree changed, or just the visibility of columns? If * it's just the columns, then we don't need to re-query the model in order to redisplay. * Unless our caller explicitly requested a redraw. */ if (!forceRedraw) { return; } /* * We need to re-query the model and redisplay some (or all) of the tree items. * Create a new job that will be run in the background, and monitored by the * progress monitor. Note that only the portions of this job that update the * UI should be run as the UI thread. Otherwise the job appears to block the * whole UI. */ IRunnableWithProgress redrawJob = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) { monitor.beginTask("Redrawing editor content...", 2); monitor.worked(1); Display.getDefault().syncExec(new Runnable() { @Override public void run() { Object[] expandedElements = actionsTreeViewer.getExpandedElements(); actionsTreeViewer.setInput(contentProvider.getRootElements()); actionsTreeViewer.refresh(); /* * Ensure that all previously-expanded items are now expanded again. * Note: we can't use setExpandedElements(), as that won't always * open all the parent elements as well. */ for (int i = 0; i < expandedElements.length; i++) { actionsTreeViewer.expandToLevel(expandedElements[i], 1); } } }); monitor.worked(1); monitor.done(); } }; /* start up the progress monitor service so that it monitors the job */ IProgressService service = PlatformUI.getWorkbench().getProgressService(); try { service.busyCursorWhile(redrawJob); } catch (InvocationTargetException e) { // TODO: what to do here? } catch (InterruptedException e) { // TODO: what to do here? } }
From source file:com.buildml.eclipse.files.FilesEditor.java
License:Open Source License
/** * Refresh the editor's content. This is typically called when some type of display * option changes (e.g. roots or packages have been added), and the content is now * different, or if the user resizes the main Eclipse shell. We use a progress monitor, * since a redraw operation might take a while. * @param forceRedraw true if we want to force a complete redraw of the viewer. *///from w w w .j av a2 s. c o m public void refreshView(boolean forceRedraw) { /* compute the set of option bits that have changed since we were last called */ int currentOptions = getOptions(); int changedOptions = previousEditorOptionBits ^ currentOptions; previousEditorOptionBits = currentOptions; /* * Determine whether the packages/scope columns should be shown. Setting the * width appropriately is important, especially if the shell was recently resized. * TODO: figure out why subtracting 20 pixels is important for matching the column * size with the size of the parent composite. */ Display.getDefault().asyncExec(new Runnable() { @Override public void run() { int editorWidth = filesEditorComposite.getClientArea().width - 20; int pkgWidth = isOptionSet(EditorOptions.OPT_SHOW_PACKAGES) ? 100 : 0; treeColumn.setWidth(editorWidth - 2 * pkgWidth); pkgColumn.setWidth(pkgWidth); scopeColumn.setWidth(pkgWidth); } }); /* * Has the content of the tree changed, or just the visibility of columns? If * it's just the columns, then we don't need to re-query the model in order to redisplay. * Unless our caller explicitly requested a redraw. */ if (!forceRedraw && ((changedOptions & (EditorOptions.OPT_COALESCE_DIRS | EditorOptions.OPT_SHOW_ROOTS) | EditorOptions.OPT_SHOW_PACKAGES) == 0)) { return; } if ((changedOptions & EditorOptions.OPT_COALESCE_DIRS) != 0) { filesTreeViewer.setInput(contentProvider.getRootElements()); } /* * We need to re-query the model and redisplay some (or all) of the tree items. * Create a new job that will be run in the background, and monitored by the * progress monitor. Note that only the portions of this job that update the * UI should be run as the UI thread. Otherwise the job appears to block the * whole UI. */ IRunnableWithProgress redrawJob = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) { monitor.beginTask("Redrawing editor content...", 2); monitor.worked(1); Display.getDefault().syncExec(new Runnable() { @Override public void run() { Object[] expandedElements = filesTreeViewer.getExpandedElements(); filesTreeViewer.setInput(contentProvider.getRootElements()); filesTreeViewer.refresh(); /* * Ensure that all previously-expanded items are now expanded again. * Note: we can't use setExpandedElements(), as that won't always * open all the parent elements as well. */ for (int i = 0; i < expandedElements.length; i++) { filesTreeViewer.expandToLevel(expandedElements[i], 1); } } }); monitor.worked(1); monitor.done(); } }; /* start up the progress monitor service so that it monitors the job */ IProgressService service = PlatformUI.getWorkbench().getProgressService(); try { service.busyCursorWhile(redrawJob); } catch (InvocationTargetException e) { // TODO: what to do here? } catch (InterruptedException e) { // TODO: what to do here? } }