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

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

Introduction

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

Prototype

@Override
public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
        throws InvocationTargetException, InterruptedException 

Source Link

Document

This implementation of IRunnableContext#run(boolean, boolean, IRunnableWithProgress) runs the given IRunnableWithProgress using the progress monitor for this progress dialog and blocks until the runnable has been run, regardless of the value of fork.

Usage

From source file:org.eclipse.gmf.runtime.diagram.ui.render.actions.CopyToImageAction.java

License:Open Source License

/**
 * Displays the dialog and performs <code>OutOfMemoryError</code> checking
 * /*from  w w w.  jav a 2s  .  c  o m*/
 * @param dialog the copy to image dialog
 */
private void runCopyToImageUI(CopyToImageDialog dialog) {
    if (dialog.open() == CopyToImageDialog.CANCEL) {
        return;
    }

    if (!overwriteExisting()) {
        return;
    }

    Trace.trace(DiagramUIRenderPlugin.getInstance(), "Copy Diagram to " + dialog.getDestination().toOSString() //$NON-NLS-1$
            + " as " + dialog.getImageFormat().toString()); //$NON-NLS-1$

    final MultiStatus status = new MultiStatus(DiagramUIRenderPlugin.getPluginId(),
            DiagramUIRenderStatusCodes.OK, DiagramUIRenderMessages.CopyToImageAction_Label, null);

    IRunnableWithProgress runnable = createRunnable(status);

    ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(
            Display.getCurrent().getActiveShell());
    try {
        progressMonitorDialog.run(false, true, runnable);
    } catch (InvocationTargetException e) {
        Log.warning(DiagramUIRenderPlugin.getInstance(), DiagramUIRenderStatusCodes.IGNORED_EXCEPTION_WARNING,
                e.getTargetException().getMessage(), e.getTargetException());

        if (e.getTargetException() instanceof OutOfMemoryError) {
            if (dialog.exportToHTML()) {
                openErrorDialog(DiagramUIRenderMessages.CopyToImageAction_outOfMemoryMessage);
            } else {
                if (new MessageDialog(dialog.getShell(),
                        DiagramUIRenderMessages.CopyToImageOutOfMemoryDialog_title, null,
                        DiagramUIRenderMessages.CopyToImageOutOfMemoryDialog_message, MessageDialog.ERROR,
                        new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0)
                                .open() == 0) {
                    runCopyToImageUI(dialog);
                }
            }
        } else if (e.getTargetException() instanceof SWTError) {
            /**
             * SWT returns an out of handles error when processing large
             * diagrams
             */
            if (dialog.exportToHTML()) {
                openErrorDialog(DiagramUIRenderMessages.CopyToImageAction_outOfMemoryMessage);
            } else {
                if (new MessageDialog(dialog.getShell(),
                        DiagramUIRenderMessages.CopyToImageOutOfMemoryDialog_title, null,
                        DiagramUIRenderMessages.CopyToImageOutOfMemoryDialog_message, MessageDialog.ERROR,
                        new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0)
                                .open() == 0) {
                    runCopyToImageUI(dialog);
                }
            }
        } else {
            openErrorDialog(e.getTargetException().getMessage());
        }
        return;
    } catch (InterruptedException e) {
        /* the user pressed cancel */
        Log.warning(DiagramUIRenderPlugin.getInstance(), DiagramUIRenderStatusCodes.IGNORED_EXCEPTION_WARNING,
                e.getMessage(), e);
    }

    if (!status.isOK()) {
        openErrorDialog(status.getChildren()[0].getMessage());
    }
}

From source file:org.eclipse.gmf.tests.runtime.diagram.ui.logic.LogicCreationTests.java

License:Open Source License

