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.cdt.cpp.ui.internal.actions.DeleteProjectAction.java

License:Open Source License

public void run() {
    ModelInterface api = ModelInterface.getInstance();
    IProject project = api.findProjectResource(_subject);
    if (project != null) {
        Shell shell = api.getDummyShell();
        String msg = "About to delete project \'" + project.getName() + "\'.\n";
        msg += "Delete all its contents under " + project.getLocation().toOSString() + " as well?";
        String title = "Delete Project Contents";

        MessageDialog dialog = new MessageDialog(shell, title, null, // accept the default window icon
                msg, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL,
                        IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
                0); // yes is the default
        int code = dialog.open();
        boolean deleteContent = false;
        switch (code) {
        case 0: // Yes
            deleteContent = true;//from  w  w  w .  ja v a 2s .  c  om
            break;
        case 1: // No
            deleteContent = false;
            break;
        default: // CANCEL
            return;
        }

        DeleteOperation op = new DeleteOperation(project, api, deleteContent);
        ProgressMonitorDialog progressDlg = new ProgressMonitorDialog(shell);
        try {
            progressDlg.run(true, true, op);
        } catch (InterruptedException e) {
            System.out.println(e);
        } catch (InvocationTargetException e) {
            System.out.println(e);
        }
    }
}

From source file:org.eclipse.cdt.cpp.ui.internal.actions.OpenProjectAction.java

License:Open Source License

public void run() {
    for (int i = 0; i < _projects.size(); i++) {
        DataElement subject = (DataElement) _subjects.get(i);
        IProject project = (IProject) _projects.get(i);

        OpenOperation op = new OpenOperation(project, subject, _api);
        ProgressMonitorDialog progressDlg = new ProgressMonitorDialog(_api.getDummyShell());
        try {//from   w w w .j  ava 2  s .com
            progressDlg.run(true, true, op);
        } catch (InterruptedException e) {
        } catch (InvocationTargetException e) {
        }
    }
}

From source file:org.eclipse.cdt.cpp.ui.internal.actions.ReplicateFromAction.java

License:Open Source License

