List of usage examples for org.eclipse.jface.operation IRunnableWithProgress run
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException;
From source file:org.tigris.subversion.subclipse.ui.actions.SVNAction.java
License:Open Source License
/** * Convenience method for running an operation with the appropriate progress. * Any exceptions are propogated so they can be handled by the * <code>SVNAction#run(IAction)</code> error handling code. * //w w w. jav a 2s . co m * @param runnable the runnable which executes the operation * @param cancelable indicate if a progress monitor should be cancelable * @param progressKind one of PROGRESS_BUSYCURSOR or PROGRESS_DIALOG */ final protected void run(final IRunnableWithProgress runnable, boolean cancelable, int progressKind) throws InvocationTargetException, InterruptedException { final Exception[] exceptions = new Exception[] { null }; // Ensure that no repository view refresh happens until after the action final IRunnableWithProgress innerRunnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { SVNUIPlugin.getPlugin().getRepositoryManager().run(runnable, monitor); } }; switch (progressKind) { case PROGRESS_BUSYCURSOR: BusyIndicator.showWhile(Display.getCurrent(), new Runnable() { public void run() { try { innerRunnable.run(new NullProgressMonitor()); } catch (InvocationTargetException e) { exceptions[0] = e; } catch (InterruptedException e) { exceptions[0] = e; } } }); break; case PROGRESS_DIALOG: default: new ProgressMonitorDialog(getShell()).run(true, cancelable, /*cancelable, true, */innerRunnable); break; } if (exceptions[0] != null) { if (exceptions[0] instanceof InvocationTargetException) throw (InvocationTargetException) exceptions[0]; else throw (InterruptedException) exceptions[0]; } }
From source file:org.tigris.subversion.subclipse.ui.repository.RepositoryManager.java
License:Open Source License
/** * Run the given runnable/*ww w .ja va 2s .c o m*/ */ public void run(IRunnableWithProgress runnable, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { runnable.run(monitor); }
From source file:org.tigris.subversion.subclipse.ui.subscriber.AddSynchronizeOperation.java
License:Open Source License
final protected void run(final IRunnableWithProgress runnable, boolean cancelable, int progressKind) throws InvocationTargetException, InterruptedException { final Exception[] exceptions = new Exception[] { null }; // Ensure that no repository view refresh happens until after the action final IRunnableWithProgress innerRunnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { SVNUIPlugin.getPlugin().getRepositoryManager().run(runnable, monitor); }/*from www . j a v a 2s . co m*/ }; switch (progressKind) { case PROGRESS_BUSYCURSOR: BusyIndicator.showWhile(Display.getCurrent(), new Runnable() { public void run() { try { innerRunnable.run(new NullProgressMonitor()); } catch (InvocationTargetException e) { exceptions[0] = e; } catch (InterruptedException e) { exceptions[0] = e; } } }); break; case PROGRESS_DIALOG: default: new ProgressMonitorDialog(getShell()).run(true, cancelable, /*cancelable, true, */innerRunnable); break; } if (exceptions[0] != null) { if (exceptions[0] instanceof InvocationTargetException) throw (InvocationTargetException) exceptions[0]; else throw (InterruptedException) exceptions[0]; } }
From source file:org.tigris.subversion.subclipse.ui.SVNUIPlugin.java
License:Open Source License
/** * Creates a busy cursor and runs the specified runnable. * May be called from a non-UI thread./*from w w w . j a v a 2s . c o m*/ * * @param parent the parent Shell for the dialog * @param cancelable if true, the dialog will support cancelation * @param runnable the runnable * * @exception InvocationTargetException when an exception is thrown from the runnable * @exception InterruptedException when the progress monitor is cancelled */ public static void runWithProgress(Shell parent, boolean cancelable, final IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException { boolean createdShell = false; try { if (parent == null || parent.isDisposed()) { Display display = Display.getCurrent(); if (display == null) { // cannot provide progress (not in UI thread) runnable.run(new NullProgressMonitor()); return; } // get the active shell or a suitable top-level shell parent = display.getActiveShell(); if (parent == null) { parent = new Shell(display); createdShell = true; } } // pop up progress dialog after a short delay final Exception[] holder = new Exception[1]; BusyIndicator.showWhile(parent.getDisplay(), new Runnable() { public void run() { try { runnable.run(new NullProgressMonitor()); } catch (InvocationTargetException e) { holder[0] = e; } catch (InterruptedException e) { holder[0] = e; } } }); if (holder[0] != null) { if (holder[0] instanceof InvocationTargetException) { throw (InvocationTargetException) holder[0]; } else { throw (InterruptedException) holder[0]; } } //new TimeoutProgressMonitorDialog(parent, TIMEOUT).run(true /*fork*/, cancelable, runnable); } finally { if (createdShell) parent.dispose(); } }
From source file:org.xmind.ui.internal.editor.MindMapEditor.java
License:Open Source License
private boolean safeRun(final IProgressMonitor monitor, final boolean promptError, final IRunnableWithProgress runnable) { final boolean[] successful = new boolean[1]; successful[0] = false;/* w w w . ja v a 2 s.co m*/ SafeRunner.run(new SafeRunnable() { @Override public void run() throws Exception { if (monitor != null) { runnable.run(monitor); } else { IWorkbenchSiteProgressService context = getSite() .getService(IWorkbenchSiteProgressService.class); Assert.isTrue(context != null); context.run(true, true, runnable); } successful[0] = true; } @Override public void handleException(Throwable e) { if (e instanceof InterruptedException) // canceled, no error return; if (e instanceof InvocationTargetException) { Throwable cause = ((InvocationTargetException) e).getTargetException(); if (cause != null) e = cause; } if (!promptError) { // log only Logger.log(e); return; } super.handleException(e); } }); return successful[0]; }
From source file:org.xmind.ui.internal.MindMapResourceManager.java
License:Open Source License
@Override public ITemplate addUserTemplateFromWorkbookURI(URI workbookURI) throws InvocationTargetException { Assert.isNotNull(workbookURI);/*w w w .jav a 2s. c om*/ final IWorkbookRef sourceWorkbookRef = MindMapUIPlugin.getDefault().getWorkbookRefFactory() .createWorkbookRef(workbookURI, null); if (sourceWorkbookRef == null) throw new IllegalArgumentException("Invalid workbook URI: " + workbookURI); //$NON-NLS-1$ final File userTemplateFile = createUserTemplateOutputFile( sourceWorkbookRef.getName() + MindMapUI.FILE_EXT_TEMPLATE); final URI templateURI = userTemplateFile.toURI(); final IWorkbookRef templateWorkbookRef = MindMapUIPlugin.getDefault().getWorkbookRefFactory() .createWorkbookRef(templateURI, null); if (templateWorkbookRef == null) throw new IllegalStateException("Failed to obtain workbook ref for local file URI: " //$NON-NLS-1$ + templateURI); IRunnableWithProgress runnable = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { SubMonitor subMonitor = SubMonitor.convert(monitor, 100); sourceWorkbookRef.open(subMonitor.newChild(30)); try { templateWorkbookRef.importFrom(subMonitor.newChild(60), sourceWorkbookRef); } finally { subMonitor.setWorkRemaining(10); sourceWorkbookRef.close(subMonitor.newChild(10)); } } finally { if (monitor != null) monitor.done(); } } }; try { if (PlatformUI.isWorkbenchRunning()) { PlatformUI.getWorkbench().getProgressService().run(false, true, runnable); } else { runnable.run(new NullProgressMonitor()); } } catch (InterruptedException e) { // canceled return null; } ITemplate template = new ClonedTemplate(templateURI, FileUtils.getNoExtensionFileName(userTemplateFile.getAbsolutePath())); fireUserTemplateAdded(template); return template; }
From source file:org.xmind.ui.internal.sharing.SharingUtils.java
License:Open Source License
public static void run(final IRunnableWithProgress runnable, Display display) { final Throwable[] exception = new Throwable[] { null }; if (display != null && !display.isDisposed()) { display.syncExec(new Runnable() { public void run() { final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null); dialog.setOpenOnRun(false); final boolean[] completed = new boolean[] { false }; Display.getCurrent().timerExec(240, new Runnable() { public void run() { if (!completed[0]) dialog.open(); }//from w w w.j av a2 s. c o m }); try { dialog.run(true, false, runnable); } catch (InterruptedException e) { // ignore } catch (InvocationTargetException e) { exception[0] = e.getCause(); } catch (Throwable e) { exception[0] = e; } finally { completed[0] = true; dialog.close(); Shell shell = dialog.getShell(); if (shell != null) { shell.dispose(); } } } }); } else { try { runnable.run(new NullProgressMonitor()); } catch (InterruptedException e) { // ignore } catch (InvocationTargetException e) { exception[0] = e.getCause(); } catch (Throwable e) { exception[0] = e; } } if (exception[0] != null) { LocalNetworkSharingUI.log("Failed to disconnect from local network sharing service:", //$NON-NLS-1$ exception[0]); } }
From source file:org.xtuml.bp.core.ui.CopyCutAction.java
License:Open Source License
public void run() { Clipboard cb = CorePlugin.getSystemClipboard(); cb.clearContents();/*from w ww. j a va 2 s . c o m*/ Object secondary = getSecondaryClipboardData(); if (secondary != null && onlyIncludeSecondaryData()) { // this occurs when copy of element data is not // allowed, but image copy is cb.setContents(new Object[] { secondary }, new Transfer[] { getSecondaryTransfer() }); return; } try { List<NonRootModelElement> elementList = null; if (getActionType() == CUT_TYPE) { startMove(); // In move we do not include graphical elements in the list. // We don't need them, we go get them. elementList = Arrays.asList(getElementsToBeCopied(false)); ELEMENT_MOVE_SOURCE_SELECTION = new ArrayList<NonRootModelElement>(elementList); } else { stopMove(); elementList = Arrays.asList(getElementsToBeCopied(true)); } ByteArrayOutputStream out = new ByteArrayOutputStream(); String streamContents = ""; String packagingHeader = getPackagingHeaderFromElements(elementList); NonRootModelElement[] nrmeList = new NonRootModelElement[elementList.size()]; IRunnableWithProgress progress = CorePlugin.getStreamExportFactory().create(out, elementList.toArray(nrmeList), true, false); progress.run(new NullProgressMonitor()); out.close(); streamContents = new String(out.toByteArray()); streamContents = streamContents.replaceFirst("\n", "\n" + packagingHeader + "\n"); if (secondary == null) { cb.setContents(new Object[] { streamContents }, new Transfer[] { TextTransfer.getInstance() }); } else { cb.setContents(new Object[] { streamContents, secondary }, new Transfer[] { TextTransfer.getInstance(), getSecondaryTransfer() }); } postRun(); } catch (Exception e) { // log error CorePlugin.logError("Exception during cut/copy of selection.", e); } }
From source file:org.xtuml.bp.io.core.CoreExport.java
License:Open Source License
/** * Parse the specified element. //from w w w . j a va 2 s .c o m * * @arg The element to parse. Currently this routine can only parse elements * of type Domain_c or Component_c */ private void parseOneElement(final NonRootModelElement selectedElement, final IProgressMonitor monitor, Shell dialogShell) throws InvocationTargetException, InterruptedException { final String className = selectedElement.getClass().getName(); final String instanceName = selectedElement.getName(); errorLoggedDuringParse = false; // This does mean that if the element passed-in is not one we know // how to parse this routine returns success if ((selectedElement instanceof Component_c) || (selectedElement instanceof Package_c)) { final NonRootModelElement nrme = selectedElement; IRunnableWithProgress rwp = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) { if (monitor != null) { monitor.subTask("Parsing " + instanceName); } ParserAllActivityModifier aam = null; boolean workBenchIsRunning = PlatformUI.isWorkbenchRunning(); if (nrme instanceof Component_c) { if (workBenchIsRunning) { aam = new AllActivityModifier((Component_c) nrme, monitor); } else { aam = new ParserAllActivityModifier((Component_c) nrme, monitor); } } else if (nrme instanceof Package_c) { if (workBenchIsRunning) { aam = new AllActivityModifier((Package_c) nrme, monitor); } else { aam = new ParserAllActivityModifier((Package_c) nrme, monitor); } } if (aam != null) { aam.processAllActivities(ParserAllActivityModifier.PARSE, false); } if (monitor != null) { monitor.done(); } } }; // parse the element if (dialogShell == null) { if (monitor == null) { rwp.run(new NullProgressMonitor()); } else { rwp.run(monitor); } } else { new ProgressMonitorDialog(dialogShell).run(true, false, rwp); } } else { // Log a warning that we received an element type that this // routine will not parse. This really shouldn't happen. If it // does it means something is being exported that may include OAL // that is not being persisted in the export. String message = "Warning: CoreExport.parseOneElement() received an element that will not be parsed. "; message += "Class: " + className + " Instance: " + instanceName; CorePlugin.logError(message, null); } if (!CoreUtil.IsRunningHeadless) { // Make sure that all events in the asynchronous event queue // are dispatched. This is here is help assure that parse errors // are detected by the ILogListener PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { public void run() { // do nothing } }); } if (errorLoggedDuringParse) { String message = "Warning: Parse errors encountered prior to model export. "; message += "Class: " + className + " Instance: " + instanceName; CorePlugin.logError(message, null); } }
From source file:org.xtuml.bp.io.mdl.wizards.ModelExportWizard.java
License:Open Source License
/** * /* w ww .j a v a2 s .c om*/ * @return true is the export was created with the prefernece to enable * export of executable oal instance and false if not. * * @throws FileNotFoundException * @throws InterruptedException * @throws InvocationTargetException */ private boolean createExportProcessor() throws FileNotFoundException, InterruptedException, InvocationTargetException { // we need to add the GD_GE instances for those elements // selected List<NonRootModelElement> elements = new ArrayList<NonRootModelElement>(); final NonRootModelElement[] selectedElements = Selection.getInstance().getSelectedNonRootModelElements(); IRunnableWithProgress runnableLoader = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) { // here we force load the selected elements to // prevent outputting null ids (which can happen // in certain circumstances) issue 3303 may // fix this at which point this code can be // removed for (int i = 0; i < selectedElements.length; i++) { PersistableModelComponent component = selectedElements[i].getPersistableComponent(); component.loadComponentAndChildren(monitor); } } }; if (getContainer() == null) { runnableLoader.run(new NullProgressMonitor()); } else { new ProgressMonitorDialog(getContainer().getShell()).run(true, false, runnableLoader); } for (int i = 0; i < selectedElements.length; i++) { elements.add(selectedElements[i]); } addGraphicalElementsFor(selectedElements, elements); outStream = new ByteArrayOutputStream(); exporter = org.xtuml.bp.core.CorePlugin.getStreamExportFactory().create(outStream, elements.toArray(new NonRootModelElement[elements.size()]), true, true); boolean exportOALInstances = false; if (exporter instanceof CoreExport) { ((CoreExport) exporter).setExportGraphics(CoreExport.USER_PREFERENCE); // Check the license. This tests the license without checking it out. If there is // no availble license this will return false. exportOALInstances = ((CoreExport) exporter).setExportOAL(CoreExport.USER_PREFERENCE); } return exportOALInstances; }