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

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

Introduction

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

Prototype

public static void openError(Shell parent, String title, String message) 

Source Link

Document

Convenience method to open a standard error dialog.

Usage

From source file:com.aptana.deploy.heroku.ui.wizard.HerokuSignupPage.java

License:Open Source License

public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NULL);
    composite.setLayout(new GridLayout());
    composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL));
    setControl(composite);//  ww w .  j a  va2s .co m

    initializeDialogUnits(parent);

    // Actual contents
    Label label = new Label(composite, SWT.NONE);
    label.setText(Messages.HerokuLoginWizardPage_EnterCredentialsLabel);

    Composite credentials = new Composite(composite, SWT.NONE);
    credentials.setLayout(new GridLayout(2, false));

    Label userIdLabel = new Label(credentials, SWT.NONE);
    userIdLabel.setText(Messages.HerokuLoginWizardPage_UserIDLabel);
    userId = new Text(credentials, SWT.SINGLE | SWT.BORDER);
    userId.setMessage(Messages.HerokuLoginWizardPage_UserIDExample);
    if (startingUserId != null && startingUserId.trim().length() > 0) {
        userId.setText(startingUserId);
    }
    GridData gd = new GridData(300, SWT.DEFAULT);
    userId.setLayoutData(gd);

    Label note = new Label(composite, SWT.WRAP);
    // We need this italic, we may need to set a font explicitly here to get it
    Font dialogFont = JFaceResources.getDialogFont();
    FontData[] data = SWTUtils.italicizedFont(JFaceResources.getDialogFont());
    final Font italic = new Font(dialogFont.getDevice(), data);
    note.setFont(italic);
    note.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            if (!italic.isDisposed()) {
                italic.dispose();
            }
        }
    });

    gd = new GridData(400, SWT.DEFAULT);
    note.setLayoutData(gd);
    note.setText(Messages.HerokuSignupPage_SignupNote);

    // Add signup button
    Button signup = new Button(composite, SWT.PUSH);
    signup.setText(Messages.HerokuSignupPage_SignupButtonLabel);
    signup.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (!isEmailValid(userId.getText())) {
                MessageDialog.openError(getShell(), "Error", Messages.HerokuSignupPage_InvalidEmail_Message); //$NON-NLS-1$
                return;
            }

            // basically just perform finish!
            if (getWizard().performFinish()) {
                ((WizardDialog) getContainer()).close();
            }
        }
    });

    Dialog.applyDialogFont(composite);
}

From source file:com.aptana.editor.common.AbstractThemeableEditor.java

License:Open Source License

