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.e4.xwt.tools.ui.designer.core.editor.Designer.java

License:Open Source License

protected void runWithDialog(IRunnableWithProgress runnable) {
    try {//from   w w  w  . j a v  a 2  s.c o m
        ProgressMonitorDialog d = new ProgressMonitorDialog(getSite().getShell());
        d.run(true, false, runnable);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.eclipse.eatop.metamodelgen.ui.handlers.EASTADLMMGenUIHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // Gets the selected file from explorer
    IFile selectedEapFile = unwrap(event, IFile.class);
    Shell shell = HandlerUtil.getActiveShell(event);

    if (selectedEapFile != null) {
        if (IConstants.EAP_FILE_EXTENSION.equals(selectedEapFile.getFileExtension())) {
            String generateEcoreOnly = event.getParameter(GENERATE_ECORE_ONLY_PARAMETER);
            String generateMMCode = event.getParameter(GENERATE_MM_EMF_CODE_PARAMETER);
            String generateAll = event.getParameter(GENERATE_ALL_PARAMETER);
            String generateCDO = event.getParameter(GENERATE_CDO);

            // Create EASTADLEcoreMMGen
            final EASTADLEcoreMMGen ecoreMMgen = new EASTADLEcoreMMGen(selectedEapFile,
                    new Boolean(generateEcoreOnly).booleanValue(), new Boolean(generateMMCode).booleanValue(),
                    new Boolean(generateAll).booleanValue(), new Boolean(generateCDO).booleanValue());

            // Progress monitor dialog
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
            try {
                dialog.run(true, true, new IRunnableWithProgress() {
                    @Override/* w  ww. j  av a  2  s  .  c  o  m*/
                    public void run(IProgressMonitor monitor) {
                        doRun(ecoreMMgen, monitor);
                    }
                });
            } catch (InvocationTargetException e) {
                PlatformLogUtil.logAsError(Activator.getDefault(), e.getMessage());
            } catch (InterruptedException e) {
                PlatformLogUtil.logAsError(Activator.getDefault(), e.getMessage());
            }
        }
    } else {
        MessageDialog.openInformation(shell, "Info", "Please select a EAP source file"); //$NON-NLS-1$//$NON-NLS-2$
    }
    return null;
}

From source file:org.eclipse.ecf.example.chat.ui.parts.ChatPart.java

License:Open Source License

@PostConstruct
public void createComposite(final Composite parent, @Optional final ConfigurationAdmin cm, MPart part,
        final Shell shell) throws UnknownHostException {
    parent.setLayout(new FillLayout(SWT.HORIZONTAL));

    fStackComposite = new Composite(parent, SWT.NONE);
    final StackLayout stackLayout = new StackLayout();
    fStackComposite.setLayout(stackLayout);

    ScrolledForm loginForm = fFormToolkit.createScrolledForm(fStackComposite);
    loginForm.setImage(//from   w  w w.  j a  va 2  s  . c  o  m
            ResourceManager.getPluginImage("org.eclipse.ecf.example.chat.product", "icons/login.gif"));
    loginForm.setFont(SWTResourceManager.getFont("Segoe UI", 11, SWT.BOLD));
    fFormToolkit.paintBordersFor(loginForm);
    loginForm.setText("Login");
    loginForm.getBody().setLayout(new FillLayout(SWT.HORIZONTAL));

    Composite loginBody = fFormToolkit.createComposite(loginForm.getBody(), SWT.NONE);
    fFormToolkit.paintBordersFor(loginBody);
    loginBody.setLayout(new GridLayout(3, false));

    // Handle
    fFormToolkit.createLabel(loginBody, "Handle", SWT.NONE);

    fHandle = fFormToolkit.createText(loginBody, "", SWT.NONE);
    if (part.getElementId().equals("org.eclipse.ecf.example.chat.ui.part.0")) {
        String canonicalHostName = "";
        try {
            canonicalHostName = InetAddress.getLocalHost().getCanonicalHostName();
        } catch (UnknownHostException e) {
            e.printStackTrace();
            canonicalHostName = "unknown";
        }
        fHandle.setText(System.getProperty("user.name", "nobody") + "@" + canonicalHostName);
    } else {
        fHandle.setText(part.getLabel());
    }
    fHandle.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1));

    // Server
    fFormToolkit.createLabel(loginBody, "DiscoServer", SWT.NONE);

    fServer = fFormToolkit.createText(loginBody, "", SWT.NONE);
    fServer.setText("zk://disco.ecf-project.org");
    fServer.selectAll();
    fServer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
    if (cm == null) {
        fServer.setEnabled(false);
        fServer.setText("No discovery and/or ConfigurationAdmin available");
    }

    // centralistic mode
    fFormToolkit.createLabel(loginBody, "Centralistic Mode", SWT.NONE);

    btnServerMode = fFormToolkit.createButton(loginBody, "", SWT.CHECK);

    final Button btnLogin = fFormToolkit.createButton(loginBody, "Go online", SWT.NONE);
    btnLogin.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            final boolean serverMode = btnServerMode.getSelection();
            final String handle = fHandle.getText();
            final URI uri;
            if (fServer.isEnabled()) {
                uri = URI.create(fServer.getText());
            } else {
                uri = URI.create("no://host");
            }

            final ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
            try {
                dialog.run(true, false, new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {
                        doLogin(serverMode, handle, uri, cm);
                        sync.syncExec(new Runnable() {
                            @Override
                            public void run() {
                                fHandle.getShell()
                                        .setText(fHandle.getShell().getText() + ": " + fHandle.getText());
                                stackLayout.topControl = fMessageComposite;
                                fStackComposite.layout();
                            }
                        });
                    }
                });
            } catch (InvocationTargetException doesNotHappen) {
                doesNotHappen.printStackTrace();
            } catch (InterruptedException doesNotHappen) {
                doesNotHappen.printStackTrace();
            }
        }
    });
    btnLogin.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));

    // Only allow to go only on a correc URI
    fServer.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            if (fServer.isEnabled()) {
                String text = fServer.getText();
                try {
                    URI uri = new URI(text);
                    if (uri.getScheme() != null && uri.getHost() != null) {
                        btnLogin.setEnabled(true);
                        return;
                    }
                } catch (URISyntaxException e1) {
                }
                btnLogin.setEnabled(false);
            }
        }
    });

    stackLayout.topControl = loginForm;

    fMessageComposite = fFormToolkit.createComposite(fStackComposite, SWT.NONE);
    fFormToolkit.paintBordersFor(fMessageComposite);
    GridLayout gl_fMessageComposite = new GridLayout(2, false);
    fMessageComposite.setLayout(gl_fMessageComposite);

    Composite composite = fFormToolkit.createComposite(fMessageComposite, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    GridLayout gl_fMessageForm = new GridLayout(1, false);
    gl_fMessageForm.marginHeight = 0;
    gl_fMessageForm.marginWidth = 0;
    composite.setLayout(gl_fMessageForm);
    fFormToolkit.paintBordersFor(composite);

    sashForm = new SashForm(composite, SWT.SMOOTH);
    sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    fFormToolkit.adapt(sashForm);
    fFormToolkit.paintBordersFor(sashForm);

    messageComposite = new MessageComposite(sashForm, SWT.NONE);
    fFormToolkit.adapt(messageComposite);
    fFormToolkit.paintBordersFor(messageComposite);

    fParticipants = fFormToolkit.createText(sashForm, "", SWT.READ_ONLY | SWT.MULTI);
    fParticipants.setForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_BLUE));
    fParticipants.setFont(SWTResourceManager.getFont("Courier", 9, SWT.BOLD));
    sashForm.setWeights(new int[] { 4, 1 });

    fMessage = new Text(fMessageComposite, SWT.BORDER);
    fMessage.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Button btnSend = new Button(fMessageComposite, SWT.NONE);
    btnSend.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
    btnSend.setText("Send");
    btnSend.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            final String text = fMessage.getText();
            final ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
            try {
                dialog.run(true, false, new IRunnableWithProgress() {
                    @Override
                    public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {
                        fTracker.publish(text);
                        sync.syncExec(new Runnable() {
                            @Override
                            public void run() {
                                fMessage.setText("");
                                fMessage.setFocus();
                            }
                        });
                    }
                });
            } catch (InvocationTargetException doesNotHappen) {
                doesNotHappen.printStackTrace();
            } catch (InterruptedException doesNotHappen) {
                doesNotHappen.printStackTrace();
            }
        }
    });
    btnSend.getShell().setDefaultButton(btnSend);
}

