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

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

Introduction

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

Prototype

@Override
public Shell getShell() 

Source Link

Document

Returns this window's shell.

Usage

From source file:be.ibridge.kettle.spoon.SpoonGraph.java

License:LGPL

/**
 * Display the input- or outputfields for a step.
 * /*from   w  w  w.j  av a 2  s.  co m*/
 * @param stepMeta The step (it's metadata) to query
 * @param before set to true if you want to have the fields going INTO the step, false if you want to see all the
 * fields that exit the step.
 */
private void inputOutputFields(StepMeta stepMeta, boolean before) {
    spoon.refreshGraph();

    SearchFieldsProgressDialog op = new SearchFieldsProgressDialog(transMeta, stepMeta, before);
    try {
        final Thread parentThread = Thread.currentThread();
        final ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);

        // Run something in the background to cancel active database queries, forecably if needed!
        Runnable run = new Runnable() {
            public void run() {
                // This is running in a new process: copy some KettleVariables info
                LocalVariables.getInstance().createKettleVariables(Thread.currentThread().getName(),
                        parentThread.getName(), true);

                IProgressMonitor monitor = pmd.getProgressMonitor();
                while (pmd.getShell() == null || (!pmd.getShell().isDisposed() && !monitor.isCanceled())) {
                    try {
                        Thread.sleep(250);
                    } catch (InterruptedException e) {
                    }
                    ;
                }

                if (monitor.isCanceled()) // Disconnect and see what happens!
                {
                    try {
                        transMeta.cancelQueries();
                    } catch (Exception e) {
                    }
                    ;
                }
            }
        };
        // Dump the cancel looker in the background!
        new Thread(run).start();

        pmd.run(true, true, op);
    } catch (InvocationTargetException e) {
        new ErrorDialog(shell, Messages.getString("SpoonGraph.Dialog.GettingFields.Title"), //$NON-NLS-1$
                Messages.getString("SpoonGraph.Dialog.GettingFields.Message"), e); //$NON-NLS-1$
    } catch (InterruptedException e) {
        new ErrorDialog(shell, Messages.getString("SpoonGraph.Dialog.GettingFields.Title"), //$NON-NLS-1$
                Messages.getString("SpoonGraph.Dialog.GettingFields.Message"), e); //$NON-NLS-1$
    }

    Row fields = op.getFields();

    if (fields != null && fields.size() > 0) {
        StepFieldsDialog sfd = new StepFieldsDialog(shell, SWT.NONE, stepMeta.getName(), fields);
        String sn = (String) sfd.open();
        if (sn != null) {
            StepMeta esi = transMeta.findStep(sn);
            if (esi != null) {
                editStep(esi);
            }
        }
    } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
        mb.setMessage(Messages.getString("SpoonGraph.Dialog.CouldntFindFields.Message")); //$NON-NLS-1$
        mb.setText(Messages.getString("SpoonGraph.Dialog.CouldntFindFields.Title")); //$NON-NLS-1$
        mb.open();
    }

}

From source file:ca.mcgill.cs.swevo.qualyzer.wizards.NewProjectWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    fOne.save();/*from  w w w.  j  a v  a 2 s. c om*/

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
    dialog.setOpenOnRun(true);
    dialog.create();
    dialog.getShell().setText(Messages.getString("wizards.NewProjectWizard.projectCreationStatus")); //$NON-NLS-1$
    try {
        dialog.run(true, false, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                QualyzerActivator.getDefault().setCreatingProject(true);
                monitor.beginTask(Messages.getString("wizards.NewProjectWizard.creatingNewProject"), //$NON-NLS-1$
                        WORK);
                monitor.worked(1);
                monitor.worked(1);
                Project project = Facade.getInstance().createProject(fOne.getProjectName(),
                        fOne.getInvestigatorNickname(), fOne.getInvestigatorFullname(), fOne.getInstitution());
                monitor.worked(2);

                fProject = ResourcesPlugin.getWorkspace().getRoot().getProject(project.getFolderName());
                monitor.worked(1);
                monitor.done();
                QualyzerActivator.getDefault().setCreatingProject(false);
            }
        });
    } catch (InvocationTargetException e) {

    } catch (InterruptedException e) {

    } catch (QualyzerException e) {
        MessageDialog.openError(getShell(), Messages.getString("wizard.NewProjectWizard.projectError"), //$NON-NLS-1$
                e.getMessage());
        return false;
    }

    return fProject != null && fProject.exists();
}

From source file:com.bdaum.zoom.db.internal.DbManager.java

License:Open Source License

