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

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

Introduction

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

Prototype

public MessageDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage,
        int dialogImageType, int defaultIndex, String... dialogButtonLabels) 

Source Link

Document

Create a message dialog.

Usage

From source file:edu.umd.cs.eclipse.courseProjectManager.Dialogs.java

License:Apache License

/**
 * Dialog to show the successful completion of a task.
 * /*  w  w w  . jav a  2  s  .  c  o  m*/
 * @param parent
 *            parent Shell, null if none
 * @param title
 *            dialog title
 * @param message
 *            message to be displayed
 */
public static void okDialog(Shell parent, String title, String message) {
    // Log the event
    AutoCVSPlugin.getPlugin().getEventLog().logMessage(title + ": " + message);

    // Tagging appears to have succeeded.
    // Inform the user.
    new MessageDialog(parent, title, null, message, Window.OK, new String[] { "OK" }, 0).open();
}

From source file:edu.utexas.cs.orc.orceclipse.project.OrcPathEditor.java

License:Open Source License

@Override
protected String getNewInputObject() {
    // prompt dir or JAR
    final MessageDialog typeDialog = new MessageDialog(getShell(), Messages.OrcPathEditor_TypeDialogTitle, null,
            Messages.OrcPathEditor_TypeDialogMessage1 + pathDescriptionForDialogMessage
                    + Messages.OrcPathEditor_TypeDialogMessage2,
            MessageDialog.QUESTION, TYPE_DIALOG_BUTTON_LABELS, SWT.DEFAULT);
    switch (typeDialog.open()) {
    case 0: // workspace dir:
        return chooseWorkspaceFolder();
    case 1: // workspace JAR:
        return chooseWorkspaceJarFile();
    case 2: // external dir:
        final String selectedFolder = super.getNewInputObject();
        if (selectedFolder != null) {
            return Path.fromOSString(selectedFolder).addTrailingSeparator().toPortableString();
        } else {/*from w  ww. j av a 2 s .co m*/
            return null;
        }
    case 3: // external JAR:
        return chooseExternalJarFile();
    default: // canceled
        return null;
    }
}

From source file:era.foss.typeeditor.TypeDialog.java

License:Open Source License

/**
 * Ok pressed.//from  w w  w .j a va 2  s. c  o m
 * 
 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
 * @since 03.03.2010
 */
protected void okPressed() {
    // validate model
    BasicDiagnostic diagnostic = Diagnostician.INSTANCE.createDefaultDiagnostic(erfModel.getCoreContent());
    for (DatatypeDefinition dataType : erfModel.getCoreContent().getDataTypes()) {
        Diagnostician.INSTANCE.validate(dataType, diagnostic);
    }
    for (SpecType specType : erfModel.getCoreContent().getSpecTypes()) {
        Diagnostician.INSTANCE.validate(specType, diagnostic);
    }
    Diagnostician.INSTANCE.validate(toolExtension, diagnostic);

    if (!diagnostic.getChildren().isEmpty()) {
        MessageDialog dialog = new MessageDialog(this.getShell(),
                typeEditorActivator.getString("_UI_ValidationErrorDialog_title"), null,
                typeEditorActivator.getString("_UI_ValidationErrorDialog_text"), MessageDialog.ERROR,
                new String[] { "OK" }, 0);
        dialog.open();

        String errorMessage = "";
        for (Diagnostic diagnosticChildren : diagnostic.getChildren()) {
            errorMessage += diagnosticChildren.getMessage() + "\n";
        }
        this.setErrorMessage(errorMessage);
    } else {
        super.okPressed();
        // the performed commands should not be available for undo after OK.
        eraCommandStack.inhibitUndos();

        // redraw the SpecObject editor
        if (editor instanceof IViewerProvider) {
            Viewer viewer = ((IViewerProvider) editor).getViewer();
            if (viewer instanceof IAllowViewerSchemaChange) {
                ((IAllowViewerSchemaChange) viewer).recreateViewerSchema();
            }
        }
    }

}

From source file:es.cv.gvcase.mdt.common.commands.DeleteDiagramCommand.java

License:Open Source License

