List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog ProgressMonitorDialog
public ProgressMonitorDialog(Shell parent)
From source file:eu.artist.migration.mut.slicing.sim.presentation.SimEditor.java
License:Open Source License
/** * This is for implementing {@link IEditorPart} and simply saves the model file. * <!-- begin-user-doc -->//from w w w . j a v a 2 s. c o m * <!-- end-user-doc --> * @generated */ @Override public void doSave(IProgressMonitor progressMonitor) { // Save only resources that have actually changed. // final Map<Object, Object> saveOptions = new HashMap<Object, Object>(); saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER); saveOptions.put(Resource.OPTION_LINE_DELIMITER, Resource.OPTION_LINE_DELIMITER_UNSPECIFIED); // Do the work within an operation because this is a long running activity that modifies the workbench. // WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { // This is the method that gets invoked when the operation runs. // @Override public void execute(IProgressMonitor monitor) { // Save the resources to the file system. // boolean first = true; for (Resource resource : editingDomain.getResourceSet().getResources()) { if ((first || !resource.getContents().isEmpty() || isPersisted(resource)) && !editingDomain.isReadOnly(resource)) { try { long timeStamp = resource.getTimeStamp(); resource.save(saveOptions); if (resource.getTimeStamp() != timeStamp) { savedResources.add(resource); } } catch (Exception exception) { resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception)); } first = false; } } } }; updateProblemIndication = false; try { // This runs the options, and shows progress. // new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation); // Refresh the necessary state. // ((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone(); firePropertyChange(IEditorPart.PROP_DIRTY); } catch (Exception exception) { // Something went wrong that shouldn't. // SimEditorPlugin.INSTANCE.log(exception); } updateProblemIndication = true; updateProblemIndication(); }
From source file:eu.celar.ui.UIAuthTokenProvider.java
License:Open Source License
/** * Validates the specified token. This method does the validation in a * separate thread and provides a progress monitor for the validation process. * /*ww w . j a v a 2 s . com*/ * @param token The token to be validated. * @throws InvocationTargetException Thrown if an exception occurs in the * validation thread. * @throws InterruptedException Thrown if the validation thread is * interrupted. */ protected void validateToken(final IAuthenticationToken token) throws InvocationTargetException, InterruptedException { final Exception[] exc = new Exception[1]; Runnable runnable = new Runnable() { public void run() { ProgressMonitorDialog progMon = new ProgressMonitorDialog(UIAuthTokenProvider.this.shell); try { progMon.run(false, false, new IRunnableWithProgress() { public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { token.validate(monitor); } catch (AuthenticationException authExc) { throw new InvocationTargetException(authExc); } } }); } catch (InvocationTargetException exception) { exc[0] = exception; } catch (InterruptedException exception) { exc[0] = exception; } } }; runInUIThread(runnable); if (exc[0] instanceof InvocationTargetException) { throw (InvocationTargetException) exc[0]; } else if (exc[0] instanceof InterruptedException) { throw (InterruptedException) exc[0]; } }
From source file:eu.celar.ui.UIAuthTokenProvider.java
License:Open Source License
/** * Activate the specified token. This method does the activation in a separate * thread and provides a progress monitor for the activation process. * // www. jav a 2 s . c o m * @param token The token to be activated. * @throws InvocationTargetException Thrown if an exception occurs in the * activation thread. * @throws InterruptedException Thrown if the activation thread is * interrupted. */ protected void activateToken(final IAuthenticationToken token) throws InvocationTargetException, InterruptedException { final Exception[] exc = new Exception[1]; Runnable uiRunnable = new Runnable() { public void run() { ProgressMonitorDialog progMon = new ProgressMonitorDialog(UIAuthTokenProvider.this.shell); try { progMon.run(false, false, new IRunnableWithProgress() { public void run(final IProgressMonitor monitor) throws InvocationTargetException { try { token.setActive(true, monitor); } catch (AuthenticationException authExc) { throw new InvocationTargetException(authExc); } } }); } catch (InvocationTargetException exception) { exc[0] = exception; } catch (InterruptedException exception) { exc[0] = exception; } } }; runInUIThread(uiRunnable); if (exc[0] instanceof InvocationTargetException) { throw (InvocationTargetException) exc[0]; } else if (exc[0] instanceof InterruptedException) { throw (InterruptedException) exc[0]; } }
From source file:eu.celar.ui.views.AuthTokenView.java
License:Open Source License
/** * Activates or deactivates the currently selected token. * /*from w w w . j av a 2 s. c o m*/ * @param active If true the token will be activated, otherwise it will be deactivated. * @see #getSelectedToken() */ protected void setSelectedTokenActive(final boolean active) { final IAuthenticationToken token = getSelectedToken(); if (active == token.isActive()) return; ProgressMonitorDialog progMon = new ProgressMonitorDialog(getSite().getShell()); Throwable exc = null; try { progMon.run(false, false, new IRunnableWithProgress() { public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { token.setActive(active, monitor); } catch (AuthenticationException authExc) { throw new InvocationTargetException(authExc); } } }); } catch (InvocationTargetException itExc) { exc = itExc.getCause(); } catch (InterruptedException intExc) { exc = intExc; } if (exc != null) { String errMsg = active ? Messages.getString("AuthTokenView.token_activation_error") //$NON-NLS-1$ : Messages.getString("AuthTokenView.token_deactivation_error"); //$NON-NLS-1$ ProblemDialog.openProblem(getSite().getShell(), Messages.getString("AuthTokenView.token_activation_error_title"), //$NON-NLS-1$ errMsg, exc); } }
From source file:eu.esdihumboldt.hale.ui.codelist.inspire.internal.CodeListSelectionDialog.java
License:Open Source License
/** * @see AbstractViewerSelectionDialog#setupViewer(StructuredViewer, Object) *///from w ww .ja v a2 s .c o m @Override protected void setupViewer(final TreeViewer viewer, final CodeListRef initialSelection) { viewer.setLabelProvider(new CodeListLabelProvider()); viewer.setContentProvider(new CodeListContentProvider()); ProgressMonitorDialog dlg = new ProgressMonitorDialog(getShell()); final Display display = Display.getCurrent(); try { dlg.run(true, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Loading available code lists from INSPIRE registry", IProgressMonitor.UNKNOWN); final Collection<CodeListRef> codeLists = RegistryCodeLists.loadCodeLists().values(); display.asyncExec(new Runnable() { @Override public void run() { viewer.setInput(codeLists); if (initialSelection != null) { viewer.setSelection(new StructuredSelection(initialSelection)); } } }); monitor.done(); } }); } catch (InvocationTargetException | InterruptedException e) { throw new IllegalStateException("Failed to load code lists", e); } }
From source file:eu.esdihumboldt.hale.ui.io.util.ThreadProgressMonitor.java
License:Open Source License
/** * Run the given operation in a forked thread with a progress monitor dialog * or in the current thread with a sub progress monitor if possible. * //from ww w .j a v a 2 s. c om * @param op the operation to execute * @param isCancelable if the operation can be canceled * @throws Exception if any error occurs executing the operation */ public static void runWithProgressDialog(final IRunnableWithProgress op, final boolean isCancelable) throws Exception { IProgressMonitor pm = getCurrent(); if (pm == null) { // no current progress monitor associated to thread, so // in display thread, launch a new progress monitor dialog final Display display = PlatformUI.getWorkbench().getDisplay(); final AtomicReference<Exception> error = new AtomicReference<Exception>(); final IRunnableWithProgress progressOp = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { // create a custom progress monitor to be able to decide // whether the progress is done StatesIfDoneProgressMonitor cpm = new StatesIfDoneProgressMonitor(monitor); // register the progress monitor register(cpm); try { op.run(cpm); } finally { // deregister the progress monitor remove(cpm); } } }; display.syncExec(new Runnable() { @Override public void run() { try { new ProgressMonitorDialog(display.getActiveShell()).run(true, isCancelable, progressOp); } catch (Exception e) { error.set(e); } } }); if (error.get() != null) { throw error.get(); } } else { // progress monitor associated to this thread, so // run the operation in the same thread boolean useOriginalMonitor = false; if (pm instanceof StatesIfDoneProgressMonitor) { useOriginalMonitor = ((StatesIfDoneProgressMonitor) pm).isDone(); } if (useOriginalMonitor) { // use the original monitor pm.subTask(""); // reset subtask name op.run(pm); } else { // use a sub progress monitor IProgressMonitor sm = new StatesIfDoneProgressMonitor( new SubProgressMonitor(pm, 0, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); register(sm); try { op.run(sm); } finally { remove(sm); } } } }
From source file:eu.esdihumboldt.hale.ui.templates.handler.OpenWebTemplate.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { final Display display = HandlerUtil.getActiveShell(event).getDisplay(); ProgressMonitorDialog taskDlg = new ProgressMonitorDialog(HandlerUtil.getActiveShell(event)); try {//from w ww . j a va 2 s . co m taskDlg.run(true, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Downloading template list", IProgressMonitor.UNKNOWN); // load templates final List<WebTemplate> templates; try { templates = WebTemplateLoader.load(); } catch (Exception e) { log.userError("Failed to download template list", e); return; } finally { monitor.done(); } if (templates != null) { // launch dialog asynchronously in display thread display.asyncExec(new Runnable() { @Override public void run() { WebTemplatesDialog dlg = new WebTemplatesDialog(display.getActiveShell(), templates); if (dlg.open() == WebTemplatesDialog.OK) { WebTemplate template = dlg.getObject(); if (template != null) { ProjectService ps = (ProjectService) PlatformUI.getWorkbench() .getService(ProjectService.class); ps.load(template.getProject()); } } } }); } } }); } catch (InvocationTargetException | InterruptedException e) { log.userError("Failed to download template list", e); } return null; }
From source file:eu.esdihumboldt.hale.ui.util.graph.ExportGraphAction.java
License:Open Source License
/** * @see Action#run()/*from w w w. j a v a 2 s . c o m*/ */ @Override public void run() { FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE); // XXX if called from TTreeExporter during transformation, the active // shell may be null! dialog.setOverwrite(true); dialog.setText("Export graph to file"); String[] imageExtensions = ImageIO.getWriterFileSuffixes(); StringBuffer extensions = new StringBuffer("*.svg;*.gv;*.dot"); for (String imageExt : imageExtensions) { extensions.append(";*."); extensions.append(imageExt); } dialog.setFilterExtensions(new String[] { extensions.toString() }); dialog.setFilterNames(new String[] { "Image, SVG or dot file (" + extensions + ")" }); String fileName = dialog.open(); if (fileName != null) { final File file = new File(fileName); // //XXX use an off-screen graph (testing) // OffscreenGraph graph = new OffscreenGraph(1000, 1000) { // // @Override // protected void configureViewer(GraphViewer viewer) { // viewer.setContentProvider(RenderAction.this.viewer.getContentProvider()); // viewer.setLabelProvider(RenderAction.this.viewer.getLabelProvider()); // viewer.setInput(RenderAction.this.viewer.getInput()); // viewer.setLayoutAlgorithm(new TreeLayoutAlgorithm(TreeLayoutAlgorithm.LEFT_RIGHT), false); // } // }; // get the graph final Graph graph = viewer.getGraphControl(); final String ext = FilenameUtils.getExtension(file.getAbsolutePath()); final IFigure root = graph.getRootLayer(); ProgressMonitorDialog progress = new ProgressMonitorDialog(Display.getCurrent().getActiveShell()); try { progress.run(false, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); if (ext.equalsIgnoreCase("gv") || ext.equalsIgnoreCase("dot")) { OffscreenGraph.saveDot(graph, out); } // else if (ext.equalsIgnoreCase("svg")) { // OffscreenGraph.saveSVG(root, out); // } else { OffscreenGraph.saveImage(root, out, ext); } } catch (Throwable e) { log.userError("Error saving graph to file", e); } } }); } catch (Throwable e) { log.error("Error launching graph export", e); } } }
From source file:eu.geclipse.batch.ui.editors.QueueEditor.java
License:Open Source License
@Override public void doSave(final IProgressMonitor monitor) { /* Do the work within an operation because this is a long running activity * that modifies the workbench.// ww w. j ava 2 s . c o m */ WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { // This is the method that gets invoked when the operation runs. @Override public void execute(final IProgressMonitor monitorIn) { // Save the resources to the file system. // boolean first = true; for (Iterator<?> i = QueueEditor.this.editingDomain.getResourceSet().getResources().iterator(); i .hasNext();) { Resource resource = (Resource) i.next(); if ((first || !resource.getContents().isEmpty() || isPersisted(resource)) && !QueueEditor.this.editingDomain.isReadOnly(resource)) { try { QueueEditor.this.savedResources.add(resource); resource.save(Collections.EMPTY_MAP); } catch (Exception exception) { QueueEditor.this.resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception)); //setDirty( false ); doTextEditorSave(); cleanDirtyState(); refreshEditor(); } first = false; } } } }; this.updateProblemIndication = false; try { // This runs the options, and shows progress. new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation); // Refresh the necessary state. ((BasicCommandStack) this.editingDomain.getCommandStack()).saveIsDone(); //setDirty( false ); doTextEditorSave(); cleanDirtyState(); refreshEditor(); } catch (Exception exception) { // Something went wrong that shouldn't. Activator.logException(exception); } this.updateProblemIndication = true; updateProblemIndication(); }
From source file:eu.geclipse.jsdl.ui.editors.JsdlEditor.java
License:Open Source License
@Override public void doSave(final IProgressMonitor monitor) { /*/* w ww. j a v a 2 s . com*/ * Do the work within an operation because this is a long running activity * that modifies the workbench. */ WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { // This is the method that gets invoked when the operation runs. @Override public void execute(@SuppressWarnings("hiding") final IProgressMonitor monitor) { // Save the resources to the file system. boolean first = true; for (Iterator<?> i = JsdlEditor.this.editingDomain.getResourceSet().getResources().iterator(); i .hasNext();) { Resource resource = (Resource) i.next(); if ((first || !resource.getContents().isEmpty() || isPersisted(resource)) && !JsdlEditor.this.editingDomain.isReadOnly(resource)) { try { JsdlEditor.this.savedResources.add(resource); resource.save(Collections.EMPTY_MAP); } catch (Exception exception) { JsdlEditor.this.resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception)); // setDirty( false ); doTextEditorSave(); cleanDirtyState(); refreshEditor(); } first = false; } } } }; this.updateProblemIndication = false; try { // This runs the options, and shows progress. new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation); // Refresh the necessary state. ((BasicCommandStack) this.editingDomain.getCommandStack()).saveIsDone(); // setDirty( false ); doTextEditorSave(); cleanDirtyState(); refreshEditor(); } catch (Exception exception) { // Something went wrong that shouldn't. Activator.logException(exception); } this.updateProblemIndication = true; updateProblemIndication(); }