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:com.motorola.studio.android.common.utilities.EclipseUtils.java

License:Apache License

/**
 * Show a question message using the given title and message
 * /*from  ww w  . ja v  a 2  s. co m*/
 * @param title
 *            of the dialog
 * @param message
 *            to be displayed in the dialog.
 */
public static int showQuestionYesAllCancelDialog(final String title, final String message) {
    class IntWrapper {
        public int diagReturn = 0;
    }

    final IntWrapper intWrapper = new IntWrapper();
    Display.getDefault().syncExec(new Runnable() {

        public void run() {
            IWorkbench workbench = PlatformUI.getWorkbench();
            IWorkbenchWindow ww = workbench.getActiveWorkbenchWindow();
            Shell shell = ww.getShell();
            MessageDialog dialog = new MessageDialog(shell, title, null, message, MessageDialog.QUESTION,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                            IDialogConstants.NO_LABEL },
                    0);
            int diagResults = dialog.open();
            switch (diagResults) {
            case 0:
                intWrapper.diagReturn = IDialogConstants.YES_ID;
                break;
            case 1:
                intWrapper.diagReturn = IDialogConstants.YES_TO_ALL_ID;
                break;
            case 2:
            default:
                intWrapper.diagReturn = IDialogConstants.NO_ID;
                break;
            }
        }
    });

    return intWrapper.diagReturn;
}

From source file:com.mountainminds.eclemma.internal.ui.launching.NoInstrumentedClassesHandler.java

License:Open Source License

public Object handleStatus(IStatus status, final Object source) throws CoreException {

    final Shell parent = EclEmmaUIPlugin.getInstance().getShell();
    String title = UIMessages.NoInstrumentedClassesError_title;
    String message = UIMessages.NoInstrumentedClassesError_message;

    MessageDialog d = new MessageDialog(parent, title, null, message, MessageDialog.ERROR,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
    if (d.open() == 0) {
        parent.getDisplay().asyncExec(new Runnable() {
            public void run() {
                DebugUITools.openLaunchConfigurationDialogOnGroup(parent, new StructuredSelection(source),
                        EclEmmaUIPlugin.ID_COVERAGE_LAUNCH_GROUP);
            }/*  ww  w .jav  a 2  s .  com*/
        });
    }
    return Boolean.FALSE;
}

From source file:com.mulgasoft.emacsplus.preferences.EmacsPlusPreferencePage.java

License:Open Source License

/**
 * Pop up a message dialog to request the restart of the workbench
 *///from www . jav  a 2 s  . c om
private void requestRestart(String rePreference) {

    String reMessage = EmacsPlusActivator.getString("EmacsPlusPref_RestartMessage"); //$NON-NLS-1$ 
    IProduct product = Platform.getProduct();
    String productName = product != null && product.getName() != null ? product.getName()
            : EmacsPlusActivator.getString("EmacsPlusPref_DefaultProduct"); //$NON-NLS-1$ 

    final String msg = String.format(reMessage, productName, rePreference);
    final String reTitle = EmacsPlusActivator.getString("EmacsPlusPref_RestartTitle"); //$NON-NLS-1$ 

    PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
        public void run() {
            if (PlatformUI.getWorkbench().isClosing())
                return;
            // yes == 0, no == 1
            MessageDialog dialog = new MessageDialog(getDefaultShell(), reTitle, null, msg,
                    MessageDialog.QUESTION,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
            if (dialog.open() != Window.CANCEL) {
                if (dialog.getReturnCode() == 0) {
                    // restart workbench
                    PlatformUI.getWorkbench().restart();
                }
            }
        }
    });
}

From source file:com.netxforge.netxstudio.screens.editing.CDOEditingService.java

License:Open Source License

