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.cdt.internal.ui.workingsets.WorkingSetConfigsController.java

License:Open Source License

/**
 * Handler for the "Build" button.//w w w .  ja va  2s  . co m
 */
private void buildConfig() {
    final IStatus[] problem = new IStatus[1];

    try {
        ProgressMonitorDialog dlg = new ProgressMonitorDialog(tree.getControl().getShell());
        dlg.run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) {
                IStatus status = currentConfig.build(monitor);
                if (status.matches(IStatus.WARNING | IStatus.ERROR)) {
                    problem[0] = status;
                }
            }
        });
    } catch (Exception e) {
        CUIPlugin.log(WorkingSetMessages.WSConfigsController_buildFailedLog, e);
    }

    // it is possible that some project configurations had to applied in
    // order to effect a build. Refresh to handle that case
    updateForActivation();

    if (problem[0] != null) {
        // show the problem
        ErrorDialog.openError(tree.getControl().getShell(),
                WorkingSetMessages.WSConfigsController_buildFailedDlgTitle,
                WorkingSetMessages.WSConfigsController_buildFailedDlgMsg, problem[0]);
    }
}

From source file:org.eclipse.cdt.linux.help.preferences.IndexPathControl.java

License:Open Source License

public boolean createIndex() {
    boolean success = false;
    String indexPathName;//from  ww w. jav  a2 s . c om

    //   if(HelpPlugin.getDefault().isRemote())
    {
        DataStore dataStore;
        if (_isRemote)
            dataStore = DataStoreCorePlugin.getDefault().getCurrentDataStore();
        else
            dataStore = DataStoreCorePlugin.getDefault().getRootDataStore();

        DataElement indexObject = dataStore.createObject(null, "Project", "linuxhelp_command");

        DataStore ids = indexObject.getDataStore();

        String helpSettings = _settings.settingsToString();
        DataElement argSettings = dataStore.createObject(null, "help_settings", helpSettings);

        DataElement descriptor = dataStore.localDescriptorQuery(indexObject.getDescriptor(),
                "C_HELPCREATEINDEX");

        DataElement status;
        if (descriptor != null) {
            ArrayList args = new ArrayList();
            args.add(argSettings);
            status = dataStore.command(descriptor, args, indexObject);

            HelpMonitor helpMonitor = new HelpMonitor(
                    plugin.getLocalizedString(IHelpNLConstants.SETTINGS_INDEX_MONITORMESSAGE), status);
            Shell shell = WorkbenchPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
            ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(shell);
            progressDialog.setCancelable(false);
            try {
                progressDialog.run(true, false, helpMonitor);
            } catch (Exception e) {
                e.printStackTrace();
            }

            while (!status.getName().equals("done")) {
                try {
                    Thread.sleep(200);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                Thread.yield();
            }

            //indicate an index was created 
            _settings.read();
            _settings.put(IHelpSearchConstants.HELP_SETTINGS_INDEXEXISTS, true);
            _settings.write();//commit 
        }
        return true;
    }
}

From source file:org.eclipse.cdt.oprofile.core.Oprofile.java

License:Open Source License

/**
 * Return a list of all the Samples in the given session.
 * @param session the session for which to get samples
 * @param shell the composite shell to use for the progress dialog
 *//*  w ww .  j a  v a2s . co m*/
public static void getSamples(final SampleSession session, Shell shell) {
    /* As much as I would like to get all this UI stuff back into the UI code, it really confuses
       things. It would be a real PITA for the UI to check whether we need samples to be read.
       Reading samples should just magically happen (as far as the UI is concerned). */
    final IRunnableWithProgress opxml;
    try {
        opxml = OprofileCorePlugin.getDefault().getOpxmlProvider().samples(session);
    } catch (OpxmlException e) {
        _showErrorDialog("opxmlProvider", e); //$NON-NLS-1$
        return;
    }

    if (shell != null) {
        IRunnableWithProgress runnable = new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                Object[] fmtArgs = null;
                String key = null;
                if (session.isDefaultSession()) {
                    key = "getSamples.caption.default-session"; //$NON-NLS-1$
                    fmtArgs = new Object[0];
                } else {
                    key = "getSamples.caption"; //$NON-NLS-1$
                    fmtArgs = new Object[] { session.getExecutableName() };
                }

                String caption = MessageFormat.format(OprofileProperties.getString(key), fmtArgs);
                monitor.beginTask(caption, session.getSampleCount());
                opxml.run(monitor);
                monitor.done();
            }
        };

        ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
        try {
            dialog.run(true, false, runnable);
        } catch (InterruptedException ie) {
        } catch (InvocationTargetException e) {
        }
    } else {
        // No shell -- just run opxml without a ProgressMonitor
        try {
            opxml.run(null);
        } catch (InvocationTargetException e) {
        } catch (InterruptedException e) {
        }
    }
}

