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

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

Introduction

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

Prototype

public int open() 

Source Link

Document

Opens this window, creating it first if it has not yet been created.

Usage

From source file:com.mindquarry.desktop.client.MindClient.java

License:Open Source License

/**
 * Displays an error message and prompts the user to check their credentials
 * in the preferences dialog, or to cancel.
 * //from   w w  w. ja  va2  s .c  o m
 * @param exception
 *            Contains the error message to be displayed.
 * @return True if and only if preferences dialog was shown to user which
 *         means that the credentials were potentially updated.
 */
public boolean handleMalformedURLException(MalformedURLException exception) {
    // create custom error message with the option to open the preferences
    // dialog
    MessageDialog messageDialog = new MessageDialog(getShell(), I18N.getString("Error"), //$NON-NLS-1$
            null,
            I18N.get(
                    "Invalid server URL given: {0}\n\nPlease check your server settings in the preferences dialog.",
                    exception.getLocalizedMessage()),
            MessageDialog.ERROR, new String[] { I18N.getString("Go to preferences"), //$NON-NLS-1$
                    I18N.getString("Cancel") //$NON-NLS-1$
            }, 0);

    int buttonClicked = messageDialog.open();
    switch (buttonClicked) {
    case 0: // go to preferences
        showPreferenceDialog(true);
        return true;

    case 1: // cancel
        displayNotConnected();
        return false;
    }
    return false;
}

From source file:com.mobilesorcery.sdk.importproject.MoSyncWizardProjectsImportPage.java

License:Open Source License

/**
 * The <code>WizardDataTransfer</code> implementation of this
 * <code>IOverwriteQuery</code> method asks the user whether the existing
 * resource at the given path should be overwritten.
 *
 * @param pathString/*from w w w .j a  v a  2 s  .  c o  m*/
 * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>,
 *    <code>"ALL"</code>, or <code>"CANCEL"</code>
 */
@Override
public String queryOverwrite(String pathString) {

    Path path = new Path(pathString);

    String messageString;
    // Break the message up if there is a file name and a directory
    // and there are at least 2 segments.
    if (path.getFileExtension() == null || path.segmentCount() < 2) {
        messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_existsQuestion, pathString);
    } else {
        messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_overwriteNameAndPathQuestion,
                path.lastSegment(), path.removeLastSegments(1).toOSString());
    }

    final MessageDialog dialog = new MessageDialog(getContainer().getShell(), IDEWorkbenchMessages.Question,
            null, messageString, MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            0) {
        @Override
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL };
    // run in syncExec because callback is from an operation,
    // which is probably not running in the UI thread.
    getControl().getDisplay().syncExec(new Runnable() {
        @Override
        public void run() {
            dialog.open();
        }
    });
    return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}

From source file:com.mobilesorcery.sdk.internal.launch.EmulatorLaunchConfigurationDelegate.java

License:Open Source License

private boolean showSwitchConfigDialog(MoSyncProject mosyncProject, String mode,
        final IBuildConfiguration activeCfg, String[] requiredTypes) {
    if (isDebugMode(mode)) {
        Display d = PlatformUI.getWorkbench().getDisplay();
        final boolean[] result = new boolean[1];
        d.syncExec(new Runnable() {
            @Override/*from   w  w  w .  ja  v  a  2  s .  co m*/
            public void run() {
                Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                MessageDialog dialog = new MessageDialog(shell, "Incompatible build configuration", null,
                        MessageFormat.format(
                                "The build configuration \"{0}\" is not intended for debugging. Debug anyway?",
                                activeCfg.getId()),
                        MessageDialog.WARNING, new String[] { "Debug", "Cancel" }, 1);
                result[0] = dialog.open() == 0;
            }
        });
        return result[0];
    }
    return true;
}

From source file:com.mobilesorcery.sdk.ui.MosyncUIPlugin.java

License:Open Source License