public void test_bugzilla124678() {
    final Command cc = getLongProgressCommand();

    IRunnableWithProgress runnable = new IRunnableWithProgress() {

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

            ((DiagramCommandStack) getCommandStack()).execute(cc, monitor);
        }// ww  w .  j  a v  a 2s .  c o m

    };
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
    try {
        dialog.run(true, true, runnable);
    } catch (InvocationTargetException e) {
        assertTrue(false);
    } catch (InterruptedException e) {
        assertTrue(false);
    }
}

From source file:org.eclipse.jdt.internal.debug.ui.jres.InstalledJREsBlock.java

License:Open Source License

/**
 * Search for installed VMs in the file system
 *///from   w w w  .j  av  a2s  .  co  m
protected void search() {
    if (Platform.OS_MACOSX.equals(Platform.getOS())) {
        doMacSearch();
        return;
    }
    // choose a root directory for the search 
    DirectoryDialog dialog = new DirectoryDialog(getShell());
    dialog.setMessage(JREMessages.InstalledJREsBlock_9);
    dialog.setText(JREMessages.InstalledJREsBlock_10);
    String path = dialog.open();
    if (path == null) {
        return;
    }

    // ignore installed locations
    final Set<File> exstingLocations = new HashSet<File>();
    for (IVMInstall vm : fVMs) {
        exstingLocations.add(vm.getInstallLocation());
    }

    // search
    final File rootDir = new File(path);
    final List<File> locations = new ArrayList<File>();
    final List<IVMInstallType> types = new ArrayList<IVMInstallType>();

    IRunnableWithProgress r = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) {
            monitor.beginTask(JREMessages.InstalledJREsBlock_11, IProgressMonitor.UNKNOWN);
            search(rootDir, locations, types, exstingLocations, monitor);
            monitor.done();
        }
    };

    try {
        ProgressMonitorDialog progress = new ProgressMonitorDialog(getShell()) {
            /*
             * Overridden createCancelButton to replace Cancel label with Stop label
             * More accurately reflects action taken when button pressed.
             * Bug [162902]
             */
            @Override
            protected void createCancelButton(Composite parent) {
                cancel = createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.STOP_LABEL, true);
                if (arrowCursor == null) {
                    arrowCursor = new Cursor(cancel.getDisplay(), SWT.CURSOR_ARROW);
                }
                cancel.setCursor(arrowCursor);
                setOperationCancelButtonEnabled(enableCancelButton);
            }
        };
        progress.run(true, true, r);
    } catch (InvocationTargetException e) {
        JDIDebugUIPlugin.log(e);
    } catch (InterruptedException e) {
        // canceled
        return;
    }

    if (locations.isEmpty()) {
        String messagePath = path.replaceAll("&", "&&"); // @see bug 29855  //$NON-NLS-1$//$NON-NLS-2$
        MessageDialog.openInformation(getShell(), JREMessages.InstalledJREsBlock_12,
                NLS.bind(JREMessages.InstalledJREsBlock_13, new String[] { messagePath })); // 
    } else {
        Iterator<IVMInstallType> iter2 = types.iterator();
        for (File location : locations) {
            IVMInstallType type = iter2.next();
            AbstractVMInstall vm = new VMStandin(type, createUniqueId(type));
            String name = location.getName();
            String nameCopy = new String(name);
            int i = 1;
            while (isDuplicateName(nameCopy)) {
                nameCopy = name + '(' + i++ + ')';
            }
            vm.setName(nameCopy);
            vm.setInstallLocation(location);
            if (type instanceof AbstractVMInstallType) {
                //set default java doc location
                AbstractVMInstallType abs = (AbstractVMInstallType) type;
                vm.setJavadocLocation(abs.getDefaultJavadocLocation(location));
                vm.setVMArgs(abs.getDefaultVMArguments(location));
            }
            vmAdded(vm);
        }
    }
}

From source file:org.eclipse.jdt.internal.debug.ui.jres.InstalledJREsBlock.java

License:Open Source License

/**
 * Calls out to {@link MacVMSearch} to find all installed JREs in the standard
 * Mac OS location//w  w  w.  ja va 2 s .  co m
 */
