Example usage for org.eclipse.jface.dialogs ErrorDialog openError

List of usage examples for org.eclipse.jface.dialogs ErrorDialog openError

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs ErrorDialog openError.

Prototype

public static int openError(Shell parentShell, String title, String message, IStatus status, int displayMask) 

Source Link

Document

Opens an error dialog to display the given error.

Usage

From source file:br.ufmg.dcc.tabuleta.ui.ProblemManager.java

License:Open Source License

/**
 * Reports an exception in a dialog and logs the exception.  The 
 * exception dialog contains the stack trace details.
 * @param pException The exception to report.
 *//*from   w  w  w . j a v a2s  .co m*/
public static void reportException(Exception pException) {
    StackTraceElement[] lStackElements = pException.getStackTrace();
    IStatus[] lStatuses = new IStatus[lStackElements.length + 1];
    lStatuses[0] = new Status(IStatus.ERROR, Tabuleta.ID_PLUGIN, IStatus.OK, pException.getClass().getName(),
            pException);
    for (int lI = 0; lI < lStackElements.length; lI++) {
        lStatuses[lI + 1] = new Status(IStatus.ERROR, Tabuleta.ID_PLUGIN, IStatus.OK,
                "     " + lStackElements[lI].toString(), pException);
    }

    String lMessage = Tabuleta.getResourceString("ui.ProblemManager.DefaultMessage");
    String lTitle = Tabuleta.getResourceString("ui.ProblemManager.DialogTitle");
    if (pException.getMessage() != null) {
        lMessage = pException.getMessage();
    }
    MultiStatus lStatus = new MultiStatus(Tabuleta.ID_PLUGIN, IStatus.OK, lStatuses, lMessage, pException);
    ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), lTitle, lMessage,
            lStatus, IStatus.ERROR);
    Tabuleta.getDefault().getLog().log(lStatus);
}

From source file:com.aptana.git.ui.internal.sharing.SharingWizard.java

License:Open Source License

public boolean performFinish() {
    final ConnectProviderOperation op = new ConnectProviderOperation(existingPage.getProjects());
    try {//w  w  w . j  a  v a  2s.c  om
        getContainer().run(true, false, new IRunnableWithProgress() {
            public void run(final IProgressMonitor monitor) throws InvocationTargetException {
                try {
                    op.run(monitor);
                } catch (CoreException ce) {
                    throw new InvocationTargetException(ce);
                }
            }
        });
        return true;
    } catch (Throwable e) {
        if (e instanceof InvocationTargetException) {
            e = e.getCause();
        }
        final IStatus status;
        if (e instanceof CoreException) {
            status = ((CoreException) e).getStatus();
            e = status.getException();
        } else {
            status = new Status(IStatus.ERROR, GitPlugin.getPluginId(), 1, Messages.SharingWizard_failed, e);
        }
        IdeLog.logError(GitUIPlugin.getDefault(), Messages.SharingWizard_failed, e, IDebugScopes.DEBUG);
        ErrorDialog.openError(getContainer().getShell(), getWindowTitle(), Messages.SharingWizard_failed,
                status, status.getSeverity());
        return false;
    }
}

From source file:com.aptana.ide.rcp.IDEWorkbenchAdvisor.java

License:Open Source License

/**
 * Disconnect from the core workspace./*from   w  w  w . j a  va  2s .c o  m*/
 */