public void redo() {
    if (getDiagramToDelete() == null) {
        return;//  w  w w  .  j  a  v  a2  s.c o m
    }
    // Get upper diagram to open in case the one deleted is active.
    Diagram diagramToOpen = MultiDiagramUtil.getUpperDiagram(getDiagramToDelete());
    if (diagramToOpen == null || diagramToOpen.equals(getDiagramToDelete())) {
        // This is the uppest diagram we'll look for a diagram at the same
        // level
        diagramToOpen = MultiDiagramUtil.getOtherDiagram(getDiagramToDelete());
        if (diagramToOpen == null) {
            // no suitable diagram to open
            return;
        }
    }

    // The diagram is Ok to be deleted. Ask user confirmation.
    MessageDialog confirmDialog = new MessageDialog(Display.getCurrent().getActiveShell(), "Delete diagram?",
            null, "Are you sure you want to delete the selected diagram?", MessageDialog.WARNING,
            new String[] { "Yes", "No" }, 1);
    int result = confirmDialog.open();
    if (result == Window.CANCEL) {
        return;
    }

    // modify the parent diagram of the diagrams that has this deleted
    // diagram as parent
    boolean hasParent = getDiagramToDelete().getEAnnotation(MultiDiagramUtil.UpperDiagram) == null ? false
            : true;
    for (Resource r : diagramToOpen.eResource().getResourceSet().getResources()) {
        if (r instanceof GMFResource) {
            for (EObject eo : r.getContents()) {
                if (eo instanceof Diagram) {
                    Diagram son = (Diagram) eo;
                    EAnnotation eAnnotation = son.getEAnnotation(MultiDiagramUtil.UpperDiagram);
                    if (eAnnotation != null && eAnnotation.getReferences().size() > 0
                            && (eAnnotation.getReferences().get(0) instanceof Diagram)) {
                        Diagram parent = (Diagram) eAnnotation.getReferences().get(0);
                        if (parent.equals(getDiagramToDelete())) {
                            if (!hasParent) {
                                // remove the eAnnotation
                                son.getEAnnotations().remove(MultiDiagramUtil.UpperDiagram);
                                if (diagramToOpen != null)
                                    diagramToOpen = son;
                            } else {
                                // change the parent diagram
                                Diagram parentDiagram = (Diagram) getDiagramToDelete()
                                        .getEAnnotation(MultiDiagramUtil.UpperDiagram).getReferences().get(0);
                                eAnnotation.getReferences().clear();
                                eAnnotation.getReferences().add(parentDiagram);
                            }
                        }
                    }
                }
            }
        }
    }

    IEditorPart editorPart = MDTUtil.getActiveEditor();
    if (!isDiagramActive()) {
        // If the diagram to delete is not active it can be deleted without
        // problems.
        MultiDiagramUtil.deleteDiagramAndSave(getDiagramToDelete(),
                !(editorPart instanceof MOSKittMultiPageEditor));
    } else {
        // If the diagram to delete is active, a complex process must be
        // followed to delete it.
        // Close all diagram editors that have the diagram to be deleted
        // active.
        // EditingDomainRegistry.getInstance().setChangingCachedEditors(true);
        MultiDiagramUtil.closeEditorsThatShowDiagram(getDiagramToDelete());
        // Delete diagram
        MultiDiagramUtil.deleteDiagramAndSave(getDiagramToDelete(),
                !(editorPart instanceof MOSKittMultiPageEditor));
        // Open its upper diagram
        try {
            MultiDiagramUtil.openDiagram(diagramToOpen);
        } catch (ExecutionException ex) {
            IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Can't open diagram");
            Activator.getDefault().getLog().log(status);
        } finally {
            // EditingDomainRegistry.getInstance().setChangingCachedEditors(
            // false);
            return;
        }
    }
}

From source file:es.cv.gvcase.mdt.common.part.MOSKittMultiPageEditor.java

License:Open Source License

/**
 * {@link ISaveablePart2} implementation. <br>
 * Will ask nested editors that implement ISaveablePart2 to perform their
 * prompt.//from  w  w  w  . j a va 2s  . co m
 * 
 */
public int promptToSaveOnClose() {
    // clear the previous map
    mapEditorIndex2SaveOnClose.clear();
    int saveOption = ISaveablePart2.DEFAULT;
    boolean saveNeeded = false;
    ISaveablePart saveablePart1 = null;
    ISaveablePart2 saveablePart2 = null;
    String partsNamesToSave = ""; //$NON-NLS-1$
    for (int i = 0; i < getPageCount(); i++) {
        IEditorPart editor = getEditor(i);
        if (editor == null) {
            continue;
        }
        saveablePart1 = (ISaveablePart) Platform.getAdapterManager().getAdapter(editor, ISaveablePart.class);
        saveablePart2 = (ISaveablePart2) Platform.getAdapterManager().getAdapter(editor, ISaveablePart2.class);
        if (saveablePart2 != null) {
            saveOption = saveablePart2.promptToSaveOnClose();
        } else if (saveablePart1 != null) {
            saveOption = saveablePart1.isSaveOnCloseNeeded() ? ISaveablePart2.YES : ISaveablePart2.NO;
        } else {
            saveOption = ISaveablePart2.DEFAULT;
        }
        mapEditorIndex2SaveOnClose.put(i, saveOption);
        if (saveOption == ISaveablePart2.YES) {
            saveNeeded = true;
            partsNamesToSave += ((partsNamesToSave.length() == 0 ? "" //$NON-NLS-1$
                    : ", ") + getPageText(i)); //$NON-NLS-1$
        }
    }

    if (saveNeeded) {
        String message = Messages.MOSKittMultiPageEditor_15;
        String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                IDialogConstants.CANCEL_LABEL };
        MessageDialog dialog = new MessageDialog(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                Messages.MOSKittMultiPageEditor_16, null, message, MessageDialog.QUESTION, buttons, 0) {
            protected int getShellStyle() {
                return SWT.CLOSE | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL | getDefaultOrientation();
            }
        };
        int choice = ISaveablePart2.NO;
        choice = dialog.open();
        // map value of choice back to ISaveablePart2 values
        switch (choice) {
        case 0: // Yes
            choice = ISaveablePart2.YES;
            break;
        case 1: // No
            choice = ISaveablePart2.NO;
            break;
        case 2: // Cancel
            choice = ISaveablePart2.CANCEL;
            break;
        default: // ??
            choice = ISaveablePart2.DEFAULT;
            break;
        }
        return choice;
    } else {
        return ISaveablePart2.NO;
    }
}

