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

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

Introduction

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

Prototype

@Override
public Shell getShell() 

Source Link

Document

Returns this window's shell.

Usage

From source file:com.arc.cdt.debug.seecode.ui.UISeeCodePlugin.java

License:Open Source License

/**
 * Show an note box./*from  w  w  w  . ja  va 2  s. c  o m*/
 * (We use JFace ErrorDialog instead of MessageBox. The latter is done outside
 * of Java and the WindowTester framework loses control).
 * @param title
 * @param message
 */
public static void showNote(String title, String message) {
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    MessageDialog dialog = new MessageDialog(shell, title, null, // accept
            // the
            // default
            // window
            // icon
            message, MessageDialog.INFORMATION, new String[] { IDialogConstants.OK_LABEL }, 0);
    dialog.setBlockOnOpen(false); // we want to be able to make box expire
    // ok is the default
    dialog.open();
    long expireTime = System.currentTimeMillis() + NOTE_TIME_OUT;
    Display display = shell.getDisplay();
    try {
        while (dialog.getShell() != null && !dialog.getShell().isDisposed()
                && System.currentTimeMillis() < expireTime) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
    } finally {
        if (dialog.getShell() != null && !dialog.getShell().isDisposed()) {
            dialog.close();
        }
    }
}

From source file:com.toedter.e4.demo.contacts.rap.views.DetailsView.java

License:Open Source License

@Inject
public void setSelection(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) Contact contact) {
    if (contact != null) {
        if (dirtyable.isDirty()) {
            MessageDialog dialog = new MessageDialog(detailComposite.getShell(), "Save vCard", null,
                    "The current vCard has been modified. Save changes?", MessageDialog.CONFIRM,
                    new String[] { "Yes", "No" }, 0);
            dialog.create();//  ww w.j  av  a 2  s  . c o m
            ThemeUtil.applyDialogStyles(engine, dialog.getShell());
            if (dialog.open() == Window.OK) {
                ParameterizedCommand saveCommand = commandService.createCommand("contacts.save",
                        Collections.EMPTY_MAP);
                handlerService.executeHandler(saveCommand);
            }
        }

        updatePartTitle(contact);
    } else {
        uiItem.setLabel("Details");
    }
    dirtyable.setDirty(false);
    detailComposite.update(contact);
}

From source file:com.toedter.e4.demo.contacts.swt.views.DetailsView.java

License:Open Source License