public void pruneEmptySystemCollections() {
    if (!readOnly && hasDirtyCollection()) {
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                pruneEmptySystemCollections(monitor, false);
            }//  www. j  av a 2s .  c om
        };
        try {
            IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            if (workbenchWindow != null) {
                ProgressMonitorDialog dialog = new ProgressMonitorDialog(workbenchWindow.getShell());
                dialog.create();
                dialog.getShell().setText(Constants.APPLICATION_NAME);
                dialog.run(false, true, runnable);
            } else
                runnable.run(new NullProgressMonitor());
        } catch (InvocationTargetException e) {
            // ignore
        } catch (InterruptedException e) {
            // ignore
        }
    }
}

From source file:com.genuitec.eclipse.gerrit.tools.internal.changes.commands.FetchChangeCommand.java

License:Open Source License

@Override
protected Object internalExecute(ExecutionEvent event) throws Exception {
    Shell shell = HandlerUtil.getActiveShell(event);

    Repository repository = RepositoryUtils.getRepository(HandlerUtil.getCurrentSelection(event));
    if (repository == null) {
        return null;
    }/*from www.j a v  a2 s .c  om*/

    //configure branch creation
    try {
        FetchChangeBranchDialog fetchChangeBranchDialog = new FetchChangeBranchDialog(shell, repository);
        if (fetchChangeBranchDialog.open() != IDialogConstants.OK_ID) {
            return null;
        }
        //perform branch operation
        try {
            ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(shell);
            final CreateChangeBranchOperation op = new CreateChangeBranchOperation(progressDialog.getShell(),
                    event, repository, fetchChangeBranchDialog.getSettings());
            progressDialog.run(true, true, op);
        } catch (InterruptedException e) {
            //ignore
        }
    } catch (NoClassDefFoundError err) {
        MessageLinkDialog.openWarning(shell, "Mylyn for Gerrit is not installed",
                "To be able to fetch a change from Gerrit, please install Mylyn Gerrit connector. Detailed instructions can be found <a>here</a>.",
                new MessageLinkDialog.IMessageLinkDialogListener() {
                    @Override
                    public void linkSelected(SelectionEvent e) {
                        try {
                            PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(
                                    "https://github.com/Genuitec/gerrit-tools/wiki/Fetch-from-Gerrit-setup"));
                        } catch (Exception ex) {
                            RepositoryUtils.handleException(ex);
                        }
                    }
                });
    }

    return null;
}

From source file:com.genuitec.eclipse.gerrit.tools.internal.changes.commands.NewChangeBranchCommand.java

License:Open Source License

@Override
protected Object internalExecute(ExecutionEvent event) throws Exception {
    Shell shell = HandlerUtil.getActiveShell(event);

    Repository repository = RepositoryUtils.getRepository(HandlerUtil.getCurrentSelection(event));
    if (repository == null) {
        return null;
    }// ww  w. j a  v a  2  s. c  om

    //fetch remote branches
    RepositoryUtils.fetchOrigin(shell, repository);

    //configure branch creation
    CreateChangeBranchDialog createChangeBranchDialog = new CreateChangeBranchDialog(shell, repository);
    if (createChangeBranchDialog.open() != IDialogConstants.OK_ID) {
        return null;
    }
    //perform branch operation
    try {
        ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(shell);
        final CreateChangeBranchOperation op = new CreateChangeBranchOperation(progressDialog.getShell(), event,
                repository, createChangeBranchDialog.getSettings());
        progressDialog.run(true, true, op);
    } catch (InterruptedException e) {
        //ignore
    }

    return null;
}

From source file:com.genuitec.eclipse.gerrit.tools.internal.fbranches.commands.CreateFeatureBranchCommand.java

License:Open Source License

@Override
protected void execute(ExecutionEvent event, List<Repository> repositories, String branchRef)
        throws ExecutionException {
    Shell shell = HandlerUtil.getActiveShell(event);

    //fetch remote branches
    for (Repository repository : repositories) {
        RepositoryUtils.fetchOrigin(shell, repository);
    }//from   ww  w.  j a  va  2 s. co m

    //configure branch creation
    CreateFeatureBranchDialog createFeatureBranchDialog = new CreateFeatureBranchDialog(shell, repositories);
    if (createFeatureBranchDialog.open() != IDialogConstants.OK_ID) {
        return;
    }

    String userId = RepositoryUtils.getUserId(repositories);

    //perform branch operation
    for (Repository repository : repositories) {
        try {
            ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(shell);
            final CreateBranchOperation op = new CreateBranchOperation(progressDialog.getShell(), event,
                    repository, userId, createFeatureBranchDialog.getSettings());
            progressDialog.run(true, true, op);
        } catch (InterruptedException e) {
            //ignore
        } catch (Exception e) {
            RepositoryUtils.handleException(e);
        }
    }

    return;
}

