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:net.rim.ejde.internal.ui.views.profiler.ProfilerView.java

License:Open Source License

public void openProfileVis() {
    File tmpFile = getTmpFile();/*www.  ja v  a2s  .c  o m*/
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(ContextManager.getActiveWorkbenchShell());
    SaveRawDataRunnale runnable = new SaveRawDataRunnale(tmpFile, this);
    try {
        dialog.run(false, true, runnable);
    } catch (InvocationTargetException e) {
        log.error(e);
        MessageDialog.openError(ContextManager.getActiveWorkbenchShell(), e.getMessage(),
                Messages.ErrorHandler_DIALOG_TITLE);
        return;
    } catch (InterruptedException e) {
        log.error(e);
        MessageDialog.openError(ContextManager.getActiveWorkbenchShell(), e.getMessage(),
                Messages.ErrorHandler_DIALOG_TITLE);
        return;
    }
    try {
        Desktop.getDesktop().open(tmpFile);
    } catch (IOException e) {
        log.error(e);
        MessageDialog.openError(ContextManager.getActiveWorkbenchShell(), Messages.ErrorHandler_DIALOG_TITLE,
                Messages.BBProfileVis_Not_Installed_ErrMsg);
    }
}

From source file:net.rim.ejde.internal.ui.wizards.imports.ProjectImportSelectionUI.java

License:Open Source License

public void loadWorkspace(IPath workspacePath) {
    if (_currentVM == null) {
        return;/*from ww w .  j a  v  a 2 s .  c om*/
    }

    if (workspacePath == null || workspacePath.isEmpty()) {
        return;
    }

    if (workspacePath.equals(_currentWorkspace)) {
        return;
    }

    _currentWorkspace = workspacePath;
    File workspaceFile = workspacePath.toFile();
    if (!workspaceFile.exists() || !workspaceFile.isFile()) {
        _isValidWorkspaceFile = false;
        _tableViewer.setInput(null);
        _callback.setComplete(false);
        return;
    }

    _isValidWorkspaceFile = true;
    LoadLegacyWorkspaceTask task = new LoadLegacyWorkspaceTask(workspaceFile);
    ProgressMonitorDialog monitorDialog = new ProgressMonitorDialog(ContextManager.getActiveWorkbenchShell());
    try {
        monitorDialog.run(false, false, task);
    } catch (Throwable e) {
        _log.debug(e.getMessage(), e);
        _callback.setComplete(false);
    }
    Workspace workspace = task.getWorkspace();
    List<Project> nonExistingProjects = new ArrayList<Project>();
    List<Project> allProjects = new ArrayList<Project>();
    int numProjects = workspace.getNumProjects();
    for (int i = 0; i < numProjects; i++) {
        Project project = workspace.getProject(i);
        String projectName = project.getDisplayName();
        // do not count AEPs
        if (project.getType() != Project.CLDC_APPLICATION_ENTRY && project.getType() != Project.MIDLET_ENTRY) {
            if (!projectExists(projectName)) { // checks if the project
                // already exists in the previous workspace
                nonExistingProjects.add(project);
            }
            allProjects.add(project);
        }
    }
    Collections.sort(allProjects, ProjectNameComparator);
    _tableViewer.setInput(allProjects);
    _tableViewer.setCheckedElements(nonExistingProjects.toArray(new Project[nonExistingProjects.size()]));
    checkExistingProjects();
    if (nonExistingProjects.size() == 0) {
        _callback.setComplete(false);
    } else {
        _callback.setComplete(true);
    }
}

From source file:net.sf.fast.ibatis.popup.actions.FastibatisCodeActionDelegate.java

License:Apache License

/**
 * @see IActionDelegate#run(IAction)//from   w  w  w  .  ja  va 2s .  com
 */
public void run(IAction action) {
    try {
        final IFile file = ((FileEditorInput) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
                .getActivePage().getActiveEditor().getEditorInput()).getFile();
        final StringBuffer hdType = new StringBuffer();
        final StringBuffer sb = new StringBuffer();
        ProgressMonitorDialog openDlg = new ProgressMonitorDialog(shell);
        openDlg.run(true, true, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(Fasti18n.getString("start_opening") + "...", 1);
                try {
                    HandleType handleType = getHandleType(file);
                    hdType.append(getHandleType(handleType));
                    String similarSQL = getSimilarSQLId(ibatisSqlMapIdName, file);
                    if (similarSQL != null)
                        sb.append(similarSQL);
                    monitor.worked(1);
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    monitor.done();
                }

            }
        });
        HandleType handleType = convertHandleType(hdType.toString());
        if (handleType == HandleType.NONE) {
            MessageDialog.openWarning(shell, "Warning", Fasti18n.getString("not_the_effective_node"));
            return;
        }

        if (sb != null && sb.length() > 0) {
            boolean b = MessageDialog.openConfirm(shell, Fasti18n.getString("Confirm"),
                    MessageFormat.format(Fasti18n.getString("similar_sql"), sb.toString()));
            if (!b)
                return;
        }
        FastIbatisDialog dialog = new FastIbatisDialog(shell);
        final FastIbatisConfig fc = dialog.open(ibatisSqlMapIdName, handleType);
        fc.setMethodName(ibatisSqlMapIdName);
        if (!dialog.isDAOGenerate() && !dialog.isServiceGenerate()) {
            return;
        }

        ProgressMonitorDialog progressDlg = new ProgressMonitorDialog(shell);
        progressDlg.run(true, true, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(Fasti18n.getString("start_working") + "...", 1);
                try {
                    generateFastIbatisCode(fc, file);
                    if (file != null)
                        file.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
                    monitor.worked(1);
                } catch (CoreException e) {
                    e.printStackTrace();
                } finally {
                    monitor.done();
                }

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

}