From source file:org.eclipse.ecf.sync.ui.resources.ResourcesShareHandler.java

License:Open Source License

private void run(Shell shell, final ResourcesShare share, final String projectName) {
    final boolean[] ret = { false };

    try {//from  w  w  w . j  a  v a 2 s  . c o  m
        ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
        dialog.open();
        dialog.run(true, true, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    monitor.beginTask("Sharing " + projectName, IProgressMonitor.UNKNOWN);
                    monitor.subTask("Sending request...");
                    share.startShare(getRosterEntry().getRoster().getUser().getID(),
                            getRosterEntry().getUser().getID(), projectName);
                    monitor.subTask("Waiting for acknowledgement...");
                    while (true) {
                        if (monitor.isCanceled()) {
                            throw new InterruptedException();
                        }

                        Thread.sleep(50);
                        Boolean response = share.getResponse();
                        if (response != null) {
                            ret[0] = response.booleanValue();
                            return;
                        }
                    }
                } catch (ECFException e) {
                    throw new InvocationTargetException(e);
                } finally {
                    monitor.done();
                }
            }
        });
    } catch (InvocationTargetException e) {
        IStatus status = new Status(IStatus.ERROR, SyncResourcesUI.PLUGIN_ID, "Could not send share request",
                e.getCause());
        StatusManager.getManager().handle(status);
        SyncResourcesUI.log(status);
    } catch (InterruptedException e) {
        // operation canceled, stop sharing this project
        share.stopSharing(projectName);
        return;
    }

    if (ret[0]) {
        IRosterManager manager = getRosterEntry().getRoster().getPresenceContainerAdapter().getRosterManager();
        manager.addRosterListener(new RosterListener(share, projectName, getRosterEntry()));
    } else {
        MessageDialog.openInformation(shell, null, "Sharing request denied.");
    }
}

