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

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

Introduction

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

Prototype

int YES_TO_ALL_ID

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

Click Source Link

Document

Button id for a "Yes to All" button (value 4).

Usage

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  w ww. j a  v  a 2s  .  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.
 * /*from   w  w  w  .j  a v a2  s  .  c  om*/
 * @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.ReadOnlyStateChecker.java

License:Open Source License

/**
 * Check an individual resource to see if it passed the read only query. If it is a file
 * just add it, otherwise it is a container and the children need to be checked too.
 * Return true if all items are selected and false if any are skipped.
 */// w ww .j  av a 2  s .  c o  m
private boolean checkAcceptedResource(IResource resourceToCheck, List selectedChildren) throws CoreException {

    if (resourceToCheck.getType() == IResource.FILE) {
        selectedChildren.add(resourceToCheck);
    } else if (getIgnoreLinkedResources() && resourceToCheck.isLinked()) {
        selectedChildren.add(resourceToCheck);
    } else {
        IContainer container = (IContainer) resourceToCheck;
        // if the project is closed, there's no point in checking
        // it's children.  bug 99858
        if (container.isAccessible()) {
            // Now check below
            int childCheck = checkReadOnlyResources(container.members(), selectedChildren);
            // Add in the resource only if nothing was left out
            if (childCheck == IDialogConstants.YES_TO_ALL_ID) {
                selectedChildren.add(resourceToCheck);
            } else {
                // Something was left out - return false
                return false;
            }
        } else {
            selectedChildren.add(resourceToCheck);
        }
    }
    return true;

}

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

License:Open Source License

/**
 * Check the supplied resources to see if they are read only. If so then
* prompt the user to see if they can be deleted.Return those that were
* accepted./*from  w  w w.  j av  a  2 s  . c o  m*/
* 
 * @param itemsToCheck
 * @return the resulting selected resources
 */
public IResource[] checkReadOnlyResources(IResource[] itemsToCheck) {

    List selections = new ArrayList();
    int result = IDialogConstants.CANCEL_ID;
    try {
        result = checkReadOnlyResources(itemsToCheck, selections);
    } catch (final CoreException exception) {
        shell.getDisplay().syncExec(new Runnable() {
            public void run() {
                ErrorDialog.openError(shell, READ_ONLY_EXCEPTION_MESSAGE, null, exception.getStatus());
            }
        });
    }

    if (result == IDialogConstants.CANCEL_ID) {
        return new IResource[0];
    }

    //All were selected so return the original items
    if (result == IDialogConstants.YES_TO_ALL_ID) {
        return itemsToCheck;
    }

    IResource[] returnValue = new IResource[selections.size()];
    selections.toArray(returnValue);
    return returnValue;
}

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/* ww  w  .j a  va 2  s  .  co  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.//from w w  w  .  j av  a  2s  .  com
  * @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.ide.undo.WorkspaceUndoUtil.java

License:Open Source License

/**
 * Delete all of the specified resources, returning resource descriptions
 * that can be used to restore them.//from  www.j  av  a2s . c om
 * 
 * @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);/*  ww  w. j a  v  a2  s.com*/
    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.jkiss.dbeaver.ui.actions.navigator.NavigatorHandlerObjectDelete.java

License:Open Source License

private ConfirmResult confirmObjectDelete(final IWorkbenchWindow workbenchWindow, final DBNNode node,
        final boolean viewScript) {
    if (deleteAll != null) {
        return deleteAll ? ConfirmResult.YES : ConfirmResult.NO;
    }/*ww w .ja  v  a  2 s  . c o  m*/
    ResourceBundle bundle = DBeaverActivator.getCoreResourceBundle();
    String objectType = node instanceof DBNLocalFolder ? DBeaverPreferences.CONFIRM_LOCAL_FOLDER_DELETE
            : DBeaverPreferences.CONFIRM_ENTITY_DELETE;
    String titleKey = ConfirmationDialog.RES_CONFIRM_PREFIX + objectType + "_" //$NON-NLS-1$
            + ConfirmationDialog.RES_KEY_TITLE;
    String messageKey = ConfirmationDialog.RES_CONFIRM_PREFIX + objectType + "_" //$NON-NLS-1$
            + ConfirmationDialog.RES_KEY_MESSAGE;

    String nodeTypeName = node.getNodeType();

    MessageDialog dialog = new MessageDialog(workbenchWindow.getShell(),
            UIUtils.formatMessage(bundle.getString(titleKey), nodeTypeName, node.getNodeName()),
            DBeaverIcons.getImage(UIIcon.REJECT),
            UIUtils.formatMessage(bundle.getString(messageKey), nodeTypeName.toLowerCase(), node.getNodeName()),
            MessageDialog.CONFIRM, null, 0) {
        @Override
        protected void createButtonsForButtonBar(Composite parent) {
            createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, true);
            createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, false);
            if (structSelection.size() > 1) {
                createButton(parent, IDialogConstants.YES_TO_ALL_ID, IDialogConstants.YES_TO_ALL_LABEL, false);
                createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
            }
            if (viewScript) {
                createButton(parent, IDialogConstants.DETAILS_ID,
                        CoreMessages.actions_navigator_view_script_button, false);
            }
        }
    };
    int result = dialog.open();
    switch (result) {
    case IDialogConstants.YES_ID:
        return ConfirmResult.YES;
    case IDialogConstants.YES_TO_ALL_ID:
        deleteAll = true;
        return ConfirmResult.YES;
    case IDialogConstants.NO_ID:
        return ConfirmResult.NO;
    case IDialogConstants.CANCEL_ID:
    case -1:
        deleteAll = false;
        return ConfirmResult.NO;
    case IDialogConstants.DETAILS_ID:
        return ConfirmResult.DETAILS;
    default:
        log.warn("Unsupported confirmation dialog result: " + result); //$NON-NLS-1$
        return ConfirmResult.NO;
    }
}

From source file:org.python.pydev.navigator.actions.copied.CopyFilesAndFoldersOperation.java

License:Open Source License

/**
 * Check if the user wishes to overwrite the supplied resource or all
 * resources.//from  www . j av a2 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);
            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];
}