Java Code Examples for org.eclipse.jface.wizard.IWizardContainer#run()

The following examples show how to use org.eclipse.jface.wizard.IWizardContainer#run() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeployArtifactsHandler.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected IStatus deployArtifacts(RepositoryAccessor repositoryAccessor,
        Collection<Artifact> artifactsToDeploy,
        Map<String, Object> deployOptions,
        IWizardContainer container) {
    MultiStatus status = new MultiStatus(ApplicationPlugin.PLUGIN_ID, 0, null, null);
    if (!checkDirtyState(container)) {
        return null;
    }
    try {
        container.run(true, true,
                performFinish(repositoryAccessor, artifactsToDeploy, deployOptions, status));
    } catch (InvocationTargetException | InterruptedException e) {
        BonitaStudioLog.error(e);
        return new Status(IStatus.ERROR, ApplicationPlugin.PLUGIN_ID, "Deploy failed",
                e.getCause() != null ? e.getCause() : e);
    }
    if (status.getSeverity() == IStatus.CANCEL) {
        openAbortDialog(Display.getDefault().getActiveShell());
    }
    return status.getSeverity() == IStatus.CANCEL ? null : status;
}
 
Example 2
Source File: DeployArtifactsHandler.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private boolean checkDirtyState(IWizardContainer container) {
    if (PlatformUI.isWorkbenchRunning()
            && PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null
            && PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() != null) {
        List<IEditorPart> dirtyEditors = Arrays
                .asList(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences())
                .stream()
                .map(ref -> ref.getEditor(false))
                .filter(editorPart -> editorPart != null)
                .filter(IEditorPart::isDirty)
                .collect(Collectors.toList());
        if (!dirtyEditors.isEmpty()) {
            SaveStrategy strategy = saveDirtyEditors();
            if (Objects.equals(strategy, SaveStrategy.CANCEL)) {
                return false;
            } else if (Objects.equals(strategy, SaveStrategy.SAVE)) {
                try {
                    container.run(false, false, monitor -> {
                        monitor.beginTask(Messages.savingEditors, dirtyEditors.size());
                        dirtyEditors.forEach(editor -> {
                            editor.doSave(monitor);
                            monitor.worked(1);
                        });
                        monitor.done();
                    });
                } catch (InvocationTargetException | InterruptedException e) {
                    throw new RuntimeException("An error occured while saving editors", e);
                }
            }
        }
    }
    return true;
}