Example usage for org.eclipse.jface.dialogs ProgressMonitorDialog ProgressMonitorDialog

List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog ProgressMonitorDialog

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs ProgressMonitorDialog ProgressMonitorDialog.

Prototype

public ProgressMonitorDialog(Shell parent) 

Source Link

Document

Creates a progress monitor dialog under the given shell.

Usage

From source file:de.plugins.eclipse.depclipse.preferences.JDependPreferencePage.java

License:Open Source License

/**
 * Utility method to create and return a selection dialog that allows
 * selection of a specific Java package.  Empty packages are not returned.
 * If Java Projects are provided, only packages found within those projects
 * are included.  If no Java projects are provided, all Java projects in the
 * workspace are considered.// w w w.  java2 s .  c  o  m
 */
public static ElementListSelectionDialog createAllPackagesDialog(Shell shell, IJavaProject[] originals,
        final boolean includeDefaultPackage) throws JavaModelException {
    final List<IPackageFragment> packageList = new ArrayList<IPackageFragment>();
    if (originals == null) {
        IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
        IJavaModel model = JavaCore.create(wsroot);
        originals = model.getJavaProjects();
    }
    final IJavaProject[] projects = originals;
    final JavaModelException[] exception = new JavaModelException[1];
    ProgressMonitorDialog monitor = new ProgressMonitorDialog(shell);
    IRunnableWithProgress r = new IRunnableWithProgress() {
        public void run(IProgressMonitor myMonitor) {
            try {
                Set<String> packageNameSet = new HashSet<String>();
                myMonitor.beginTask(Messages.JDependPreferencePage_Searching_Progress_Monitor, projects.length);
                for (int i = 0; i < projects.length; i++) {
                    IPackageFragment[] pkgs = projects[i].getPackageFragments();
                    for (int j = 0; j < pkgs.length; j++) {
                        IPackageFragment pkg = pkgs[j];
                        if (!pkg.hasChildren() && (pkg.getNonJavaResources().length > 0)) {
                            continue;
                        }
                        String pkgName = pkg.getElementName();
                        if (!includeDefaultPackage && pkgName.length() == 0) {
                            continue;
                        }
                        if (packageNameSet.add(pkgName)) {
                            packageList.add(pkg);
                        }
                    }
                    myMonitor.worked(1);
                }
                myMonitor.done();
            } catch (JavaModelException jme) {
                exception[0] = jme;
            }
        }
    };
    try {
        monitor.run(false, false, r);
    } catch (InvocationTargetException e) {
        DepclipsePlugin.logError(e, "ooo"); //$NON-NLS-1$
    } catch (InterruptedException e) {
        DepclipsePlugin.logError(e, "ooo"); //$NON-NLS-1$
    }
    if (exception[0] != null) {
        throw exception[0];
    }
    int flags = JavaElementLabelProvider.SHOW_DEFAULT;
    ElementListSelectionDialog dialog = new ElementListSelectionDialog(shell,
            new JavaElementLabelProvider(flags));
    dialog.setIgnoreCase(false);
    dialog.setElements(packageList.toArray()); // XXX inefficient
    return dialog;
}

From source file:de.quamoco.adaptation.model.presentation.AdaptationModelEditor.java