@Override
protected void performSaveAs(IProgressMonitor progressMonitor) {
    progressMonitor = (progressMonitor == null) ? new NullProgressMonitor() : progressMonitor;
    IEditorInput input = getEditorInput();

    if (input instanceof UntitledFileStorageEditorInput) {
        Shell shell = getSite().getShell();

        // checks if user wants to save on the file system or in a workspace project
        boolean saveToProject = false;
        boolean byPassDialog = Platform.getPreferencesService().getBoolean(CommonEditorPlugin.PLUGIN_ID,
                IPreferenceConstants.REMEMBER_UNTITLED_FILE_SAVE_TYPE, false, null);
        if (byPassDialog) {
            // grabs from preferences
            saveToProject = Platform.getPreferencesService().getBoolean(CommonEditorPlugin.PLUGIN_ID,
                    IPreferenceConstants.SAVE_UNTITLED_FILE_TO_PROJECT, false, null);
        } else {// w  w w.  j a v a 2 s  . c o m
            // asks the user
            MessageDialogWithToggle dialog = new MessageDialogWithToggle(shell,
                    Messages.AbstractThemeableEditor_SaveToggleDialog_Title, null,
                    Messages.AbstractThemeableEditor_SaveToggleDialog_Message, MessageDialog.NONE,
                    new String[] { Messages.AbstractThemeableEditor_SaveToggleDialog_LocalFilesystem,
                            Messages.AbstractThemeableEditor_SaveToggleDialog_Project },
                    0, null, false);
            int code = dialog.open();
            if (code == SWT.DEFAULT) {
                return;
            }
            saveToProject = (code != IDialogConstants.INTERNAL_ID);
            if (dialog.getToggleState()) {
                // the decision is remembered, so saves it
                IEclipsePreferences prefs = (EclipseUtil.instanceScope()).getNode(CommonEditorPlugin.PLUGIN_ID);
                prefs.putBoolean(IPreferenceConstants.REMEMBER_UNTITLED_FILE_SAVE_TYPE, true);
                prefs.putBoolean(IPreferenceConstants.SAVE_UNTITLED_FILE_TO_PROJECT, saveToProject);
                try {
                    prefs.flush();
                } catch (BackingStoreException e) {
                    IdeLog.logError(CommonEditorPlugin.getDefault(), e);
                }
            }
        }

        if (!saveToProject) {
            // saves to local filesystem
            FileDialog fileDialog = new FileDialog(shell, SWT.SAVE);
            String path = fileDialog.open();
            if (path == null) {
                progressMonitor.setCanceled(true);
                return;
            }

            // Check whether file exists and if so, confirm overwrite
            File localFile = new File(path);
            if (localFile.exists()) {
                if (!MessageDialog.openConfirm(shell, Messages.AbstractThemeableEditor_ConfirmOverwrite_Title,
                        MessageFormat.format(Messages.AbstractThemeableEditor_ConfirmOverwrite_Message,
                                path))) {
                    progressMonitor.setCanceled(true);
                }
            }

            IFileStore fileStore;
            try {
                fileStore = EFS.getStore(localFile.toURI());
            } catch (CoreException e) {
                IdeLog.logError(CommonEditorPlugin.getDefault(), e);
                MessageDialog.openError(shell, Messages.AbstractThemeableEditor_Error_Title,
                        MessageFormat.format(Messages.AbstractThemeableEditor_Error_Message, path));
                return;
            }

            IDocumentProvider provider = getDocumentProvider();
            if (provider == null) {
                return;
            }

            IEditorInput newInput;
            IFile file = getWorkspaceFile(fileStore);
            if (file != null) {
                newInput = new FileEditorInput(file);
            } else {
                newInput = new FileStoreEditorInput(fileStore);
            }

            boolean success = false;
            try {
                provider.aboutToChange(newInput);
                provider.saveDocument(progressMonitor, newInput, provider.getDocument(input), true);
                success = true;
            } catch (CoreException e) {
                IStatus status = e.getStatus();
                if (status == null || status.getSeverity() != IStatus.CANCEL) {
                    MessageDialog.openError(shell, Messages.AbstractThemeableEditor_Error_Title,
                            MessageFormat.format(Messages.AbstractThemeableEditor_Error_Message, path));
                }
            } finally {
                provider.changed(newInput);
                if (success) {
                    setInput(newInput);
                }
            }

            progressMonitor.setCanceled(!success);
        } else {
            super.performSaveAs(progressMonitor);
        }
    } else {
        super.performSaveAs(progressMonitor);
    }
}

From source file:com.aptana.editor.common.scripting.snippets.SnippetTemplateProposal.java

License:Open Source License

private void openErrorDialog(Shell shell, Exception e) {
    MessageDialog.openError(shell, Messages.SnippetTemplateProposal_TITLE_SnippetTemplateProposalError,
            e.getMessage());
}

From source file:com.aptana.editor.js.JSMetadataLoader.java

License:Open Source License

/**
 * rebuildProjectIndexes//from   w ww  . j  a v a  2  s  . c o m
 */
private void rebuildProjectIndexes() {
    Job job = new Job(Messages.JSMetadataLoader_Rebuilding_Project_Indexes) {
        @Override
        protected IStatus run(IProgressMonitor monitor) {
            IWorkspace ws = ResourcesPlugin.getWorkspace();

            try {
                ws.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
            } catch (final CoreException e) {
                UIUtils.getDisplay().asyncExec(new Runnable() {

                    public void run() {
                        IStatus status = e.getStatus();
                        if (status.isMultiStatus()) {
                            IStatus[] children = status.getChildren();
                            if (children.length > 0) {
                                status = children[0];
                            }
                        }
                        MessageDialog.openError(UIUtils.getActiveShell(),
                                Messages.JSMetadataLoader_RebuildingProjectIndexError_Title,
                                MessageFormat.format("{0} {1}", status.getMessage(), //$NON-NLS-1$
                                        Messages.JSMetadataLoader_RebuildingProjectIndexError_Message));
                    }
                });
            }

            return Status.OK_STATUS;
        }
    };

    job.schedule();
}