From source file:net.sf.jmoney.serializeddatastore.formats.JMoneyXmlFormat.java

License:Open Source License

/**
 * Read session from file. The session is set as the open session in the
 * given session manager.//  www. j a  v a2 s. c om
 * <P>
 * The opened session is set as the current open JMoney session. If no
 * session can be opened then an appropriate message is displayed to the
 * user and the previous session, if any, is left open.
 * <P>
 * If this method returns false then any previous session will be left open.
 * The caller will not display any error message. This method must display
 * an appropriate error message if the file cannot be read.
 * 
 * @return true if the file was successfully read and the session was set in
 *         the given session manager, false if the user cancelled the
 *         operation or if a failure occurred
 */
public boolean readSession(final File sessionFile, final SessionManager sessionManager,
        final IWorkbenchWindow window) {
    try {
        if (sessionFile.length() < 500000) {
            // If the file is smaller than 500K then it is
            // not worthwhile using a progress monitor.
            // The monitor would flash up so quickly that the
            // user could not read it.
            readSessionQuietly(sessionFile, sessionManager, null);
        } else {
            IRunnableWithProgress readSessionRunnable = new IRunnableWithProgress() {

                public void run(IProgressMonitor monitor) throws InvocationTargetException {
                    // Set the number of work units in the monitor where
                    // one work unit is reading 100 Kbytes.
                    int workUnits = (int) (sessionFile.length() / 100000);

                    monitor.beginTask(MessageFormat.format(Messages.JMoneyXmlFormat_OpeningFile, sessionFile),
                            workUnits);

                    try {
                        readSessionQuietly(sessionFile, sessionManager, monitor);
                    } catch (Exception ex) {
                        throw new InvocationTargetException(ex);
                    } finally {
                        monitor.done();
                    }
                }

            };

            ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(window.getShell());

            try {
                progressDialog.run(true, false, readSessionRunnable);
            } catch (InvocationTargetException e) {
                throw e.getCause();
            }
        }
    } catch (InterruptedException e) {
        /*
         * If the user interrupted the read then no error message is
         * displayed. Currently this cannot happen because the cancel button
         * is not enabled in the progress dialog, but if the cancel button
         * is enabled then we do nothing here, leaving the previous session,
         * if any, open.
         */
        return false;
    } catch (Throwable ex) {
        JMoneyPlugin.log(ex);

        String message = MessageFormat.format(Messages.JMoneyXmlFormat_ReadErrorMessage, sessionFile.getPath());
        String title = Messages.JMoneyXmlFormat_ReadErrorTitle;
        MessageDialog.openError(window.getShell(), title, message);

        return false;
    }

    return true;
}

From source file:net.sf.jmoney.serializeddatastore.formats.JMoneyXmlFormat.java

License:Open Source License

/**
 * Write session to file./*from   w w w.jav  a2  s .  c om*/
 */
public void writeSession(final SessionManager sessionManager, final File sessionFile, IWorkbenchWindow window) {
    // If there is any modified data in the controls in any of the
    // views, then commit these to the database now.
    // TODO: How do we do this? Should framework call first
    // commitRemainingUserChanges();

    try {
        if (/* session.getTransactionCount() < 1000 */false) {
            // If the session has less than 1000 transactions then it is
            // not worthwhile using a progress monitor.
            // The monitor would flash up so quickly that the
            // user could not read it.
            writeSessionQuietly(sessionManager, sessionFile, null);
        } else {
            IRunnableWithProgress writeSessionRunnable = new IRunnableWithProgress() {

                public void run(IProgressMonitor monitor) throws InvocationTargetException {
                    // Set the number of work units in the monitor where
                    // one work unit is writing 500 transactions
                    // int workUnits =
                    // (int)(session.getTransactionCount()/500);
                    int workUnits = IProgressMonitor.UNKNOWN;

                    monitor.beginTask(MessageFormat.format(Messages.JMoneyXmlFormat_SavingFile, sessionFile),
                            workUnits);

                    try {
                        writeSessionQuietly(sessionManager, sessionFile, monitor);
                    } catch (Exception ex) {
                        throw new InvocationTargetException(ex);
                    } finally {
                        monitor.done();
                    }
                }

            };

            ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(window.getShell());

            try {
                progressDialog.run(true, false, writeSessionRunnable);
            } catch (InvocationTargetException e) {
                throw e.getCause();
            }
        }
    } catch (InterruptedException e) {
        // If the user inturrupted the write then we do nothing.
        // Currently this cannot happen because the cancel button is not
        // enabled in the progress dialog, but if the cancel button is
        // enabled
        // then a message should perhaps be displayed here indicating that
        // the
        // file is unusable.
    } catch (Throwable ex) {
        JMoneyPlugin.log(ex);
        fileWriteError(sessionFile, window);
    }
}