public void run() {
    ModelInterface api = ModelInterface.getInstance();
    ChooseProjectDialog dlg = new ChooseProjectDialog("Choose a Project To Replicate From",
            api.findWorkspaceElement());

    dlg.open();//from   ww w.j av  a 2 s . c o  m

    if (dlg.getReturnCode() == dlg.OK) {
        List projects = dlg.getSelected();

        ReplicateFromOperation op = new ReplicateFromOperation(_subject, projects, api);
        ProgressMonitorDialog progressDlg = new ProgressMonitorDialog(api.getDummyShell());
        try {
            progressDlg.run(true, true, op);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

        IProgressMonitor monitor = progressDlg.getProgressMonitor();
        if (monitor.isCanceled()) {
            System.out.println("cancelled");
        }

    }
}

From source file:org.eclipse.cdt.cpp.ui.internal.actions.ReplicateToAction.java

License:Open Source License

public void run() {
    ModelInterface api = ModelInterface.getInstance();
    ChooseProjectDialog dlg = new ChooseProjectDialog("Choose a Project To Replicate To",
            api.findWorkspaceElement());

    dlg.open();//  w w w  .ja va2  s .  c o  m
    if (dlg.getReturnCode() == dlg.OK) {
        List projects = dlg.getSelected();

        ReplicateToOperation op = new ReplicateToOperation(_subject, projects, api);
        ProgressMonitorDialog progressDlg = new ProgressMonitorDialog(api.getDummyShell());
        try {
            progressDlg.run(true, true, op);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.eclipse.cdt.cpp.ui.internal.actions.SynchronizeWithAction.java

License:Open Source License

public void run() {
    ModelInterface api = ModelInterface.getInstance();

    ChooseProjectDialog dlg = new ChooseProjectDialog("Choose a Project To Synchronize With",
            api.findWorkspaceElement());
    dlg.open();/*from   w w w  .  ja  v a2  s. c o  m*/

    if (dlg.getReturnCode() == dlg.OK) {
        List projects = dlg.getSelected();

        SynchronizeWithOperation op = new SynchronizeWithOperation(_subject, projects, api);
        ProgressMonitorDialog progressDlg = new ProgressMonitorDialog(api.getDummyShell());
        try {
            progressDlg.run(true, true, op);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

    }
}

From source file:org.eclipse.cdt.debug.application.ApplicationWorkbenchWindowAdvisor.java

License:Open Source License

private void disconnectFromWorkspace() {

    // save the workspace
    final MultiStatus status = new MultiStatus(Activator.PLUGIN_ID, 1, Messages.ProblemSavingWorkbench, null);
    try {// w w  w .j a v  a 2  s  .  c o  m
        final ProgressMonitorDialog p = new ProgressMonitorDialog(null);
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) {
                try {
                    status.merge(ResourcesPlugin.getWorkspace().save(true, monitor));
                } catch (CoreException e) {
                    status.merge(e.getStatus());
                }
            }
        };
        p.run(true, false, runnable);
    } catch (InvocationTargetException e) {
        status.merge(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 1, Messages.InternalError,
                e.getTargetException()));
    } catch (InterruptedException e) {
        status.merge(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 1, Messages.InternalError, e));
    }

    ErrorDialog.openError(null, Messages.ProblemsSavingWorkspace, null, status,
            IStatus.ERROR | IStatus.WARNING);

    if (!status.isOK()) {
        ResourcesPlugin.getPlugin().getLog().log(status);
    }

}

From source file:org.eclipse.cdt.debug.internal.ui.launch.CApplicationLaunchShortcut.java

License:Open Source License

/**
 * Method searchAndLaunch./*  w  w  w  . j  av  a2  s .co  m*/
 * @param objects
 * @param mode
 */
private 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<IBinary> results = new ArrayList<IBinary>();
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
            IRunnableWithProgress runnable = new IRunnableWithProgress() {
                @Override
                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].isExecutable()) {
                                                    results.add(bins[j]);
                                                }
                                            }
                                        } catch (CModelException e) {
                                        }
                                    }
                                }
                            }
                            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(),
                        LaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), //$NON-NLS-1$
                        e.getMessage());
                return;
            }
            int count = results.size();
            if (count == 0) {
                MessageDialog.openError(getShell(),
                        LaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), //$NON-NLS-1$
                        LaunchMessages.getString("CApplicationLaunchShortcut.Launch_failed_no_binaries")); //$NON-NLS-1$
            } else if (count > 1) {
                bin = chooseBinary(results, mode);
            } else {
                bin = results.get(0);
            }
        }
        if (bin != null) {
            launch(bin, mode);
        }
    } else {
        MessageDialog.openError(getShell(),
                LaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), //$NON-NLS-1$
                LaunchMessages.getString("CApplicationLaunchShortcut.Launch_failed_no_project_selected")); //$NON-NLS-1$
    }
}

From source file:org.eclipse.cdt.dstore.ui.connections.Connection.java

License:Open Source License

