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.byterefinery.rmbench.util.ModelManager.java

License:Open Source License

/**
 * show a 3-option dialog asking the user whether the current model should be saved
 * //from w w w  .  ja  v  a 2 s .c  o  m
 * @return false if the dialog was cancelled, and thus the operation should not 
 * proceed
 */
private boolean querySaveModel(final Shell shell) {

    MessageDialog dialog = new MessageDialog(shell, RMBenchMessages.ModelView_SaveDlg_Title, null,
            RMBenchMessages.ModelView_SaveChanged_Message, MessageDialog.QUESTION, new String[] {
                    IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
            0);
    int result = dialog.open();
    if (result == 0) {
        IRunnableWithProgress runnable = new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

                doSave(shell, monitor);
            }
        };
        try {
            new ProgressMonitorDialog(shell).run(false, true, runnable);
        } catch (InvocationTargetException e) {
            RMBenchPlugin.logError(e);
        } catch (InterruptedException e) {
            RMBenchPlugin.logError(e);
        }
    }

    return result != 2;
}

From source file:com.centurylink.mdw.plugin.actions.ProjectUpdateAction.java

License:Apache License

/**
 * @see IActionDelegate#run(IAction)//www . j a  v  a  2  s .  c o m
 */
public void run(final IAction action) {
    IProject project = null;
    WorkflowProject workflowProject = null;
    try {
        if (selection instanceof IStructuredSelection
                && ((IStructuredSelection) selection).getFirstElement() instanceof IProject) {
            project = (IProject) ((IStructuredSelection) selection).getFirstElement();
            workflowProject = WorkflowProjectManager.getInstance().getWorkflowProject(project);
        }
        if (workflowProject == null) {
            MessageDialog.openError(shell, "MDW Update", "Selection must be a Workflow project.");
            return;
        }

        final ProjectUpdater updater = new ProjectUpdater(workflowProject, MdwPlugin.getSettings());

        if (action.getId().equals("mdw.workflow.updateFrameworkJars")) {
            updater.updateFrameworkJars(null);
            ExtensionModulesUpdater modulesUpdater = new ExtensionModulesUpdater(workflowProject);
            modulesUpdater.doUpdate(shell);
        } else if (action.getId().equals("mdw.workflow.associateFrameworkSourceCode")) {
            ProgressMonitorDialog pmDialog = new MdwProgressMonitorDialog(shell);
            final WorkflowProject wfProject = workflowProject;
            pmDialog.run(true, false, new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    monitor.beginTask("Setting Java source attachment locations", 100);
                    monitor.worked(20);
                    ProjectConfigurator configurator = new ProjectConfigurator(wfProject,
                            MdwPlugin.getSettings());
                    try {
                        configurator.createFrameworkSourceCodeAssociations(shell, monitor);
                    } catch (CoreException ex) {
                        PluginMessages.log(ex);
                    }
                }
            });
        }
    } catch (Exception ex) {
        PluginMessages.log(ex);
    }
}

From source file:com.centurylink.mdw.plugin.actions.WebUpdateAction.java

License:Apache License

/**
 * @see IActionDelegate#run(IAction)//from   w ww.j  a va 2s  .co m
 */
public void run(final IAction action) {
    IProject webProject = null;
    WorkflowProject workflowProject = null;
    try {
        if (selection instanceof IStructuredSelection
                && ((IStructuredSelection) selection).getFirstElement() instanceof IProject) {
            webProject = (IProject) ((IStructuredSelection) selection).getFirstElement();
            workflowProject = WorkflowProjectManager.getInstance().getWorkflowProject(webProject);
        }
        if (workflowProject == null) {
            MessageDialog.openError(shell, "MDW Update",
                    "Selection must be a Workflow Web project.\n(Try refreshing Process Explorer view.)");
            return;
        }

        ProjectUpdater updater = new ProjectUpdater(workflowProject, MdwPlugin.getSettings());

        if (action.getId().equals("mdw.workflow.updateFrameworkWebJars")) {
            updater.updateWebProjectJars(null);
        } else if (action.getId().equals("mdw.workflow.associateWebAppSourceCode")) {
            ProgressMonitorDialog pmDialog = new MdwProgressMonitorDialog(shell);
            final WorkflowProject wfProject = workflowProject;
            pmDialog.run(true, false, new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    monitor.beginTask("Setting Java source attachment locations", 100);
                    monitor.worked(20);
                    ProjectConfigurator configurator = new ProjectConfigurator(wfProject,
                            MdwPlugin.getSettings());
                    try {
                        configurator.createWebProjectSourceCodeAssociations(shell, monitor);
                    } catch (CoreException ex) {
                        PluginMessages.log(ex);
                    }
                }
            });
        }
    } catch (Exception ex) {
        PluginMessages.log(ex);
    }
}