@Override
public void doSave(IProgressMonitor monitor) {

    // save could be triggered from
    CDOView view = dawnEditorSupport.getView();
    if (view instanceof CDOTransaction) {

        if (view.isDirty()) {
            StudioUtils.cdoDumpDirtyObject((CDOTransaction) view);
        }//from   ww w  .  j  a  v a  2 s. c o  m

        if (((CDOTransaction) view).hasConflict()) {
            MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), "Conflict", null,
                    "There is a conflict with another user. Would you like to rollback your current transaction?",
                    MessageDialog.QUESTION, new String[] { "yes", "no", "Cancel" }, 1);
            switch (dialog.open()) {
            case 0: // yes
                ((IDawnEditor) this).getDawnEditorSupport().rollback();
                break;
            case 1: // no
                break;
            default: // cancel
                break;
            }
        } else {
            // this.doSaveHistory(monitor);
            IRunnableWithProgress operation = doGetSaveOperation(monitor);
            if (operation == null)
                return;
            try {
                // This runs the options, and shows progress.
                new ProgressMonitorDialog(Display.getDefault().getActiveShell()).run(true, false, operation);

                // Refresh the necessary state.
                ((BasicCommandStack) getEditingDomain().getCommandStack()).saveIsDone();

            } catch (Exception exception) {

            }
        }
    }
}

From source file:com.netxforge.screens.editing.base.dialogs.MessageDialogWithResult.java

License:Open Source License

/**
 * Convenience method to open a simple dialog as specified by the
 * <code>kind</code> flag.//from  www .  j a va2 s . c o m
 * 
 * @param kind
 *            the kind of dialog to open, one of {@link #ERROR},
 *            {@link #INFORMATION}, {@link #QUESTION}, {@link #WARNING},
 *            {@link #CONFIRM}, or {@link #QUESTION_WITH_CANCEL}.
 * @param parent
 *            the parent shell of the dialog, or <code>null</code> if none
 * @param title
 *            the dialog's title, or <code>null</code> if none
 * @param message
 *            the message
 * @param style
 *            {@link SWT#NONE} for a default dialog, or {@link SWT#SHEET}
 *            for a dialog with sheet behavior
 * @return <code>true</code> if the user presses the OK or Yes button,
 *         <code>false</code> otherwise
 * @since 3.5
 */
public static int openWithResult(int kind, Shell parent, String title, String message, int style) {
    MessageDialog dialog = new MessageDialog(parent, title, null, message, kind, getButtonLabels(kind), 0);
    return dialog.open();
}

From source file:com.nokia.carbide.cpp.internal.pi.button.ui.BupProfileEditDialog.java

License:Open Source License

public void cancelPressed() {
    if (cachedMap.haveUncommitedChanges()) {
        MessageDialog dialog = new MessageDialog(getShell(),
                Messages.getString("BupProfileEditDialog.uncommittedChanges"), //$NON-NLS-1$
                null,//w  w w .  ja  va  2 s .c  o  m
                Messages.getString("BupProfileEditDialog.saveChanges") + profileForThisEdit.getProfileId() //$NON-NLS-1$
                        + "?", //$NON-NLS-1$
                MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                        IDialogConstants.CANCEL_LABEL },
                0); // default yes
        switch (dialog.open()) {
        case 0: // yes
            cachedMap.commitChanges(); // fall thru to no
        case 1: // no
            super.cancelPressed();
            cleanUp();
        case 2: // cancel
        default:
            return;
        }
    }
    super.cancelPressed();
    cleanUp();
}

From source file:com.nokia.carbide.cpp.internal.project.ui.editors.common.CarbideFormEditor.java

License:Open Source License

void handleResourceChanged() {
    // The file has changed. If this editor is clean then simply
    // reload, otherwise ask the user if they want to reload first.
    boolean doReload;
    if (isDirty()) {
        String fmt = Messages.CarbideFormEditor_reloadOnChangedFilePrompt;
        String msg = MessageFormat.format(fmt, getEditorInput().getName());
        String btnLabels[] = { Messages.CarbideFormEditor_yesButtonLabel,
                Messages.CarbideFormEditor_noButtonLabel };
        MessageDialog dialog = new MessageDialog(this.getSite().getShell(),
                Messages.CarbideFormEditor_reloadOnChangedFileDialogTitle, null, msg, MessageDialog.QUESTION,
                btnLabels, 1);/*w  w  w. j av a2 s.c  o m*/
        doReload = Dialog.OK == dialog.open();
    } else {
        doReload = true;
    }

    if (doReload) {
        reload();
    } else {
        reloadRejected();
    }
}

