Example usage for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress

List of usage examples for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress

Introduction

In this page you can find the example usage for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress.

Prototype

IRunnableWithProgress

Source Link

Usage

From source file:com.arc.cdt.importer.internal.ui.AccessModel.java

License:Open Source License

public ICodewrightProjectSpace getProjectSpace() throws IOException, PSPException {
    if (mProjectSpace == null && mPspFile != null) {
        IRunnableWithProgress runnable = new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    mProjectSpace = Factory.getProjectSpaceFinder().extractProjectSpace(mPspFile, monitor);
                } catch (Exception e) {
                    throw new InvocationTargetException(e);
                }/* w ww  . jav a  2s  .co  m*/
            }
        };
        try {
            mContext.run(false, false, runnable);
        } catch (InvocationTargetException e) {
            Throwable t = e.getTargetException();
            if (t instanceof IOException) {
                throw (IOException) t;
            }
            if (t instanceof PSPException) {
                throw (PSPException) t;
            }
            if (t instanceof RuntimeException)
                throw (RuntimeException) t;
            throw new Error(t); // shouldn't get here
        } catch (InterruptedException e) {
            //shouldn't get here
        }

    }
    return mProjectSpace;
}

From source file:com.arc.cdt.importer.internal.ui.CodeWrightImportWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            IProjectCreator creator = Factory.createProjectCreator();

            if (monitor == null) {
                monitor = new NullProgressMonitor();
            }//from  w w  w  .ja v a  2 s.  c  o  m

            try {
                monitor.beginTask("Importing project space", 3);
                boolean isCplusplus = hasCPlusPlusProject(mAccess.getSelectedProjects());
                IProjectType type = mAccess.getProjectType();
                ICProject cproject = creator.createProject(mAccess.getNewProjectLocation(), isCplusplus,
                        mAccess.getNewProjectName(), type, monitor);
                importOrLinkSourceFiles(creator, cproject, monitor);
                createConfigurations(creator, cproject, monitor);
                ManagedBuildManager.saveBuildInfo(cproject.getProject(), true);
                exportSeeCodeOptions(cproject.getProject());
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();
            }
        }
    };
    runnable = new WorkspaceModifyDelegatingOperation(runnable);

    try {
        this.getContainer().run(false, false, runnable);
    } catch (InvocationTargetException e) {
        final Throwable t = e.getTargetException();
        ImporterPlugin.log(t);
        getShell().getDisplay().syncExec(new Runnable() {

            public void run() {
                MessageBox box = new MessageBox(getShell(), SWT.OK | SWT.ICON_ERROR);
                box.setMessage("Exception occurred during operation: \n" + t.getMessage()
                        + "\nSee the error log for details."
                        + "\nThe construction of the new project did not complete.");
                box.setText("Error");
                box.open();
            }
        });

    } catch (InterruptedException e) {
        //Shouldn't get here.
    }

    return true;
}

From source file:com.arc.embeddedcdt.launch.LaunchShortcut.java

License:Open Source License

/**
 * Method searchAndLaunch./*from ww  w.j av a  2  s.  c o m*/
 * @param objects
 * @param mode
 */
private void searchAndLaunch(final Object[] elements, String mode) {
    if (elements != null && elements.length > 0) {
        IBinary bin = null;
        if (elements.length == 1 && elements[0] instanceof IBinary) {
            bin = (IBinary) elements[0];
        } else {
            final List results = new ArrayList();
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
            IRunnableWithProgress runnable = new IRunnableWithProgress() {
                public void run(IProgressMonitor pm) throws InterruptedException {
                    int nElements = elements.length;
                    pm.beginTask("Looking for executables", nElements); //$NON-NLS-1$
                    try {
                        IProgressMonitor sub = new SubProgressMonitor(pm, 1);
                        for (int i = 0; i < nElements; i++) {
                            if (elements[i] instanceof IAdaptable) {
                                IResource r = (IResource) ((IAdaptable) elements[i])
                                        .getAdapter(IResource.class);
                                if (r != null) {
                                    ICProject cproject = CoreModel.getDefault().create(r.getProject());
                                    if (cproject != null) {
                                        try {
                                            IBinary[] bins = cproject.getBinaryContainer().getBinaries();

                                            for (int j = 0; j < bins.length; j++) {
                                                if (bins[j].isExecutable()) {
                                                    results.add(bins[j]);
                                                }
                                            }
                                        } catch (CModelException e) {
                                        }
                                    }
                                }
                            }
                            if (pm.isCanceled()) {
                                throw new InterruptedException();
                            }
                            sub.done();
                        }
                    } finally {
                        pm.done();
                    }
                }
            };
            try {
                dialog.run(true, true, runnable);
            } catch (InterruptedException e) {
                return;
            } catch (InvocationTargetException e) {
                MessageDialog.openError(getShell(),
                        LaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), //$NON-NLS-1$
                        e.getMessage());
                return;
            }
            int count = results.size();
            if (count == 0) {
                MessageDialog.openError(getShell(),
                        LaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), //$NON-NLS-1$
                        LaunchMessages.getString("CApplicationLaunchShortcut.Launch_failed_no_binaries")); //$NON-NLS-1$
            } else if (count > 1) {
                bin = chooseBinary(results, mode);
            } else {
                bin = (IBinary) results.get(0);
            }
        }
        if (bin != null) {
            launch(bin, mode);
        }
    } else {
        MessageDialog.openError(getShell(),
                LaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), //$NON-NLS-1$
                LaunchMessages.getString("CApplicationLaunchShortcut.Launch_failed_no_project_selected")); //$NON-NLS-1$
    }
}

