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:com.nokia.carbide.search.system.internal.ui.text.ReplaceAction2.java

License:Open Source License

private boolean validateResources(final FileSearchQuery operation) {
    IFile[] readOnlyFiles = getReadOnlyFiles();
    IStatus status = ResourcesPlugin.getWorkspace().validateEdit(readOnlyFiles, fSite.getShell());
    if (!status.isOK()) {
        if (status.getSeverity() != IStatus.CANCEL) {
            ErrorDialog.openError(fSite.getShell(), SearchMessages.ReplaceAction2_error_validate_title,
                    SearchMessages.ReplaceAction2_error_validate_message, status);
        }//w w w  .  j  a  v  a 2  s.c  om
        return false;
    }

    final List outOfDateEntries = new ArrayList();
    for (int j = 0; j < fElements.length; j++) {
        IFileStore entry = fElements[j];
        Match[] markers = fPage.getDisplayedMatches(entry);
        for (int i = 0; i < markers.length; i++) {
            if (isOutOfDate((FileMatch) markers[i])) {
                outOfDateEntries.add(entry);
                break;
            }
        }
    }

    final List outOfSyncEntries = new ArrayList();
    //      for (int i= 0; i < fElements.length; i++) {
    //         IFileStore entry = fElements[i];
    //         if (isOutOfSync(entry)) {
    //            outOfSyncEntries.add(entry);
    //         }
    //      }

    if (outOfDateEntries.size() > 0 || outOfSyncEntries.size() > 0) {
        if (askForResearch(outOfDateEntries, outOfSyncEntries)) {
            ProgressMonitorDialog pmd = new ProgressMonitorDialog(fSite.getShell());
            try {
                pmd.run(true, true, new WorkspaceModifyOperation(null) {
                    protected void execute(IProgressMonitor monitor) throws CoreException {
                        research(monitor, outOfDateEntries, operation);
                    }
                });
                return true;
            } catch (InvocationTargetException e) {
                ExceptionHandler.handle(e, fSite.getShell(), SearchMessages.ReplaceAction_label,
                        SearchMessages.ReplaceAction_research_error);
            } catch (InterruptedException e) {
                // canceled
            }
        }
        return false;
    }
    return true;
}

From source file:com.nokia.s60tools.compatibilityanalyser.ui.wizards.LibraryFilesPage.java

License:Open Source License

