List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog run
@Override public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException
IRunnableWithProgress
using the progress monitor for this progress dialog and blocks until the runnable has been run, regardless of the value of fork
. From source file:DiversityBenchmark.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();//ww w . j a v a 2s . co m 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(); } } }); pmContext.dispose(); }
From source file:e4rcp.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 w w w .j av a 2 s . co m 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); } } }); pmContext.dispose(); }
From source file:edu.pitt.dbmi.odie.ui.editors.analysis.RepeatAnalysisSection.java
License:Apache License
protected void repeatAnalysis() { ProgressMonitorDialog pd = GeneralUtils.getProgressMonitorDialog(); try {// www . ja v a2 s . c o m pd.run(true, true, new AnalysisReprocessor(currentAnalysis)); GeneralUtils.showPerformanceDialog(currentAnalysis); GeneralUtils.openEditor(AnalysisEditor.ID, new AnalysisEditorInput(currentAnalysis), true); GeneralUtils.refreshViews(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:edu.tsinghua.lumaqq.ui.InfoManagerWindow.java
License:Open Source License
protected void onSearch() { records.clear();// ww w.j a va2 s. c o m if (scope == 0) { // ? try { ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()); dialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { RecordManager rm = main.getRecordManager(); monitor.beginTask("Searching...", scopes.size()); for (Object obj : scopes) { int scope; if (obj instanceof User) scope = ((User) obj).qq; else scope = ((Cluster) obj).clusterId; records.addAll( rm.search(scope, IKeyConstants.ALL, IKeyConstants.SUB_ALL, keyword, false, 0)); monitor.worked(1); if (monitor.isCanceled()) break; } monitor.done(); } }); } catch (InvocationTargetException e) { } catch (InterruptedException e) { } } else { records.clear(); records.addAll(searchOne(scope)); } RecordManager rm = main.getRecordManager(); if (records.isEmpty()) pageCount = 0; else pageCount = (records.size() + rm.getPageSize() - 1) / rm.getPageSize(); pageNum = 0; if (pageCount > 0) lblPage.setText(NLS.bind(info_page, String.valueOf(pageNum + 1), String.valueOf(pageCount))); else lblPage.setText(""); recordViewer.refresh(); refreshRichBox(null); resetNavigator(); }
From source file:edu.umd.cs.eclipse.courseProjectManager.CVSOperations.java
License:Apache License
/** * Run a CVS operation synchronously (in the context of the current thread), * in a progress dialog or workbench status bar. Displays an error dialog if * the CVS operation does not complete successfully. * <p>/* w w w. ja va 2 s .c o m*/ * <b> NOTE: </b> I'm not sure this method works for adding files because it * keeps raising org.eclipse.swt.SWTException: Invalid thread access (error * code = 22 (ERROR_THREAD_INVALID_ACCESS)), which means that the wrong * thread is trying to do something. * * @param runnable * the operation * @param how * IN_STATUS_BAR to request running using the status bar, * IN_DIALOG to request running in a progress dialog * @param context * the OperationContext * @throws InvocationTargetException * @throws InterruptedException */ private static void syncExec(final Operation cvsOp, final int how, final OperationContext context) { // The Operation context, if present, may veto this entire operation. // This generally means that a previous asynchronously scheduled // operation // failed. final IWorkbenchWindow wwin = AutoCVSPlugin.getActiveWorkbenchWindow(); final Shell parent = (wwin != null) ? wwin.getShell() : null; try { Debug.print("syncExec: " + cvsOp.getOperationName() + " " + cvsOp.getMessage() + " " + Thread.currentThread().getName()); if (context != null && !context.operationMayProceed()) { Debug.print("Context is vetoing the following operation: " + cvsOp.getOperationName()); return; } // NOTE that the current plugin never uses the BUSY_INDICATOR option if (how == BUSY_INDICATOR) { Debug.print("BUSY_INDICATOR\n"); Runnable task = new Runnable() { public void run() { try { cvsOp.execute(null, null); } catch (Exception e) { // TODO what to do when BusyIndicator handles an // exception? System.err.println("Exception! " + e); } } }; org.eclipse.swt.custom.BusyIndicator.showWhile(null, task); return; } ISchedulingRule rule; IResource[] resources = cvsOp.getResources(); if (false && resources.length == 1) rule = resources[0]; else rule = cvsOp.getProject(); rule = ResourcesPlugin.getWorkspace().getRoot(); // Wrap the Operation in a WorkspaceModifyOperation WorkspaceModifyOperation runnable = new WorkspaceModifyOperation(rule) { protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { try { monitor.setTaskName(cvsOp.getOperationName()); cvsOp.execute(parent, monitor); } finally { monitor.done(); } } }; try { if (how == IN_STATUS_BAR) { boolean bail = false; Debug.print("IN_STATUS_BAR"); if (false) for (StackTraceElement element : new RuntimeException().getStackTrace()) { if (element.getClassName() .equals("org.eclipse.jface.operation.ModalContext$ModalContextThread") && element.getMethodName().equals("block")) { Debug.print("invocation of " + cvsOp.getOperationName() + " since we are being invoked from a model context"); System.out.println("invocation of " + cvsOp.getOperationName() + " since we are being invoked from a model context"); bail = true; } } if (!bail && wwin != null) { // wwin.run(false, true, runnable); wwin.run(true, true, runnable); if (context != null) context.success(parent); return; } } // A modal progress dialog is the fall back for the // case where we can't get a handle on the workbench window. Debug.print("modal progress dialog rather than IN_STATUS_BAR"); System.out.println("modal progress dialog rather than IN_STATUS_BAR"); ProgressMonitorDialog dialog = new ProgressMonitorDialog(null); try { dialog.run(false, true, runnable); } catch (SWTException e) { System.out.println("Error code: " + e.code); if (e.getCause() != null) System.out.println("Cause: " + e.getCause()); else System.out.println("Cause is null!"); throw e; } context.success(parent); return; } catch (Throwable e) { Debug.print("Exception thrown by runnable"); // Failed operation! if (context != null) context.failure(parent); Debug.print("Exception, about to call parseStatus(): ", e); // Attempt to figure out the reason for the failure from the // exception. int statusCode = parseStatus(e); // Build a detailed message describing the failure and its // consequences. StringBuffer msg = new StringBuffer(); msg.append("The following operation failed: " + cvsOp.getOperationName()); String consequenceMessage = null; if (context != null) consequenceMessage = context.getConsequenceMessage(statusCode); if (consequenceMessage != null) { msg.append("\n\n"); msg.append(consequenceMessage); } if (AutoCVSPlugin.getPlugin().hasFailedOperation()) { // Add the generic message about how automatic CVS commands // are disabled. msg.append("\n\n"); msg.append(AutoCVSPlugin.getMessage("error.offline")); } // Alert the user. Dialogs.errorDialog(parent, "Warning: " + cvsOp.getOperationName() + " failed", msg.toString(), e); if (context != null) context.failure(parent); else Debug.print("context is null!"); } } catch (RuntimeException e) { Dialogs.errorDialog(parent, "Warning: runtime exception during " + cvsOp.getOperationName() + " failed", e.getMessage(), e); throw e; } }
From source file:edu.utah.cdmcc.e4.glucose.application.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();// ww w.j a v a2 s .c om 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); } } }); pmContext.dispose(); }
From source file:es.axios.udig.ui.commons.util.DialogUtil.java
License:LGPL
/** * Runs a blocking task in a ProgressDialog. It is ran in such a way that * even if the task blocks it can be cancelled. This is unlike the normal * ProgressDialog.run(...) method which requires that the * {@link IProgressMonitor} be checked and the task to "nicely" cancel. * /*w ww.j ava 2 s.c om*/ * @param dialogTitle * The title of the Progress dialog * @param showRunInBackground * if true a button added to the dialog that will make the job be * ran in the background. * @param process * the task to execute. * @param runASync * @param confirmCancelRequests * wether to ask the user to confirm the cancelation when the * cancel button is pressed */ public static void runInProgressDialog(final String dialogTitle, final boolean showRunInBackground, final IRunnableWithProgress process, boolean runASync, final boolean confirmCancelRequests) { Runnable object = new Runnable() { public void run() { Shell shell = Display.getDefault().getActiveShell(); ProgressMonitorDialog dialog = DialogUtil.openProgressMonitorDialog(shell, dialogTitle, showRunInBackground, confirmCancelRequests); try { dialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { PlatformGISMediator.runBlockingOperation(new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { process.run(monitor); } }, monitor); } catch (InvocationTargetException e) { throw e; } catch (InterruptedException e) { throw e; } catch (Exception e) { // TODO feedback to user is required e.printStackTrace(); } } }); } catch (Exception e) { // TODO feedback to user is required e.printStackTrace(); } } }; if (runASync) Display.getDefault().asyncExec(object); // TODO should be tested with this method // PlatformGISMediator.asyncInDisplayThread(object, false); else PlatformGISMediator.syncInDisplayThread(object); }
From source file:es.axios.udig.ui.commons.util.DialogUtil.java
License:LGPL
public static void runsyncInDisplayThread(final String dialogTitle, final boolean showRunInBackground, final IRunnableWithProgress process, final boolean confirmCancelRequests) { Runnable object = new Runnable() { public void run() { Shell shell = Display.getDefault().getActiveShell(); ProgressMonitorDialog dialog = DialogUtil.openProgressMonitorDialog(shell, dialogTitle, showRunInBackground, confirmCancelRequests); try { dialog.run(true, true, new IRunnableWithProgress() { public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { PlatformGISMediator.syncInDisplayThread(new Runnable() { public void run() { try { process.run(monitor); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); }//from www . j a v a 2 s .com } }); } catch (Exception e) { // TODO feedback to user is required e.printStackTrace(); } } }); } catch (Exception e) { // TODO feedback to user is required e.printStackTrace(); } } }; // if (runASync) // Display.getDefault().asyncExec(object); // TODO should be tested with this method // PlatformGISMediator.asyncInDisplayThread(object, false); // else PlatformGISMediator.syncInDisplayThread(object); }
From source file:es.bsc.servicess.ide.dialogs.JarFileDialog.java
License:Apache License
private boolean loadWarFile(final String selectedDirectory) { final ProgressMonitorDialog dialog = new ProgressMonitorDialog(this.getShell()); try {// w ww . j a v a2 s . c om log.debug("Selected dir: " + selectedDirectory); final File warFile = new File(selectedDirectory); if (warFile.exists()) { dialog.run(false, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException { try { IFolder importFolder = project.getProject().getFolder(ProjectMetadata.IMPORT_FOLDER); if (!importFolder.exists()) importFolder.create(true, true, monitor); String name = PackagingUtils.getPackageName(warFile); log.debug("Package name is " + name); IFolder extractFolder = importFolder.getFolder(name); if (!extractFolder.exists()) { extractWar(warFile, extractFolder, monitor); } else log.info("Package already exists. Not extracting"); } catch (Exception e) { throw (new InvocationTargetException(e)); } } }); return true; } else throw (new InvocationTargetException(new Exception("The selected file doesn't exists"))); } catch (InvocationTargetException e) { log.error("Error loading package"); ErrorDialog.openError(dialog.getShell(), "Error loading new package file", "Exception when loading package", new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e)); return false; } catch (InterruptedException e) { log.error("Error loading package"); ErrorDialog.openError(dialog.getShell(), "Package load interrumped", "Exception when loading package", new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e)); return false; } }
From source file:es.bsc.servicess.ide.editors.BuildingDeploymentFormPage.java
License:Apache License
/** * Build the service packages/* ww w .ja va2 s . c o m*/ */ private void buildPackages() { final ProgressMonitorDialog dialog = new ProgressMonitorDialog(getSite().getShell()); try { dialog.run(true, true, new IRunnableWithProgress() { /* (non-Javadoc) * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor) */ public void run(IProgressMonitor monitor) throws InvocationTargetException { IJavaProject project = ((ServiceFormEditor) getEditor()).getProject(); try { ProjectMetadata pr_meta = ((ServiceFormEditor) getEditor()).getProjectMetadata(); PackagingUtils.buildPackages(project, pr_meta, monitor); /* monitor.beginTask("Building project classes...", 100); IFolder output = project.getProject().getFolder( ProjectMetadata.OUTPUT_FOLDER); if (output == null || !output.exists()) { output.create(true, true, monitor); } project.getProject().build( IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor); // monitor.beginTask("Instrumenting Orchestrations...", // 100); // PackagingUtils.instrumentOrchestrations(pr_meta.getRuntimeLocation(),pr_meta.getOrchestrationClasses(), // output, monitor); monitor.beginTask("Creating packages...", 100); IFolder packages = output .getFolder(ProjectMetadata.PACKAGES_FOLDER); if (packages != null && packages.exists()) { packages.delete(true, monitor); } packages.create(true, true, monitor); // PackagingUtils.copyConfigFiles((ServiceFormEditor)getEditor()); log.debug("Getting packages..."); String[] packs = pr_meta.getPackages(); String runtime = pr_meta.getRuntimeLocation(); String[] orch_cls = pr_meta.getOrchestrationClasses(); IFolder src_fld = project.getProject().getFolder( pr_meta.getSourceDir()); IPackageFragmentRoot source = null; if (src_fld != null) source = project.findPackageFragmentRoot(src_fld .getFullPath()); IFolder gen_fld = project.getProject().getFolder( "generated"); IPackageFragmentRoot generated = null; if (gen_fld != null) generated = project.findPackageFragmentRoot(project .getProject().getFolder("generated") .getFullPath()); if (source != null && source.exists()) { if (constraintsElements == null) { constraintsElements = getElements(orch_cls, ProjectMetadata.CORE_TYPE, project, pr_meta); } if (packs != null && packs.length > 0) { log.debug("Building core element packages"); for (String p : packs) { String[] elements = pr_meta .getElementsInPackage(p); if (elements != null && elements.length > 0) { PackagingUtils.createCorePackage( runtime, p, elements, pr_meta.getDependencies(elements), constraintsElements, source, output, packages, monitor); } } } else { log.warn("Warning: No core element packages built"); monitor.setCanceled(true); throw (new InvocationTargetException( new Exception("No core element packages built"))); } if (orch_cls!= null && orch_cls.length>0){ log.debug("Generating Orchestration"); PackagingUtils.createServiceOrchestrationPackage( runtime, PackagingUtils.getClasspath(project), project.getProject().getName(), orch_cls, pr_meta.getDependencies(getOrchestrationElementsLabels( orch_cls, project, pr_meta)), source, generated, output, packages, monitor, shouldBeWarFile(pr_meta.getOrchestrationClassesTypes())); monitor.done(); }else{ log.warn("Warning: No orchestration element packages built"); monitor.setCanceled(true); throw (new InvocationTargetException( new Exception("No orchestration packages built"))); } } else { log.error("Source dir not found"); monitor.setCanceled(true); throw (new InvocationTargetException(new Exception( "Source dir " + src_fld.getFullPath() + " not found"))); }*/ } catch (Exception e) { throw (new InvocationTargetException(e)); } } }); } catch (InvocationTargetException e) { ErrorDialog.openError(dialog.getShell(), "Error creating packages", e.getMessage(), new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e)); e.printStackTrace(); } catch (InterruptedException e) { ErrorDialog.openError(dialog.getShell(), "Building interrumped", e.getMessage(), new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e)); e.printStackTrace(); } }