From source file:com.centurylink.mdw.plugin.actions.WorkflowElementActionHandler.java

License:Apache License

public void remoteImportVcs(final WorkflowProject workflowProject) {
    VcsRepository repo = workflowProject.getMdwVcsRepository();
    String msg = "Pull latest assets into " + workflowProject.getName() + " from Git branch: "
            + repo.getBranch() + "?";
    boolean proceed = MessageDialog.openConfirm(getShell(), "Import from VCS", msg);
    if (proceed) {
        ProgressMonitorDialog pmDialog = new MdwProgressMonitorDialog(getShell());
        try {/*from w  w w  .jav a 2s .c  o  m*/
            pmDialog.run(true, false, new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    monitor.beginTask("Importing remote project from Git...", IProgressMonitor.UNKNOWN);
                    monitor.worked(20);
                    try {
                        workflowProject.getDesignerProxy().remoteImportVcs();
                    } catch (Exception ex) {
                        PluginMessages.log(ex);
                        throw new InvocationTargetException(ex);
                    }
                }
            });
        } catch (Exception ex) {
            PluginMessages.uiError(getShell(), ex, "Import From VCS", workflowProject);
        }
    }
}

From source file:com.centurylink.mdw.plugin.actions.WorkflowElementActionHandler.java

License:Apache License

public void syncOpenEditors(final WorkflowProject project) {
    final WorkflowProjectManager projectMgr = WorkflowProjectManager.getInstance();
    final List<ProcessEditor> processEditors = getOpenProcessEditors(project);
    final List<IEditorPart> assetEditors = getOpenAssetEditors(project);

    if (!processEditors.isEmpty() || !assetEditors.isEmpty()) {
        // sync open editors
        IRunnableWithProgress loader = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Loading " + project.getLabel(), 100);
                monitor.worked(25);/*from   ww w  .  jav  a 2s  .co  m*/

                // sync process editors
                for (ProcessEditor ed : processEditors) {
                    WorkflowProcess pv = ed.getProcess();
                    pv.setProject(projectMgr.getWorkflowProject(pv.getProject().getName()));
                    if (pv.getPackage() != null && !pv.getPackage().isDefaultPackage()) {
                        WorkflowPackage pkg = pv.getProject().getPackage(pv.getPackage().getName());
                        WorkflowProcess oldPv = pkg.getProcess(pv.getName());
                        if (oldPv != null)
                            pkg.removeProcess(oldPv);
                        pkg.addProcess(pv);
                        pv.setPackage(pkg);
                    }
                }
                monitor.worked(50);
                // sync asset editors
                Map<IFile, AssetWorkbenchListener> assetListeners = WorkflowAssetFactory
                        .getWorkbenchListeners();
                for (IEditorPart assetEd : assetEditors) {
                    FileEditorInput fileInput = (FileEditorInput) assetEd.getEditorInput();
                    AssetWorkbenchListener wbListener = assetListeners.get(fileInput.getFile());
                    if (wbListener != null) {
                        WorkflowAsset asset = wbListener.getAsset();
                        WorkflowProject wfProj = projectMgr.getWorkflowProject(asset.getProject().getName());
                        WorkflowAsset oldAsset = wfProj.getAsset(asset.getName(), asset.getLanguage(),
                                asset.getVersion());
                        if (asset.getPackage() != null && !asset.getPackage().isDefaultPackage()) {
                            WorkflowPackage pkg = wfProj.getPackage(asset.getPackage().getName());
                            if (pkg != null) {
                                pkg.removeAsset(oldAsset);
                                pkg.addAsset(asset);
                                asset.setPackage(pkg);
                            } else {
                                asset.setPackage(wfProj.getDefaultPackage());
                            }
                        } else {
                            asset.setPackage(wfProj.getDefaultPackage());
                        }

                        asset.addElementChangeListener(wfProj);

                        if (oldAsset != null)
                            WorkflowAssetFactory.deRegisterAsset(oldAsset);
                        WorkflowAssetFactory.registerAsset(asset);
                        assetEd.addPropertyListener(asset.new AssetEditorPropertyListener(assetEd));
                        WorkflowAssetFactory.registerWorkbenchListener(fileInput.getFile(), wbListener);
                    }
                }
                monitor.worked(25);
                monitor.done();
            }
        };

        ProgressMonitorDialog progMonDlg = new MdwProgressMonitorDialog(Display.getCurrent().getActiveShell());
        try {
            progMonDlg.run(true, false, loader);
        } catch (Exception ex) {
            PluginMessages.uiError(ex, "Sync Open Editors", project);
        }

    }
}