From source file:org.eclipse.cft.server.ui.internal.wizards.ConnectSsoServerDialog.java

License:Open Source License

protected void buttonPressed(int buttonId) {
    if (buttonId == IDialogConstants.OK_ID) {
        final ConnectThread ct = new ConnectThread(cloudServer, passcodeText.getText());

        getShell().setCursor(Display.getCurrent().getSystemCursor(SWT.CURSOR_WAIT));
        SafeRunner.run(new SafeRunnable() {
            public void run() throws Exception {
                IServerWorkingCopy server = cloudServer.getServerWorkingCopy();
                if (server == null) {
                    server = cloudServer.getServer().createWorkingCopy();
                    cloudServer.getBehaviour();
                }/*from   ww  w.  ja  v  a2  s . co m*/
                server.setAttribute(CloudFoundryServer.PROP_PASSCODE_ID, passcodeText.getText());
                server.save(true, new NullProgressMonitor());

                ct.start();

                // Wait for thread to complete w/o blocking the UI thread.
                ProgressMonitorDialog dialog = new ProgressMonitorDialog(
                        PlatformUI.getWorkbench().getDisplay().getActiveShell());
                dialog.run(true, true, new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {
                        while (!monitor.isCanceled() && !ct.isJobComplete()) {
                            Thread.sleep(100);
                        }
                    }
                });

                CoreException exception = ct.getException();
                if (exception != null) {
                    if (exception.getMessage() != null) {
                        setErrorMessage(exception.getMessage());
                    }
                    CloudFoundryServerUiPlugin.logError(exception);
                }
            }

            @Override
            public void handleException(Throwable e) {
                setErrorMessage(e.getMessage());
                CloudFoundryServerUiPlugin.logError(e);
            }
        });
        getShell().setCursor(null);
        if (ct.isConnected()) {
            connectionSuccess = true;
            super.buttonPressed(buttonId);
        }
    } else {
        super.buttonPressed(buttonId);
    }
}

From source file:org.eclipse.cmf.occi.docker.design.services.DockerServices.java

License:Open Source License

/**
 * Popup menu importModel action./*from   w  w  w.  jav  a2  s . c  om*/
 */
public void importModel(final Configuration conf) {
    try {
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            @Override
            public void run(final IProgressMonitor monitor)
                    throws InvocationTargetException, InterruptedException {
                DockerModelHelper dockerModelHelper = new DockerModelHelper(conf);
                try {

                    dockerModelHelper.importModel();
                } catch (DockerException ex) {
                    ex.printStackTrace();
                }
            }
        };
        Shell shell = this.getShell();
        ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
        dialog.run(false, true, runnable);
    } catch (Throwable ex) {
        ex.printStackTrace();
    }
}

From source file:org.eclipse.cmf.occi.docker.design.services.DockerServices.java

License:Open Source License

/**
 * Called by all basic command (not by import command).
 * /*from w ww. ja  v  a  2  s.c  o m*/
 * @param eo
 * @param command
 * @param occiCommand
 */