From source file:es.cv.gvcase.mdt.common.util.MultiDiagramUtil.java

License:Open Source License

/**
 * Perform delete {@link Diagram}./*w ww.  j  a  v  a 2 s.  c  om*/
 * 
 * @param diagram
 *            the diagram
 * @param confirm
 *            the confirm
 * 
 * @return the diagram
 */
public static Diagram performDeleteDiagram(Diagram diagram, boolean confirm) {
    if (diagram == null) {
        return null;
    }
    // Get upper diagram to open in case the one deleted is active.
    Diagram diagramToOpen = getUpperDiagram(diagram);
    if (diagramToOpen == null || diagramToOpen.equals(diagram)) {
        // This is the uppest diagram we'll look for a diagram at the same
        // level
        diagramToOpen = getOtherDiagram(diagram);
        if (diagramToOpen == null) {
            // no suitable diagram to open
            return null;
        }
    }

    // The diagram is Ok to be deleted. Ask user confirmation.
    if (confirm) {
        MessageDialog confirmDialog = new MessageDialog(Display.getCurrent().getActiveShell(),
                "Delete diagram?", null, "Are oyu sure you want to delete the selected diagram?",
                MessageDialog.WARNING, new String[] { "Yes", "No" }, 1);
        int result = confirmDialog.open();
        if (result == Window.CANCEL) {
            return null;
        }
    }

    if (!isDiagramActive(diagram)) {
        // If the diagram to delete is not active it can be deleted without
        // problems.
        deleteDiagramAndSave(diagram);
    } else {
        // If the diagram to delete is active, a complex process must be
        // folowed to delete it.
        // Close all diagram editors that have the diagram to be deleted
        // active.
        // EditingDomainRegistry.getInstance().setChangingCachedEditors(true);
        closeEditorsThatShowDiagram(diagram);
        // Delete diagram
        deleteDiagramAndSave(diagram);
        // Open its upper diagram
        try {
            openDiagram(diagramToOpen);
        } catch (ExecutionException ex) {
            IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Can't open diagram");
            Activator.getDefault().getLog().log(status);
            return null;
        } finally {
            // EditingDomainRegistry.getInstance().setChangingCachedEditors(
            // false);
        }
    }
    return diagramToOpen;
}

From source file:eu.aniketos.securebpmn.util.DialogUtil.java

License:Apache License

/**
 * Opens a dialog window that contains an image and a message.
 *
 * @param title/*www. ja v  a  2  s .co  m*/
 *            The title of the message window.
 * @param message
 *            The message to be displayed in the window.
 * @param image
 *            The image that should be displayed in the window.
 * @param buttons
 *            The labels of the Buttons the window should contain.
 * @param defaultButton
 *            The index of the Button that should be selected by default.
 * @return The index of the Button that was pressed.
 */
public static int openMessageDialog(String title, String message, int image, String[] buttons,
        int defaultButton) {
    MessageDialog dialog;
    switch (image) {
    case INFO:
        dialog = new MessageDialog(getShell(), title, null, message, MessageDialog.INFORMATION, buttons,
                defaultButton);
        break;
    case WARNING:
        dialog = new MessageDialog(getShell(), title, null, message, MessageDialog.WARNING, buttons,
                defaultButton);
        break;
    case ERROR:
        dialog = new MessageDialog(getShell(), title, null, message, MessageDialog.ERROR, buttons,
                defaultButton);
        break;
    default:
        dialog = new MessageDialog(getShell(), title, null, message, MessageDialog.NONE, buttons,
                defaultButton);
        break;
    }
    return dialog.open();
}

From source file:eu.cloudwave.wp5.feedback.eclipse.base.ui.dialogs.AbstractMessageDialog.java