From source file:com.genuitec.eclipse.gerrit.tools.internal.utils.commands.TagAndPushHandler.java

License:Open Source License

@Override
protected Object internalExecute(ExecutionEvent event) throws Exception {
    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
    final Shell shell = HandlerUtil.getActiveShell(event);

    List<Repository> repositories = new ArrayList<Repository>();

    //acquire the list of repositories
    for (Object o : selection.toArray()) {
        RepositoryNode node = (RepositoryNode) o;
        repositories.add(node.getRepository());
        assert node.getRepository() != null;
    }//  w  ww  . ja  v  a  2  s. co m

    //configure tagging operation
    TagAndPushDialog tagAndPushConfigDialog = new TagAndPushDialog(shell, repositories);
    if (tagAndPushConfigDialog.open() != IDialogConstants.OK_ID) {
        return null;
    }
    //perform tagging operation
    try {
        ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(shell);
        final TagAndPushOperation op = new TagAndPushOperation(progressDialog.getShell(), repositories,
                tagAndPushConfigDialog.getSettings());
        progressDialog.run(true, true, op);
        shell.getDisplay().asyncExec(new Runnable() {

            public void run() {
                if (op.getResult().getSeverity() >= IStatus.WARNING) {
                    Policy.getStatusHandler().show(op.getResult(), "Results of the operation");
                } else {
                    MessageDialog.openInformation(shell, "Create and Push Tag",
                            "Repositories has been successfully tagged.");
                }
            }
        });
    } catch (InterruptedException e) {
        //ignore
    } catch (Exception e) {
        GerritToolsPlugin.getDefault().getLog()
                .log(new Status(IStatus.ERROR, GerritToolsPlugin.PLUGIN_ID, e.getLocalizedMessage(), e));
        MessageDialog.openError(shell, "Create and Push Tag", e.getLocalizedMessage());
    }

    return null;
}

From source file:com.google.cloud.tools.eclipse.appengine.login.ui.LoginServiceUi.java

License:Apache License

private String showProgressDialogAndWaitForCode(final String message, final LocalServerReceiver codeReceiver,
        final String redirectUrl) throws IOException {
    try {//  w w  w.  jav a2  s.  co m
        final Semaphore wait = new Semaphore(0 /* initially zero permit */);

        final ProgressMonitorDialog dialog = new ProgressMonitorDialog(shellProvider.getShell()) {
            @Override
            protected void configureShell(Shell shell) {
                super.configureShell(shell);
                shell.setText(Messages.LOGIN_PROGRESS_DIALOG_TITLE);
            }

            @Override
            protected void cancelPressed() {
                wait.release(); // Allow termination of the attached task.
                stopCodeWaitingJob(redirectUrl);

                AnalyticsPingManager.getInstance().sendPing(AnalyticsEvents.LOGIN_CANCELED, null, null,
                        getParentShell());
            }
        };

        final String[] codeHolder = new String[1];
        final IOException[] exceptionHolder = new IOException[1];

        dialog.run(true /* fork */, true /* cancelable */, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                AnalyticsPingManager.getInstance().sendPing(AnalyticsEvents.LOGIN_START, null, null,
                        dialog.getShell());

                monitor.beginTask(message != null ? message : Messages.LOGIN_PROGRESS_DIALOG_MESSAGE,
                        IProgressMonitor.UNKNOWN);
                // Fork another sub-job to circumvent the limitation of LocalServerReceiver.
                // (See the comments of scheduleCodeWaitingJob().)
                scheduleCodeWaitingJob(new LocalServerReceiverWrapper(codeReceiver), wait, codeHolder,
                        exceptionHolder);
                wait.acquireUninterruptibly(); // Block until signaled.
            }
        });

        if (exceptionHolder[0] != null) {
            throw exceptionHolder[0];
        }
        return codeHolder[0];

    } catch (InvocationTargetException | InterruptedException ex) {
        // Never thrown from the attached task.
        return null;
    }
}

From source file:com.google.cloud.tools.eclipse.login.ui.LoginServiceUi.java

License:Apache License