public void widgetSelected(SelectionEvent e) {
    if (e.widget == userDirs_radioBtn || e.widget == default_build_target_radioBtn) {
        removeDsoDir_Btn.setEnabled(userDirs_radioBtn.getSelection() && userDsoPath_list.getItemCount() != 0);
        removeAllDsoDir_Btn/* w w w  .  j a  v  a2 s . c o  m*/
                .setEnabled(userDirs_radioBtn.getSelection() && userDsoPath_list.getItemCount() != 0);

        removeDllDir_Btn.setEnabled(userDirs_radioBtn.getSelection() && userDllPath_list.getItemCount() != 0);
        removeAllDllDir_Btn
                .setEnabled(userDirs_radioBtn.getSelection() && userDllPath_list.getItemCount() != 0);

        GridData data = (GridData) buildTarget_list.getLayoutData();
        data.exclude = !buildtarget_radioBtn.getSelection();
        buildTarget_list.setVisible(buildtarget_radioBtn.getSelection());

        GridData data2 = (GridData) dllPaths_Folder.getLayoutData();
        data2.exclude = !userDirs_radioBtn.getSelection();
        dllPaths_Folder.setVisible(userDirs_radioBtn.getSelection());

        composite.getParent().setSize(composite.getParent().getSize().x + 1, composite.getParent().getSize().y);

        this.getContainer().updateButtons();
    } else if (e.widget == addDsoDir_Btn) {
        DirectoryDialog dirDialog = new DirectoryDialog(this.getShell());
        dirDialog.setFilterPath(releaseRoot);
        String newDir = dirDialog.open();
        if (newDir != null) {
            new TableItem(userDsoPath_list, SWT.NONE).setText(0, newDir);
            userDsoPath_list.select(0);
        }
        removeDsoDir_Btn.setEnabled(userDsoPath_list.getItemCount() != 0);
        removeAllDsoDir_Btn.setEnabled(userDsoPath_list.getItemCount() != 0);
        this.getContainer().updateButtons();
    } else if (e.widget == addDllDir_Btn) {
        DirectoryDialog dirDialog = new DirectoryDialog(this.getShell());
        dirDialog.setFilterPath(releaseRoot);
        String newDir = dirDialog.open();
        if (newDir != null) {
            new TableItem(userDllPath_list, SWT.NONE).setText(0, newDir);
            userDllPath_list.select(0);
        }
        removeDllDir_Btn.setEnabled(userDllPath_list.getItemCount() != 0);
        removeAllDllDir_Btn.setEnabled(userDllPath_list.getItemCount() != 0);
        this.getContainer().updateButtons();
    } else if (e.widget == buildTarget_list) {
        selectedPlatform = buildTarget_list.getSelection();
    }
    if (e.widget == analyseSelected_radioBtn) {
        dsoFiles_list.setEnabled(analyseSelected_radioBtn.getSelection());
        addDso_Btn.setEnabled(analyseSelected_radioBtn.getSelection() && userDsoPath_list.getItemCount() != 0);
        removeDso_Btn
                .setEnabled(analyseSelected_radioBtn.getSelection() && userDsoPath_list.getItemCount() != 0);
        removeAllDso_Btn
                .setEnabled(analyseSelected_radioBtn.getSelection() && userDsoPath_list.getItemCount() != 0);
        removeNonExistingDso_Btn
                .setEnabled(analyseSelected_radioBtn.getSelection() && userDsoPath_list.getItemCount() != 0);
        this.getContainer().updateButtons();
    }
    if (e.widget == addDso_Btn) {
        filesNamesList = new ArrayList<String>();
        displayFiles = new ArrayList<String>();
        children = new ArrayList<String>();
        subChildren = new ArrayList<String>();
        isMonitorCancelled = false;

        if (userDirs_radioBtn.getSelection() && userDsoPath_list.getItemCount() == 1) {
            absolutePath = userDsoPath_list.getItem(0).getText(0);
            absolutePath = FileMethods.convertForwardToBackwardSlashes(absolutePath);

            addDialog = new ShowFilesListDialog(Display.getCurrent().getActiveShell(), dsoFiles_list, this,
                    absolutePath, false);

            IRunnableWithProgress op = new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor) {
                    try {
                        monitor.beginTask("Getting files from " + absolutePath, 10);
                        getFiles(absolutePath, monitor);
                        monitor.worked(5);
                        getFilesFromSubDirs(absolutePath, monitor);
                        monitor.done();
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            };
            try {
                IWorkbench wb = PlatformUI.getWorkbench();
                IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
                Shell shell = win != null ? win.getShell() : null;
                ProgressMonitorDialog progDlg = new ProgressMonitorDialog(shell);
                progDlg.run(true, true, op);
                progDlg.setBlockOnOpen(true);
            } catch (InvocationTargetException err) {
                err.printStackTrace();
            } catch (InterruptedException err) {
                err.printStackTrace();
            }

        } else if (userDirs_radioBtn.getSelection() && userDsoPath_list.getItemCount() > 1) {
            addDialog = new ShowFilesListDialog(Display.getCurrent().getActiveShell(), dsoFiles_list, this, "",
                    false);

            String[] paths = new String[userDsoPath_list.getItems().length];
            for (int i = 0; i < userDsoPath_list.getItems().length; i++)
                paths[i] = userDsoPath_list.getItem(i).getText(0);
            allLibsPaths = paths;

            IRunnableWithProgress op = new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor) {
                    try {
                        int i = 1;
                        for (String path : allLibsPaths) {
                            absolutePath = FileMethods.convertForwardToBackwardSlashes(path);
                            monitor.beginTask("Getting files from " + absolutePath, allLibsPaths.length);
                            getFiles(absolutePath, monitor);
                            getFilesFromSubDirs(absolutePath, monitor);
                            monitor.worked(i++);
                        }
                        monitor.done();

                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            };

            try {
                IWorkbench wb = PlatformUI.getWorkbench();
                IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
                Shell shell = win != null ? win.getShell() : null;
                ProgressMonitorDialog progDlg = new ProgressMonitorDialog(shell);
                progDlg.run(true, true, op);
                progDlg.setBlockOnOpen(true);
            } catch (InvocationTargetException err) {
                err.printStackTrace();
            } catch (InterruptedException err) {
                err.printStackTrace();
            }
        } else if (buildtarget_radioBtn.getSelection()) {
            if (releaseRoot != null) {
                addDialog = new ShowFilesListDialog(Display.getCurrent().getActiveShell(), dsoFiles_list, this,
                        "", false);
                String[] paths = new String[buildTarget_list.getSelectionCount()];

                for (int i = 0; i < buildTarget_list.getSelectionCount(); i++) {
                    paths[i] = FileMethods.appendPathSeparator(releaseRoot) + buildTarget_list.getSelection()[i]
                            + File.separator + Messages.getString("LibraryFilesPage.lib"); //$NON-NLS-1$ //$NON-NLS-2$;
                }

                allLibsPaths = paths;

                IRunnableWithProgress op = new IRunnableWithProgress() {
                    public void run(IProgressMonitor monitor) {
                        try {
                            int i = 1;
                            for (String path : allLibsPaths) {
                                absolutePath = FileMethods.convertForwardToBackwardSlashes(path);
                                monitor.beginTask("Getting files from " + absolutePath, allLibsPaths.length);
                                getFiles(absolutePath, monitor);
                                getFilesFromSubDirs(absolutePath, monitor);
                                monitor.worked(i++);
                            }
                            monitor.done();

                        } catch (Exception e1) {
                            e1.printStackTrace();
                        }
                    }
                };

                try {
                    IWorkbench wb = PlatformUI.getWorkbench();
                    IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
                    Shell shell = win != null ? win.getShell() : null;
                    ProgressMonitorDialog progDlg = new ProgressMonitorDialog(shell);
                    progDlg.run(true, true, op);
                    progDlg.setBlockOnOpen(true);
                } catch (InvocationTargetException err) {
                    err.printStackTrace();
                } catch (InterruptedException err) {
                    err.printStackTrace();
                }
            }

        } else if (default_build_target_radioBtn.getSelection()) {
            String buildTarget = CompatibilityAnalyserEngine.getDefaultBuildPlatform(releaseRoot,
                    currentSdk.productSdkVersion);

            absolutePath = FileMethods.appendPathSeparator(releaseRoot) + buildTarget + File.separator
                    + Messages.getString("LibraryFilesPage.lib"); //$NON-NLS-1$ //$NON-NLS-2$
            absolutePath = FileMethods.convertForwardToBackwardSlashes(absolutePath);
            addDialog = new ShowFilesListDialog(Display.getCurrent().getActiveShell(), dsoFiles_list, this,
                    absolutePath, false);

            IRunnableWithProgress op = new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor) {
                    try {
                        monitor.beginTask("Getting files from " + absolutePath, 10);
                        getFiles(absolutePath, monitor);
                        monitor.worked(5);
                        getFilesFromSubDirs(absolutePath, monitor);
                        monitor.done();
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            };
            try {
                IWorkbench wb = PlatformUI.getWorkbench();
                IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
                Shell shell = win != null ? win.getShell() : null;
                ProgressMonitorDialog progDlg = new ProgressMonitorDialog(shell);
                progDlg.run(true, true, op);
                progDlg.setBlockOnOpen(true);
            } catch (InvocationTargetException err) {
                err.printStackTrace();
            } catch (InterruptedException err) {
                err.printStackTrace();
            }

        }

        if (!isMonitorCancelled) {
            if (filesNamesList.size() != dsoFiles_list.getItemCount())
                for (String name : filesNamesList) {
                    if (!isPreviouslySelected(name))
                        displayFiles.add(name);
                    else {
                        if (subChildren.contains(name))
                            subChildren.remove(name);
                        if (children.contains(name))
                            children.remove(name);
                    }
                }
            Collections.sort(displayFiles);
            addDialog.children = children;
            addDialog.subChildren = subChildren;

            if (displayFiles.size() == 0 && filesNamesList.size() != 0) {
                Runnable showMessageRunnable = new Runnable() {
                    public void run() {
                        MessageDialog.openInformation(Display.getCurrent().getActiveShell(),
                                Messages.getString("HeaderFilesPage.CompatibilityAnalyser"), //$NON-NLS-1$
                                "All libraries in the root directory are already selected"); //$NON-NLS-1$
                    }
                };
                Display.getDefault().asyncExec(showMessageRunnable);
            } else if (filesNamesList.size() == 0) {
                Runnable showMessageRunnable = new Runnable() {
                    public void run() {
                        MessageDialog.openInformation(Display.getCurrent().getActiveShell(),
                                Messages.getString("HeaderFilesPage.CompatibilityAnalyser"), //$NON-NLS-1$
                                "No libraries exist under the given directory path"); //$NON-NLS-1$
                    }
                };
                Display.getDefault().asyncExec(showMessageRunnable);
            } else {
                addDialog.open();
                addDialog.filesList.setItems(displayFiles.toArray(new String[displayFiles.size()]));
                addDialog.filesList.select(0);
                addDialog.fileNamesList = addDialog.filesList.getItems();
            }

        }
        this.getContainer().updateButtons();
    } else if (e.widget == removeDso_Btn) {
        dsoFiles_list.remove(dsoFiles_list.getSelectionIndices());
        dsoFiles_list.select(0);
        this.getContainer().updateButtons();
    } else if (e.widget == removeAllDso_Btn) {
        dsoFiles_list.removeAll();
        this.getContainer().updateButtons();
    } else if (e.widget == removeNonExistingDso_Btn) {
        int[] invalidIndices = new int[invalidLibsCount];
        int j = 0;

        for (int i = 0; i < dsoFiles_list.getItemCount(); i++) {
            System.out.println("Item Color is " + dsoFiles_list.getItem(i).getForeground()
                    + " And InvalidColor is " + invalidColor);
            if (dsoFiles_list.getItem(i).getForeground().equals(invalidColor)) {
                invalidIndices[j] = i;
                j++;
            }
        }
        dsoFiles_list.remove(invalidIndices);
        invalidLibsCount = 0;

        this.getContainer().updateButtons();
    } else if (e.widget == removeDsoDir_Btn) {
        userDsoPath_list.remove(userDsoPath_list.getSelectionIndices());
        userDsoPath_list.select(0);
        removeDsoDir_Btn.setEnabled(userDsoPath_list.getItemCount() != 0);
        removeAllDsoDir_Btn.setEnabled(userDsoPath_list.getItemCount() != 0);
        this.getContainer().updateButtons();
    } else if (e.widget == removeAllDsoDir_Btn) {
        userDsoPath_list.removeAll();
        removeDsoDir_Btn.setEnabled(userDsoPath_list.getItemCount() != 0);
        removeAllDsoDir_Btn.setEnabled(userDsoPath_list.getItemCount() != 0);
        this.getContainer().updateButtons();
    } else if (e.widget == removeDllDir_Btn) {
        userDllPath_list.remove(userDllPath_list.getSelectionIndices());
        userDllPath_list.select(0);
        removeDllDir_Btn.setEnabled(userDllPath_list.getItemCount() != 0);
        removeAllDllDir_Btn.setEnabled(userDllPath_list.getItemCount() != 0);
        this.getContainer().updateButtons();
    } else if (e.widget == removeAllDllDir_Btn) {
        userDllPath_list.removeAll();
        removeDllDir_Btn.setEnabled(userDllPath_list.getItemCount() != 0);
        removeAllDllDir_Btn.setEnabled(userDllPath_list.getItemCount() != 0);
        this.getContainer().updateButtons();
    }
}

