Example usage for org.eclipse.jface.dialogs IDialogConstants YES_ID

List of usage examples for org.eclipse.jface.dialogs IDialogConstants YES_ID

Introduction

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

Prototype

int YES_ID

To view the source code for org.eclipse.jface.dialogs IDialogConstants YES_ID.

Click Source Link

Document

Button id for a "Yes" button (value 2).

Usage

From source file:org.eclipse.ui.externaltools.internal.ui.BuilderPropertyPage.java

License:Open Source License

/**
 * Prompts the user to proceed with the migration of a project builder from
 * the old format to the new, launch configuration-based, format and returns
 * whether or not the user wishes to proceed with the migration.
 * /*from   w ww  . jav  a2 s  . c  o  m*/
 * @return boolean whether or not the user wishes to proceed with migration
 */
private boolean shouldProceedWithMigration() {
    if (!ExternalToolsPlugin.getDefault().getPreferenceStore()
            .getBoolean(IPreferenceConstants.PROMPT_FOR_TOOL_MIGRATION)) {
        // User has asked not to be prompted
        return true;
    }
    Shell shell = getShell();
    if (shell == null) {
        return false;
    }
    // Warn the user that editing an old config will cause storage migration.
    MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(getShell(),
            ExternalToolsUIMessages.BuilderPropertyPage_Migrate_project_builder_10,
            ExternalToolsUIMessages.BuilderPropertyPage_Not_Support,
            ExternalToolsUIMessages.BuilderPropertyPage_Prompt, false,
            ExternalToolsPlugin.getDefault().getPreferenceStore(),
            IPreferenceConstants.PROMPT_FOR_TOOL_MIGRATION);
    return dialog.getReturnCode() == IDialogConstants.YES_ID;
}

From source file:org.eclipse.ui.ide.IDE.java

License:Open Source License

/**
 * Prompt the user to inform them of the possible side effects of an
 * operation on resources. Do not prompt for side effects from ignored model
 * providers. A model provider can be ignored if it is the client calling
 * this API. Any message from the provided model provider id or any model
 * providers it extends will be ignored.
 * //  w  w  w  .  j  av a2 s  .com
 * @param shell
 *            the shell to parent the prompt dialog
 * @param title
 *            the title of the dialog
 * @param message
 *            the message for the dialog
 * @param delta
 *            a delta built using an
 *            {@link IResourceChangeDescriptionFactory}
 * @param ignoreModelProviderIds
 *            model providers to be ignored
 * @param syncExec
 *            prompt in a sync exec (required when called from a non-UI
 *            thread)
 * @return whether the user chose to continue
 * @since 3.2
 */
public static boolean promptToConfirm(final Shell shell, final String title, String message,
        IResourceDelta delta, String[] ignoreModelProviderIds, boolean syncExec) {
    IStatus status = ResourceChangeValidator.getValidator().validateChange(delta, null);
    if (status.isOK()) {
        return true;
    }
    final IStatus displayStatus;
    if (status.isMultiStatus()) {
        List result = new ArrayList();
        IStatus[] children = status.getChildren();
        for (int i = 0; i < children.length; i++) {
            IStatus child = children[i];
            if (!isIgnoredStatus(child, ignoreModelProviderIds)) {
                result.add(child);
            }
        }
        if (result.isEmpty()) {
            return true;
        }
        if (result.size() == 1) {
            displayStatus = (IStatus) result.get(0);
        } else {
            displayStatus = new MultiStatus(status.getPlugin(), status.getCode(),
                    (IStatus[]) result.toArray(new IStatus[result.size()]), status.getMessage(),
                    status.getException());
        }
    } else {
        if (isIgnoredStatus(status, ignoreModelProviderIds)) {
            return true;
        }
        displayStatus = status;
    }

    if (message == null) {
        message = IDEWorkbenchMessages.IDE_sideEffectWarning;
    }
    final String dialogMessage = NLS.bind(IDEWorkbenchMessages.IDE_areYouSure, message);

    final boolean[] result = new boolean[] { false };
    Runnable runnable = new Runnable() {
        public void run() {
            ErrorDialog dialog = new ErrorDialog(shell, title, dialogMessage, displayStatus,
                    IStatus.ERROR | IStatus.WARNING | IStatus.INFO) {
                protected void createButtonsForButtonBar(Composite parent) {
                    createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, false);
                    createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, true);
                    createDetailsButton(parent);
                }

                /*
                 * (non-Javadoc)
                 * 
                 * @see org.eclipse.jface.dialogs.ErrorDialog#buttonPressed(int)
                 */
                protected void buttonPressed(int id) {
                    if (id == IDialogConstants.YES_ID) {
                        super.buttonPressed(IDialogConstants.OK_ID);
                    } else if (id == IDialogConstants.NO_ID) {
                        super.buttonPressed(IDialogConstants.CANCEL_ID);
                    }
                    super.buttonPressed(id);
                }

                protected int getShellStyle() {
                    return super.getShellStyle() | SWT.SHEET;
                }
            };
            int code = dialog.open();
            result[0] = code == 0;
        }
    };
    if (syncExec) {
        shell.getDisplay().syncExec(runnable);
    } else {
        runnable.run();
    }
    return result[0];
}