private void doMacSearch() {
    final List<VMStandin> added = new ArrayList<VMStandin>();
    IRunnableWithProgress r = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            Set<String> exists = new HashSet<String>();
            for (IVMInstall vm : fVMs) {
                exists.add(vm.getId());
            }
            SubMonitor localmonitor = SubMonitor.convert(monitor, JREMessages.MacVMSearch_0, 5);
            VMStandin[] standins = null;
            try {
                standins = MacInstalledJREs.getInstalledJREs(localmonitor);
                for (int i = 0; i < standins.length; i++) {
                    if (!exists.contains(standins[i].getId())) {
                        added.add(standins[i]);
                    }
                }
            } catch (CoreException ce) {
                JDIDebugUIPlugin.log(ce);
            }
            monitor.done();
        }
    };

    try {
        ProgressMonitorDialog progress = new ProgressMonitorDialog(getShell());
        progress.run(true, true, r);
    } catch (InvocationTargetException e) {
        JDIDebugUIPlugin.log(e);
    } catch (InterruptedException e) {
        // canceled
        return;
    }
    for (VMStandin vm : added) {
        vmAdded(vm);
    }
}

From source file:org.eclipse.jface.snippets.dialogs.Snippet058VistaProgressBars.java

License:Open Source License

/**
 * Open a progress monitor dialog and switch the blocking.
 *
 * @param args/*from   ww  w . j a va 2s .co  m*/
 */
public static void main(String[] args) {

    Display display = new Display();

    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
    IRunnableWithProgress runnable = createRunnableFor(dialog);
    try {
        dialog.run(true, true, runnable);
    } catch (InvocationTargetException | InterruptedException e) {
        e.printStackTrace();
    }

    display.dispose();
}

From source file:org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditor.java

License:Open Source License

private void initWithFileEditorInput(final IEditorSite site, final IFile entityFile) {
    Diagram diagram = null;/*from w  w  w  . ja  v  a  2  s.c  o  m*/
    try {
        ProgressMonitorDialog dialog = new ProgressMonitorDialog(site.getShell());
        dialog.run(true, false, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(JPAEditorMessages.JPADiagramEditor_waitingForMoin, IProgressMonitor.UNKNOWN);
                monitor.done();
            }
        });

        inputJptType = JPAEditorUtil.getJPType(JavaCore.createCompilationUnitFrom(entityFile));
        setPartProperty(JPAEditorConstants.OPEN_WHOLE_PERSISTENCE_UNIT_EDITOR_PROPERTY, inputJptType.getName());
        PersistenceUnit persistenceUnit = inputJptType.getPersistenceUnit();
        String diagramURIAsString = ModelIntegrationUtil.createDiagramPath(persistenceUnit).toString();
        URI diagramURI = URI.createFileURI(diagramURIAsString);
        diagram = ModelIntegrationUtil.createDiagram(persistenceUnit, 10, true);
        JPADiagramEditorInput diagramInput = new JPADiagramEditorInput(diagram, diagramURI,
                JPAEditorDiagramTypeProvider.ID);
        //ModelIntegrationUtil.mapDiagramToProject(diagram, persistenceUnit
        //      .getJpaProject());
        super.init(site, diagramInput);
    } catch (CoreException e) {
        JPADiagramEditorPlugin.getDefault().getLog().log(e.getStatus());
        //ModelIntegrationUtil.removeDiagramProjectMapping(diagram);
    } catch (InvocationTargetException e) {
        IStatus status = new Status(IStatus.ERROR, JPADiagramEditorPlugin.PLUGIN_ID, e.getMessage(), e);
        JPADiagramEditorPlugin.getDefault().getLog().log(status);
        //ModelIntegrationUtil.removeDiagramProjectMapping(diagram);
    } catch (InterruptedException e) {
        IStatus status = new Status(IStatus.ERROR, JPADiagramEditorPlugin.PLUGIN_ID, e.getMessage(), e);
        JPADiagramEditorPlugin.getDefault().getLog().log(status);
        //ModelIntegrationUtil.removeDiagramProjectMapping(diagram);
    }
}

