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

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

Introduction

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

Prototype

int QUESTION

To view the source code for org.eclipse.jface.dialogs MessageDialog QUESTION.

Click Source Link

Document

Constant for the question image, or a simple dialog with the question image and Yes/No buttons (value 3).

Usage

From source file:org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor.java

License:Open Source License

/**
 * Handles an external change of the editor's input element. Subclasses may
 * extend.// w  w w  .j a  v  a 2  s .c  o  m
 */
protected void handleEditorInputChanged() {

    String title;
    String msg;
    Shell shell = getSite().getShell();

    final IDocumentProvider provider = getDocumentProvider();
    if (provider == null) {
        // fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=15066
        close(false);
        return;
    }

    final IEditorInput input = getEditorInput();
    if (provider.isDeleted(input)) {
        try {
            isHandlingElementDeletion = true;
            if (isSaveAsAllowed()) {
                title = EditorMessages.Editor_error_activated_deleted_save_title;
                msg = EditorMessages.Editor_error_activated_deleted_save_message;

                String[] buttons = { EditorMessages.Editor_error_activated_deleted_save_button_save,
                        EditorMessages.Editor_error_activated_deleted_save_button_close, };

                MessageDialog dialog = new MessageDialog(shell, title, null, msg, MessageDialog.QUESTION,
                        buttons, 0);

                if (dialog.open() == 0) {
                    IProgressMonitor pm = getProgressMonitor();
                    performSaveAs(pm);
                    if (pm.isCanceled())
                        handleEditorInputChanged();
                } else {
                    close(false);
                }
            } else {
                title = EditorMessages.Editor_error_activated_deleted_close_title;
                msg = EditorMessages.Editor_error_activated_deleted_close_message;
                if (MessageDialog.openConfirm(shell, title, msg))
                    close(false);
            }
        } finally {
            isHandlingElementDeletion = false;
        }
    } else {

        title = EditorMessages.Editor_error_activated_outofsync_title;
        msg = EditorMessages.Editor_error_activated_outofsync_message;

        if (MessageDialog.openQuestion(shell, title, msg)) {

            try {
                provider.synchronize(input);
                //               if (provider instanceof IDocumentProviderExtension) {
                //                  IDocumentProviderExtension extension= (IDocumentProviderExtension) provider;
                //                  extension.synchronize(input);
                //               } else {
                //                  setInput(input);
                //               }
            } catch (CoreException x) {
                IStatus status = x.getStatus();
                if (status == null || status.getSeverity() != IStatus.CANCEL) {
                    title = EditorMessages.Editor_error_refresh_outofsync_title;
                    msg = EditorMessages.Editor_error_refresh_outofsync_message;
                    ErrorDialog.openError(shell, title, msg, x.getStatus());
                }
            }
        }
    }
}

From source file:org.eclipse.gyrex.admin.ui.internal.widgets.NonBlockingMessageDialogs.java

License:Open Source License

private static String[] getButtonLabels(final int kind) {
    String[] dialogButtonLabels;/*from  w  w  w .  j a v a 2  s .co m*/
    switch (kind) {
    case MessageDialog.ERROR:
    case MessageDialog.INFORMATION:
    case MessageDialog.WARNING: {
        dialogButtonLabels = new String[] { IDialogConstants.get().OK_LABEL };
        break;
    }
    case MessageDialog.CONFIRM: {
        dialogButtonLabels = new String[] { IDialogConstants.get().OK_LABEL,
                IDialogConstants.get().CANCEL_LABEL };
        break;
    }
    case MessageDialog.QUESTION: {
        dialogButtonLabels = new String[] { IDialogConstants.get().YES_LABEL, IDialogConstants.get().NO_LABEL };
        break;
    }
    case MessageDialog.QUESTION_WITH_CANCEL: {
        dialogButtonLabels = new String[] { IDialogConstants.get().YES_LABEL, IDialogConstants.get().NO_LABEL,
                IDialogConstants.get().CANCEL_LABEL };
        break;
    }
    default: {
        throw new IllegalArgumentException("Illegal value for kind in MessageDialog.open()");
    }
    }
    return dialogButtonLabels;
}