From source file:org.eclipse.edt.ide.egldoc.actions.GenerateEGLDoc.java

License:Open Source License

@Override
public void run(IAction action) {
    if (generator != null && selection instanceof StructuredSelection) {
        ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(site.getShell());

        try {//from   w ww .j a  v a2 s.c  om
            progressDialog.run(true, true, new WorkspaceModifyOperation() {
                @Override
                public void execute(IProgressMonitor monitor) throws CoreException {
                    Map<IEGLProject, Set<PartKey>> parts = gatherParts((StructuredSelection) selection,
                            monitor);
                    IGenerationMessageRequestor requestor = new AccumulatingGenerationMessageRequestor();

                    int size = 0;
                    for (Set<PartKey> key : parts.values()) {
                        size += key.size();
                    }

                    monitor.beginTask("", size);
                    for (Map.Entry<IEGLProject, Set<PartKey>> entry : parts.entrySet()) {
                        Set<PartKey> generatedParts = new HashSet<PartKey>();

                        ProjectEnvironment env = ProjectEnvironmentManager.getInstance()
                                .getProjectEnvironment(entry.getKey().getProject());
                        try {
                            Environment.pushEnv(env.getIREnvironment());
                            env.initIREnvironments();

                            for (PartKey key : entry.getValue()) {
                                if (monitor.isCanceled()) {
                                    throw new CanceledException();
                                }
                                monitor.subTask(NLS.bind(Messages.GeneratingPart, key.getQualifiedName()));
                                try {
                                    Part part = env.findPart(key.packageName, key.partName);
                                    if (part != null && !part.hasCompileErrors()) {
                                        generator.generate(key.filePath, part, env.getIREnvironment(),
                                                requestor);
                                        generatedParts.add(key);
                                    }
                                } catch (CanceledException ce) {
                                    throw ce;
                                } catch (Exception e) {
                                    e.printStackTrace();
                                } finally {
                                    monitor.worked(1);
                                }
                            }

                            // Create HTML Index for the generated parts
                            generateIndex(entry.getKey().getProject(), sortPartsByPackage(generatedParts));

                            writeCSSFile(entry.getKey().getProject());
                        } catch (CanceledException ce) {
                            throw ce;
                        } finally {
                            Environment.popEnv();
                        }
                    }
                    monitor.done();

                    //TODO report results? or only if there was an error?
                }
            });
        } catch (InvocationTargetException ite) {
            Throwable cause = ite.getCause();
            if (!(cause instanceof CanceledException)) {
                cause.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:org.eclipse.edt.ide.eunit.internal.actions.GenTestDriverAction.java

License:Open Source License

@Override
public void run(IAction action) {
    ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(fSite.getShell());

    IResource selResource = (IResource) (fSelection.getFirstElement());

    IProject baseProj = selResource.getProject();
    String baseProjName = baseProj.getName();
    IEGLProject baseEGLProj = EGLCore.create(baseProj);
    IWorkspaceRoot wsRoot = baseProj.getWorkspace().getRoot();

    try {//from w ww. j  av  a 2 s .c o m
        List<WorkspaceModifyOperation> ops = getGenTestDriverOperatoins(wsRoot, baseProjName, baseProj,
                baseEGLProj);
        for (WorkspaceModifyOperation op : ops) {
            progressDialog.run(true, true, op);
        }

    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.eclipse.edt.ide.ui.internal.property.pages.VariableBlock.java

License:Open Source License

public boolean performOk() {
    ArrayList removedVariables = new ArrayList();
    ArrayList changedVariables = new ArrayList();
    removedVariables.addAll(Arrays.asList(JavaCore.getClasspathVariableNames()));

    // remove all unchanged
    List changedElements = fVariablesList.getElements();
    for (int i = changedElements.size() - 1; i >= 0; i--) {
        CPVariableElement curr = (CPVariableElement) changedElements.get(i);
        if (curr.isReadOnly()) {
            changedElements.remove(curr);
        } else {//from  w  w  w . j a v a  2  s. c om
            IPath path = curr.getPath();
            IPath prevPath = JavaCore.getClasspathVariable(curr.getName());
            if (prevPath != null && prevPath.equals(path)) {
                changedElements.remove(curr);
            } else {
                changedVariables.add(curr.getName());
            }
        }
        removedVariables.remove(curr.getName());
    }
    int steps = changedElements.size() + removedVariables.size();
    if (steps > 0) {

        boolean needsBuild = false;
        if (fAskToBuild && doesChangeRequireFullBuild(removedVariables, changedVariables)) {
            String title = NewWizardMessages.VariableBlock_needsbuild_title;
            String message = NewWizardMessages.VariableBlock_needsbuild_message;

            MessageDialog buildDialog = new MessageDialog(getShell(), title, null, message,
                    MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL,
                            IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
                    2);
            int res = buildDialog.open();
            if (res != 0 && res != 1) {
                return false;
            }
            needsBuild = (res == 0);
        }

        final VariableBlockRunnable runnable = new VariableBlockRunnable(removedVariables, changedElements);
        final ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
        try {
            dialog.run(true, true, runnable);
        } catch (InvocationTargetException e) {
            ExceptionHandler.handle(new InvocationTargetException(new NullPointerException()), getShell(),
                    NewWizardMessages.VariableBlock_variableSettingError_titel,
                    NewWizardMessages.VariableBlock_variableSettingError_message);
            return false;
        } catch (InterruptedException e) {
            return false;
        }

        if (needsBuild) {
            CoreUtility.getBuildJob(null).schedule();
        }
    }
    return true;
}

From source file:org.eclipse.egit.ui.internal.repository.RepositorySearchDialog.java

License:Open Source License

private void doSearch() {

    setMessage(null);/* w ww.j  a  v a 2s  .  c  om*/
    setErrorMessage(null);
    // perform the search...
    final Set<String> directories = new HashSet<String>();
    final File file = new File(dir.getText());
    final boolean lookForNested = lookForNestedButton.getSelection();
    if (file.exists()) {
        try {
            prefs.put(PREF_PATH, file.getCanonicalPath());
            try {
                prefs.flush();
            } catch (BackingStoreException e1) {
                // ignore here
            }
        } catch (IOException e2) {
            // ignore
        }

        IRunnableWithProgress action = new IRunnableWithProgress() {

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

                try {
                    findGitDirsRecursive(file, directories, monitor, lookForNested);
                } catch (Exception ex) {
                    Activator.getDefault().getLog()
                            .log(new Status(IStatus.ERROR, Activator.getPluginId(), ex.getMessage(), ex));
                }
                if (monitor.isCanceled()) {
                    throw new InterruptedException();
                }
            }
        };
        try {
            ProgressMonitorDialog pd = new ProgressMonitorDialog(getShell());
            pd.getProgressMonitor().setTaskName(UIText.RepositorySearchDialog_ScanningForRepositories_message);
            pd.run(true, true, action);

        } catch (InvocationTargetException e1) {
            org.eclipse.egit.ui.Activator.handleError(UIText.RepositorySearchDialog_errorOccurred, e1, true);
        } catch (InterruptedException e1) {
            // ignore
        }

        int foundOld = 0;

        final TreeSet<String> validDirs = new TreeSet<String>();

        for (String foundDir : directories) {
            if (!fExistingDirectories.contains(foundDir)) {
                validDirs.add(foundDir);
            } else {
                foundOld++;
            }
        }

        if (foundOld > 0) {
            String message = NLS.bind(UIText.RepositorySearchDialog_SomeDirectoriesHiddenMessage,
                    Integer.valueOf(foundOld));
            setMessage(message, IMessageProvider.INFORMATION);
        } else if (directories.isEmpty())
            setMessage(UIText.RepositorySearchDialog_NothingFoundMessage, IMessageProvider.INFORMATION);

        toggleSelectionButton.setEnabled(!validDirs.isEmpty());
        fTree.clearFilter();
        fTreeViewer.setInput(validDirs);
        // this sets all to selected
        fTreeViewer.setAllChecked(true);
        enableOk();

    }

}

From source file:org.eclipse.emf.codegen.action.AddJETNatureAction.java

License:Open Source License

public void run(IAction action) {
    if (action.isEnabled()) {
        IRunnableWithProgress op = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) {
                try {
                    JETAddNatureOperation addNature = new JETAddNatureOperation(projects);
                    addNature.run(monitor);
                } catch (CoreException e) {
                    CodeGenUIPlugin.write(e);
                }/*from ww w . j ava2 s. com*/
            }
        };

        try {
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(
                    CodeGenUIPlugin.getPlugin().getWorkbench().getActiveWorkbenchWindow().getShell());
            dialog.run(false, true, op);
        } catch (Exception e) {
            CodeGenUIPlugin.write(e);
        }
    }
}

From source file:org.eclipse.emf.codegen.action.CompileTemplateAction.java

License:Open Source License

public void run(IAction action) {
    if (action.isEnabled()) {
        IRunnableWithProgress op = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) {
                try {
                    for (Iterator<?> i = getSelectedObjects().iterator(); i.hasNext();) {
                        IFile file = (IFile) i.next();
                        JETNature jetNature = JETNature.getRuntime(file.getProject());
                        if (jetNature != null) {
                            JETCompileTemplateOperation compileTemplate = new JETCompileTemplateOperation(
                                    file.getProject(), jetNature.getTemplateContainers(),
                                    Collections.singleton(file));
                            compileTemplate.run(monitor);
                        }/*w w  w .  j  a v  a2 s.c o  m*/
                    }
                } catch (Exception e) {
                    CodeGenUIPlugin.write(e);
                }
            }
        };

        try {
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(
                    CodeGenUIPlugin.getPlugin().getWorkbench().getActiveWorkbenchWindow().getShell());
            dialog.run(false, true, op);
        } catch (Exception e) {
            CodeGenUIPlugin.write(e);
        }
    }
}