License:Apache License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model file.
 * <!-- begin-user-doc -->/*from   w  ww  .  j  a  va2 s . c o  m*/
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void doSave(IProgressMonitor progressMonitor) {
    // Save only resources that have actually changed.
    //
    final Map<Object, Object> saveOptions = new HashMap<Object, Object>();
    saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);

    // Do the work within an operation because this is a long running activity that modifies the workbench.
    //
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
        // This is the method that gets invoked when the operation runs.
        //
        @Override
        public void execute(IProgressMonitor monitor) {
            // Save the resources to the file system.
            //
            boolean first = true;
            for (Resource resource : editingDomain.getResourceSet().getResources()) {
                if ((first || !resource.getContents().isEmpty() || isPersisted(resource))
                        && !editingDomain.isReadOnly(resource)) {
                    try {
                        long timeStamp = resource.getTimeStamp();
                        resource.save(saveOptions);
                        if (resource.getTimeStamp() != timeStamp) {
                            savedResources.add(resource);
                        }
                    } catch (Exception exception) {
                        resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
                    }
                    first = false;
                }
            }
        }
    };

    updateProblemIndication = false;
    try {
        // This runs the options, and shows progress.
        //
        new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);

        // Refresh the necessary state.
        //
        ((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone();
        firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (Exception exception) {
        // Something went wrong that shouldn't.
        //
        AdaptationEditorPlugin.INSTANCE.log(exception);
    }
    updateProblemIndication = true;
    updateProblemIndication();
}

From source file:de.quamoco.qm.application.QmEditorAdvisor.java

License:Apache License

/**
 * {@inheritDoc}/* w ww  . ja  va 2s  . c  o m*/
 */
@Override
public void postShutdown() {
    // save the workspace
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) {
            try {
                ResourcesPlugin.getWorkspace().save(true, monitor);
            } catch (CoreException e) {
                QmEditorPlugin.INSTANCE.log(e);
            }
        }
    };

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(Display.getDefault().getActiveShell());
    try {
        dialog.run(true, true, runnable);
    } catch (InvocationTargetException e) {
        QmEditorPlugin.INSTANCE.log(e);
    } catch (InterruptedException e) {
        QmEditorPlugin.INSTANCE.log(e);
    }
}

From source file:de.quamoco.qm.conqat.wizard.GeneratorPage.java

License:Apache License

/**
 * Run generator.//from ww w. j  a  va2s .  co  m
 * 
 * @return always returns <code>true</code>
 */
@Override
public boolean performFinish() {

    final String bundleLocation = bundleLocationText.getText();
    final String blockName = blockNameText.getText();
    final String language = LANGUAGES[languageCombo.getSelectionIndex()];

    getDialogSettings().put(BUNDLE_LOCATION_KEY, bundleLocation);
    getDialogSettings().put(BLOCK_NAME_KEY, blockName);
    getDialogSettings().put(LANGUAGE_INDEX_KEY, languageCombo.getSelectionIndex());

    IRunnableWithProgress op = new IRunnableWithProgress() {
        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                new ConQATBlockGenerator(new File(bundleLocation), blockName, language, models)
                        .generate(monitor);
            } catch (IOException e) {
                throw new InvocationTargetException(e);
            } catch (ConQATBlockGenerationException e) {
                throw new InvocationTargetException(e);
            }

        }
    };

    try {
        new ProgressMonitorDialog(getShell()).run(true, true, op);
    } catch (InvocationTargetException e) {
        Throwable targetException = e.getTargetException();
        String message;
        if (targetException instanceof ConQATBlockGenerationException) {
            message = "Block could not be generated: " + targetException.getMessage();
        } else {
            message = "Unexpected error: " + targetException.getMessage() + StringUtils.CR
                    + StringUtils.obtainStackTrace(targetException);
        }
        MessageUtils.showError("Error", message);

    } catch (InterruptedException e) {
        MessageUtils.showError("Error", e.getMessage());
    }
    return true;
}

From source file:de.quamoco.qm.editor.action.EvaluateAction.java

License:Apache License

/** {@inheritDoc} */
@Override//from w  ww . j  av  a2  s.  c o  m
public void run(IAction action) {
    EvaluateWizardPageBase page = "Java".equals(model.getName()) ? new JavaEvaluateWizardPage(model, editor)
            : new CSharpEvaluationWizardPage(model, editor);
    Wizard wizard = new SinglePageWizard(page);
    WizardDialog dialog = new WizardDialog(Display.getDefault().getActiveShell(), wizard);
    if (dialog.open() == IDialogConstants.OK_ID) {
        ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(Display.getDefault().getActiveShell());
        try {
            progressDialog.run(true, true, page.getRunnable());
        } catch (InvocationTargetException e) {
            reportError(e, "Quality evaluation could not be started");
        } catch (InterruptedException e) {
            reportError(e, "Quality evaluation has been interrupted");
        }
    }
}

From source file:de.quamoco.qm.editor.CustomQmEditor.java