public ConnectionStatus connect(DomainNotifier notifier, String minersFile) {
    _notifier = notifier;/*w  ww  .ja va  2 s  .c  o m*/
    if (_client == null) {
        _client = new ClientConnection(_name, notifier);
        _client.setLoaders(_element.getDataStore().getLoaders());
    }

    _client.setHost(_host);
    _client.setPort(_port);
    _client.setHostDirectory(_dir);

    DataStore parentDS = _element.getDataStore();
    DataStore newDS = _client.getDataStore();

    newDS.setAttribute(DataStoreAttributes.A_PLUGIN_PATH,
            parentDS.getAttribute(DataStoreAttributes.A_PLUGIN_PATH));

    ConnectionStatus connectStatus = null;
    if (!_isLocal) {
        if (_isUsingDaemon) {
            Shell shell = notifier.findShell();
            LoginDialog ldialog = new LoginDialog();
            ldialog.open();
            if (ldialog.getReturnCode() != ldialog.OK)
                return null;
            _user = ldialog.getUser();
            _password = ldialog.getPassword();
        }
    }

    Shell shell = notifier.findShell();
    ConnectOperation op = new ConnectOperation(minersFile);
    ProgressMonitorDialog progressDlg = new ProgressMonitorDialog(shell);
    try {
        progressDlg.run(true, true, op);
    } catch (InterruptedException e) {
    } catch (InvocationTargetException e) {
    }

    if (_client != null && _client.isConnected()) {
        notifier.addDomainListener(this);
    }

    return op.getStatus();
}

From source file:org.eclipse.cdt.internal.docker.launcher.LaunchShortcut.java

License:Open Source License

/**
 * Search and launch binary.//  w  ww.j  a v  a2 s .  co m
 * 
 * @param elements
 *            Binaries to search.
 * @param mode
 *            Launch mode.
 */
private 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<IBinary> results = new ArrayList<>();
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(getActiveWorkbenchShell());
            IRunnableWithProgress runnable = new IRunnableWithProgress() {
                @Override
                public void run(IProgressMonitor pm) throws InterruptedException {
                    int nElements = elements.length;
                    pm.beginTask(Messages.LaunchShortcut_Looking_for_executables, nElements);
                    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 (IBinary bin : bins) {
                                                if (bin.isExecutable()) {
                                                    results.add(bin);
                                                }
                                            }
                                        } catch (CModelException e) {
                                            // TODO should this be simply
                                            // ignored ?
                                        }
                                    }
                                }
                            }
                            if (pm.isCanceled()) {
                                throw new InterruptedException();
                            }
                            sub.done();
                        }
                    } finally {
                        pm.done();
                    }
                }
            };
            try {
                dialog.run(true, true, runnable);
            } catch (InterruptedException e) {
                return;
            } catch (InvocationTargetException e) {
                handleFail(e.getMessage());
                return;
            }
            int count = results.size();
            if (count == 0) {
                handleFail(Messages.LaunchShortcut_Binary_not_found);
            } else if (count > 1) {
                bin = chooseBinary(results, mode);
            } else {
                bin = results.get(0);
            }
        }
        if (bin != null) {
            launch(bin, mode);
        }
    } else {
        handleFail(Messages.LaunchShortcut_no_project_selected);
    }
}

From source file:org.eclipse.cdt.internal.ui.refactoring.ChangeExceptionHandler.java

License:Open Source License

private void performUndo(final Change undo) {
    IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
        @Override/* w  w  w  .  ja  v a  2s.c o m*/
        public void run(IProgressMonitor monitor) throws CoreException {
            monitor.beginTask("", 11); //$NON-NLS-1$
            try {
                undo.initializeValidationData(
                        new NotCancelableProgressMonitor(new SubProgressMonitor(monitor, 1)));
                if (undo.isValid(new SubProgressMonitor(monitor, 1)).hasFatalError()) {
                    monitor.done();
                    return;
                }
                undo.perform(new SubProgressMonitor(monitor, 9));
            } finally {
                undo.dispose();
            }
        }
    };
    WorkbenchRunnableAdapter adapter = new WorkbenchRunnableAdapter(runnable,
            ResourcesPlugin.getWorkspace().getRoot());
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(fParent);
    try {
        dialog.run(false, false, adapter);
    } catch (InvocationTargetException e) {
        ExceptionHandler.handle(e, fParent, Messages.ChangeExceptionHandler_undo_dialog_title,
                NLS.bind(Messages.ChangeExceptionHandler_undo_dialog_message, fName));
    } catch (InterruptedException e) {
        // can't happen
    }
}