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.triquetrum.workflow.editor.features.TriqDefaultDeleteFeature.java

License:Open Source License

/**
 * Shows a dialog which asks the user to confirm the deletion of one or more elements.
 * (if the preference is not set to not show the confirmation dialog)
 * //from   w w w.j a v  a2s .c o  m
 * @param context
 *            delete context
 * @return <code>true</code> to delete element(s); <code>false</code> to
 *         cancel delete
 */
@Override
protected boolean getUserDecision(IDeleteContext context) {
    IPreferenceStore store = TriqEditorPlugin.getDefault().getPreferenceStore();
    if (!store.getBoolean(DELETE_CONFIRMATION_PREFNAME)) {
        return true;
    } else {
        String msg;
        IMultiDeleteInfo multiDeleteInfo = context.getMultiDeleteInfo();
        if (multiDeleteInfo != null) {
            msg = MessageFormat.format(Messages.DeleteFeature_2_xmsg, multiDeleteInfo.getNumber());
        } else {
            String deleteName = getDeleteName(context);
            if (deleteName != null && deleteName.length() > 0) {
                msg = MessageFormat.format(Messages.DeleteFeature_3_xmsg, deleteName);
            } else {
                msg = Messages.DeleteFeature_4_xmsg;
            }
        }
        MessageDialogWithToggle toggleDialog = MessageDialogWithToggle.openYesNoQuestion(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.DeleteFeature_5_xfld,
                msg, Messages.DeleteFeature_6_xtgl, false, null, null);

        boolean deleteIsConfirmed = toggleDialog.getReturnCode() == IDialogConstants.YES_ID;
        if (deleteIsConfirmed) {
            store.setValue(DELETE_CONFIRMATION_PREFNAME, !toggleDialog.getToggleState());
        }
        return deleteIsConfirmed;
    }
}

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

License:Open Source License

/**
 * Check if the user wishes to overwrite the supplied resource or all
 * resources./*from ww  w . j  a v a  2  s.  c om*/
 * 
 * @param source
 *            the source resource
 * @param destination
 *            the resource to be overwritten
 * @return one of IDialogConstants.YES_ID, IDialogConstants.YES_TO_ALL_ID,
 *         IDialogConstants.NO_ID, IDialogConstants.CANCEL_ID indicating
 *         whether the current resource or all resources can be overwritten,
 *         or if the operation should be canceled.
 */
private int checkOverwrite(final IResource source, final IResource destination) {
    final int[] result = new int[1];

    // Dialogs need to be created and opened in the UI thread
    Runnable query = new Runnable() {
        public void run() {
            String message;
            int resultId[] = { IDialogConstants.YES_ID, IDialogConstants.YES_TO_ALL_ID, IDialogConstants.NO_ID,
                    IDialogConstants.CANCEL_ID };
            String labels[] = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };

            if (destination.getType() == IResource.FOLDER) {
                if (homogenousResources(source, destination)) {
                    message = NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteMergeQuestion,
                            destination.getFullPath().makeRelative());
                } else {
                    if (destination.isLinked()) {
                        message = NLS.bind(
                                IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteNoMergeLinkQuestion,
                                destination.getFullPath().makeRelative());
                    } else {
                        message = NLS.bind(
                                IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteNoMergeNoLinkQuestion,
                                destination.getFullPath().makeRelative());
                    }
                    resultId = new int[] { IDialogConstants.YES_ID, IDialogConstants.NO_ID,
                            IDialogConstants.CANCEL_ID };
                    labels = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                            IDialogConstants.CANCEL_LABEL };
                }
            } else {
                String[] bindings = new String[] { IDEResourceInfoUtils.getLocationText(destination),
                        IDEResourceInfoUtils.getDateStringValue(destination),
                        IDEResourceInfoUtils.getLocationText(source),
                        IDEResourceInfoUtils.getDateStringValue(source) };
                message = NLS.bind(
                        IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteWithDetailsQuestion,
                        bindings);
            }
            MessageDialog dialog = new MessageDialog(messageShell,
                    IDEWorkbenchMessages.CopyFilesAndFoldersOperation_resourceExists, null, message,
                    MessageDialog.QUESTION, labels, 0) {
                protected int getShellStyle() {
                    return super.getShellStyle() | SWT.SHEET;
                }
            };
            dialog.open();
            if (dialog.getReturnCode() == SWT.DEFAULT) {
                // A window close returns SWT.DEFAULT, which has to be
                // mapped to a cancel
                result[0] = IDialogConstants.CANCEL_ID;
            } else {
                result[0] = resultId[dialog.getReturnCode()];
            }
        }
    };
    messageShell.getDisplay().syncExec(query);
    return result[0];
}

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