License:Apache License

/** Perform migration of the model if necessary. */
private void checkMigration(final URI resourceURI) {
    String nsURI = ReleaseUtils.getNamespaceURI(resourceURI);
    final Migrator migrator = MigratorRegistry.getInstance().getMigrator(nsURI);
    if (migrator != null) {
        final Release release = migrator.getRelease(resourceURI).iterator().next();
        if (!release.isLatestRelease()) {
            IFile[] files = WorkspaceResourceDialog.openFileSelection(Display.getDefault().getActiveShell(),
                    "Select Files", "Select the files that need to be migrated together", true,
                    new Object[] { URIUtils.getFile(resourceURI) }, Collections.<ViewerFilter>emptyList());
            if (files.length == 0) {
                return;
            }//from  w w w. ja v  a  2s.  c  o  m
            final List<URI> uris = new ArrayList<URI>();
            for (IFile file : files) {
                uris.add(URIUtils.getURI(file));
            }
            IRunnableWithProgress runnable = new IRunnableWithProgress() {

                public void run(IProgressMonitor monitor) throws InvocationTargetException {
                    try {
                        ResourceSet resourceSet = migrator.migrateAndLoad(uris, release, null, monitor);
                        editingDomain.getResourceSet().getResources().addAll(resourceSet.getResources());
                    } catch (MigrationException e) {
                        throw new InvocationTargetException(e);
                    }
                }

            };
            try {
                new ProgressMonitorDialog(Display.getCurrent().getActiveShell()).run(false, false, runnable);
            } catch (InvocationTargetException e) {
                MessageDialog.openError(Display.getDefault().getActiveShell(), "Migration error",
                        "An error occured during migration of the model. More information on the error can be found in the error log.");
                QmEditorPlugin.getPlugin().log(e.getCause());
            } catch (InterruptedException e) {
                QmEditorPlugin.getPlugin().log(e);
            }
        }
    }
}

From source file:de.quamoco.qm.editor.export.ImportExportActionBase.java

License:Apache License

/** Perform a long-running task on a file. */
private boolean process(final String fileName) {
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(Display.getDefault().getActiveShell());
    try {/* www.j a v a2 s.c o m*/
        dialog.run(true, false, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException {
                doProcess(fileName, monitor);
            }
        });
        return true;
    } catch (InvocationTargetException e) {
        LoggingUtils.error(QmEditorPlugin.getPlugin(), "Error during export", e);
        MessageDialog.openError(Display.getDefault().getActiveShell(), "Error during export",
                e.getCause().getMessage());
    } catch (InterruptedException e) {
        LoggingUtils.error(QmEditorPlugin.getPlugin(), "Interruption during export", e);
        MessageDialog.openError(Display.getDefault().getActiveShell(), "Interruption during export",
                e.getMessage());
    }
    return false;
}

From source file:de.quamoco.qm.presentation.QmEditor.java

