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.osp.debugger.launch.shortcut.OSPSimulLaunchShortcut.java

License:Open Source License

private void searchAndLaunchProgress(final Object[] elements, String mode) {
    if (elements != null && elements.length > 0) {
        IBinary bin = null;/*  w w  w. j  av  a 2 s  . c  o m*/
        if (elements.length == 1 && elements[0] instanceof IBinary) {
            bin = (IBinary) elements[0];
        } else {
            final List results = new ArrayList();
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
            IRunnableWithProgress runnable = new IRunnableWithProgress() {
                public void run(IProgressMonitor pm) throws InterruptedException {
                    int nElements = elements.length;
                    pm.beginTask("Looking for executables", nElements); //$NON-NLS-1$
                    try {
                        IProgressMonitor sub = new SubProgressMonitor(pm, 1);
                        for (int i = 0; i < nElements; i++) {
                            if (elements[i] instanceof IAdaptable) {
                                IResource r = (IResource) ((IAdaptable) elements[i])
                                        .getAdapter(IResource.class);
                                if (r != null) {
                                    ICProject cproject = CoreModel.getDefault().create(r.getProject());
                                    if (cproject != null) {
                                        try {
                                            IBinary[] bins = cproject.getBinaryContainer().getBinaries();

                                            for (int j = 0; j < bins.length; j++) {
                                                if (bins[j].isSharedLib()) {
                                                    IPath path = bins[j].getPath().removeLastSegments(1);
                                                    if (path != null) {
                                                        String dirName = path.lastSegment();
                                                        if (dirName != null && dirName
                                                                .equals(IConstants.CONFIG_SIMUAL_DEBUG_DIR))
                                                            results.add(bins[j]);
                                                    }
                                                }
                                            }
                                        } catch (CModelException e) {
                                            e.printStackTrace();
                                        }
                                    }
                                }
                            }
                            if (pm.isCanceled()) {
                                throw new InterruptedException();
                            }
                            sub.done();
                        }
                    } finally {
                        pm.done();
                    }
                }
            };
            try {
                dialog.run(true, true, runnable);
            } catch (InterruptedException e) {
                return;
            } catch (InvocationTargetException e) {
                MessageDialog.openError(getShell(),
                        OspLaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), //$NON-NLS-1$
                        e.getMessage());
                return;
            }
            int count = results.size();
            if (count == 0) {
                MessageDialog.openError(getShell(),
                        OspLaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), //$NON-NLS-1$
                        OspLaunchMessages.getString("CApplicationLaunchShortcut.Launch_failed_no_binaries")); //$NON-NLS-1$
            } else if (count > 1) {
                bin = chooseBinary(results, mode);
            } else {
                bin = (IBinary) results.get(0);
            }
        }
        if (bin != null) {
            launch(bin, mode);
        }
    } else {
        MessageDialog.openError(getShell(),
                OspLaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), //$NON-NLS-1$
                OspLaunchMessages.getString("CApplicationLaunchShortcut.Launch_failed_no_project_selected")); //$NON-NLS-1$
    }
}

From source file:com.osp.debugger.launch.shortcut.OSPTargetLaunchShortcut.java

License:Open Source License

/**
 * Method searchAndLaunch./* w w w .j  a  v  a 2 s . co m*/
 * @param objects
 * @param mode
 */