From source file:com.centurylink.mdw.plugin.designer.DesignerRunner.java

License:Apache License

public RunnerResult run(boolean forked) {
    result = new RunnerResult();

    shell = MdwPlugin.getActiveWorkbenchWindow().getShell();
    progressMonitorDialog = new MdwProgressMonitorDialog(shell);
    try {/* www .ja v  a  2 s.  c o  m*/
        shell.setFocus(); // this is absolutely needed
        progressMonitorDialog.run(forked, false, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(progressMessage, IProgressMonitor.UNKNOWN);
                try {
                    perform();
                    result.setStatus(RunnerStatus.SUCCESS);
                } catch (Exception ex) {
                    result.setStatus(RunnerStatus.FAILURE);
                    throw new InvocationTargetException(ex);
                }
            }
        });
        return result;
    } catch (Exception ex) {
        int messageLevel = PluginMessages.isDataIntegrityException(ex) ? PluginMessages.DATA_INTEGRITY_MESSAGE
                : PluginMessages.ERROR_MESSAGE;
        PluginMessages.uiMessage(shell, ex, errorMessage, workflowProject, messageLevel);
        if (ex.getCause() instanceof ValidationException) {
            if (DesignerProxy.INCOMPATIBLE_INSTANCES.equals(ex.getCause().getMessage())
                    || (ex.getCause().getMessage() != null
                            && ex.getCause().getMessage().contains(DesignerProxy.ALREADY_EXISTS)))
                result.setStatus(RunnerStatus.DISALLOW);
            else
                result.setStatus(RunnerStatus.INVALID);
        }

        return result;
    }
}

From source file:com.centurylink.mdw.plugin.designer.model.Template.java

License:Apache License

public void runWith(final String inputPath, final String outputLocation, final String velocityPropFile,
        final String velocityToolboxFile) {
    try {/*from w  w w .j  ava  2  s.c  o  m*/
        VelocityEngine engine = new VelocityEngine();
        Properties vProps = new Properties();
        if (velocityPropFile != null && velocityPropFile.length() > 0)
            vProps.load(new FileInputStream(velocityPropFile));
        String loadPath = vProps.getProperty("file.resource.loader.path");
        String tempFolder = getTempFolder().getLocation().toString();
        if (loadPath == null)
            loadPath = tempFolder;
        else
            loadPath += "," + tempFolder;
        vProps.setProperty("file.resource.loader.path", loadPath);
        engine.init(vProps);

        final VelocityContext velocityContext = getVelocityContext(velocityToolboxFile);

        final org.apache.velocity.Template velocityTemplate = engine.getTemplate(getTempFileName());

        final java.io.File input = new java.io.File(inputPath);
        if (input.isDirectory()) {
            ProgressMonitorDialog pmDialog = new MdwProgressMonitorDialog(
                    MdwPlugin.getActiveWorkbenchWindow().getShell());
            pmDialog.run(true, false, new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    java.io.File[] inputFiles = input.listFiles();
                    monitor.beginTask("Creating output files", inputFiles.length);
                    for (java.io.File inputFile : inputFiles) {
                        if (!inputFile.isDirectory()) {
                            String outputFile = outputLocation + "/" + getOutputFileName(inputFile.getName());
                            monitor.subTask(inputFile.getName());
                            InputStream inputStream = null;
                            try {
                                inputStream = new FileInputStream(inputFile);
                                processInput(inputStream, outputLocation, outputFile, velocityContext,
                                        velocityTemplate);
                            } catch (Exception ex) {
                                throw new InvocationTargetException(ex,
                                        "Problem applying input:\n'" + inputFile.getName() + "'");
                            } finally {
                                if (inputStream != null) {
                                    try {
                                        inputStream.close();
                                    } catch (Exception ex) {
                                    }
                                }

                            }
                        }
                        monitor.worked(1);
                    }
                }
            });

        } else {
            int sepIdx = inputPath.lastIndexOf(System.getProperty("file.separator"));
            String inputFileName = sepIdx == -1 ? inputPath : inputPath.substring(sepIdx + 1);
            String outputFile = outputLocation + "/" + getOutputFileName(inputFileName);
            processInput(new FileInputStream(inputPath), outputLocation, outputFile, velocityContext,
                    velocityTemplate);

            final IWorkbenchPage page = MdwPlugin.getActivePage();
            if (page != null) {
                IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(outputFile));
                IDE.openEditorOnFileStore(page, fileStore);
            }
        }
    } catch (InvocationTargetException ex) {
        PluginMessages.log(ex);
        String message = ex.getMessage() + ":\n\nCause:\n---------\n" + PluginMessages.getRootCause(ex);
        PluginMessages.uiError(message, "Run Template", getProject());
    } catch (Exception ex) {
        PluginMessages.uiError(ex, "Run Template", getProject());
    }
}