From source file:org.eclipse.ui.ide.markers.compatibility.internal.FiltersConfigurationDialog.java

License:Open Source License

/**
 * Return whether or not deselected elements should have been selected.
 * //from   w w w . j  a v a  2  s  . c om
 * @return boolean
 */
private boolean shouldContinue() {
    Iterator browsed = browsedFilters.iterator();

    while (browsed.hasNext()) {
        if (!filtersList.getChecked(browsed.next()) && IDEWorkbenchPlugin.getDefault().getPreferenceStore()
                .getBoolean(IDEInternalPreferences.PROMPT_FOR_UNSELECTED_FILTERS)) {
            MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(getShell(),
                    MarkerMessages.filtersDialogDeselectedFiltersTitle,
                    MarkerMessages.filtersDialogDeselectedFiltersMessage, MarkerMessages.filtersDialogDoNotAsk,
                    false, IDEWorkbenchPlugin.getDefault().getPreferenceStore(),
                    IDEInternalPreferences.PROMPT_FOR_UNSELECTED_FILTERS);
            return dialog.getReturnCode() == IDialogConstants.YES_ID;
        }
    }
    return true;
}

From source file:org.eclipse.ui.ide.undo.WorkspaceUndoUtil.java

License:Open Source License

/**
 * Delete all of the specified resources, returning resource descriptions
 * that can be used to restore them.//w w w.j a v  a  2  s .c  o m
 * 
 * @param resourcesToDelete
 *            an array of resources to be deleted
 * @param monitor
 *            the progress monitor to use to show the operation's progress
 * @param uiInfo
 *            the IAdaptable (or <code>null</code>) provided by the
 *            caller in order to supply UI information for prompting the
 *            user if necessary. When this parameter is not
 *            <code>null</code>, it contains an adapter for the
 *            org.eclipse.swt.widgets.Shell.class
 * 
 * @param deleteContent
 *            a boolean indicating whether project content should be deleted
 *            when a project resource is to be deleted
 * @return an array of ResourceDescriptions that can be used to restore the
 *         deleted resources.
 * @throws CoreException
 *             propagates any CoreExceptions thrown from the resources API
 */
static ResourceDescription[] delete(IResource[] resourcesToDelete, IProgressMonitor monitor, IAdaptable uiInfo,
        boolean deleteContent) throws CoreException {
    final List exceptions = new ArrayList();
    boolean forceOutOfSyncDelete = false;
    ResourceDescription[] returnedResourceDescriptions = new ResourceDescription[resourcesToDelete.length];
    monitor.beginTask("", resourcesToDelete.length); //$NON-NLS-1$
    monitor.setTaskName(UndoMessages.AbstractResourcesOperation_DeleteResourcesProgress);
    try {
        for (int i = 0; i < resourcesToDelete.length; ++i) {
            if (monitor.isCanceled()) {
                throw new OperationCanceledException();
            }
            IResource resource = resourcesToDelete[i];
            try {
                returnedResourceDescriptions[i] = delete(resource, new SubProgressMonitor(monitor, 1), uiInfo,
                        forceOutOfSyncDelete, deleteContent);
            } catch (CoreException e) {
                if (resource.getType() == IResource.FILE) {
                    IStatus[] children = e.getStatus().getChildren();
                    if (children.length == 1 && children[0].getCode() == IResourceStatus.OUT_OF_SYNC_LOCAL) {
                        int result = queryDeleteOutOfSync(resource, uiInfo);

                        if (result == IDialogConstants.YES_ID) {
                            // retry the delete with a force out of sync
                            delete(resource, new SubProgressMonitor(monitor, 1), uiInfo, true, deleteContent);
                        } else if (result == IDialogConstants.YES_TO_ALL_ID) {
                            // all future attempts should force out of
                            // sync
                            forceOutOfSyncDelete = true;
                            delete(resource, new SubProgressMonitor(monitor, 1), uiInfo, forceOutOfSyncDelete,
                                    deleteContent);
                        } else if (result == IDialogConstants.CANCEL_ID) {
                            throw new OperationCanceledException();
                        } else {
                            exceptions.add(e);
                        }
                    } else {
                        exceptions.add(e);
                    }
                } else {
                    exceptions.add(e);
                }
            }
        }
        IStatus result = createResult(exceptions);
        if (!result.isOK()) {
            throw new CoreException(result);
        }
    } finally {
        monitor.done();
    }
    return returnedResourceDescriptions;
}