From source file:org.eclipse.gyrex.admin.ui.internal.widgets.NonBlockingMessageDialogs.java

License:Open Source License

public static void openQuestion(final Shell parent, final String title, final String message,
        final DialogCallback callback) {
    open(MessageDialog.QUESTION, parent, title, message, callback);
}

From source file:org.eclipse.ice.client.widgets.reactoreditor.lwr.PlotAnalysisView.java

License:Open Source License

/**
 * The default constructor.//from w  w  w .  j ava 2s  .  c  om
 * 
 * @param dataSource
 *            The data source associated with this view (input, reference,
 *            comparison).
 */
public PlotAnalysisView(DataSource dataSource) {
    super(dataSource);

    // Default values for all fields, including final collections.
    assembly = null;
    size = 0;
    assemblyLocations = new ArrayList<LWRComponent>();
    assemblyData = new ArrayList<IDataProvider>();
    featureSet = new TreeSet<String>();
    feature = null;
    traces = new HashMap<String, Trace>();
    validLocations = new HashMap<String, BitSet>();
    selectedLocations = new HashMap<String, BitSet>();
    colorFactory = new PaletteColorFactory();

    // Populate the list of actions (for ToolBar and context Menu).

    // Add an ActionTree (single button) for selecting series.
    ActionTree selectSeries = new ActionTree(new Action("Select Plotted Series") {
        @Override
        public void run() {
            requestPlotSeries();
        }
    });
    actions.add(selectSeries);

    // Add an ActionTree (single button) for clearing the plot.
    actions.add(new ActionTree(new Action("Clear Plot") {
        @Override
        public void run() {
            MessageDialog dialog = new MessageDialog(container.getShell(), "Clear Plot", null,
                    "Are you sure you want to remove all plotted series?", MessageDialog.QUESTION,
                    new String[] { "Yes", "No" }, 0);

            if (dialog.open() == Window.OK) {
                /* ---- Clear the currently-graphed data. ---- */
                BitSet selected = selectedLocations.get(feature);
                if (selected != null) {
                    for (int i = selected.nextSetBit(0); i >= 0; i = selected.nextSetBit(i + 1)) {
                        unplotData(i);
                    }
                }
                // Reset the color palette.
                colorFactory.reset();
                /* ------------------------------------------- */
            }
        }
    }));

    // Add an ActionTree to list the available features.
    featureTree = new ActionTree("Data Feature");
    actions.add(featureTree);

    // Add an ActionTree (single button) for saving the viewer image.
    ActionTree saveImage = new ActionTree(new Action("Save Image") {
        @Override
        public void run() {
            saveCanvasImage(canvas);
        }
    });
    actions.add(saveImage);

    return;
}

From source file:org.eclipse.ice.client.widgets.reactoreditor.sfr.PlotAnalysisView.java

License:Open Source License

/**
 * The default constructor./*from w  ww  . j  a v  a 2 s .  c  o  m*/
 * 
 * @param dataSource
 *            The data source associated with this view (input, reference,
 *            comparison).
 */