From source file:com.centurylink.mdw.plugin.designer.ToolboxWrapper.java

License:Apache License

/**
 * Reloads from the database.//  ww w  . j a  va2 s .  c  o m
 */
public void refresh() {
    try {
        IRunnableWithProgress loader = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                ProgressMonitor progressMonitor = new SwtProgressMonitor(monitor);
                progressMonitor.start("Loading Activity Implementors for " + getProject().getLabel());
                progressMonitor.progress(25);
                getProject().reloadActivityImplementors();
                progressMonitor.done();
            }
        };
        ProgressMonitorDialog progMonDlg = new MdwProgressMonitorDialog(Display.getCurrent().getActiveShell());
        progMonDlg.run(true, false, loader);
    } catch (Exception ex) {
        PluginMessages.uiError(ex, "Refresh Implementors", getProject());
    }
    update();
    clearDirty();
}

From source file:com.centurylink.mdw.plugin.designer.views.ProcessExplorerContentProvider.java

License:Apache License

public Object[] getChildren(Object parentElement) {
    if (parentElement instanceof WorkflowProject) {
        final WorkflowProject workflowProject = (WorkflowProject) parentElement;

        if (!workflowProject.isLoaded()) {
            try {
                IRunnableWithProgress loader = new IRunnableWithProgress() {
                    public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {
                        ProgressMonitor progressMonitor = new SwtProgressMonitor(monitor);
                        progressMonitor.start("Loading " + workflowProject.getLabel());
                        progressMonitor.progress(5);
                        try {
                            workflowProject.initialize(progressMonitor);
                            if (workflowProject.getDataAccess() != null) {
                                workflowProject.getTopLevelUserVisiblePackages(progressMonitor);
                                workflowProject.getArchivedUserVisiblePackagesFolder(progressMonitor);
                                progressMonitor.done();
                            }//  w  w w . ja  v a  2  s .c o  m
                        } catch (Exception ex) {
                            throw new InvocationTargetException(ex);
                        }
                    }
                };
                ProgressMonitorDialog progMonDlg = new MdwProgressMonitorDialog(MdwPlugin.getShell());
                progMonDlg.run(true, false, loader);
            } catch (InvocationTargetException itx) {
                if (itx.getCause() instanceof DataUnavailableException) {
                    PluginMessages.log(itx);
                    MessageDialog.openWarning(MdwPlugin.getShell(), "Load Workflow Project",
                            itx.getCause().getMessage());
                } else if (itx.getCause() instanceof DataAccessOfflineException) {
                    PluginMessages.log(itx);
                    MessageDialog.openError(MdwPlugin.getShell(), "Load Workflow Project",
                            itx.getCause().getMessage());
                    return new WorkflowPackage[0];
                } else {
                    PluginMessages.uiError(itx, "Load Workflow Project", workflowProject);
                    return new WorkflowPackage[0];
                }
            } catch (Exception ex) {
                PluginMessages.uiError(ex, "Load Workflow Project", workflowProject);
                return new WorkflowPackage[0];
            }
        }

        if (workflowProject.getDataAccess() == null)
            return new WorkflowPackage[0];

        List<WorkflowPackage> topLevelPackages = workflowProject.getTopLevelUserVisiblePackages();
        Folder archivedPackageFolder = workflowProject.getArchivedUserVisiblePackagesFolder();

        int size = topLevelPackages.size();
        boolean showArchived = isShowArchivedItems(workflowProject);
        if (showArchived)
            size++;

        AutomatedTestSuite testSuite = workflowProject.getLegacyTestSuite();
        if (testSuite != null && !testSuite.isEmpty())
            size++;

        Object[] objects = new Object[size];
        for (int i = 0; i < topLevelPackages.size(); i++)
            objects[i] = topLevelPackages.get(i);

        int cur = topLevelPackages.size();
        if (showArchived) {
            objects[cur] = archivedPackageFolder;
            cur++;
        }

        if (testSuite != null && !testSuite.isEmpty())
            objects[cur] = testSuite;

        return objects;
    } else if (parentElement instanceof WorkflowPackage) {
        WorkflowPackage packageVersion = (WorkflowPackage) parentElement;
        if (packageVersion.isArchived() && packageVersion.hasDescendantPackageVersions()) {
            return packageVersion.getDescendantPackageVersions().toArray(new WorkflowPackage[0]);
        } else {
            List<WorkflowElement> elements = new ArrayList<WorkflowElement>();
            IPreferenceStore prefsStore = MdwPlugin.getDefault().getPreferenceStore();

            if (!prefsStore.getBoolean(PreferenceConstants.PREFS_FILTER_PROCESSES_IN_PEX))
                elements.addAll(packageVersion.getProcesses());
            if (!prefsStore.getBoolean(PreferenceConstants.PREFS_FILTER_WORKFLOW_ASSETS_IN_PEX))
                elements.addAll(packageVersion.getAssets());
            if (!prefsStore.getBoolean(PreferenceConstants.PREFS_FILTER_EVENT_HANDLERS_IN_PEX))
                elements.addAll(packageVersion.getExternalEvents());
            if (prefsStore.getBoolean(PreferenceConstants.PREFS_SHOW_ACTIVITY_IMPLEMENTORS_IN_PEX))
                elements.addAll(packageVersion.getActivityImpls());
            if (!prefsStore.getBoolean(PreferenceConstants.PREFS_FILTER_TASK_TEMPLATES_IN_PEX))
                elements.addAll(packageVersion.getTaskTemplates());
            elements.addAll(packageVersion.getChildFolders());

            if (isSortPackageContentsAtoZ()) {
                Collections.sort(elements, new Comparator<WorkflowElement>() {
                    public int compare(WorkflowElement e1, WorkflowElement e2) {
                        return e1.getLabel().compareToIgnoreCase(e2.getLabel());
                    }
                });
            }

            return elements.toArray(new Object[0]);
        }
    } else if (parentElement instanceof WorkflowProcess) {
        WorkflowProcess processVersion = (WorkflowProcess) parentElement;
        if (processVersion.hasDescendantProcessVersions()) {
            return processVersion.getDescendantProcessVersions().toArray(new WorkflowProcess[0]);
        } else {
            return EMPTY_ARRAY;
        }
    } else if (parentElement instanceof Folder) {
        Folder folder = (Folder) parentElement;
        return folder.getChildren().toArray(new WorkflowElement[0]);
    } else if (parentElement instanceof AutomatedTestSuite) {
        AutomatedTestSuite testSuite = (AutomatedTestSuite) parentElement;
        return testSuite.getTestCases().toArray(new AutomatedTestCase[0]);
    } else if (parentElement instanceof AutomatedTestCase) {
        AutomatedTestCase testCase = (AutomatedTestCase) parentElement;
        if (!testCase.isLegacy())
            return EMPTY_ARRAY;
        List<LegacyExpectedResults> expectedResults = testCase.getLegacyExpectedResults();
        List<File> files = testCase.getFiles();
        Object[] objects = new Object[expectedResults.size() + files.size()];
        for (int i = 0; i < expectedResults.size(); i++)
            objects[i] = expectedResults.get(i);
        for (int i = expectedResults.size(); i < objects.length; i++)
            objects[i] = files.get(i - expectedResults.size());
        return objects;
    } else {
        return EMPTY_ARRAY;
    }
}