From source file:com.nokia.s60tools.imaker.internal.model.Environment.java

License:Open Source License

public List<UIConfiguration> load() throws InvocationTargetException {
    if (loaded) {
        return configurations;
    }/*  www .j  a  v a  2s .c  o m*/
    IRunnableWithProgress op = new IMakerCoreRunnable();
    ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(getDisplay().getActiveShell());
    try {
        progressMonitorDialog.run(true, true, op);
    } catch (InvocationTargetException e) {
        configurations = null;
        loaded = false;
        throw e;
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    loaded = true;
    return configurations;
}

From source file:com.nokia.s60tools.imaker.internal.model.Environment.java

License:Open Source License

public String getTargetSteps(final String target) {
    targetSteps = null;//  ww w. ja  v a2s  . com
    ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(getDisplay().getActiveShell());
    try {
        progressMonitorDialog.run(true, false, new IRunnableWithProgress() {

            //            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    targetSteps = wrapper.getTargetSteps(target, getCurrentProduct().getFilePath(), monitor);
                } catch (IMakerCoreExecutionException e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InvocationTargetException e) {
    } catch (InterruptedException e) {
    }
    return targetSteps;
}

From source file:com.nokia.s60tools.imaker.internal.viewers.PreferencesTab.java

License:Open Source License

private void executeRunnable(IRunnableWithProgress op) {
    IWorkbench wb = PlatformUI.getWorkbench();
    IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
    Shell shell = win != null ? win.getShell() : null;
    try {//from w  ww.  j  ava2 s  .c  om
        ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(shell);
        progressMonitorDialog.run(true, false, op);
        settingsTab.getTableViewer().refresh();
    } catch (InvocationTargetException e) {
        StatusHandler.handle(IStatus.ERROR, Messages.getString("Error.1"), e.getTargetException()); //$NON-NLS-1$
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:com.nokia.s60tools.imaker.UIConfiguration.java

License:Open Source License

public void load() throws Throwable {
    if (loaded) {
        return;//from   w  w w.j  a va 2 s  . co m
    }
    Display display = PlatformUI.getWorkbench().getDisplay();
    IRunnableWithProgress op = new IMakerCoreRunnable();
    ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(display.getActiveShell());
    try {
        progressMonitorDialog.run(true, false, op);
    } catch (InvocationTargetException e) {
        throw e.getTargetException();
    } catch (InterruptedException e) {
        throw e;
    }
    loaded = true;
}

From source file:com.nokia.tools.s60.preferences.ExampleThemesPreferencePage.java

License:Open Source License

/**
 * //from   w w  w. j  av  a  2 s .c  om
 */
public void widgetSelected(SelectionEvent e) {
    if (e.getSource() == btnAdd) {
        FileDialog fd = new FileDialog(new Shell(), SWT.SYSTEM_MODAL | SWT.OPEN);
        fd.setFilterExtensions(externalToolFilter);

        if (selImportTheme != "") {
            fd.setFileName(selImportTheme);
        }

        source = fd.open();
        if (source != null) {
            final Map<String, String> details = getThemeDetails();
            final String project = details.get(PRJ_NAME) == null ? null : details.get(PRJ_NAME);
            final String model = details.get(MODEL) == null ? null : details.get(MODEL);
            final String tdfPath = details.get(TDFPATH) == null ? null : details.get(TDFPATH);
            try {
                if (project != null) {
                    // check for importing theme is exist already
                    // if so error message dialog is shown
                    final String path = themeFolderLocation + THEME_FOLDER;
                    if (new File(path + project).mkdir()) {
                        ProgressMonitorDialog dialog = new ProgressMonitorDialog(
                                Display.getCurrent().getActiveShell());
                        dialog.run(true, false, new IRunnableWithProgress() {
                            public void run(IProgressMonitor monitor)
                                    throws InvocationTargetException, InterruptedException {
                                monitor.beginTask(
                                        NLS.bind(Messages.ExampleThemesPreferencePage_AddThemeMsg, project),
                                        IProgressMonitor.UNKNOWN);
                                try {
                                    copyZipDirectory(source, new File(path + project));
                                    // Writing into properties file
                                    String value = THEME_FOLDER + project + tdfPath;
                                    writeIntoFile(value, model, TYPE.Add);
                                    clearAndRefreshComponentPool();
                                    Display.getDefault().syncExec(new Runnable() {
                                        public void run() {
                                            refreshTableViewer();
                                        }
                                    });
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                                monitor.done();

                            }
                        });
                    } else {
                        MessageDialog.openError(null, Messages.ExampleThemesPreferencePage_ErrorNoteTitle,
                                NLS.bind(Messages.ExampleThemesPreferencePage_ThemeAlreadyExist, project));
                    }
                } else {
                    MessageDialog.openError(null, Messages.ExampleThemesPreferencePage_ErrorNoteTitle,
                            Messages.ExampleThemesPreferencePage_NotValidZip);
                }
            } catch (Throwable e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }
    }
    if (e.getSource() == btnRemove) {
        if (selectedBean != null) {
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
            try {
                dialog.run(true, false, new IRunnableWithProgress() {
                    public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {
                        monitor.beginTask(NLS.bind(Messages.ExampleThemesPreferencePage_RemoveThemeMsg,
                                selectedBean.getName()), IProgressMonitor.UNKNOWN);
                        String path = selectedBean.getPath()
                                .substring(selectedBean.getPath().indexOf(File.separator) + 1);
                        String toRemove = themeFolderLocation + THEME_FOLDER + selectedBean.getName();
                        toRemove = themeFolderLocation + THEME_FOLDER
                                + path.substring(0, path.indexOf(File.separator));
                        writeIntoFile(selectedBean.getKey(), null, TYPE.Remove);
                        deleteThemeDir(new File(toRemove));
                        clearAndRefreshComponentPool();
                        Display.getDefault().syncExec(new Runnable() {
                            public void run() {
                                refreshTableViewer();
                                // refresh buttons state
                                if ((exampleThemesViewer.getTable().getItemCount()) == 0)
                                    btnRemove.setEnabled(false);
                            }
                        });
                        monitor.done();
                    }

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

From source file:com.nokia.tools.variant.carbidev.perspective.actions.UpdateAction.java

License:Open Source License

/**
 * Software Updates//from  www.  j a  va 2s . c  om
 * 
 */
public void run(IAction action) {
    final Shell activeShell = Display.getCurrent().getActiveShell();

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(activeShell);

    try {
        dialog.run(false, true, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) {

                UpdateCommand command;

                try {
                    boolean updated = false;

                    command = new UpdateCommand("com.nokia.tools.variant.feature.carbidev2", "false");
                    if (command.run(monitor)) {
                        updated = true;
                    }

                    if (isFeatureInstalled("com.nokia.tools.variant.feature.s60.components")) {
                        command = new UpdateCommand("com.nokia.tools.variant.feature.s60.components", "false");
                        if (command.run(monitor)) {
                            updated = true;
                        }
                    }

                    if (updated) {

                        String message = "Carbide.v was updated successfully. "
                                + "It is recommended you restart Carbide.v for the changes to take effect. "
                                + "Would you like to restart now?";
                        int choice = showQuestionMessage(activeShell, message);

                        switch (choice) {
                        case SWT.YES:
                            PlatformUI.getWorkbench().restart();
                            break;
                        case SWT.NO:
                            break;
                        }

                        // boolean temp =
                        // PlatformUI.getPreferenceStore().getBoolean
                        // (IWorkbenchPreferenceConstants
                        // .CLOSE_EDITORS_ON_EXIT);
                        // PlatformUI.getPreferenceStore().setValue(
                        // IWorkbenchPreferenceConstants
                        // .CLOSE_EDITORS_ON_EXIT, false);
                        // PlatformUI.getWorkbench().restart();
                        // PlatformUI.getPreferenceStore().setValue(
                        // IWorkbenchPreferenceConstants
                        // .CLOSE_EDITORS_ON_EXIT, temp);

                    } else {
                        String message = "No updates for the currently installed feature(s) found, "
                                + "try again later.";
                        showInfoMessage(activeShell, message);
                    }
                } catch (Exception e) {
                    // e.printStackTrace();
                    String message = "No updates for the currently installed feature(s) found, "
                            + "try again later.";
                    showInfoMessage(activeShell, message);
                }

            }

        });

    } catch (InvocationTargetException e) {
        //         e.printStackTrace();
    } catch (InterruptedException e) {
        //         e.printStackTrace();
    }

}

From source file:com.opcoach.training.e4.rental.ui.handlers.SaveHandler.java

License:Open Source License

@Execute
public void execute(IEclipseContext context, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
        @Named(IServiceConstants.ACTIVE_PART) final MContribution contribution)
        throws InvocationTargetException, InterruptedException {
    final IEclipseContext pmContext = context.createChild();

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
    dialog.open();/*from w w  w  .ja  va  2  s  .com*/
    dialog.run(true, true, new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            pmContext.set(IProgressMonitor.class.getName(), monitor);
            if (contribution != null) {
                Object clientObject = contribution.getObject();
                //               ContextInjectionFactory.invoke(clientObject, Persist.class, //$NON-NLS-1$
                // pmContext, null);
            }
        }
    });

    pmContext.dispose();
}

From source file:com.opengridsystems.wtf.submission.ui.wizard.SubmitWizard.java

License:Open Source License

@Override
public boolean performFinish() {

    final String name = page.name.getText().trim();
    final String email = page.email.getText().trim();
    final String subject = page.subject.getText().trim();
    final String message = page.message.getText();
    final String code = page.code.getText();
    final boolean doNotPublish = page.publish.getSelection();

    ProgressMonitorDialog pmD = new ProgressMonitorDialog(this.getShell());
    IRunnableWithProgress loader = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            SubmitWTF ws = new SubmitWTF(WSDL_URL);

            SubmitWTFSoap wsSoap = ws.getSubmitWTFSoap();
            try {
                String response = wsSoap.submit(name, email, subject, message, code, doNotPublish);
                if (response == null || !response.equals(""))
                    throw new InvocationTargetException(
                            new Exception("Your WTF has not been submitted\n\nResponse: " + response));
            } catch (Exception ex) {
                throw new InvocationTargetException(ex);
            }/*from  w w w . j ava 2  s. c  o  m*/
        }

    };
    try {
        pmD.run(true, false, loader);
    } catch (InvocationTargetException ex) {
        ErrorDialog.openError(getShell(), "Error", ex.getMessage(),
                new Status(Status.ERROR, Activator.PLUGIN_ID, ex.getMessage(), ex));
        return false;
    } catch (InterruptedException ex) {
        ErrorDialog.openError(getShell(), "Error", ex.getMessage(),
                new Status(Status.ERROR, Activator.PLUGIN_ID, ex.getMessage(), ex));
        return false;
    }
    MessageDialog.openInformation(getShell(), "Submitted", "Your WTF has been submitted");
    return true;
}