License:Open Source License

/**
 * Returns whether moving all of the given source resources to the given
 * destination container could be done without causing name collisions.
 * /*www  .j a v a  2 s .  co  m*/
 * @param destination
 *            the destination container
 * @param sourceResources
 *            the list of resources
 * @return <code>true</code> if there would be no name collisions, and
 *         <code>false</code> if there would
 */
private IResource[] validateNoNameCollisions(IContainer destination, IResource[] sourceResources) {
    List copyItems = new ArrayList();
    IWorkspaceRoot workspaceRoot = destination.getWorkspace().getRoot();
    int overwrite = IDialogConstants.NO_ID;

    // Check to see if we would be overwriting a parent folder.
    // Cancel entire copy operation if we do.
    for (int i = 0; i < sourceResources.length; i++) {
        final IResource sourceResource = sourceResources[i];
        final IPath destinationPath = destination.getFullPath().append(sourceResource.getName());
        final IPath sourcePath = sourceResource.getFullPath();

        IResource newResource = workspaceRoot.findMember(destinationPath);
        if (newResource != null && destinationPath.isPrefixOf(sourcePath)) {
            displayError(NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteProblem,
                    destinationPath, sourcePath));

            canceled = true;
            return null;
        }
    }
    // Check for overwrite conflicts
    for (int i = 0; i < sourceResources.length; i++) {
        final IResource source = sourceResources[i];
        final IPath destinationPath = destination.getFullPath().append(source.getName());

        IResource newResource = workspaceRoot.findMember(destinationPath);
        if (newResource != null) {
            if (overwrite != IDialogConstants.YES_TO_ALL_ID || (newResource.getType() == IResource.FOLDER
                    && homogenousResources(source, destination) == false)) {
                overwrite = checkOverwrite(source, newResource);
            }
            if (overwrite == IDialogConstants.YES_ID || overwrite == IDialogConstants.YES_TO_ALL_ID) {
                copyItems.add(source);
            } else if (overwrite == IDialogConstants.CANCEL_ID) {
                canceled = true;
                return null;
            }
        } else {
            copyItems.add(source);
        }
    }
    return (IResource[]) copyItems.toArray(new IResource[copyItems.size()]);
}

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

License:Open Source License

/**
 * Returns the preference for whether to open required projects when opening
 * a project. Consults the preference and prompts the user if necessary.
 * /*w ww  .  j a v a2 s  .  c  om*/
 * @return <code>true</code> if referenced projects should be opened, and
 *         <code>false</code> otherwise.
 */
private boolean promptToOpenWithReferences() {
    IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore();
    String key = IDEInternalPreferences.OPEN_REQUIRED_PROJECTS;
    String value = store.getString(key);
    if (MessageDialogWithToggle.ALWAYS.equals(value)) {
        return true;
    }
    if (MessageDialogWithToggle.NEVER.equals(value)) {
        return false;
    }
    String message = IDEWorkbenchMessages.OpenResourceAction_openRequiredProjects;
    MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(getShell(),
            IDEWorkbenchMessages.Question, message, null, false, store, key);
    int result = dialog.getReturnCode();
    // the result is equal to SWT.DEFAULT if the user uses the 'esc' key to close the dialog
    if (result == Window.CANCEL || result == SWT.DEFAULT) {
        throw new OperationCanceledException();
    }
    return dialog.getReturnCode() == IDialogConstants.YES_ID;
}

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  w  w  .  j av  a  2s .c  o m
 * 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.//  w ww  . ja  v a 2  s  .  c o 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 .j  av a2  s . com
        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 yes button of this dialog has been pressed. Do the same
 * as an OK but set the return code to YES_ID instead.
 *///www  . j  a v a  2 s  .c o m
