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

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

Introduction

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

Prototype

int NO_ID

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

Click Source Link

Document

Button id for a "No" button (value 3).

Usage

From source file:org.eclipse.ui.actions.ReadOnlyStateChecker.java

License:Open Source License

/**
 * Check the children of the container to see if they are read only.
 * @return int/*  w  ww .  ja  v  a2 s  . c  om*/
 * one of
 *    YES_TO_ALL_ID - all elements were selected
 *    NO_ID - No was hit at some point
 *    CANCEL_ID - cancel was hit
 * @param itemsToCheck IResource[]
 * @param allSelected the List of currently selected resources to add to.
 */
private int checkReadOnlyResources(IResource[] itemsToCheck, List allSelected) throws CoreException {

    //Shortcut. If the user has already selected yes to all then just return it
    if (yesToAllSelected) {
        return IDialogConstants.YES_TO_ALL_ID;
    }

    boolean noneSkipped = true;
    List selectedChildren = new ArrayList();

    for (int i = 0; i < itemsToCheck.length; i++) {
        IResource resourceToCheck = itemsToCheck[i];
        ResourceAttributes checkAttributes = resourceToCheck.getResourceAttributes();
        if (!yesToAllSelected && shouldCheck(resourceToCheck) && checkAttributes != null
                && checkAttributes.isReadOnly()) {
            int action = queryYesToAllNoCancel(resourceToCheck);
            if (action == IDialogConstants.YES_ID) {
                boolean childResult = checkAcceptedResource(resourceToCheck, selectedChildren);
                if (!childResult) {
                    noneSkipped = false;
                }
            }
            if (action == IDialogConstants.NO_ID) {
                noneSkipped = false;
            }
            if (action == IDialogConstants.CANCEL_ID) {
                cancelSelected = true;
                return IDialogConstants.CANCEL_ID;
            }
            if (action == IDialogConstants.YES_TO_ALL_ID) {
                yesToAllSelected = true;
                selectedChildren.add(resourceToCheck);
            }
        } else {
            boolean childResult = checkAcceptedResource(resourceToCheck, selectedChildren);
            if (cancelSelected) {
                return IDialogConstants.CANCEL_ID;
            }
            if (!childResult) {
                noneSkipped = false;
            }
        }

    }

    if (noneSkipped) {
        return IDialogConstants.YES_TO_ALL_ID;
    }
    allSelected.addAll(selectedChildren);
    return IDialogConstants.NO_ID;

}

From source file:org.eclipse.ui.actions.ReadOnlyStateChecker.java

License:Open Source License

/**
  * Open a message dialog with Yes No, Yes To All and Cancel buttons. Return the
  * code that indicates the selection.//from  w w  w . j  a  v a2 s . co  m
  * @return int 
  *   one of
  *      YES_TO_ALL_ID
  *      YES_ID
  *      NO_ID
  *      CANCEL_ID
  *       
  * @param resource - the resource being queried.
  */
private int queryYesToAllNoCancel(IResource resource) {

    final MessageDialog dialog = new MessageDialog(this.shell, this.titleMessage, null,
            MessageFormat.format(this.mainMessage, new Object[] { 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.dialogs.YesNoCancelListSelectionDialog.java

License:Open Source License

protected void buttonPressed(int buttonId) {
    switch (buttonId) {
    case IDialogConstants.YES_ID: {
        yesPressed();//from ww  w .jav  a  2s. c  om
        return;
    }
    case IDialogConstants.NO_ID: {
        noPressed();
        return;
    }
    case IDialogConstants.CANCEL_ID: {
        cancelPressed();
        return;
    }
    }
}

From source file:org.eclipse.ui.dialogs.YesNoCancelListSelectionDialog.java

License:Open Source License

protected void createButtonsForButtonBar(Composite parent) {
    createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, true);
    createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, false);
    createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
}

From source file:org.eclipse.ui.dialogs.YesNoCancelListSelectionDialog.java

License:Open Source License

/**
 * Notifies that the no button of this dialog has been pressed.
 * <p>/*from   w w  w .  j  ava2 s . c  om*/
 * The <code>Dialog</code> implementation of this framework method sets
 * this dialog's return code to <code>IDialogConstants.NO_ID</code> and
 * closes the dialog. Subclasses may override if desired.
 * </p>
 */
protected void noPressed() {
    setReturnCode(IDialogConstants.NO_ID);
    close();
}

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  a 2s  . c  om*/
 * @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.undo.WorkspaceUndoUtil.java

License:Open Source License

private static int queryDeleteOutOfSync(IResource resource, IAdaptable uiInfo) {
    Shell shell = getShell(uiInfo);/*  w w  w. j av  a2 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.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/*from  ww  w  .  j av a 2s . 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.tests.harness.util.DialogCheck.java

License:Open Source License

/**
 * Asserts that a given dialog is not null and that it passes
 * certain visual tests.  These tests will be verified manually
 * by the tester using an input dialog.  Use this assert method
 * to verify a dialog's sizing, initial focus, or accessiblity.
 * To ensure that both the input dialog and the test dialog are
 * accessible by the tester, the getShell() method should be used
 * when creating the test dialog.//from  w ww  .  j  a  v a 2 s .  c  om
 * 
 * Example usage:
 * <code>Dialog dialog = new AboutDialog( DialogCheck.getShell() );
 * DialogCheck.assertDialog(dialog, this);</code>
 * 
 * @param dialog the test dialog to be verified.
 * @param assert this is the test case object, assertions will be
 * executed on this object.
 */
public static void assertDialog(Dialog dialog, Assert assertion) {
    Assert.assertNotNull(dialog);
    if (_verifyDialog.getShell() == null) {
        //force the creation of the verify dialog
        getShell();
    }
    if (_verifyDialog.open(dialog) == IDialogConstants.NO_ID) {
        Assert.assertTrue(_verifyDialog.getFailureText(), false);
    }
}

From source file:org.eclipse.ui.tests.internal.util.VerifyDialog.java

License:Open Source License

private void handleFailure() {
    IDialogTestPass test = _dialogTests[TEST_TYPE];
    StringBuffer text = new StringBuffer();
    String label = test.label();//from w w  w.j  a v  a2  s.c  o m
    label = label.substring(0, label.indexOf("&")) + label.substring(label.indexOf("&") + 1);
    text.append(label).append(" failed on the ").append(Util.getWS()).append(" platform:\n");

    String failureMessages[] = test.failureTexts();
    for (int i = 0; i < test.checkListTexts().size(); i++) {
        if (!_checkList[i].getSelection()) {
            text.append("- ").append(failureMessages[i]).append("\n");
        }
    }
    FailureDialog dialog = new FailureDialog(getShell());
    dialog.create();
    dialog.setText(text.toString());
    if (dialog.open() == IDialogConstants.OK_ID) {
        _failureText = dialog.toString();
        setReturnCode(IDialogConstants.NO_ID);
        if (_testDialog.getShell() != null) {
            _testDialog.close();
        }
        close();
    }
}