From source file:org.eclipse.ui.ide.undo.WorkspaceUndoUtil.java

License:Open Source License

private static int queryDeleteOutOfSync(IResource resource, IAdaptable uiInfo) {
    Shell shell = getShell(uiInfo);/*from w  ww .  ja  va 2  s  . c  o  m*/
    final MessageDialog dialog = new MessageDialog(shell,
            UndoMessages.AbstractResourcesOperation_deletionMessageTitle, null,
            NLS.bind(UndoMessages.AbstractResourcesOperation_outOfSyncQuestion, resource.getName()),
            MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
            0) {
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    shell.getDisplay().syncExec(new Runnable() {
        public void run() {
            dialog.open();
        }
    });
    int result = dialog.getReturnCode();
    if (result == 0) {
        return IDialogConstants.YES_ID;
    }
    if (result == 1) {
        return IDialogConstants.YES_TO_ALL_ID;
    }
    if (result == 2) {
        return IDialogConstants.NO_ID;
    }
    return IDialogConstants.CANCEL_ID;
}

From source file:org.eclipse.ui.internal.handlers.ResetPerspectiveHandler.java

License:Open Source License

public Object execute(ExecutionEvent event) {

    IWorkbenchWindow activeWorkbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    if (activeWorkbenchWindow != null) {
        WorkbenchPage page = (WorkbenchPage) activeWorkbenchWindow.getActivePage();
        if (page != null) {
            IPerspectiveDescriptor descriptor = page.getPerspective();
            if (descriptor != null) {
                boolean offerRevertToBase = false;
                if (descriptor instanceof PerspectiveDescriptor) {
                    PerspectiveDescriptor desc = (PerspectiveDescriptor) descriptor;
                    offerRevertToBase = desc.isPredefined() && desc.hasCustomDefinition();
                }/*from   w w  w  .  j  a  v  a  2  s  . c om*/

                if (offerRevertToBase) {
                    String message = NLS.bind(WorkbenchMessages.RevertPerspective_message,
                            descriptor.getLabel());
                    boolean toggleState = false;
                    MessageDialogWithToggle dialog = MessageDialogWithToggle.open(MessageDialog.QUESTION,
                            activeWorkbenchWindow.getShell(), WorkbenchMessages.RevertPerspective_title,
                            message, WorkbenchMessages.RevertPerspective_option, toggleState, null, null,
                            SWT.SHEET);
                    if (dialog.getReturnCode() == IDialogConstants.YES_ID) {
                        if (dialog.getToggleState()) {
                            PerspectiveRegistry reg = (PerspectiveRegistry) PlatformUI.getWorkbench()
                                    .getPerspectiveRegistry();
                            reg.revertPerspective(descriptor);
                        }
                        page.resetPerspective();
                    }
                } else {
                    String message = NLS.bind(WorkbenchMessages.ResetPerspective_message,
                            descriptor.getLabel());
                    boolean result = MessageDialog.open(MessageDialog.QUESTION,
                            activeWorkbenchWindow.getShell(), WorkbenchMessages.ResetPerspective_title, message,
                            SWT.SHEET);
                    if (result) {
                        page.resetPerspective();
                    }
                }
            }
        }
    }

    return null;
}

From source file:org.eclipse.ui.internal.SaveablesList.java

License:Open Source License

/**
 * Prompt the user to save the given saveables.
 * @param modelsToSave the saveables to be saved
 * @param shellProvider the provider used to obtain a shell in prompting is
 *            required. Clients can use a workbench window for this.
 * @param runnableContext a runnable context that will be used to provide a
 *            progress monitor while the save is taking place. Clients can
 *            use a workbench window for this.
 * @param canCancel whether the operation can be canceled
 * @param stillOpenElsewhere whether the models are referenced by open parts
 * @return true if the user canceled// ww  w  . j  av  a  2  s  .c o m
 */
public boolean promptForSaving(List modelsToSave, final IShellProvider shellProvider,
        IRunnableContext runnableContext, final boolean canCancel, boolean stillOpenElsewhere) {
    // Save parts, exit the method if cancel is pressed.
    if (modelsToSave.size() > 0) {
        boolean canceled = SaveableHelper.waitForBackgroundSaveJobs(modelsToSave);
        if (canceled) {
            return true;
        }

        IPreferenceStore apiPreferenceStore = PrefUtil.getAPIPreferenceStore();
        boolean dontPrompt = stillOpenElsewhere && !apiPreferenceStore
                .getBoolean(IWorkbenchPreferenceConstants.PROMPT_WHEN_SAVEABLE_STILL_OPEN);

        if (dontPrompt) {
            modelsToSave.clear();
            return false;
        } else if (modelsToSave.size() == 1) {
            Saveable model = (Saveable) modelsToSave.get(0);
            // Show a dialog.
            String[] buttons;
            if (canCancel) {
                buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                        IDialogConstants.CANCEL_LABEL };
            } else {
                buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL };
            }

            // don't save if we don't prompt
            int choice = ISaveablePart2.NO;

            MessageDialog dialog;
            if (stillOpenElsewhere) {
                String message = NLS.bind(WorkbenchMessages.EditorManager_saveChangesOptionallyQuestion,
                        model.getName());
                MessageDialogWithToggle dialogWithToggle = new MessageDialogWithToggle(shellProvider.getShell(),
                        WorkbenchMessages.Save_Resource, null, message, MessageDialog.QUESTION, buttons, 0,
                        WorkbenchMessages.EditorManager_closeWithoutPromptingOption, false) {
                    protected int getShellStyle() {
                        return (canCancel ? SWT.CLOSE : SWT.NONE) | SWT.TITLE | SWT.BORDER
                                | SWT.APPLICATION_MODAL | SWT.SHEET | getDefaultOrientation();
                    }
                };
                dialog = dialogWithToggle;
            } else {
                String message = NLS.bind(WorkbenchMessages.EditorManager_saveChangesQuestion, model.getName());
                dialog = new MessageDialog(shellProvider.getShell(), WorkbenchMessages.Save_Resource, null,
                        message, MessageDialog.QUESTION, buttons, 0) {
                    protected int getShellStyle() {
                        return (canCancel ? SWT.CLOSE : SWT.NONE) | SWT.TITLE | SWT.BORDER
                                | SWT.APPLICATION_MODAL | SWT.SHEET | getDefaultOrientation();
                    }
                };
            }

            choice = SaveableHelper.testGetAutomatedResponse();
            if (SaveableHelper.testGetAutomatedResponse() == SaveableHelper.USER_RESPONSE) {
                choice = dialog.open();

                if (stillOpenElsewhere) {
                    // map value of choice back to ISaveablePart2 values
                    switch (choice) {
                    case IDialogConstants.YES_ID:
                        choice = ISaveablePart2.YES;
                        break;
                    case IDialogConstants.NO_ID:
                        choice = ISaveablePart2.NO;
                        break;
                    case IDialogConstants.CANCEL_ID:
                        choice = ISaveablePart2.CANCEL;
                        break;
                    default:
                        break;
                    }
                    MessageDialogWithToggle dialogWithToggle = (MessageDialogWithToggle) dialog;
                    if (choice != ISaveablePart2.CANCEL && dialogWithToggle.getToggleState()) {
                        apiPreferenceStore
                                .setValue(IWorkbenchPreferenceConstants.PROMPT_WHEN_SAVEABLE_STILL_OPEN, false);
                    }
                }
            }

            // Branch on the user choice.
            // The choice id is based on the order of button labels
            // above.
            switch (choice) {
            case ISaveablePart2.YES: // yes
                break;
            case ISaveablePart2.NO: // no
                modelsToSave.clear();
                break;
            default:
            case ISaveablePart2.CANCEL: // cancel
                return true;
            }
        } else {
            MyListSelectionDialog dlg = new MyListSelectionDialog(shellProvider.getShell(), modelsToSave,
                    new ArrayContentProvider(), new WorkbenchPartLabelProvider(),
                    stillOpenElsewhere ? WorkbenchMessages.EditorManager_saveResourcesOptionallyMessage
                            : WorkbenchMessages.EditorManager_saveResourcesMessage,
                    canCancel, stillOpenElsewhere);
            dlg.setInitialSelections(modelsToSave.toArray());
            dlg.setTitle(WorkbenchMessages.EditorManager_saveResourcesTitle);

            // this "if" statement aids in testing.
            if (SaveableHelper.testGetAutomatedResponse() == SaveableHelper.USER_RESPONSE) {
                int result = dlg.open();
                // Just return null to prevent the operation continuing
                if (result == IDialogConstants.CANCEL_ID)
                    return true;

                if (dlg.getDontPromptSelection()) {
                    apiPreferenceStore.setValue(IWorkbenchPreferenceConstants.PROMPT_WHEN_SAVEABLE_STILL_OPEN,
                            false);
                }

                modelsToSave = Arrays.asList(dlg.getResult());
            }
        }
    }
    // Create save block.
    return saveModels(modelsToSave, shellProvider, runnableContext);
}