From source file:com.archimatetool.jasperreports.ExportJasperReportsWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    fPage1.saveSettings();/* w w  w  .j a  v a  2s  .  c  o m*/

    fMainTemplateFile = fPage2.getMainTemplateFile();

    // Check this exists
    if (fMainTemplateFile == null || !fMainTemplateFile.exists()) {
        MessageDialog.openError(getShell(), Messages.ExportJasperReportsWizard_1,
                Messages.ExportJasperReportsWizard_2);
        return false;
    }

    fExportFolder = fPage1.getExportFolder();
    fExportFileName = fPage1.getExportFilename();
    fReportTitle = fPage1.getReportTitle();
    fIsPDF = fPage1.isExportPDF();
    fIsHTML = fPage1.isExportHTML();
    fIsDOCX = fPage1.isExportDOCX();
    fIsPPT = fPage1.isExportPPT();
    fIsODT = fPage1.isExportODT();
    fIsRTF = fPage1.isExportRTF();

    // Check valid dir and file name
    try {
        File file = new File(fExportFolder, fExportFileName);
        file.getCanonicalPath();
        fExportFolder.mkdirs();
    } catch (Exception ex) {
        MessageDialog.openError(getShell(), Messages.ExportJasperReportsWizard_3,
                Messages.ExportJasperReportsWizard_4);
        return false;
    }

    Display.getCurrent().asyncExec(new Runnable() {
        @Override
        public void run() {
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
            try {
                dialog.run(false, true, new IRunnableWithProgress() {
                    @Override
                    public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {
                        try {
                            export(monitor);
                        } catch (Exception ex) {
                            ex.printStackTrace();
                            MessageDialog.openError(getShell(), Messages.ExportJasperReportsWizard_5,
                                    ex.getMessage());
                        } finally {
                            monitor.done();
                        }
                    }
                });
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });

    return true;
}

From source file:com.architexa.diagrams.relo.jdt.actions.OpenForBrowsingAction.java

License:Open Source License

public static void openReloViz(IWorkbenchWindow activeWorkbenchWindow, final List<?> selList,
        final Map<IDocument, IDocument> lToRDocMap, final Map<IDocument, String> lToPathMap,
        final StringBuffer docBuff, final IPath wkspcPath, final RunWithObjectParam runWithEditor) {
    try {/*from  w ww . j a v  a 2s.  c  o m*/
        ReloView view = (ReloView) activeWorkbenchWindow.getActivePage().findView(ReloView.viewId);
        final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        if (view != null) {
            // Check why support for Relo View is being added here
            // view is always null here?

            // make sure the view is shown
            activeWorkbenchWindow.getActivePage().activate(view);

            ReloController rc = view.getReloController();
            CreateCommand createCmd = new CreateCommand(rc, selList);
            CompoundCommand cc = new CompoundCommand("Show Included Relationships");
            cc.add(createCmd);
            ((ReloDoc) rc.getRootArtifact()).showIncludedRelationships(cc, createCmd.getAddedAFs());

            if (!ResourceQueue.isEmpty())
                rc.addUnbuiltWarning();
            rc.execute(cc);
            return;
        }

        new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()).run(true,
                false, new IRunnableWithProgress() {

                    public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {
                        monitor.beginTask("Creating Class Diagram...", IProgressMonitor.UNKNOWN);

                        PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

                            public void run() {
                                try {
                                    ReloEditor reloEditor = null;
                                    RSEMultiPageEditor mpe = null;
                                    RSEShareableDiagramEditorInput edInput = null;
                                    if (lToRDocMap == null || lToPathMap == null) {
                                        edInput = new ListEditorInput(new ArrayList<Object>(),
                                                new ClassStrucBrowseModel());
                                    } else {
                                        edInput = new ListEditorInput(new ArrayList<Object>(),
                                                new ClassStrucBrowseModel(), lToRDocMap, lToPathMap, docBuff);
                                    }

                                    // The exploration server uses this to dynamically get the repo for a diagram from a code element
                                    if (wkspcPath != null) {
                                        edInput.wkspcPath = wkspcPath;
                                        //                             ((ListEditorInput)edInput).browseModel.setRepo(StoreUtil.getStoreRepository(wkspcPath));
                                    }

                                    mpe = (RSEMultiPageEditor) page.openEditor(edInput,
                                            RSEMultiPageEditor.editorId);
                                    if (runWithEditor != null)
                                        runWithEditor.run(mpe);

                                    reloEditor = (ReloEditor) mpe.getRseEditor();

                                    ReloController rc = reloEditor.getReloController();

                                    CreateCommand createCmd = new CreateCommand(reloEditor.getReloController(),
                                            selList);

                                    CompoundCommand cc = new CompoundCommand("Show Included Relationships");
                                    cc.add(createCmd);
                                    ((ReloDoc) rc.getRootArtifact()).showIncludedRelationships(cc,
                                            createCmd.getAddedAFs());

                                    if (!ResourceQueue.isEmpty())
                                        rc.addUnbuiltWarning();

                                    rc.execute(cc);
                                } catch (PartInitException e) {
                                    logger.error("Unexpected Exception.", e);
                                }
                            }
                        });
                    }
                });
    } catch (Throwable e) {
        logger.error("Unexepected exception while opening relo visualization", e);
    }
}