From source file:net.sourceforge.eclipseccase.ui.wizards.MergeWizardPage.java

License:Open Source License

private void loadBranches() {
    final IProject project = ResourcesPlugin.getWorkspace().getRoot()
            .getProject(resources[0].getProject().getName());
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
    try {/*from   w w w.j  a  v a  2 s  .  c o m*/
        dialog.run(true, true, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) {
                monitor.beginTask("Loading branches for project ...", 100);
                // execute the task ...

                if (project != null) {
                    File workingDir = new File(project.getLocation().toOSString());

                    if (provider != null && (provider.isClearCaseElement(project))) {
                        branches = provider.loadBrancheList(workingDir);

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

}

From source file:net.sourceforge.javahexeditor.plugin.editors.HexEditor.java

License:Open Source License

void saveToFile(final boolean selection) {
    final File file = getManager().showSaveAsDialog(getEditorSite().getShell(), selection);
    if (file == null) {
        return;/*from w  ww  .ja  v a2 s .c  om*/
    }

    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        @Override
        public void run(IProgressMonitor monitor) {
            saveToFile(file, selection, monitor);
        }
    };
    ProgressMonitorDialog monitorDialog = new ProgressMonitorDialog(getEditorSite().getShell());
    try {
        monitorDialog.run(false, false, runnable);
    } catch (InvocationTargetException ex) {
        throw new RuntimeException(ex);
    } catch (InterruptedException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:net.sourceforge.pmd.eclipse.ui.quickfix.PMDResolution.java

License:Open Source License

/**
 * @see org.eclipse.ui.IMarkerResolution#run(org.eclipse.core.resources.IMarker)
 *//*  ww w  . ja  va 2  s.  c  o  m*/
public void run(IMarker marker) {
    log.debug("fixing...");
    IResource resource = marker.getResource();
    this.lineNumber = marker.getAttribute(IMarker.LINE_NUMBER, 0);
    if (resource instanceof IFile) {
        this.file = (IFile) resource;

        try {
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
            dialog.run(false, false, this);
        } catch (InvocationTargetException e) {
            showError(StringKeys.ERROR_INVOCATIONTARGET_EXCEPTION, e);
        } catch (InterruptedException e) {
            showError(StringKeys.ERROR_INTERRUPTED_EXCEPTION, e);
        }
    }

}

From source file:net.sourceforge.tagsea.core.ui.internal.actions.TagDeleteAction.java

License:Open Source License

@Override
public void run() {
    final ISelection selection = getContext().getSelection();
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
    try {//from w  ww  .  j  a va  2s . c o m
        dialog.run(false, true, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                if (selection instanceof IStructuredSelection) {
                    List<?> selectionList = ((IStructuredSelection) selection).toList();
                    monitor.beginTask("Deleting Tags...", selectionList.size() + 10);
                    IProgressMonitor modelMonitor = new SubProgressMonitor(monitor, selectionList.size());
                    IProgressMonitor updateMonitor = new SubProgressMonitor(monitor, 10);
                    IStatus status = TagSEAPlugin.syncRun(getOperation(selectionList), modelMonitor);
                    if (!status.isOK()) {
                        TagSEAPlugin.getDefault().getLog().log(status);
                    }
                    updateMonitor.worked(10);
                    monitor.done();
                }
            }
        });
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:net.sourceforge.tagsea.resources.sharing.ui.ResourceWaypointExportWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
    final List<IResourceWaypointDescriptor> selected = page.getSelectedDescriptorList();
    try {//from   ww w.  jav a2  s. c  o  m
        dialog.run(true, false, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Exporting waypoints", 1);
                String pathString = page.getPath();
                IPath path = new Path(pathString);
                IPath parents = path.removeLastSegments(1);
                if (parents.segmentCount() > 0) {
                    File dirs = parents.toFile();
                    if (!dirs.exists()) {
                        if (!dirs.mkdirs()) {
                            throw new InvocationTargetException(
                                    new IOException("Failed to create directories."));
                        }
                    }
                }
                File file = path.toFile();
                try {
                    if (!file.exists()) {
                        if (!file.createNewFile()) {
                            throw new InvocationTargetException(
                                    new IOException("Failed to create directories."));
                        }
                    }
                    XMLMemento memento = XMLMemento.createWriteRoot("resource-waypoints");
                    WaypointShareUtilities.writeWaypoints(selected, memento);
                    FileWriter writer = new FileWriter(file);
                    memento.save(writer);
                    monitor.done();
                } catch (IOException e) {
                    throw new InvocationTargetException(e);
                } finally {
                    monitor.worked(1);
                    monitor.done();
                }
            }

        });
    } catch (InvocationTargetException e) {
        ResourceWaypointPlugin.getDefault().log(e);
        MessageDialog.openError(getShell(), "Export Error", e.getCause().getMessage());
        return false;
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return false;
    }
    return true;
}