protected void checkConfig(final IWorkbench wb) {
    if (!MoSyncTool.getDefault().isValid()) {
        wb.getDisplay().syncExec(new Runnable() {
            public void run() {
                MessageDialog dialog = new MessageDialog(wb.getModalDialogShellProvider().getShell(),
                        "Fatal error", null,
                        MessageFormat.format(
                                "The environment variable MOSYNCDIR has not been properly set, or some other serious error has occurred. (Reason: {0})\n\nMoSync will not work properly. Press Ok to quit, or Cancel to continue anyway.",
                                MoSyncTool.getDefault().validate()),
                        MessageDialog.ERROR,
                        new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
                if (dialog.open() == IDialogConstants.OK_ID) {
                    wb.close();/* w w  w. jav  a 2  s  .c o m*/
                }
            }
        });
    }
}

From source file:com.motorola.studio.android.common.utilities.EclipseUtils.java

License:Apache License

private static int showInformationDialog(final String dialogTitle, final String dialogMessage,
        final String detailsMessage, final String[] buttonLabels, final int dialogImageType) {
    final int[] returnCode = new int[1];
    PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
        public void run() {
            Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

            Rectangle parentSize;
            if (shell.getParent() != null) {
                parentSize = shell.getParent().getBounds();
            } else {

                parentSize = shell.getBounds();
            }/*from  w w  w.  j  av a2 s.  c o m*/

            MessageDialog dlg;
            String[] internButtonLabels = buttonLabels;
            if (internButtonLabels == null) {
                internButtonLabels = new String[] { "OK" };
            }

            if (detailsMessage == null) {
                dlg = new MessageDialog(shell, dialogTitle, null, dialogMessage, dialogImageType,
                        internButtonLabels, 0);
            } else {
                dlg = new MessageDialog(shell, dialogTitle, null, dialogMessage, dialogImageType,
                        internButtonLabels, 0) {
                    @Override
                    protected Control createCustomArea(Composite parent) {
                        final Composite main = new Composite(parent, parent.getStyle());
                        GridLayout layout = new GridLayout();
                        main.setLayout(layout);
                        GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
                        main.setLayoutData(data);

                        final Button detailsButton = new Button(main, SWT.PUSH);
                        detailsButton.setText(UtilitiesNLS.UI_EclipseUtils_OpenDetails);
                        data = new GridData(SWT.RIGHT, SWT.CENTER, true, false);
                        detailsButton.setLayoutData(data);
                        detailsButton.addSelectionListener(new SelectionAdapter() {
                            private Label detailsText;

                            @Override
                            public void widgetSelected(SelectionEvent e) {
                                if ((detailsText != null) && !detailsText.isDisposed()) {
                                    detailsButton.setText(UtilitiesNLS.UI_EclipseUtils_OpenDetails);
                                    detailsText.dispose();
                                } else {
                                    detailsButton.setText(UtilitiesNLS.UI_EclipseUtils_CloseDetails);
                                    detailsText = new Label(main, SWT.WRAP | SWT.BORDER);
                                    detailsText.setText(detailsMessage);
                                    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
                                    detailsText.setLayoutData(data);
                                    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.BEGINNING)
                                            .grab(true, false)
                                            .hint(convertHorizontalDLUsToPixels(
                                                    IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH), SWT.DEFAULT)
                                            .applyTo(detailsText);
                                }
                                getShell().pack();
                            }
                        });

                        return main;
                    }
                };
            }

            Rectangle dialogSize = shell.getBounds();

            int x = ((parentSize.width - dialogSize.width) / 2) + parentSize.x;
            int y = ((parentSize.height - dialogSize.height) / 2) + parentSize.y;

            shell.setLocation(x, y);

            returnCode[0] = dlg.open();
        }
    });

    return returnCode[0];
}

From source file:com.motorola.studio.android.common.utilities.EclipseUtils.java

License:Apache License

/**
 * Show a question message using the given title and message
 * //  www  . j  a v a2 s  .co  m
 * @param title
 *            of the dialog
 * @param message
 *            to be displayed in the dialog.
 */
public static int showQuestionWithCancelDialog(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.NO_LABEL,
                            IDialogConstants.CANCEL_LABEL },
                    0);
            int diagResults = dialog.open();
            switch (diagResults) {
            case 0:
                intWrapper.diagReturn = SWT.YES;
                break;
            case 1:
                intWrapper.diagReturn = SWT.NO;
                break;
            case 2:
            default:
                intWrapper.diagReturn = SWT.CANCEL;
                break;
            }
        }
    });

    return intWrapper.diagReturn;
}

From source file:com.motorola.studio.android.common.utilities.EclipseUtils.java

License:Apache License

/**
 * Show a question message using the given title and message
 * //w  w w.  jav  a2 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);
            }//w w  w  .j  a  va2  s . c  o  m
        });
    }
    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
 *//*  w w  w .  ja  va 2 s  .  com*/
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 www .j av a 2s .  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) {

            }
        }
    }
}