private String showProgressDialogAndWaitForCode(final String message, final LocalServerReceiver codeReceiver,
        final String redirectUrl) throws IOException {
    try {/*from  w w  w .j a v  a 2  s  .c o m*/
        final Semaphore wait = new Semaphore(0 /* initially zero permit */);

        final ProgressMonitorDialog dialog = new ProgressMonitorDialog(shellProvider.getShell()) {
            @Override
            protected void configureShell(Shell shell) {
                super.configureShell(shell);
                shell.setText(Messages.getString("LOGIN_PROGRESS_DIALOG_TITLE"));
            }

            @Override
            protected void cancelPressed() {
                wait.release(); // Allow termination of the attached task.
                stopCodeWaitingJob(redirectUrl);

                AnalyticsPingManager.getInstance().sendPing(AnalyticsEvents.LOGIN_CANCELED, null, null,
                        getParentShell());
            }
        };

        final String[] codeHolder = new String[1];
        final IOException[] exceptionHolder = new IOException[1];

        dialog.run(true /* fork */, true /* cancelable */, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                AnalyticsPingManager.getInstance().sendPing(AnalyticsEvents.LOGIN_START, null, null,
                        dialog.getShell());

                monitor.beginTask(
                        message != null ? message : Messages.getString("LOGIN_PROGRESS_DIALOG_MESSAGE"),
                        IProgressMonitor.UNKNOWN);
                // Fork another sub-job to circumvent the limitation of LocalServerReceiver.
                // (See the comments of scheduleCodeWaitingJob().)
                scheduleCodeWaitingJob(new LocalServerReceiverWrapper(codeReceiver), wait, codeHolder,
                        exceptionHolder);
                wait.acquireUninterruptibly(); // Block until signaled.
            }
        });

        if (exceptionHolder[0] != null) {
            throw exceptionHolder[0];
        }
        return codeHolder[0];

    } catch (InvocationTargetException | InterruptedException ex) {
        // Never thrown from the attached task.
        return null;
    }
}

From source file:com.microsoft.tfs.client.common.ui.framework.runnable.DeferredProgressMonitorDialogContext.java

License:Open Source License

private Job createProgressUIJob(final IRunnableWithProgress inputRunnable,
        final RunnableWithProgressWrapper wrappedRunnable, final ProgressMonitorDialog dialog) {
    return new Job("") //$NON-NLS-1$
    {//  w  w  w .j  av  a  2 s .  c om
        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            Display.getDefault().asyncExec(new Runnable() {
                @Override
                public void run() {
                    setUserInterfaceActive(true);

                    /*
                     * Note that this job is executed regardless of whether
                     * the command is still executing. If it has finished,
                     * the progress monitor dialog will be disposed (and
                     * getShell will return null.)
                     */
                    if (dialog.getShell() != null) {
                        /*
                         * Attempt to avoid a UI hang problem. If there is
                         * already a modal Shell, opening the progress
                         * monitor will result in multiple modal Shells.
                         * Note that this cannot be avoided with a
                         * parent-child relationship on all window managers.
                         *
                         * If this occurs, reschedule this deferred runnable
                         * for another interval of the deferTimeMillis. The
                         * blocking dialog may have been removed in this
                         * time (eg, in the case of an authentication
                         * dialog.)
                         */
                        final Shell blocker = ShellUtils.getModalBlockingShell(dialog.getShell());
                        if (blocker != null) {
                            final String messageFormat = "unsafe modal operation - shell [{0} ({1})] for [{2}] blocked by shell [{3} ({4})]"; //$NON-NLS-1$
                            final String message = MessageFormat.format(messageFormat, dialog.getShell(),
                                    Integer.toHexString(System.identityHashCode(dialog.getShell())),
                                    inputRunnable, blocker,
                                    Integer.toHexString(System.identityHashCode(blocker)));

                            log.info(message);

                            /* Requeue the dialog */
                            final Job showProgressUIJob = createProgressUIJob(inputRunnable, wrappedRunnable,
                                    dialog);

                            showProgressUIJob.setSystem(true);
                            showProgressUIJob.schedule(deferTimeMillis);

                            return;
                        }
                    }

                    if (dialog.getShell() != null) {
                        if (log.isTraceEnabled()) {
                            final String messageFormat = "opening shell [{0} ({1})] for [{2}]"; //$NON-NLS-1$
                            final String message = MessageFormat.format(messageFormat, dialog.getShell(),
                                    Integer.toHexString(System.identityHashCode(dialog.getShell())),
                                    inputRunnable);

                            log.trace(message);
                        }
                    }

                    /*
                     * It is safe to call dialog.open() even when the
                     * command has finished executing.
                     */
                    dialog.open();

                    /*
                     * this line works around a problem with progress
                     * monitor dialog: updates to the task name are not
                     * always displayed if openOnRun is false and the
                     * updates are made before the dialog is opened
                     *
                     * the fix is to cache changes made to the task name
                     * (through the interface wrapper classes defined below)
                     * and re-set the task name to the same value at a same
                     * time (after the dialog has opened)
                     */
                    wrappedRunnable.getCustomProgressMonitor().updateTaskNameIfSet();
                }
            });
            return Status.OK_STATUS;
        }
    };
}