@Inject
public void setSelection(@Optional Contact contact) {
    if (contact != null) {
        if (dirtyable.isDirty()) {
            MessageDialog dialog = new MessageDialog(detailComposite.getShell(), "Save vCard", null,
                    "The current vCard has been modified. Save changes?", MessageDialog.CONFIRM,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
            dialog.create();/*w  ww  .  java2  s.  c om*/
            if (engine != null) {
                ThemeUtil.applyDialogStyles(engine, dialog.getShell());
            }
            if (dialog.open() == Window.OK) {
                ParameterizedCommand saveCommand = commandService.createCommand("contacts.save",
                        Collections.EMPTY_MAP);
                handlerService.executeHandler(saveCommand);
            }
        }

        updatePartTitle(contact);
    } else {
        uiItem.setLabel("Details");
    }
    dirtyable.setDirty(false);
    detailComposite.update(contact);
}

From source file:org.eclipse.e4.demo.contacts.views.DetailsView.java

License:Open Source License

@Inject
public void setSelection(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) Contact contact) {
    if (contact != null) {
        if (dirtyable.isDirty()) {
            MessageDialog dialog = new MessageDialog(detailComposite.getShell(), "Save vCard", null,
                    "The current vCard has been modified. Save changes?", MessageDialog.CONFIRM,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
            dialog.create();//from  w  w w  .ja  v  a 2  s  .c  om
            ThemeUtil.applyDialogStyles(engine, dialog.getShell());
            if (dialog.open() == Window.OK) {
                ParameterizedCommand saveCommand = commandService.createCommand("contacts.save",
                        Collections.EMPTY_MAP);
                handlerService.executeHandler(saveCommand);
            }
        }

        updatePartTitle(contact);
    } else {
        uiItem.setLabel("Details");
    }
    dirtyable.setDirty(false);
    if (!detailComposite.isDisposed()) {
        detailComposite.update(contact);
    }
}

From source file:org.eclipse.jdt.internal.ui.preferences.ProblemSeveritiesConfigurationBlock.java

License:Open Source License

@Override
protected void validateSettings(Key changedKey, String oldValue, String newValue) {
    if (!areSettingsEnabled()) {
        return;/*from  w ww. j a v  a  2  s . co m*/
    }

    if (changedKey != null) {
        if (PREF_PB_UNUSED_PARAMETER.equals(changedKey) || PREF_PB_DEPRECATION.equals(changedKey)
                || PREF_PB_LOCAL_VARIABLE_HIDING.equals(changedKey)
                || PREF_15_PB_INCOMPLETE_ENUM_SWITCH.equals(changedKey)
                || PREF_PB_UNUSED_DECLARED_THROWN_EXCEPTION.equals(changedKey)
                || PREF_PB_SUPPRESS_WARNINGS.equals(changedKey)
                || PREF_ANNOTATION_NULL_ANALYSIS.equals(changedKey)) {
            updateEnableStates();
        }

        if (checkValue(PREF_ANNOTATION_NULL_ANALYSIS, ENABLED)
                && (PREF_ANNOTATION_NULL_ANALYSIS.equals(changedKey)
                        || PREF_PB_NULL_REFERENCE.equals(changedKey)
                        || PREF_PB_POTENTIAL_NULL_REFERENCE.equals(changedKey)
                        || PREF_PB_NULL_SPECIFICATION_VIOLATION.equals(changedKey)
                        || PREF_PB_POTENTIAL_NULL_ANNOTATION_INFERENCE_CONFLICT.equals(changedKey))) {
            boolean badNullRef = lessSevere(getValue(PREF_PB_NULL_REFERENCE),
                    getValue(PREF_PB_NULL_SPECIFICATION_VIOLATION));
            boolean badPotNullRef = lessSevere(getValue(PREF_PB_POTENTIAL_NULL_REFERENCE),
                    getValue(PREF_PB_POTENTIAL_NULL_ANNOTATION_INFERENCE_CONFLICT));
            boolean ask = false;
            ask |= badNullRef && (PREF_PB_NULL_REFERENCE.equals(changedKey)
                    || PREF_PB_NULL_SPECIFICATION_VIOLATION.equals(changedKey));
            ask |= badPotNullRef && (PREF_PB_POTENTIAL_NULL_REFERENCE.equals(changedKey)
                    || PREF_PB_POTENTIAL_NULL_ANNOTATION_INFERENCE_CONFLICT.equals(changedKey));
            ask |= (badNullRef || badPotNullRef) && PREF_ANNOTATION_NULL_ANALYSIS.equals(changedKey);
            if (ask) {
                final Combo comboBoxNullRef = getComboBox(PREF_PB_NULL_REFERENCE);
                final Label labelNullRef = fLabels.get(comboBoxNullRef);
                int highlightNullRef = getHighlight(labelNullRef);
                final Combo comboBoxPotNullRef = getComboBox(PREF_PB_POTENTIAL_NULL_REFERENCE);
                final Label labelPotNullRef = fLabels.get(comboBoxPotNullRef);
                int highlightPotNullRef = getHighlight(labelPotNullRef);

                getShell().getDisplay().asyncExec(new Runnable() {
                    public void run() {
                        highlight(comboBoxNullRef.getParent(), labelNullRef, comboBoxNullRef, HIGHLIGHT_FOCUS);
                        highlight(comboBoxPotNullRef.getParent(), labelPotNullRef, comboBoxPotNullRef,
                                HIGHLIGHT_FOCUS);
                    }
                });

                MessageDialog messageDialog = new MessageDialog(getShell(),
                        PreferencesMessages.ProblemSeveritiesConfigurationBlock_adapt_null_pointer_access_settings_dialog_title,
                        null,
                        PreferencesMessages.ProblemSeveritiesConfigurationBlock_adapt_null_pointer_access_settings_dialog_message,
                        MessageDialog.QUESTION,
                        new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
                messageDialog.create();
                Shell messageShell = messageDialog.getShell();
                messageShell.setLocation(messageShell.getLocation().x, getShell().getLocation().y + 40);
                if (messageDialog.open() == 0) {
                    if (badNullRef) {
                        setValue(PREF_PB_NULL_REFERENCE, getValue(PREF_PB_NULL_SPECIFICATION_VIOLATION));
                        updateCombo(getComboBox(PREF_PB_NULL_REFERENCE));
                    }
                    if (badPotNullRef) {
                        setValue(PREF_PB_POTENTIAL_NULL_REFERENCE,
                                getValue(PREF_PB_POTENTIAL_NULL_ANNOTATION_INFERENCE_CONFLICT));
                        updateCombo(getComboBox(PREF_PB_POTENTIAL_NULL_REFERENCE));
                    }
                }

                highlight(comboBoxNullRef.getParent(), labelNullRef, comboBoxNullRef, highlightNullRef);
                highlight(comboBoxPotNullRef.getParent(), labelPotNullRef, comboBoxPotNullRef,
                        highlightPotNullRef);
            }

        } else if (PREF_PB_SIGNAL_PARAMETER_IN_OVERRIDING.equals(changedKey)) {
            // merging the two options
            setValue(PREF_PB_SIGNAL_PARAMETER_IN_ABSTRACT, newValue);

        } else if (INTR_DEFAULT_NULL_ANNOTATIONS.equals(changedKey)) {
            if (ENABLED.equals(newValue)) {
                setValue(PREF_NULLABLE_ANNOTATION_NAME, NULL_ANNOTATIONS_DEFAULTS[0]);
                setValue(PREF_NONNULL_ANNOTATION_NAME, NULL_ANNOTATIONS_DEFAULTS[1]);
                setValue(PREF_NONNULL_BY_DEFAULT_ANNOTATION_NAME, NULL_ANNOTATIONS_DEFAULTS[2]);
            } else {
                openNullAnnotationsConfigurationDialog();
            }

        } else {
            return;
        }
    } else {
        updateEnableStates();
        updateNullAnnotationsSetting();
    }
}

From source file:org.eclipse.ptp.internal.rdt.sync.ui.handlers.CommonMissingConnectionHandler.java

License:Open Source License

@Override
public void handle(final IRemoteServices remoteServices, final String connectionName) {
    RDTSyncUIPlugin.getStandardDisplay().syncExec(new Runnable() {
        @Override/* ww w.  j a  v a2s  .c o m*/
        public void run() {
            // Avoid flooding the display with missing connection dialogs
            if (System.currentTimeMillis() - lastMissingConnectiontDialogTimeStamp <= timeBetweenDialogs) {
                return;
            }
            lastMissingConnectiontDialogTimeStamp = System.currentTimeMillis();
            String[] buttonLabels = new String[2];
            buttonLabels[0] = IDialogConstants.OK_LABEL;
            buttonLabels[1] = Messages.CommonMissingConnectionHandler_6;
            String newline = System.getProperty("line.separator"); //$NON-NLS-1$
            MessageDialog dialog = new MessageDialog(null, Messages.CommonMissingConnectionHandler_0, null,
                    Messages.CommonMissingConnectionHandler_1 + connectionName
                            + Messages.CommonMissingConnectionHandler_2 + newline + newline
                            + Messages.CommonMissingConnectionHandler_3 + newline
                            + Messages.CommonMissingConnectionHandler_4 + newline
                            + Messages.CommonMissingConnectionHandler_5,
                    MessageDialog.ERROR, buttonLabels, 0);
            int buttonPressed = dialog.open();
            if (buttonPressed == 1) {
                IRemoteUIConnectionManager connectionManager = RemoteUIServices
                        .getRemoteUIServices(remoteServices).getUIConnectionManager();
                if (connectionManager != null) {
                    IRemoteUIConnectionWizard wizard = connectionManager.getConnectionWizard(dialog.getShell());
                    wizard.setConnectionName(RemoteConnectionWidget.DEFAULT_CONNECTION_NAME);
                    IRemoteConnectionWorkingCopy wc = wizard.open();
                    wc.save();
                }
            }
        }
    });
}