private void executeCommand(final EObject eo, final String command, final boolean occiCommand) {
    Shell shell = this.getShell();
    try {
        final int kind = this.eobjectKind(eo);

        String machineName = null;
        final Compute compute;
        final Entity entity;
        if (command == null) {
            MessageDialog.openInformation(shell, "Warning", "This command : " + command + " is not supported.");
            return;
        }

        switch (kind) {
        case 0:
            Machine machine = ((Machine) eo);
            machineName = machine.getName();
            if (machineName == null || machineName.trim().isEmpty()) {
                MessageDialog.openInformation(shell, "Warning", "Machine name is required !");
                return;
            }
            compute = (Compute) eo;
            break;
        case 1:
            Container container = ((Container) eo);
            machineName = container.getName();
            if (machineName == null || machineName.trim().isEmpty()) {
                MessageDialog.openInformation(shell, "Warning", "Container name is required !");
                return;
            }
            compute = (Container) eo;
            break;
        default:
            if (!occiCommand) {
                MessageDialog.openInformation(shell, "Warning", "Unsupported compute !");
                return;
            }
            compute = null;
            break;
        }
        if (eo instanceof Entity) {
            entity = (Entity) eo;
        } else {
            System.err.println("Not an entity !");
            return;
        }

        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            @Override
            public void run(final IProgressMonitor monitor)
                    throws InvocationTargetException, InterruptedException {
                if (!monitor.isCanceled()) {
                    monitor.beginTask("Operation in progress : " + command, Monitor.UNKNOWN);
                    Display display = Display.getCurrent();
                    boolean result = display.readAndDispatch();
                    System.out.println("result display read and dispatch : " + result);
                    SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
                    // consume..
                    subMonitor.worked(10);
                    if (occiCommand) {
                        switch (command) {
                        case "occiCreate":
                            entity.occiCreate();
                            break;
                        case "occiUpdate":
                            entity.occiUpdate();
                            break;
                        case "occiDelete":
                            boolean confirm = showConfirmDialog();
                            if (confirm) {
                                entity.occiDelete();
                            }
                            break;
                        case "occiRetrieve":
                            entity.occiRetrieve();
                            break;
                        }
                    } else {
                        if (compute != null) {

                            switch (command) {

                            case "start":
                                compute.start();
                                break;
                            case "startall":
                                if (compute instanceof Machine) {
                                    Machine machine = (Machine) compute;
                                    machine.startall();
                                }

                                break;
                            case "stop":
                                compute.stop(StopMethod.GRACEFUL);
                                break;
                            case "synchronize":
                                compute.occiRetrieve();
                                break;
                            case "restart":
                                compute.restart(RestartMethod.GRACEFUL);
                                break;
                            default:
                                System.err.println("command : " + command + " is not supported.");
                                break;
                            }
                        }
                    }
                    result = display.readAndDispatch();
                    System.out.println("result display read and dispatch : " + result);
                    subMonitor.worked(100);
                    monitor.done();
                } else {
                    System.out.println("Operation : " + command + " cancelled.");
                }

            }
        };

        ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
        dialog.setOpenOnRun(true);

        dialog.run(false, true, runnable);
        //  dialog.run(false, true, runnable);
        // MessageDialog.openInformation(shell, "Operation succeed",
        //      "Command " + command + " has been successfully executed !");
    } catch (Throwable ex) {
        ex.printStackTrace();
        MessageDialog.openError(shell, "Error on command " + command,
                ex.getCause().getClass().getName() + " --> " + ex.getCause().getMessage());
    }

}

From source file:org.eclipse.compare.internal.AddFromHistoryAction.java

License:Open Source License

private void updateWorkspace(final ResourceBundle bundle, Shell shell,
        final AddFromHistoryDialog.HistoryInput[] selected)
        throws InvocationTargetException, InterruptedException {

    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
        public void execute(IProgressMonitor pm) throws InvocationTargetException {
            try {
                String taskName = Utilities.getString(bundle, "taskName"); //$NON-NLS-1$
                pm.beginTask(taskName, selected.length);

                for (int i = 0; i < selected.length; i++) {
                    IFile file = selected[i].fFile;
                    IFileState fileState = selected[i].fFileState;
                    createContainers(file);

                    SubProgressMonitor subMonitor = new SubProgressMonitor(pm, 1);
                    try {
                        file.create(fileState.getContents(), false, subMonitor);
                    } finally {
                        subMonitor.done();
                    }// ww  w  .j a va 2 s .  co  m
                }
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            } finally {
                pm.done();
            }
        }
    };

    ProgressMonitorDialog pmdialog = new ProgressMonitorDialog(shell);
    pmdialog.run(false, true, operation);
}

From source file:org.eclipse.compare.internal.EditionAction.java

License:Open Source License

private void updateWorkspace(final ResourceBundle bundle, Shell shell, final IStreamContentAccessor sa,
        final IFile file) throws InvocationTargetException, InterruptedException {
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
        public void execute(IProgressMonitor pm) throws InvocationTargetException {
            try {
                String taskName = Utilities.getString(bundle, "taskName"); //$NON-NLS-1$
                pm.beginTask(taskName, IProgressMonitor.UNKNOWN);
                file.setContents(sa.getContents(), false, true, pm);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            } finally {
                pm.done();//  w ww .  j a  va2  s .c o  m
            }
        }
    };

    ProgressMonitorDialog pmdialog = new ProgressMonitorDialog(shell);
    pmdialog.run(false, true, operation);
}

From source file:org.eclipse.datatools.connectivity.internal.ui.drivers.DriverClassEditDialog.java

License:Open Source License