From source file:com.aptana.explorer.internal.ui.GitProjectView.java

License:Open Source License

private boolean setNewBranch(String branchName) {
    // Strip off the indicators...
    branchName = stripIndicators(branchName);

    final GitRepository repo = getGitRepositoryManager().getAttached(selectedProject);
    if (repo == null)
        return false;
    if (branchName.equals(repo.currentBranch()))
        return false;

    // If user selected "Create New..." then pop a dialog to generate a new branch
    if (branchName.equals(CREATE_NEW_BRANCH_TEXT)) {
        CreateBranchDialog dialog = new CreateBranchDialog(getSite().getShell(), repo);
        if (dialog.open() != Window.OK) {
            revertToCurrentBranch(repo);
            return false;
        }/* w  ww. jav a  2  s . c o m*/
        branchName = dialog.getValue().trim();
        boolean track = dialog.track();
        String startPoint = dialog.getStartPoint();
        if (!repo.createBranch(branchName, track, startPoint)) {
            revertToCurrentBranch(repo);
            return false;
        }
    }
    IStatus switchStatus = repo.switchBranch(branchName, new NullProgressMonitor());
    if (switchStatus.isOK()) {
        refreshViewer(); // might be new file structure
        return true;
    }
    String msg = switchStatus.getMessage();
    if (switchStatus instanceof ProcessStatus) {
        msg = ((ProcessStatus) switchStatus).getStdErr();
    }
    MessageDialog.openError(getSite().getShell(), Messages.GitProjectView_SwitchBranchFailedTitle, msg);
    // revertToCurrentBranch(repo);
    return false;
}

From source file:com.aptana.formatter.ui.util.ExceptionHandler.java

License:Open Source License

private void displayMessageDialog(Throwable t, String exceptionMessage, Shell shell, String title,
        String message) {// w  w  w  .  j  av a2s .c  o m
    StringWriter msg = new StringWriter();
    if (message != null) {
        msg.write(message);
        msg.write("\n\n"); //$NON-NLS-1$
    }
    if (exceptionMessage == null || exceptionMessage.length() == 0)
        msg.write(UIEplMessages.ExceptionHandler_seeErrorLogMessage);
    else
        msg.write(exceptionMessage);
    MessageDialog.openError(shell, title, msg.toString());
}

From source file:com.aptana.git.ui.internal.actions.AbstractGitHandler.java

License:Open Source License

protected void openError(final String title, final String msg) {
    PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

        public void run() {
            MessageDialog.openError(getShell(), Messages.CommitAction_MultipleRepos_Title,
                    Messages.CommitAction_MultipleRepos_Message);
        }//from  w w w .  jav  a2  s. c o  m
    });
}

From source file:com.aptana.git.ui.internal.preferences.GithubAccountPageProvider.java

License:Open Source License

private boolean login(boolean test) {
    final String username = usernameText.getText();
    final String password = passwordText.getText();
    if (StringUtil.isEmpty(username)) {
        if (test) {
            MessageDialog.openError(main.getShell(), Messages.GithubAccountPageProvider_InvalidInputTitle,
                    Messages.GithubAccountPageProvider_EmptyUsername);
            return false;
        }//w  w w.j a v a2 s .c  om
        return true;
    }
    if (StringUtil.isEmpty(password)) {
        if (test) {
            MessageDialog.openError(main.getShell(), Messages.GithubAccountPageProvider_InvalidInputTitle,
                    Messages.GithubAccountPageProvider_EmptyPassword);
            return false;
        }
        return true;
    }

    setUILocked(true);
    firePreValidationStartEvent();
    try {
        ModalContext.run(new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(Messages.GithubAccountPageProvider_ValidatingCredentials,
                        IProgressMonitor.UNKNOWN);
                try {
                    IStatus status = getGithubManager().login(username, password);
                    if (status.isOK()) {
                        // successful; now re-layout to show the logout components
                        UIUtils.getDisplay().asyncExec(new Runnable() {

                            public void run() {
                                updateUserText();
                                layout();
                            }
                        });
                        fireLoggedInEvent();
                    } else {
                        throw new InvocationTargetException(new CoreException(status));
                    }
                } finally {
                    if (!monitor.isCanceled()) {
                        monitor.done();
                    }
                }
            }
        }, true, getProgressMonitor(), UIUtils.getDisplay());
    } catch (InvocationTargetException e) {
        if (main != null && !main.isDisposed()) {
            MessageDialog.openError(main.getShell(), Messages.GithubAccountPageProvider_LoginFailed,
                    e.getTargetException().getMessage());
        }
        return false;
    } catch (Exception e) {
        IdeLog.logError(GitUIPlugin.getDefault(), e);
    } finally {
        setUILocked(false);
        firePostValidationEndEvent();
    }

    return true;
}