public PlotAnalysisView(DataSource dataSource) {
    super(dataSource);

    // Default values for all fields, including final collections.
    assembly = null;
    size = 0;
    assemblyLocations = new ArrayList<SFRComponent>();
    assemblyData = new ArrayList<IDataProvider>();
    featureSet = new TreeSet<String>();
    feature = null;
    traces = new HashMap<String, Trace>();
    validLocations = new HashMap<String, BitSet>();
    selectedLocations = new HashMap<String, BitSet>();
    colorFactory = new PaletteColorFactory();

    // Populate the list of actions (for ToolBar and context Menu).

    // Add an ActionTree (single button) for selecting series.
    ActionTree selectSeries = new ActionTree(new Action("Select Plotted Series") {
        @Override
        public void run() {
            requestPlotSeries();
        }
    });
    actions.add(selectSeries);

    // Add an ActionTree (single button) for clearing the plot.
    actions.add(new ActionTree(new Action("Clear Plot") {
        @Override
        public void run() {
            MessageDialog dialog = new MessageDialog(container.getShell(), "Clear Plot", null,
                    "Are you sure you want to remove all plotted series?", MessageDialog.QUESTION,
                    new String[] { "Yes", "No" }, 0);

            if (dialog.open() == Window.OK) {
                /* ---- Clear the currently-graphed data. ---- */
                BitSet selected = selectedLocations.get(feature);
                if (selected != null) {
                    for (int i = selected.nextSetBit(0); i >= 0; i = selected.nextSetBit(i + 1)) {
                        unplotData(i);
                    }
                }
                // Reset the color palette.
                colorFactory.reset();
                /* ------------------------------------------- */
            }
        }
    }));

    // Add an ActionTree to list the available features.
    featureTree = new ActionTree("Data Feature");
    actions.add(featureTree);

    // Add an ActionTree (single button) for saving the viewer image.
    ActionTree saveImage = new ActionTree(new Action("Save Image") {
        @Override
        public void run() {
            saveCanvasImage(canvas);
        }
    });
    actions.add(saveImage);

    return;
}

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

License:Open Source License

/**
 * If there are changed settings, save them and ask user whether to rebuild.
 * This is called by performOk() and performApply().
 * @param container null when called from performApply().
 * @return false to abort exiting the preference pane.
 *///w  ww.  jav  a  2  s  . com