protected void yesPressed() {
    okPressed();
    setReturnCode(IDialogConstants.YES_ID);
}

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

License:Open Source License

/**
 * Add the project's build to the table viewer.
 *//*from   w w  w.ja  v  a 2 s.c  o  m*/
private void addBuildersToTable() {
    IProject project = getInputProject();
    if (project == null) {
        return;
    }
    //add build spec entries to the table
    ICommand[] commands = null;
    try {
        commands = project.getDescription().getBuildSpec();
    } catch (CoreException e) {
        handleException(e);
        return;
    }

    boolean projectNeedsMigration = false;
    for (int i = 0; i < commands.length; i++) {
        String[] version = new String[] { IExternalToolConstants.EMPTY_STRING };
        ILaunchConfiguration config = BuilderUtils.configFromBuildCommandArgs(project,
                commands[i].getArguments(), version);
        if (BuilderCoreUtils.VERSION_2_1.equals(version[0])) {
            // Storing the .project file of a project with 2.1 configs, will
            // edit the file in a way that isn't backwards compatible.
            projectNeedsMigration = true;
        }
        Object element = null;
        if (config != null) {
            if (!config.isWorkingCopy() && !config.exists()) {
                Shell shell = getShell();
                if (shell == null) {
                    return;
                }
                IStatus status = new Status(IStatus.ERROR, ExternalToolsPlugin.PLUGIN_ID, 0,
                        NLS.bind(ExternalToolsUIMessages.BuilderPropertyPage_Exists,
                                new String[] { config.getName() }),
                        null);
                ErrorDialog.openError(getShell(), ExternalToolsUIMessages.BuilderPropertyPage_errorTitle, NLS
                        .bind(ExternalToolsUIMessages.BuilderPropertyPage_External_Tool_Builder__0__Not_Added_2,
                                new String[] { config.getName() }),
                        status);
                userHasMadeChanges = true;
            } else {
                element = config;
            }
        } else {
            String builderID = commands[i].getBuilderName();
            if (builderID.equals(ExternalToolBuilder.ID)
                    && commands[i].getArguments().get(BuilderCoreUtils.LAUNCH_CONFIG_HANDLE) != null) {
                // An invalid external tool entry.
                element = new ErrorConfig(commands[i]);
            } else {
                element = commands[i];
            }
        }
        if (element != null) {
            viewer.add(element);
            viewer.setChecked(element, isEnabled(element));
        }
    }
    if (projectNeedsMigration) {
        IPreferenceStore store = ExternalToolsPlugin.getDefault().getPreferenceStore();
        boolean prompt = store.getBoolean(IPreferenceConstants.PROMPT_FOR_PROJECT_MIGRATION);
        boolean proceed = true;
        if (prompt) {
            Shell shell = getShell();
            if (shell == null) {
                return;
            }
            MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(shell,
                    ExternalToolsUIMessages.BuilderPropertyPage_0,
                    ExternalToolsUIMessages.BuilderPropertyPage_1,
                    ExternalToolsUIMessages.BuilderPropertyPage_2, false, null, null);
            proceed = dialog.getReturnCode() == IDialogConstants.YES_ID;
            store.setValue(IPreferenceConstants.PROMPT_FOR_PROJECT_MIGRATION, !dialog.getToggleState());
        }
        if (!proceed) {
            // Open the page read-only
            viewer.getTable().setEnabled(false);
            downButton.setEnabled(false);
            editButton.setEnabled(false);
            importButton.setEnabled(false);
            newButton.setEnabled(false);
            removeButton.setEnabled(false);
        }
    }
}