From source file:com.aptana.git.ui.internal.wizards.CloneWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    final String sourceURI = cloneSource.getSource();
    final String dest = cloneSource.getDestination();
    try {//from w ww  . ja  v a  2 s . co m
        getContainer().run(true, true, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                CloneJob job = new CloneJob(sourceURI, dest);
                IStatus status = job.run(monitor);
                if (!status.isOK()) {
                    if (status instanceof ProcessStatus) {
                        ProcessStatus ps = (ProcessStatus) status;
                        String stderr = ps.getStdErr();
                        throw new InvocationTargetException(new CoreException(
                                new Status(status.getSeverity(), status.getPlugin(), stderr)));
                    }
                    throw new InvocationTargetException(new CoreException(status));
                }
            }
        });
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof CoreException) {
            CoreException ce = (CoreException) e.getCause();
            MessageDialog.openError(getShell(), Messages.CloneWizard_CloneFailedTitle, ce.getMessage());
        } else {
            IdeLog.logError(GitUIPlugin.getDefault(), e, IDebugScopes.DEBUG);
        }
    } catch (InterruptedException e) {
        IdeLog.logError(GitUIPlugin.getDefault(), e, IDebugScopes.DEBUG);
    }
    return true;
}

From source file:com.aptana.git.ui.internal.wizards.GithubForkWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    final IGithubManager ghManager = GitPlugin.getDefault().getGithubManager();
    final String owner = cloneSource.getOwner();
    final String repoName = cloneSource.getRepoName();
    // TODO Allow selecting a destination org to fork to!
    final String organization = null; // cloneSource.getOrganization();
    final String dest = cloneSource.getDestination();
    try {//from w  w  w  . ja  va  2s .co  m
        getContainer().run(true, true, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    monitor.subTask(Messages.GithubForkWizard_ForkSubTaskName);
                    IGithubRepository repo = ghManager.fork(owner, repoName, organization);

                    // Now clone the repo!
                    CloneJob job = new CloneJob(repo.getSSHURL(), dest);
                    IStatus status = job.run(monitor);
                    if (!status.isOK()) {
                        if (status instanceof ProcessStatus) {
                            ProcessStatus ps = (ProcessStatus) status;
                            String stderr = ps.getStdErr();
                            throw new InvocationTargetException(new CoreException(
                                    new Status(status.getSeverity(), status.getPlugin(), stderr)));
                        }
                        throw new InvocationTargetException(new CoreException(status));
                    }

                    // Add upstream remote pointing at parent!
                    Set<IProject> projects = job.getCreatedProjects();
                    if (!CollectionsUtil.isEmpty(projects)) {
                        monitor.subTask(Messages.GithubForkWizard_UpstreamSubTaskName);
                        IProject project = projects.iterator().next();
                        IGitRepositoryManager grManager = GitPlugin.getDefault().getGitRepositoryManager();
                        GitRepository clonedRepo = grManager.getAttached(project);
                        if (clonedRepo != null) {
                            IGithubRepository parentRepo = repo.getParent();
                            clonedRepo.addRemote("upstream", parentRepo.getSSHURL(), false); //$NON-NLS-1$
                        }
                    }
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof CoreException) {
            CoreException ce = (CoreException) e.getCause();
            MessageDialog.openError(getShell(), Messages.GithubForkWizard_FailedForkErr, ce.getMessage());
        } else {
            IdeLog.logError(GitUIPlugin.getDefault(), e, IDebugScopes.DEBUG);
        }
    } catch (InterruptedException e) {
        IdeLog.logError(GitUIPlugin.getDefault(), e, IDebugScopes.DEBUG);
    }
    return true;
}