private void disconnectFromWorkspace() {
    // save the workspace
    final MultiStatus status = new MultiStatus(IDEWorkbenchPlugin.IDE_WORKBENCH, 1,
            IDEWorkbenchMessages.ProblemSavingWorkbench, null);
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) {
            try {
                status.merge(ResourcesPlugin.getWorkspace().save(true, monitor));
            } catch (CoreException e) {
                status.merge(e.getStatus());
            }
        }
    };
    try {
        new ProgressMonitorJobsDialog(null).run(true, false, runnable);
    } catch (InvocationTargetException e) {
        status.merge(new Status(IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH, 1,
                IDEWorkbenchMessages.InternalError, e.getTargetException()));
    } catch (InterruptedException e) {
        status.merge(new Status(IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH, 1,
                IDEWorkbenchMessages.InternalError, e));
    }
    ErrorDialog.openError(null, IDEWorkbenchMessages.ProblemsSavingWorkspace, null, status,
            IStatus.ERROR | IStatus.WARNING);
    if (!status.isOK()) {
        IDEWorkbenchPlugin.log(IDEWorkbenchMessages.ProblemsSavingWorkspace, status);
    }
}

From source file:com.aptana.ide.ui.io.navigator.resources.FileDropAdapterAssistant.java

License:Open Source License

private void openError(IStatus status) // $codepro.audit.disable overridingPrivateMethod
{
    if (status == null) {
        return;//from ww w  .  j  a  v a2 s . co m
    }

    String title = Messages.FileDropAdapterAssistant_ERR_DragAndDrop_Title;
    int codes = IStatus.ERROR | IStatus.WARNING;

    if (status.isMultiStatus()) {
        IStatus[] children = status.getChildren();
        if (children.length == 1) {
            ErrorDialog.openError(getShell(), status.getMessage(), null, children[0], codes);
        } else {
            ErrorDialog.openError(getShell(), title, null, status, codes);
        }
    } else {
        ErrorDialog.openError(getShell(), title, null, status, codes);
    }
}

From source file:com.google.dart.tools.deploy.ApplicationWorkbenchAdvisor.java

License:Open Source License

/**
 * Disconnect from the core workspace.//  w ww.j  a  va  2  s  .c om
 */
private void disconnectFromWorkspace() {
    IStatus status;

    try {
        // Save the workspace.
        status = ResourcesPlugin.getWorkspace().save(true, new NullProgressMonitor());
    } catch (CoreException e) {
        status = e.getStatus();
    }

    if (status != null && !status.isOK()) {
        ErrorDialog.openError(null, IDEWorkbenchMessages.ProblemsSavingWorkspace, null, status,
                IStatus.ERROR | IStatus.WARNING);
        IDEWorkbenchPlugin.log(IDEWorkbenchMessages.ProblemsSavingWorkspace, status);
    }
}

From source file:com.google.dart.tools.ui.actions.CreateAndRevealProjectAction.java

License:Open Source License

private boolean nestsAnExistingProject(IPath path) {
    // Reference the set of projects in the workspace
    final IProject[] projectArray = ResourcesPlugin.getWorkspace().getRoot().getProjects();

    // Create a list of Strings which we will populate with project names which are sub directories
    // of the passed IPath, if there aren't many projects in the workspace, no reason to create a
    // large array.
    ArrayList<String> violatingProjectNameList = new ArrayList<String>(Math.min(projectArray.length, 10));

    // Loop through each of the projects to populate projectArray
    for (IProject project : projectArray) {
        IPath location = project.getLocation();
        if (path.isPrefixOf(location)) {
            violatingProjectNameList.add(project.getName());
        }/*from   w ww. j  a va 2s.c om*/
    }
    // If there are any violating projects, throw an error message.
    if (!violatingProjectNameList.isEmpty()) {
        // For the error message in the dialog, we need the name of the project we are trying to create.
        String folderName = path.lastSegment();
        // And we need the list of violating project names, the following converts the list of strings
        // into a comma separated list to make it human readable.
        String violatingNamesMessage = "'" + violatingProjectNameList.get(0) + "'";
        for (int i = 1; i < violatingProjectNameList.size() - 1; i++) {
            violatingNamesMessage += ", '" + violatingProjectNameList.get(i) + "'";
        }
        if (violatingProjectNameList.size() > 1) {
            violatingNamesMessage += " and '"
                    + violatingProjectNameList.get(violatingProjectNameList.size() - 1) + "'";
        }
        // Finally, open the dialog and then return true.
        String message1 = NLS.bind(ProjectMessages.OpenExistingFolderWizardAction_nesting_msg1, folderName,
                violatingNamesMessage);
        String message2 = NLS.bind(ProjectMessages.OpenExistingFolderWizardAction_nesting_msg2, folderName,
                violatingNamesMessage);
        ErrorDialog.openError(getShell(), ProjectMessages.OpenExistingFolderWizardAction_nesting_title,
                ProjectMessages.OpenExistingFolderWizardAction_nesting_title,
                new MultiStatus(DartToolsPlugin.PLUGIN_ID, 1,
                        new IStatus[] { new Status(IStatus.ERROR, DartToolsPlugin.PLUGIN_ID, message2) },
                        message1, null),
                IStatus.ERROR);
        return true;
    }

    // Otherwise, none of the projects in the workspace are children of the new project, return false.
    return false;
}