From source file:org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.java

License:Open Source License

/**
 * Validates the editor input for derived state.
 * If the given input is derived then this method
 * can show a dialog asking whether to edit the
 * derived file.//from  w ww . j a v  a 2 s .c o  m
 *
 * @return <code>true</code> if the input is OK for editing, <code>false</code> otherwise
 * @since 3.3
 */
private boolean validateEditorInputDerived() {
    if (fIsDerivedStateValidated)
        return fIsEditingDerivedFileAllowed;

    if (getDocumentProvider() instanceof IDocumentProviderExtension) {
        IDocumentProviderExtension extension = (IDocumentProviderExtension) getDocumentProvider();
        IStatus status = extension.getStatus(getEditorInput());
        String pluginId = status.getPlugin();
        boolean isDerivedStatus = status.getCode() == IFileBufferStatusCodes.DERIVED_FILE
                && (FileBuffers.PLUGIN_ID.equals(pluginId) || EditorsUI.PLUGIN_ID.equals(pluginId));
        if (!isDerivedStatus)
            return true;
    }

    final String warnKey = AbstractDecoratedTextEditorPreferenceConstants.EDITOR_WARN_IF_INPUT_DERIVED;
    IPreferenceStore store = getPreferenceStore();
    if (!store.getBoolean(warnKey))
        return true;

    MessageDialogWithToggle toggleDialog = MessageDialogWithToggle.openYesNoQuestion(getSite().getShell(),
            TextEditorMessages.AbstractDecoratedTextEditor_warning_derived_title,
            TextEditorMessages.AbstractDecoratedTextEditor_warning_derived_message,
            TextEditorMessages.AbstractDecoratedTextEditor_warning_derived_dontShowAgain, false, null, null);

    EditorsUI.getPreferenceStore().setValue(warnKey, !toggleDialog.getToggleState());
    fIsDerivedStateValidated = true;
    return fIsEditingDerivedFileAllowed = toggleDialog.getReturnCode() == IDialogConstants.YES_ID;
}