From source file:org.eclipse.jst.ws.internal.consumption.ui.command.StartServerCommand.java

License:Open Source License

private IStatus publish(final IServer server, final int kind, IProgressMonitor monitor) {
    IStatus status = Status.OK_STATUS;//from   w w w.  j a v  a2  s. c o m
    final IStatus[] istatus = new IStatus[1];
    monitor.subTask(ConsumptionMessages.PROGRESS_INFO_PUBLISHING_SERVER);
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor shellMonitor) throws InvocationTargetException, InterruptedException {
            ServerPublishOperationListener publishListener = new ServerPublishOperationListener();
            server.publish(IServer.PUBLISH_INCREMENTAL, null, null, publishListener);
            istatus[0] = publishListener.getPublishStatus();
        }
    };

    try {
        if (doAsyncPublish_) {
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
            dialog.run(true, true, runnable);
        } else {
            runnable.run(monitor);
        }

    } catch (InvocationTargetException ite) {
        istatus[0] = new org.eclipse.core.runtime.Status(IStatus.ERROR, "id", 0, ite.getMessage(), ite);
        ite.printStackTrace();
    } catch (InterruptedException ie) {
        istatus[0] = new org.eclipse.core.runtime.Status(IStatus.ERROR, "id", 0, ie.getMessage(), ie);
        ie.printStackTrace();
    }

    if (istatus[0].getSeverity() != IStatus.OK) {
        status = istatus[0];
        if (status.getSeverity() == IStatus.CANCEL)
            status = StatusUtils.errorStatus("");
        return status;
    }

    log.log(ILog.INFO, 5051, this, "publishProject", "IServer=" + server + ", Publish command completed");
    return status;
}

From source file:org.eclipse.jubula.client.ui.rcp.handlers.OMEDeleteUnusedComponentNamesHandler.java

License:Open Source License

/**
 * {@inheritDoc}/* www . j av  a2  s.  co m*/
 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ObjectMappingMultiPageEditor editor = ((ObjectMappingMultiPageEditor) HandlerUtil
            .getActivePartChecked(event));
    if (editor.getEditorHelper().requestEditableState() != EditableState.OK) {
        return null;
    }
    // run in UI thread
    List<Object> allTreeElements = new ArrayList<Object>();
    for (final TreeViewer tv : editor.getTreeViewers()) {
        OMEditorTreeContentProvider ometcp = (OMEditorTreeContentProvider) tv.getContentProvider();
        for (Object o : ometcp.getElements(tv.getInput())) {
            allTreeElements.addAll(getAllElements(o, ometcp));
        }
    }
    final Object[] aObjects = allTreeElements.toArray();
    final Shell activeShell = HandlerUtil.getActiveShell(event).getShell();
    // run in background
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(activeShell);
    try {
        dialog.run(true, true, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) {
                monitor.beginTask(Messages.Searching, aObjects.length);
                final OMEUsedComponentNameSearch vf = new OMEUsedComponentNameSearch(editor.getAut());
                vf.performSearch(aObjects, monitor);

                final List<IComponentNamePO> unusedNames = new ArrayList<IComponentNamePO>();

                for (Object o : vf.getResult().keySet()) {
                    if (o instanceof IComponentNamePO) {
                        if (vf.getResult().get(o)) {
                            unusedNames.add((IComponentNamePO) o);
                        }
                    }
                }
                if (unusedNames.size() > 0) {
                    if (!monitor.isCanceled()) {
                        openDialog(unusedNames, editor);
                    }
                } else {
                    Plugin.getDisplay().syncExec(new Runnable() {
                        public void run() {
                            MessageDialog.openInformation(activeShell,
                                    Messages.CleanCompNamesNoResultDialogTitle,
                                    Messages.CleanCompNamesNoResultDialogMsg);
                        }
                    });
                }
                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
        LOG.error(e.getLocalizedMessage(), e);
    } catch (InterruptedException e) {
        LOG.error(e.getLocalizedMessage(), e);
    }
    return null;
}