License:Apache License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model file.
 * <!-- begin-user-doc -->/*ww  w  .j  a v  a 2  s  . c om*/
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void doSave(IProgressMonitor progressMonitor) {
    // Save only resources that have actually changed.
    //
    final Map<Object, Object> saveOptions = new HashMap<Object, Object>();
    saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);

    // Do the work within an operation because this is a long running activity that modifies the workbench.
    //
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
        // This is the method that gets invoked when the operation runs.
        //
        @Override
        public void execute(IProgressMonitor monitor) {
            // Save the resources to the file system.
            //
            boolean first = true;
            for (Resource resource : editingDomain.getResourceSet().getResources()) {
                if ((first || !resource.getContents().isEmpty() || isPersisted(resource))
                        && !editingDomain.isReadOnly(resource)) {
                    try {
                        long timeStamp = resource.getTimeStamp();
                        resource.save(saveOptions);
                        if (resource.getTimeStamp() != timeStamp) {
                            savedResources.add(resource);
                        }
                    } catch (Exception exception) {
                        resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
                    }
                    first = false;
                }
            }
        }
    };

    updateProblemIndication = false;
    try {
        // This runs the options, and shows progress.
        //
        new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);

        // Refresh the necessary state.
        //
        ((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone();
        firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (Exception exception) {
        // Something went wrong that shouldn't.
        //
        QmEditorPlugin.INSTANCE.log(exception);
    }
    updateProblemIndication = true;
    updateProblemIndication();
}

From source file:de.rowlo.diffeclipse.event.ButtonExtractMissingExtensionsHandler.java

License:Open Source License

protected void extractSelectedElements(IStructuredSelection selection) {
    final Text text = getTargetLocationText();
    if (selection != null && text != null) {
        final String sourceLocation = DiffEclipseUtil.INSTANCE.getExtendedEclipseLocation();
        final String targetLocation = text.getText();
        final String dropStructure = File.separator + "additionalExtensions" + File.separator + "eclipse";

        final List<?> selectedElements = selection.toList();
        final int size = count(selectedElements);
        final ArrayList<Integer> counterResult = new ArrayList<Integer>(1);
        Shell shell = text.getShell();/*from   w  w  w  .j a v a2  s  .c o  m*/
        try {
            ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(shell);
            progressMonitorDialog.run(true, true, new IRunnableWithProgress() {
                @Override
                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    String taskMsg = MessageFormat.format("Extracting Missing Extensions to: {0}",
                            targetLocation + dropStructure);
                    monitor.beginTask(taskMsg, size);
                    totalCounter = 0;
                    processElements(selectedElements, monitor);
                    counterResult.clear();
                    counterResult.add(totalCounter);
                    monitor.done();
                    if (monitor.isCanceled()) {
                        throw new InterruptedException("The long extraction was cancelled");
                    }
                }

                private void processElements(List<?> selectedElements, IProgressMonitor monitor) {
                    if (selectedElements == null || monitor == null) {
                        return;
                    }
                    for (Object selectedElement : selectedElements) {
                        if (selectedElement instanceof TreeModel) {
                            TreeModel treeModel = (TreeModel) selectedElement;
                            String filePath = treeModel.getFilePath();
                            String sourceFilePath = sourceLocation + filePath;
                            String targetFilePath = targetLocation + dropStructure + filePath;
                            if (treeModel.isFile()) {
                                copyFile(sourceFilePath, targetFilePath);
                            } else {
                                createDirectory(targetFilePath);
                                ArrayList<Object> childElements = new ArrayList<Object>(treeModel.children);
                                processElements(childElements, monitor);
                            }
                            totalCounter++;
                            monitor.worked(1);
                            String taskMsg = MessageFormat.format(
                                    "Extracting Missing Extensions to: {0} ({1}/{2})",
                                    targetLocation + dropStructure, totalCounter, size);
                            monitor.setTaskName(taskMsg);
                        }
                    }
                }
            });
        } catch (InvocationTargetException e) {
            MessageDialog.openError(shell, "Error", e.getMessage());
        } catch (InterruptedException e) {
            MessageDialog.openInformation(shell, "Cancelled", e.getMessage());
        }

        int counter = counterResult.size() > 0 ? counterResult.get(0) : 0;
        String msg = MessageFormat.format("Extracted {1} extensions to: {0}", targetLocation + dropStructure,
                counter);
        MessageDialog.openInformation(shell, "Extract Missing Extensions", msg);
    }
}

From source file:de.thischwa.pmcms.gui.dialog.DialogManager.java

License:LGPL

/**
 * Open the progress dialog and run a {@link IProgressViewer}.
 *///from   w  ww  .  j a v a  2 s.com
public static void startProgressDialog(final Shell parentShell, final IProgressViewer progressViewer) {
    IRunnableWithProgress runnableWithProgress = new IRunnableWithProgress() {
        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            progressViewer.setMonitor(monitor);
            try {
                progressViewer.run();
            } catch (Exception e) {
                logger.error("While IProgressViewer was running: " + e.getMessage(), e);
                throw new ProgressException(e);
            }
        }
    };

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(parentShell);
    try {
        dialog.run(true, true, runnableWithProgress);
    } catch (Exception e) {
        throw new FatalException(e.getCause().getMessage(), e.getCause());
    }
}