From source file:com.mansfield.pde.api.tools.internal.ui.preferencepages.TargetBaselinePreferencePage.java

License:Open Source License

private void internalReloadTargetDefinition(final ITargetDefinition target) {
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()) {
        protected void configureShell(Shell shell) {
            super.configureShell(shell);
            shell.setText(PDEUIMessages.TargetPlatformPreferencePage2_12);
        }/*from  w w  w .  jav  a 2  s  . c o  m*/
    };
    try {
        dialog.run(true, true, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                if (monitor.isCanceled()) {
                    throw new InterruptedException();
                }
                // Resolve the target
                target.resolve(monitor);
                if (monitor.isCanceled()) {
                    throw new InterruptedException();
                }
            }
        });
    } catch (InvocationTargetException e) {
        PDEPlugin.log(e);
        setErrorMessage(e.getMessage());
    } catch (InterruptedException e) {
        // Do nothing, resolve will happen when user presses ok
    }

    if (target.isResolved()) {
        // Check if the bundle resolution has errors
        IStatus bundleStatus = target.getStatus();
        if (bundleStatus.getSeverity() == IStatus.ERROR) {
            ErrorDialog.openError(getShell(), PDEUIMessages.TargetPlatformPreferencePage2_14,
                    PDEUIMessages.TargetPlatformPreferencePage2_15, bundleStatus, IStatus.ERROR);
        }
    }
    fTableViewer.refresh(true);
}

From source file:com.siteview.mde.internal.ui.preferences.TargetPlatformPreferencePage.java

License:Open Source License

private void handleReload() {
    IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();
    if (!selection.isEmpty()) {
        isOutOfSynch = false;// w w  w.  ja va 2 s  .  co m
        ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()) {
            protected void configureShell(Shell shell) {
                super.configureShell(shell);
                shell.setText(MDEUIMessages.TargetPlatformPreferencePage2_12);
            }
        };
        try {
            dialog.run(true, true, new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    if (monitor.isCanceled()) {
                        throw new InterruptedException();
                    }
                    // Resolve the target
                    fActiveTarget.resolve(monitor);
                    if (monitor.isCanceled()) {
                        throw new InterruptedException();
                    }
                }
            });
        } catch (InvocationTargetException e) {
            MDEPlugin.log(e);
            setErrorMessage(e.getMessage());
        } catch (InterruptedException e) {
            // Do nothing, resolve will happen when user presses ok
        }

        if (fActiveTarget.isResolved()) {
            // Check if the bundle resolution has errors
            IStatus bundleStatus = fActiveTarget.getBundleStatus();
            if (bundleStatus.getSeverity() == IStatus.ERROR) {
                ErrorDialog.openError(getShell(), MDEUIMessages.TargetPlatformPreferencePage2_14,
                        MDEUIMessages.TargetPlatformPreferencePage2_15, bundleStatus, IStatus.ERROR);
            }

            // Compare the target to the existing platform
            try {
                if (bundleStatus.getSeverity() != IStatus.ERROR && fActiveTarget.getHandle().equals(fPrevious)
                        && ((TargetDefinition) fPrevious.getTargetDefinition())
                                .isContentEquivalent(fActiveTarget)) {
                    IStatus compare = getTargetService().compareWithTargetPlatform(fActiveTarget);
                    if (!compare.isOK()) {
                        MessageDialog.openInformation(getShell(),
                                MDEUIMessages.TargetPlatformPreferencePage2_17,
                                MDEUIMessages.TargetPlatformPreferencePage2_18);
                        isOutOfSynch = true;
                    }
                }
            } catch (CoreException e) {
                MDEPlugin.log(e);
                setErrorMessage(e.getMessage());
            }
        }
        fTableViewer.refresh(true);
    }
}