From source file:org.eclipse.wb.internal.os.linux.Activator.java

License:Open Source License

private void scheduleCompizCheck() {
    if (!gconfAvailable) {
        // no necessary gconf libs installed, skip checks.
        return;//from   w w  w .jav  a  2 s.  c o m
    }
    getStandardDisplay().asyncExec(new Runnable() {
        public void run() {
            try {
                if (isRunningCompiz() && !isCompizSet() && askAgain()) {
                    MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(null,
                            BrandingUtils.getBranding().getProductName(), Messages.Activator_compizMessage,
                            Messages.Activator_compizDontAsk, false, getPreferenceStore(),
                            PK_ASK_FOR_WORKAROUND);
                    int returnCode = dialog.getReturnCode();
                    if (returnCode == IDialogConstants.YES_ID) {
                        setupCompiz();
                    }
                }
            } catch (Throwable e) {
                DesignerPlugin.log(e);
            }
        }
    });
}

From source file:org.eclipse.wst.jsdt.internal.ui.actions.ActionUtil.java

License:Open Source License

public static boolean isEditable(Shell shell, IJavaScriptElement element) {
    if (!isProcessable(shell, element))
        return false;

    IJavaScriptElement cu = element.getAncestor(IJavaScriptElement.JAVASCRIPT_UNIT);
    if (cu != null) {
        IResource resource = cu.getResource();
        if (resource != null && resource.isDerived()) {

            // see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#validateEditorInputState()
            final String warnKey = AbstractDecoratedTextEditorPreferenceConstants.EDITOR_WARN_IF_INPUT_DERIVED;
            IPreferenceStore store = EditorsUI.getPreferenceStore();
            if (!store.getBoolean(warnKey))
                return true;

            MessageDialogWithToggle toggleDialog = MessageDialogWithToggle.openYesNoQuestion(shell,
                    ActionMessages.ActionUtil_warning_derived_title,
                    Messages.format(ActionMessages.ActionUtil_warning_derived_message,
                            resource.getFullPath().toString()),
                    ActionMessages.ActionUtil_warning_derived_dontShowAgain, false, null, null);

            EditorsUI.getPreferenceStore().setValue(warnKey, !toggleDialog.getToggleState());

            return toggleDialog.getReturnCode() == IDialogConstants.YES_ID;
        }// w ww .  ja  va2s . c  o m
    }
    return true;
}