protected boolean processChanges(IWorkbenchPreferenceContainer container) {

    boolean projectSpecificnessChanged = false;
    boolean isProjectSpecific = (fProject != null) && fBlockControl.getEnabled();
    if (fOriginallyHadProjectSettings ^ isProjectSpecific) {
        // the project-specificness changed.
        projectSpecificnessChanged = true;
    } else if ((fProject != null) && !isProjectSpecific) {
        // no project specific data, and there never was, and this
        // is a project preferences pane, so nothing could have changed.
        return true;
    }

    if (!projectSpecificnessChanged && !settingsChanged(fLookupOrder[0])) {
        return true;
    }

    int response = 1; // "NO" rebuild unless we put up the dialog.
    String[] strings = getFullBuildDialogStrings(fProject == null);
    if (strings != null) {
        MessageDialog dialog = new MessageDialog(
                getShell(), strings[0], null, strings[1], MessageDialog.QUESTION, new String[] {
                        IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
                2);
        response = dialog.open();
    }
    if (response == 0 || response == 1) { // "YES" or "NO" - either way, save.
        saveSettings();
        if (container == null) {
            // we're doing an Apply, so update the reference values.
            cacheOriginalValues();
        }
    }
    if (response == 0) { // "YES", rebuild
        if (container != null) {
            // build after dialog exits
            container.registerUpdateJob(CoreUtility.getBuildJob(fProject));
        } else {
            // build immediately
            CoreUtility.getBuildJob(fProject).schedule();
        }
    } else if (response != 1) { // "CANCEL" - no save, no rebuild.
        return false;
    }
    return true;
}

From source file:org.eclipse.jdt.internal.debug.ui.actions.InstanceFiltersAction.java

License:Open Source License

/**
 * @see org.eclipse.ui.IActionDelegate#run(IAction)
 */// w  ww. ja  v  a  2  s  .c om
public void run(IAction action) {
    IStructuredSelection selection = getCurrentSelection();
    if (selection == null || selection.size() > 1) {
        return;
    }

    Object o = selection.getFirstElement();
    if (o instanceof IJavaVariable) {
        final IJavaVariable var = (IJavaVariable) o;
        try {
            IValue value = var.getValue();
            if (value instanceof IJavaObject) {
                final IJavaObject object = (IJavaObject) value;
                final List<IJavaBreakpoint> breakpoints = getApplicableBreakpoints(var, object);
                final IDebugModelPresentation modelPresentation = DebugUITools.newDebugModelPresentation();

                if (breakpoints.isEmpty()) {
                    MessageDialog.openInformation(JDIDebugUIPlugin.getActiveWorkbenchShell(),
                            ActionMessages.InstanceFiltersAction_0, ActionMessages.InstanceFiltersAction_4);
                    return;
                }

                InstanceFilterDialog dialog = new InstanceFilterDialog(
                        JDIDebugUIPlugin.getActiveWorkbenchShell(), breakpoints, modelPresentation,
                        NLS.bind(ActionMessages.InstanceFiltersAction_1, new String[] { var.getName() })) {
                    @Override
                    public void okPressed() {
                        // check if breakpoints have already been restricted to other objects.
                        Object[] checkBreakpoint = getCheckBoxTableViewer().getCheckedElements();
                        for (int k = 0; k < checkBreakpoint.length; k++) {
                            IJavaBreakpoint breakpoint = (IJavaBreakpoint) checkBreakpoint[k];
                            try {
                                IJavaObject[] instanceFilters = breakpoint.getInstanceFilters();
                                boolean sameTarget = false;
                                for (int i = 0; i < instanceFilters.length; i++) {
                                    IJavaObject instanceFilter = instanceFilters[i];
                                    if (instanceFilter.getDebugTarget().equals(object.getDebugTarget())) {
                                        sameTarget = true;
                                        break;
                                    }
                                }
                                if (sameTarget) {
                                    MessageDialog messageDialog = new MessageDialog(
                                            JDIDebugUIPlugin.getActiveWorkbenchShell(),
                                            ActionMessages.InstanceFiltersAction_2, null,
                                            NLS.bind(ActionMessages.InstanceFiltersAction_3,
                                                    new String[] { modelPresentation.getText(breakpoint),
                                                            var.getName() }),
                                            MessageDialog.QUESTION,
                                            new String[] { ActionMessages.InstanceFiltersAction_Yes_2,
                                                    ActionMessages.InstanceFiltersAction_Cancel_3 }, // 
                                            0);
                                    if (messageDialog.open() == Window.OK) {
                                        for (int i = 0; i < instanceFilters.length; i++) {
                                            breakpoint.removeInstanceFilter(instanceFilters[i]);
                                        }
                                    } else {
                                        // if 'cancel', do not close the instance filter dialog
                                        return;
                                    }
                                }
                            } catch (CoreException e) {
                                JDIDebugUIPlugin.log(e);
                            }
                        }
                        super.okPressed();
                    }
                };
                dialog.setTitle(ActionMessages.InstanceFiltersAction_2);

                // determine initial selection
                List<IJavaBreakpoint> existing = new ArrayList<IJavaBreakpoint>();
                Iterator<IJavaBreakpoint> iter = breakpoints.iterator();
                while (iter.hasNext()) {
                    IJavaBreakpoint bp = iter.next();
                    IJavaObject[] filters = bp.getInstanceFilters();
                    for (int i = 0; i < filters.length; i++) {
                        if (filters[i].equals(object)) {
                            existing.add(bp);
                            break;
                        }
                    }
                }
                dialog.setInitialSelections(existing.toArray());

                if (dialog.open() == Window.OK) {
                    Object[] selectedBreakpoints = dialog.getResult();
                    if (selectedBreakpoints != null) {
                        // add
                        for (int i = 0; i < selectedBreakpoints.length; i++) {
                            IJavaBreakpoint bp = (IJavaBreakpoint) selectedBreakpoints[i];
                            bp.addInstanceFilter(object);
                            existing.remove(bp);
                        }
                        // remove
                        iter = existing.iterator();
                        while (iter.hasNext()) {
                            IJavaBreakpoint bp = iter.next();
                            bp.removeInstanceFilter(object);
                        }
                    }
                }
            } else {
                // only allowed for objects
            }
        } catch (CoreException e) {
            JDIDebugUIPlugin.log(e);
        }
    }
}

From source file:org.eclipse.jdt.internal.debug.ui.jres.JREsPreferencePage.java

License:Open Source License

@Override
public boolean okToLeave() {
    if (fJREBlock != null && fJREBlock.hasChangesInDialog()) {
        String title = JREMessages.JREsPreferencePage_4;
        String message = JREMessages.JREsPreferencePage_5;
        String[] buttonLabels = new String[] { JREMessages.JREsPreferencePage_6,
                JREMessages.JREsPreferencePage_7, JREMessages.JREsPreferencePage_8 };
        MessageDialog dialog = new MessageDialog(getShell(), title, null, message, MessageDialog.QUESTION,
                buttonLabels, 0);/*from   w w  w. jav a2 s.co  m*/
        int res = dialog.open();
        if (res == 0) { // apply
            return performOk() && super.okToLeave();
        } else if (res == 1) { // discard
            fJREBlock.fillWithWorkspaceJREs();
            fJREBlock.restoreColumnSettings(JDIDebugUIPlugin.getDefault().getDialogSettings(),
                    IJavaDebugHelpContextIds.JRE_PREFERENCE_PAGE);
            initDefaultVM();
            fJREBlock.initializeTimeStamp();
        } else {
            // apply later
        }
    }
    return super.okToLeave();
}

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

License:Open Source License

@Override
public boolean okToLeave() {
    if (fBuildPathsBlock != null && fBuildPathsBlock.hasChangesInDialog()) {
        String title = PreferencesMessages.BuildPathsPropertyPage_unsavedchanges_title;
        String message = PreferencesMessages.BuildPathsPropertyPage_unsavedchanges_message;
        String[] buttonLabels = new String[] {
                PreferencesMessages.BuildPathsPropertyPage_unsavedchanges_button_save,
                PreferencesMessages.BuildPathsPropertyPage_unsavedchanges_button_discard,
                PreferencesMessages.BuildPathsPropertyPage_unsavedchanges_button_ignore };
        MessageDialog dialog = new MessageDialog(getShell(), title, null, message, MessageDialog.QUESTION,
                buttonLabels, 0);/*  ww  w .  j a va 2 s. c  o  m*/
        int res = dialog.open();
        if (res == 0) { //save
            fBlockOnApply = true;
            return performOk() && super.okToLeave();
        } else if (res == 1) { // discard
            fBuildPathsBlock.init(JavaCore.create(getProject()), null, null);
        } else {
            // keep unsaved
        }
    }
    return super.okToLeave();
}

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

License:Open Source License

protected boolean processChanges(IWorkbenchPreferenceContainer container) {
    IScopeContext currContext = fLookupOrder[0];

    List<Key> changedOptions = new ArrayList<Key>();
    boolean needsBuild = getChanges(currContext, changedOptions);
    if (changedOptions.isEmpty()) {
        return true;
    }/*  w w w.  ja  va 2 s.  c o  m*/
    if (needsBuild) {
        int count = getRebuildCount();
        if (count > fRebuildCount) {
            needsBuild = false; // build already requested
            fRebuildCount = count;
        }
    }

    boolean doBuild = false;
    if (needsBuild) {
        String[] strings = getFullBuildDialogStrings(fProject == null);
        if (strings != null) {
            if (ResourcesPlugin.getWorkspace().getRoot().getProjects().length == 0) {
                doBuild = true; // don't bother the user
            } else {
                MessageDialog dialog = new MessageDialog(getShell(), strings[0], null, strings[1],
                        MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL,
                                IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
                        2);
                int res = dialog.open();
                if (res == 0) {
                    doBuild = true;
                } else if (res != 1) {
                    return false; // cancel pressed
                }
            }
        }
    }
    if (container != null) {
        // no need to apply the changes to the original store: will be done by the page container
        if (doBuild) { // post build
            incrementRebuildCount();
            container.registerUpdateJob(CoreUtility.getBuildJob(fProject));
        }
    } else {
        // apply changes right away
        try {
            fManager.applyChanges();
        } catch (BackingStoreException e) {
            JavaPlugin.log(e);
            return false;
        }
        if (doBuild) {
            CoreUtility.getBuildJob(fProject).schedule();
        }

    }
    return true;
}