From source file:de.innot.avreclipse.ui.views.supportedmcu.URLColumnLabelProvider.java

License:Open Source License

/**
 * Load and Display the given URL./*from w  w w  .j av a2s . c o  m*/
 * <p>
 * The File from the URL is first downloaded via the {@link URLDownloadManager} and then opened
 * using the default Editor registered for this filetype.
 * </p>
 * <p>
 * The download and the opening of the file is done in a Job, so this method returns immediatly.
 * </p>
 * <p>
 * If a download of the same URL is still in progress, this method does nothing to avoid
 * multiple parallel downloads of the same file by nervous users. </p
 * 
 * @param urlstring
 *            A String with an URL.
 */
private void openURL(final URL url) {
    final Display display = PlatformUI.getWorkbench().getDisplay();
    // Test if a download of this file is already in progress.
    // If yes: do nothing and return, assuming that the user has clicked
    // on the url twice accidentally
    if (URLDownloadManager.isDownloading(url)) {
        return;
    }

    // The actual download is done in this Job.
    // For any Exception during the download an ErrorDialog is displayed
    // with the cause(s)
    // The Job also returns an IStatus result, but by the time this is
    // returned, the openURL() method has long finished and there is
    // no one there to actually read this message :-)
    Job loadandopenJob = new Job("Download and Open") {
        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            try {
                monitor.beginTask("Download " + url.toExternalForm(), 100);

                // Download the file and...
                final File file = URLDownloadManager.download(url, new SubProgressMonitor(monitor, 95));

                // ...open the file in an editor.
                monitor.subTask("Opening Editor for " + file.getName());
                if (display == null || display.isDisposed()) {
                    return new Status(Status.ERROR, AVRPlugin.PLUGIN_ID, "Cannot open Editor: no Display found",
                            null);
                }
                openFileInEditor(file);

                monitor.worked(5);
            } catch (URLDownloadException ude) {
                final URLDownloadException exc = ude;
                // ErrorDialog for all Exceptions, in an
                // Display.syncExec() to run in the UI Thread.
                display.syncExec(new Runnable() {
                    public void run() {
                        Shell shell = display.getActiveShell();
                        String title = "Download Failed";
                        String message = "The requested file could not be downloaded\nFile:  " + url.getPath()
                                + "\nHost:  " + url.getHost();
                        String reason = exc.getMessage();
                        MultiStatus status = new MultiStatus(AVRPlugin.PLUGIN_ID, 0, reason, null);
                        Throwable cause = exc.getCause();
                        // in case there are multiple root causes
                        // (unlikely, but who knows?)
                        while (cause != null) {
                            status.add(new Status(Status.ERROR, AVRPlugin.PLUGIN_ID,
                                    cause.getClass().getSimpleName(), cause));
                            cause = cause.getCause();
                        }

                        ErrorDialog.openError(shell, title, message, status, Status.ERROR);
                        AVRPlugin.getDefault().log(status);
                    }
                }); // fDisplay.asyncExec
            } finally {
                monitor.done();
            }
            return Status.OK_STATUS;
        } // run
    }; // new Job()

    // set some options and start the Job.
    loadandopenJob.setUser(true);
    loadandopenJob.setPriority(Job.LONG);
    loadandopenJob.schedule();

    return;
}