protected void searchAndLaunch(final Object[] elements, String mode) {
    if (elements != null && elements.length > 0) {
        IBinary bin = null;
        if (elements.length == 1 && elements[0] instanceof IBinary) {
            bin = (IBinary) elements[0];
        } else {
            final List results = new ArrayList();
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
            IRunnableWithProgress runnable = new IRunnableWithProgress() {
                public void run(IProgressMonitor pm) throws InterruptedException {
                    int nElements = elements.length;
                    pm.beginTask("Looking for executables", nElements); //$NON-NLS-1$
                    try {
                        IProgressMonitor sub = new SubProgressMonitor(pm, 1);
                        for (int i = 0; i < nElements; i++) {
                            if (elements[i] instanceof IAdaptable) {
                                IResource r = (IResource) ((IAdaptable) elements[i])
                                        .getAdapter(IResource.class);
                                if (r != null) {
                                    ICProject cproject = CoreModel.getDefault().create(r.getProject());
                                    if (cproject != null) {

                                        try {
                                            IBinary[] bins = cproject.getBinaryContainer().getBinaries();

                                            for (int j = 0; j < bins.length; j++) {
                                                if (bins[j].isSharedLib()) {
                                                    IPath path = bins[j].getPath().removeLastSegments(1);
                                                    if (path != null) {
                                                        String dirName = path.lastSegment();
                                                        if (dirName != null && dirName.startsWith(
                                                                IConstants.CONFIG_TARGET_DIR_PREFIX)) {
                                                            results.add(bins[j]);
                                                        }
                                                    }
                                                }
                                            }
                                        } catch (CModelException e) {
                                            e.printStackTrace();
                                        }
                                    }
                                }
                            }
                            if (pm.isCanceled()) {
                                throw new InterruptedException();
                            }
                            sub.done();
                        }
                    } finally {
                        pm.done();
                    }
                }
            };
            try {
                dialog.run(true, true, runnable);
            } catch (InterruptedException e) {
                return;
            } catch (InvocationTargetException e) {
                MessageDialog.openError(getShell(),
                        OspLaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), //$NON-NLS-1$
                        e.getMessage());
                return;
            }
            int count = results.size();
            if (count == 0) {
                MessageDialog.openError(getShell(),
                        OspLaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), //$NON-NLS-1$
                        OspLaunchMessages.getString("CApplicationLaunchShortcut.Launch_failed_no_binaries")); //$NON-NLS-1$
            } else if (count > 1) {
                bin = chooseBinary(results, mode);
            } else {
                bin = (IBinary) results.get(0);
            }
        }
        if (bin != null) {
            launch(bin, mode);
        }
    } else {
        MessageDialog.openError(getShell(),
                OspLaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), //$NON-NLS-1$
                OspLaunchMessages.getString("CApplicationLaunchShortcut.Launch_failed_no_project_selected")); //$NON-NLS-1$
    }
}

From source file:com.python.pydev.actions.PyShowHierarchy.java

License:Open Source License

@Override
protected String perform(IAction action, IProgressMonitor monitor) throws Exception {
    try {/*w ww .ja  v a2s. c  om*/
        final PyHierarchyView view;
        IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        IWorkbenchPage page = workbenchWindow.getActivePage();
        view = (PyHierarchyView) page.showView("com.python.pydev.ui.hierarchy.PyHierarchyView", null,
                IWorkbenchPage.VIEW_VISIBLE);

        ProgressMonitorDialog monitorDialog = new AsynchronousProgressMonitorDialog(EditorUtils.getShell());
        try {
            IRunnableWithProgress operation = new IRunnableWithProgress() {

                public void run(final IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    try {
                        final HierarchyNodeModel model;

                        //set whatever is needed for the hierarchy
                        IPyRefactoring pyRefactoring = AbstractPyRefactoring.getPyRefactoring();
                        if (pyRefactoring instanceof IPyRefactoring2) {
                            RefactoringRequest refactoringRequest = getRefactoringRequest(monitor);
                            IPyRefactoring2 r2 = (IPyRefactoring2) pyRefactoring;
                            model = r2.findClassHierarchy(refactoringRequest, false);

                            if (monitor.isCanceled()) {
                                return;
                            }
                            Runnable r = new Runnable() {
                                public void run() {
                                    if (!monitor.isCanceled()) {
                                        view.setHierarchy(model);
                                    }
                                }
                            };
                            Display.getDefault().asyncExec(r);
                        }
                    } catch (Exception e) {
                        Log.log(e);
                    }

                }
            };

            boolean fork = true;
            monitorDialog.run(fork, true, operation);
        } catch (Throwable e) {
            Log.log(e);
        }
    } catch (Exception e) {
        Log.log(e);
    }
    return "";
}