License:Apache License

/**
 * Displays the current {@link MessageDialog}.
 * //from  w  w w  .  j a  v a2 s  .c  o m
 * @param title
 *          the title of the {@link MessageDialog}
 * @param message
 *          the message of the {@link MessageDialog}
 * @param dialogImageType
 *          one of the following values:
 *          <ul>
 *          <li>MessageDialog.NONE for a dialog with no image</li>
 *          <li>MessageDialog.ERROR for a dialog with an error image</li>
 *          <li>MessageDialog.INFORMATION for a dialog with an information image</li>
 *          <li>MessageDialog.QUESTION for a dialog with a question image</li>
 *          <li>MessageDialog.WARNING for a dialog with a warning image</li>
 *          </ul>
 * @param buttonText
 *          the text of the button
 */
public final void display(final String title, final String message, final int dialogImageType,
        final String buttonText) {
    new AbstractUiTask() {
        @Override
        public void doWork() {
            final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
            final String[] buttons = new String[] { "Cancel", buttonText };
            final MessageDialog messageDialog = new MessageDialog(shell, title, null, message,
                    MessageDialog.ERROR, buttons, 0);
            final int action = messageDialog.open();
            if (action == 1) {
                action(shell);
            }
        }
    }.run();
}

From source file:eu.esdihumboldt.hale.io.haleconnect.ui.projects.ShareProjectWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    boolean result = super.performFinish();

    if (result) {
        try {/*from   w  w w.  j a  v  a 2s  .c o m*/
            URI clientAccessUrl = this.getProvider().getClientAccessUrl();
            MessageDialog successDialog = new MessageDialog(getShell(), "Project upload successful", null,
                    "Project was successfully uploaded to hale connect.", MessageDialog.INFORMATION,
                    new String[] { IDialogConstants.OK_LABEL }, 0) {

                @Override
                protected Control createCustomArea(Composite parent) {
                    Link link = new Link(parent, SWT.WRAP);
                    link.setText(MessageFormat.format(
                            "To access this project online, please visit the following URL (login may be required):\n<a href=\"{0}\">{0}</a>.",
                            clientAccessUrl));
                    link.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            try {
                                // Open default external browser
                                PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser()
                                        .openURL(new URL(e.text));
                            } catch (Exception ex) {
                                log.error(MessageFormat.format("Error opening browser: {0}", ex.getMessage()),
                                        e);
                            }
                        }
                    });
                    return link;
                }

            };
            successDialog.open();

            log.info(MessageFormat.format(
                    "Project was successfully uploaded to hale connect and is available online at \"{0}\"",
                    clientAccessUrl));
        } catch (IllegalArgumentException e) {
            // bad base path?
            log.error(MessageFormat.format("Error creating client access URL: {0}", e.getMessage()), e);
            log.userInfo("Project was successfully uploaded to hale connect.");
        }
    }

    return result;
}

From source file:eu.geclipse.ui.internal.actions.DeleteGridElementAction.java

License:Open Source License

private void deleteWorkflowJobDescriptions(final List<IGridJobDescription> selectedJobDescriptions) {
    MessageDialog dialog = null;/*ww w.j  a  v  a 2 s  .  co  m*/
    String dialogMessage = ""; //$NON-NLS-1$
    if (selectedJobDescriptions.size() == 1) {
        IGridJobDescription selectedJobDesc = selectedJobDescriptions.get(0);
        String jsdl = selectedJobDesc.getResource().getName();
        dialogMessage = String.format(Messages.getString("DeleteGridElementAction.confirmJobDescDeleteOne"), //$NON-NLS-1$
                jsdl);
    } else {
        String jsdlList = ""; //$NON-NLS-1$
        for (Iterator<IGridJobDescription> i = selectedJobDescriptions.iterator(); i.hasNext();) {
            jsdlList = jsdlList + " " + i.next().getResource().getName(); //$NON-NLS-1$
        }
        dialogMessage = String.format(Messages.getString("DeleteGridElementAction.confirmJobDescDeleteMany"), //$NON-NLS-1$
                jsdlList);
    }
    dialog = new MessageDialog(DeleteGridElementAction.this.shell,
            Messages.getString("DeleteGridElementAction.confirmationTitle"), //$NON-NLS-1$
            null, dialogMessage, MessageDialog.WARNING,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);

    if (dialog.open() == Window.OK) {
        try {
            for (Iterator<IGridJobDescription> i1 = selectedJobDescriptions.iterator(); i1.hasNext();) {
                IResource r = i1.next().getResource();
                r.delete(true, new NullProgressMonitor()); // TODO add a proper progress monitor to use           
            }

        } catch (CoreException e) {
            // TODO Auto-generated catch block, add proper problem reporting
            e.printStackTrace();
        }
    }
}