private ArrayList getClassList() {
    final ArrayList classes = new ArrayList();
    for (int i = 0; i < mJarList.length; i++) {
        String filepath = mJarList[i];
        final File file = new File(filepath);
        try {//from  ww  w  .ja v a 2 s. com
            new JarFile(file);
        } catch (ZipException e) {
            // must not be a zip file - skip it
            continue;
        } catch (IOException e) {
            String msg = e.getLocalizedMessage();
            if (e.getLocalizedMessage() == null || e.getLocalizedMessage().trim().length() == 0) {
                msg = ConnectivityUIPlugin.getDefault().getResourceString("PropertyDescriptor.error.msg");//$NON-NLS-1$
            }
            ExceptionHandler.showException(getShell(),
                    ConnectivityUIPlugin.getDefault().getResourceString("PropertyDescriptor.error.title"), //$NON-NLS-1$
                    msg, e);
            return null;
        }
        ProgressMonitorDialog pmd = new ProgressMonitorDialog(getShell());
        try {
            pmd.run(true, false, new IRunnableWithProgress() {

                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    try {
                        String[] classStr = DriverUtil.getDriverClassesFromJar(file, monitor);
                        classes.addAll(Arrays.asList(classStr));
                    } catch (Exception e1) {
                        InvocationTargetException ce = new InvocationTargetException(e1);
                        throw ce;
                    }
                }
            });
        } catch (InvocationTargetException e) {
            String msg = e.getLocalizedMessage();
            if (e.getLocalizedMessage() == null || e.getLocalizedMessage().trim().length() == 0) {
                msg = ConnectivityUIPlugin.getDefault().getResourceString("PropertyDescriptor.error.msg");//$NON-NLS-1$
            }
            ExceptionHandler.showException(getShell(),
                    ConnectivityUIPlugin.getDefault().getResourceString("PropertyDescriptor.error.title"), //$NON-NLS-1$
                    msg, e);
            return null;
        } catch (InterruptedException e) {
            String msg = e.getLocalizedMessage();
            if (e.getLocalizedMessage() == null || e.getLocalizedMessage().trim().length() == 0) {
                msg = ConnectivityUIPlugin.getDefault().getResourceString("PropertyDescriptor.error.msg");//$NON-NLS-1$
            }
            ExceptionHandler.showException(getShell(),
                    ConnectivityUIPlugin.getDefault().getResourceString("PropertyDescriptor.error.title"), //$NON-NLS-1$
                    msg, e);
            return null;
        }
    }
    return classes;
}

From source file:org.eclipse.debug.examples.ui.pda.adapters.PDAVirtualFindAction.java

License:Open Source License

public void run() {
    final VirtualViewerListener listener = new VirtualViewerListener();
    VirtualTreeModelViewer virtualViewer = initVirtualViewer(fClientViewer, listener);

    ProgressMonitorDialog dialog = new TimeTriggeredProgressMonitorDialog(fClientViewer.getControl().getShell(),
            500);//from  ww w .  j ava 2 s  . co  m
    final IProgressMonitor monitor = dialog.getProgressMonitor();
    dialog.setCancelable(true);

    try {
        dialog.run(true, true, new IRunnableWithProgress() {
            public void run(final IProgressMonitor m) throws InvocationTargetException, InterruptedException {
                synchronized (listener) {
                    listener.fProgressMonitor = m;
                    listener.fProgressMonitor.beginTask(DebugUIPlugin.removeAccelerators(getText()),
                            listener.fRemainingUpdatesCount);
                }

                while ((!listener.fLabelUpdatesComplete || !listener.fViewerUpdatesComplete)
                        && !listener.fProgressMonitor.isCanceled()) {
                    Thread.sleep(1);
                }
                synchronized (listener) {
                    listener.fProgressMonitor = null;
                }
            }
        });
    } catch (InvocationTargetException e) {
        DebugUIPlugin.log(e);
        return;
    } catch (InterruptedException e) {
        return;
    }

    VirtualItem root = virtualViewer.getTree();
    if (!monitor.isCanceled()) {
        List list = new ArrayList();
        collectAllChildren(root, list);
        FindLabelProvider labelProvider = new FindLabelProvider(virtualViewer, list);
        VirtualItem result = performFind(list, labelProvider);
        if (result != null) {
            setSelectionToClient(virtualViewer, labelProvider, result);
        }
    }

    virtualViewer.removeLabelUpdateListener(listener);
    virtualViewer.removeViewerUpdateListener(listener);
    virtualViewer.dispose();
}