From source file:com.centurylink.mdw.plugin.designer.wizards.ImportExportWizard.java

License:Apache License

@Override
public boolean performFinish() {
    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            ProgressMonitor progressMonitor = new SwtProgressMonitor(monitor);
            try {
                progressMonitor.start((page.isExport ? "Exporting from " : "Importing into ") + "'"
                        + getProject().getLabel() + "'");
                progressMonitor.progress(5);

                performImportExport(progressMonitor);
                progressMonitor.done();/*w  w  w  . jav a  2 s . c o m*/
            } catch (ActionCancelledException ex) {
                throw new OperationCanceledException();
            } catch (Exception ex) {
                PluginMessages.log(ex);
                throw new InvocationTargetException(ex);
            }
        }
    };

    try {
        getContainer().run(true, true, op);
        postRunUpdates();
        return true;
    } catch (InvocationTargetException ex) {
        if (ex.getCause() instanceof DataAccessOfflineException)
            MessageDialog.openError(getShell(), "Export Attributes",
                    "Server appears to be offline: " + ex.getMessage());
        else
            PluginMessages.uiError(getShell(), ex, page.getTitle(), getProject());
        return false;
    } catch (Exception ex) {
        PluginMessages.uiError(getShell(), ex, page.getTitle(), getProject());
        return false;
    }
}