From source file:com.python.pydev.ui.search.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);
        }//from  w w  w .  ja  va2s  .  c o m
        return false;
    }

    final List<IFile> outOfDateEntries = new ArrayList<IFile>();
    for (int j = 0; j < fElements.length; j++) {
        IFile 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<IFile> outOfSyncEntries = new ArrayList<IFile>();
    for (int i = 0; i < fElements.length; i++) {
        IFile entry = fElements[i];
        if (isOutOfSync(entry)) {
            outOfSyncEntries.add(entry);
        }
    }

    if (outOfDateEntries.size() > 0 || outOfSyncEntries.size() > 0) {
        if (askForResearch(outOfDateEntries, outOfSyncEntries)) {
            ProgressMonitorDialog pmd = new AsynchronousProgressMonitorDialog(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.quantcomponents.ui.marketdata.NewHistoricalData.java

License:Open Source License

private List<IContract> searchContracts() {
    final List<IContract> contractList = new ArrayList<IContract>();
    try {//from w w  w  . ja  va  2 s  .  c  o  m
        ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
        dialog.setCancelable(true);
        dialog.run(true, true, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    contractList.addAll(marketDataManager.searchContracts(contractCriteria,
                            new TaskMonitorAdapter(monitor, "Searching contracts...")));
                } catch (ConnectException e) {
                    throw new InvocationTargetException(e);
                } catch (RequestFailedException e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (Exception e) {
        MessageDialog.openError(getShell(), "Error", "Contract search error: " + LangUtils.exceptionMessage(e));
        return Collections.emptyList();
    }
    if (contractList == null || contractList.isEmpty()) {
        MessageDialog.openError(this.getShell(), "No results",
                "Search for contracts returned empty set. Please revise your criteria");
        return Collections.emptyList();
    }
    return contractList;
}

From source file:com.quantcomponents.ui.marketdata.NewHistoricalData.java

License:Open Source License

private void retrieveHistoricalData(final IStockDatabase stockDatabase, final Date startDateTime,
        final Date endDateTime) throws InvocationTargetException, InterruptedException {
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
    dialog.setCancelable(true);//ww w. j a  v  a  2 s  . c o  m
    dialog.run(true, true, new IRunnableWithProgress() {
        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                ITaskMonitor taskMonitor = new TaskMonitorAdapter(monitor, "Retrieving historical data...");
                marketDataManager.fillHistoricalData(stockDatabase, startDateTime, endDateTime, taskMonitor);
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            }
        }
    });
}

From source file:com.quantcomponents.ui.marketdata.NewHistoricalData.java

License:Open Source License

private void startAutoUpdate(final IStockDatabase stockDatabase)
        throws InvocationTargetException, InterruptedException {
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
    dialog.setCancelable(true);/*from   w w  w.  j a  va  2 s. c o m*/
    final IRealTimeMarketDataManager realTimeMarketDataManager = (IRealTimeMarketDataManager) marketDataManager;
    dialog.run(true, true, new IRunnableWithProgress() {
        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                ITaskMonitor taskMonitor = new TaskMonitorAdapter(monitor, "Starting auto-update...");
                realTimeMarketDataManager.startRealtimeUpdate(stockDatabase, true, taskMonitor);
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            }
        }
    });
}

From source file:com.quantcomponents.ui.marketdata.TimeChartDialog.java

License:Open Source License

private boolean executeChange() {
    final Date newStartDate = getStartDate();
    final Date newEndDate = getEndDate();
    try {//from  www . j  a  v  a 2  s .c o m
        ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
        dialog.setCancelable(true);
        dialog.run(true, true, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    chartModel.setSuspendUpdates(true);
                    stockDatabase.getParent().fillHistoricalData(stockDatabase, newStartDate, newEndDate,
                            new TaskMonitorAdapter(monitor, "Retrieving historical data..."));
                    chartModel.setSuspendUpdates(false);
                } catch (Exception e) {
                    MessageDialog.openError(getShell(), "Error",
                            "Error while retrieving historical data: " + LangUtils.exceptionMessage(e));
                }
            }
        });
    } catch (InvocationTargetException e) {
        MessageDialog.openError(getShell(), "Error", "A problem occurred while retrieving historical data");
        return false;
    } catch (InterruptedException e) {
        MessageDialog.openError(getShell(), "Error",
                "Task interrupted while retrieving historical data: " + LangUtils.exceptionMessage(e));
        return false;
    }
    if (isMovingWindow()) {
        chartModel.setFixedDurationWindow(newStartDate, tradingCalendar);
    } else {
        chartModel.setFixedWindow(newStartDate, newEndDate, tradingCalendar);
    }
    return true;
}