From source file:com.nokia.carbide.cpp.internal.project.ui.editors.common.CarbideFormEditor.java

License:Open Source License

/**
 * If the file has been deleted, and the editor is dirty,
 * offer to save the file or close the editor.
 *///from  www  .  java2 s .c  o m
protected void handleResourceDeleted() {
    // offer user the choice of saving the file or closing the editor
    boolean doSaveAs = false;
    if (isDirty()) {
        MessageDialog dialog = new MessageDialog(getSite().getShell(),
                Messages.CarbideFormEditor_saveResourceTitle, null,
                Messages.CarbideFormEditor_saveResourceMessage, MessageDialog.INFORMATION,
                new String[] { Messages.CarbideFormEditor_saveResourceLabel, IDialogConstants.CLOSE_LABEL }, 0);
        if (dialog.open() == 0) {
            doSaveAs = true;
            resourceDeleted = false;
        }
    }

    // save the file or close the editor at the next reasonable opportunity
    final boolean saveAs = doSaveAs;
    Display.getDefault().asyncExec(new Runnable() {
        public void run() {
            if (saveAs)
                doSaveAs();
            else
                getSite().getPage().closeEditor(CarbideFormEditor.this, false);
        }
    });
}

From source file:com.nokia.carbide.cpp.internal.project.ui.editors.images.MultiImageEditorContext.java

License:Open Source License

/**
 * Save changes to the multi-image source.
 * <p>/*from   w  ww.j a va2s . c  o m*/
 * If the context was initialized with a null IOperationHistory,
 * the incoming IMultiImageSource is directly modified.  Otherwise,
 * the change is executed and added as an operation to that history. 
 */
public void doSave() {
    if (sourceDisposition == SourceDisposition.FROM_VIEW) {
        // modify through the parent editor's operation history
        if (editorHistory != null) {
            // make the save operation for the parent editor
            IUndoableOperation operation = getEditingOperation();
            try {
                operation.addContext(editorUndoContext);
                editorHistory.execute(operation, null, null);
            } catch (ExecutionException e) {
                ProjectUIPlugin.log(e);
            }
        } else {
            ownedMultiImageSource.set(multiImageSource);
        }
    } else {
        // in this mode, we directly update the view
        while (true) {
            try {
                ownedMultiImageSource.set(multiImageSource);
                view.commit();
                break;
            } catch (IllegalStateException e) {
                // rollback or overwrite?
                ProjectUIPlugin.log(e);
                MessageDialog dialog = new MessageDialog((Shell) editorContext.getAdapter(Shell.class),
                        Messages.getString("MultiImageEditorContext.ConflictingChangesTitle"), //$NON-NLS-1$
                        MessageDialog.getImage(MessageDialog.DLG_IMG_MESSAGE_ERROR),
                        MessageFormat.format(
                                Messages.getString("MultiImageEditorContext.ConflictingChangesMessage"), //$NON-NLS-1$
                                new Object[] { ((IOwnedModel) view.getModel()).getPath() }),
                        MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);
                dialog.open();
                view.revert();
            }
        }

        try {
            getMultiImageSourceWorkaround();

            // redraw entire UI
            this.page.dispose();
            createControl(this.parent);
            this.page.setVisible(true);
        } catch (PartInitException e) {
            // just fail -- this is a workaround, after all 
            ProjectUIPlugin.log(e);
        }
    }
}

From source file:com.nokia.carbide.cpp.sysdoc.internal.hover.uitlis.DialogHelper.java

License:Open Source License

public static void displayErrorDialog(final String msg, final String title, final int icon) {

    Runnable mssageRunnable = new Runnable() {
        public void run() {
            MessageDialog message = new MessageDialog(
                    Activator.getDefault().getWorkbench().getDisplay().getActiveShell(), title, null, msg, icon,
                    new String[] { "OK" }, 1);
            message.open();//from w  w  w  . j a v  a  2 s  .c o  m

        }
    };
    if (!HoverManager.isTestMode() && !HoverManager.isJunitRunning()) {
        ExecutorAgent.run(mssageRunnable);
    }
}