From source file:com.architexa.diagrams.relo.parts.ArtifactEditPart.java

License:Open Source License

public Action getRelAction(final String text, final DirectedRel rel, final Predicate filter) {
    return new Action(text) {
        @Override//from  w w  w .j  a  va2s.  c  om
        public void run() {
            final CompoundCommand actionCmd = new CompoundCommand();

            final IRunnableWithProgress op = new IRunnableWithProgress() {
                public void run(final IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    monitor.beginTask(text, IProgressMonitor.UNKNOWN);
                    Display.getDefault().asyncExec(new Runnable() {
                        public void run() {
                            ArtifactEditPart.this.showAllDirectRelation(actionCmd, rel, filter);
                            if (actionCmd.size() > 0)
                                ArtifactEditPart.this.execute(actionCmd);
                        }
                    });
                }
            };
            try {
                new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell())
                        .run(true, false, op);
            } catch (InvocationTargetException e) {
                logger.error(e.getMessage());
            } catch (InterruptedException e) {
                logger.error(e.getMessage());
            }
        }
    };
}

From source file:com.arm.cmsis.pack.installer.ui.handlers.ReloadPacksHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    IRunnableContext context = window.getWorkbench().getProgressService();
    try {//from  w w w. j  ava2 s  . co  m
        context.run(true, false, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(Messages.ReloadPacksHandler_RefreshPacks, 1);
                Display.getDefault().syncExec(new Runnable() {
                    @Override
                    public void run() {
                        CpPlugIn.getPackManager().reload();
                    }
                });
                monitor.worked(1);
                monitor.done();
            }
        });

    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.arm.cmsis.pack.installer.ui.handlers.UpdatePacksHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IRunnableContext context = HandlerUtil.getActiveWorkbenchWindow(event).getWorkbench().getProgressService();
    try {/*w  ww . ja v  a  2  s  .  co m*/
        context.run(true, true, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                CpPlugIn.getPackManager().getPackInstaller().updatePacks(monitor);
            }
        });

    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.arm.cmsis.pack.project.wizards.CmsisCodeTemplateNewWizard.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  va 2s.c o m*/
@Override
public boolean performFinish() {
    final String containerName = page.getContainerName();
    final String[] fileNames = page.getFileName().split(" "); //$NON-NLS-1$
    final String[] templateFileNames = page.getCodeTemplateFileNames();
    IRunnableWithProgress op = new IRunnableWithProgress() {
        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                doFinish(containerName, fileNames, templateFileNames, 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.CmsisCodeTemplate_Error, realException.getMessage());
        return false;
    }
    return true;
}

From source file:com.asakusafw.shafu.ui.util.ProgressUtils.java

License:Apache License

/**
 * Invokes {@link ICallable#call(IProgressMonitor)} using {@link IRunnableContext the context}.
 * @param context the target context// w  ww  . j ava  2s.c  o  m
 * @param callable the target operation
 * @return the operation result
 * @param <T> the operation result type
 * @throws CoreException if the operation was failed
 */
public static <T> T call(IRunnableContext context, final ICallable<T> callable) throws CoreException {
    try {
        final AtomicReference<T> result = new AtomicReference<T>();
        context.run(true, true, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException {
                try {
                    result.set(callable.call(monitor));
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
        return result.get();
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        if (cause instanceof CoreException) {
            throw (CoreException) cause;
        } else if (cause instanceof OperationCanceledException) {
            throw new CoreException(Status.CANCEL_STATUS);
        } else if (cause instanceof Error) {
            throw (Error) cause;
        } else if (cause instanceof RuntimeException) {
            throw (RuntimeException) cause;
        } else {
            throw new AssertionError(cause);
        }
    } catch (InterruptedException e) {
        throw new CoreException(Status.CANCEL_STATUS);
    }
}