From source file:org.eclipse.jubula.client.ui.rcp.wizards.pages.ImportXLSTestdataWizardPage.java

License:Open Source License

/**
 * Update the tree to only select those elements that match the selected
 * types//from w w  w.  j  a v a  2 s . c o m
 */
protected void setupSelectionsBasedOnSelectedTypes() {
    ProgressMonitorDialog dialog = new ProgressMonitorJobsDialog(getContainer().getShell());
    final Map selectionMap = new Hashtable();
    final IElementFilter filter = new IElementFilter() {
        public void filterElements(Collection files, IProgressMonitor monitor) throws InterruptedException {
            if (files == null) {
                throw new InterruptedException();
            }
            Iterator filesList = files.iterator();
            while (filesList.hasNext()) {
                if (monitor.isCanceled()) {
                    throw new InterruptedException();
                }
                checkFile(filesList.next());
            }
        }

        public void filterElements(Object[] files, IProgressMonitor monitor) throws InterruptedException {
            if (files == null) {
                throw new InterruptedException();
            }
            for (int i = 0; i < files.length; i++) {
                if (monitor.isCanceled()) {
                    throw new InterruptedException();
                }
                checkFile(files[i]);
            }
        }

        private void checkFile(Object fileElement) {
            MinimizedFileSystemElement file = (MinimizedFileSystemElement) fileElement;
            if (isExportableExtension(file.getFileNameExtension())) {
                List elements = new ArrayList();
                FileSystemElement parent = file.getParent();
                if (selectionMap.containsKey(parent)) {
                    elements = (List) selectionMap.get(parent);
                }
                elements.add(file);
                selectionMap.put(parent, elements);
            }
        }
    };
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(final IProgressMonitor monitor) throws InterruptedException {
            monitor.beginTask(DataTransferMessages.ImportPage_filterSelections, IProgressMonitor.UNKNOWN);
            getSelectedResources(filter, monitor);
        }
    };
    try {
        dialog.run(true, true, runnable);
    } catch (InvocationTargetException exception) {
        return;
    } catch (InterruptedException exception) {
        return;
    }
    // make sure that all paint operations caused by closing the progress
    // dialog get flushed, otherwise extra pixels will remain on the screen
    // until
    // updateSelections is completed
    getShell().update();
    // The updateSelections method accesses SWT widgets so cannot be
    // executed
    // as part of the above progress dialog operation since the operation
    // forks
    // a new process.
    if (selectionMap != null) {
        updateSelections(selectionMap);
    }
}

From source file:org.eclipse.linuxtools.changelog.core.actions.PrepareChangeLogAction.java

License:Open Source License

/**
 * @see IActionDelegate#run(IAction)/*from   w  ww.  ja va  2 s  .c om*/
 */
protected void doRun() {
    IRunnableWithProgress code = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitor.beginTask(Messages.getString("ChangeLog.PrepareChangeLog"), 1000); // $NON-NLS-1$
            prepareChangeLog(monitor);
            monitor.done();
        }
    };

    ProgressMonitorDialog pd = new ProgressMonitorDialog(getWorkbench().getActiveWorkbenchWindow().getShell());

    try {
        pd.run(false /* fork */, false /* cancelable */, code);
    } catch (InvocationTargetException e) {
        ChangelogPlugin.getDefault().getLog()
                .log(new Status(IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
        return;
    } catch (InterruptedException e) {
        ChangelogPlugin.getDefault().getLog()
                .log(new Status(IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
    }
}