From source file:com.safi.workshop.util.SafletPersistenceManager.java

public IProject createNewProject(SafletProject sr) throws CoreException {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    final IProject project = root.getProject(sr.getName());
    // project.create(null);
    // project.open(null);
    final IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(project.getName());
    // final IProjectDescription desc = project.getDescription();
    desc.setLocation(null);/*w  w  w  . ja  v  a  2 s.  co  m*/

    // String[] natures = description.getNatureIds();
    // String[] newNatures = new String[natures.length + 1];
    // System.arraycopy(natures, 0, newNatures, 0, natures.length);
    // newNatures[natures.length] = SafiProjectNature.NATURE_ID;
    // description.setNatureIds(newNatures);

    String[] natures = desc.getNatureIds();
    String[] newNatures = new String[natures.length + 1];
    System.arraycopy(natures, 0, newNatures, 0, natures.length);
    newNatures[natures.length] = SafiProjectNature.NATURE_ID;
    desc.setNatureIds(newNatures);

    // desc.setNatureIds(new String[] { SafiProjectNature.NATURE_ID });
    // project.setDescription(desc, null);

    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            CreateProjectOperation op = new CreateProjectOperation(desc,
                    ResourceMessages.NewProject_windowTitle);
            try {
                PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, monitor,
                        WorkspaceUndoUtil.getUIInfoAdapter(SafiWorkshopEditorUtil.getActiveShell()));
            } catch (ExecutionException e) {
                throw new InvocationTargetException(e);
            }
        }
    };

    ProgressMonitorDialog pd = new ProgressMonitorDialog(SafiWorkshopEditorUtil.getActiveShell());
    // run the new project creation operation
    try {
        pd.run(false, true, op);
    } catch (InterruptedException e) {
        return null;
    } catch (InvocationTargetException e) {
        Throwable t = e.getTargetException();
        if (t instanceof ExecutionException && t.getCause() instanceof CoreException) {
            CoreException cause = (CoreException) t.getCause();
            StatusAdapter status;
            if (cause.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
                status = new StatusAdapter(StatusUtil.newStatus(IStatus.WARNING,
                        NLS.bind(ResourceMessages.NewProject_caseVariantExistsError, project.getName()),
                        cause));
            } else {
                status = new StatusAdapter(StatusUtil.newStatus(cause.getStatus().getSeverity(),
                        ResourceMessages.NewProject_errorMessage, cause));
            }
            status.setProperty(StatusAdapter.TITLE_PROPERTY, ResourceMessages.NewProject_errorMessage);
            StatusManager.getManager().handle(status, StatusManager.BLOCK);
        } else {
            StatusAdapter status = new StatusAdapter(
                    new Status(IStatus.WARNING, IDEWorkbenchPlugin.IDE_WORKBENCH, 0,
                            NLS.bind(ResourceMessages.NewProject_internalError, t.getMessage()), t));
            status.setProperty(StatusAdapter.TITLE_PROPERTY, ResourceMessages.NewProject_errorMessage);
            StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.BLOCK);
        }
    }
    return project;
}

From source file:com.siteview.mde.internal.ui.launcher.OpenLogDialog.java

License:Open Source License

private void readLargeFileWithMonitor(final PrintWriter writer) {
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitor.beginTask(MDEUIMessages.OpenLogDialog_message, IProgressMonitor.UNKNOWN);
            try {
                readLargeFile(writer);/* w ww. j ava  2s. c  om*/
            } catch (IOException e) {
                writer.println(MDEUIMessages.OpenLogDialog_cannotDisplay);
            }
        }
    };
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getParentShell());
    try {
        dialog.run(true, true, runnable);
    } catch (InvocationTargetException e) {
    } catch (InterruptedException e) {
    }
}