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.ebayopensource.vjet.eclipse.internal.ui.dialogs.UnknownContentTypeDialog.java

License:Open Source License

protected void buttonPressed(int buttonId) {
    super.buttonPressed(buttonId);

    // overwritten so that value stored is boolean, not string
    if (buttonId != IDialogConstants.CANCEL_ID && getToggleState() && getPrefStore() != null
            && getPrefKey() != null) {
        switch (buttonId) {
        case IDialogConstants.YES_ID:
        case IDialogConstants.YES_TO_ALL_ID:
        case IDialogConstants.PROCEED_ID:
        case IDialogConstants.OK_ID:
            getPrefStore().setValue(getPrefKey(), false);
            break;
        case IDialogConstants.NO_ID:
        case IDialogConstants.NO_TO_ALL_ID:
            getPrefStore().setValue(getPrefKey(), true);
            break;
        }//from w  w  w .j  a va  2 s. c o m
    }

}

From source file:org.eclipse.andmore.android.common.utilities.EclipseUtils.java

License:Apache License

/**
 * Show a question message using the given title and message
 * // w  w w .ja  v a  2 s  .  co m
 * @param title
 *            of the dialog
 * @param message
 *            to be displayed in the dialog.
 */
public static int showQuestionYesAllCancelDialog(final String title, final String message) {
    class IntWrapper {
        public int diagReturn = 0;
    }

    final IntWrapper intWrapper = new IntWrapper();
    Display.getDefault().syncExec(new Runnable() {

        @Override
        public void run() {
            IWorkbench workbench = PlatformUI.getWorkbench();
            IWorkbenchWindow ww = workbench.getActiveWorkbenchWindow();
            Shell shell = ww.getShell();
            MessageDialog dialog = new MessageDialog(shell, title, null, message, MessageDialog.QUESTION,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                            IDialogConstants.NO_LABEL },
                    0);
            int diagResults = dialog.open();
            switch (diagResults) {
            case 0:
                intWrapper.diagReturn = IDialogConstants.YES_ID;
                break;
            case 1:
                intWrapper.diagReturn = IDialogConstants.YES_TO_ALL_ID;
                break;
            case 2:
            default:
                intWrapper.diagReturn = IDialogConstants.NO_ID;
                break;
            }
        }
    });

    return intWrapper.diagReturn;
}

From source file:org.eclipse.andmore.android.common.utilities.FileUtil.java

License:Apache License

public static boolean extractZipArchive(File file, File destination, List<String> selectedEntries,
        IProgressMonitor monitor) throws IOException {
    SubMonitor subMonitor = SubMonitor.convert(monitor);
    ZipFile zipFile = null;/*  w  w  w .j  av a2 s .c o  m*/
    CRC32 crc = new CRC32();
    byte[] buf = new byte[BUFFER_SIZE];

    File extractDestination = destination != null ? destination : file.getParentFile();

    if (!extractDestination.exists()) {
        extractDestination.mkdirs();
    }

    boolean unziped = true;
    try {
        zipFile = new ZipFile(file);
    } catch (Throwable e) {
        unziped = false;
        AndmoreLogger.error(FileUtil.class, "Error extracting file: " + file.getAbsolutePath() //$NON-NLS-1$
                + " to " + extractDestination, e); //$NON-NLS-1$

    }
    if (zipFile != null) {
        Enumeration<? extends ZipEntry> entries = zipFile.entries();

        subMonitor.beginTask("Extracting files", Collections.list(entries).size()); //$NON-NLS-1$
        entries = zipFile.entries();
        InputStream input = null;
        FileOutputStream output = null;
        int diagReturn = IDialogConstants.YES_ID;
        while (entries.hasMoreElements()) {
            crc.reset();
            try {
                ZipEntry entry = entries.nextElement();
                if (selectedEntries.contains(entry.getName())) {
                    File newFile = new File(extractDestination, entry.getName());
                    if ((diagReturn != IDialogConstants.YES_TO_ALL_ID) && newFile.exists()) {
                        diagReturn = EclipseUtils.showQuestionYesAllCancelDialog(
                                UtilitiesNLS.FileUtil_File_Exists_Title,
                                NLS.bind(UtilitiesNLS.FileUtil_File_Exists_Message, newFile.getAbsolutePath()));
                    }

                    if ((diagReturn == IDialogConstants.YES_ID)
                            || (diagReturn == IDialogConstants.YES_TO_ALL_ID)) {
                        newFile.delete();
                        if (entry.isDirectory()) {
                            newFile.mkdirs();
                        } else {
                            newFile.getParentFile().mkdirs();
                            if (newFile.createNewFile()) {
                                input = zipFile.getInputStream(entry);
                                output = new FileOutputStream(newFile);
                                int length = 0;
                                while ((length = input.read(buf, 0, BUFFER_SIZE)) > 1) {
                                    output.write(buf, 0, length);
                                    crc.update(buf, 0, length);
                                }

                                if (crc.getValue() != entry.getCrc()) {
                                    throw new IOException();
                                }

                            }
                        }
                    } else {
                        diagReturn = IDialogConstants.YES_ID; // Attempt to
                        // extract
                        // next
                        // entry
                    }
                }
            } catch (IOException e) {
                unziped = false;
                AndmoreLogger.error(FileUtil.class, "Error extracting file: " + file.getAbsolutePath() + " to " //$NON-NLS-1$ //$NON-NLS-2$
                        + extractDestination, e);
                throw e;
            } catch (Throwable t) {
                unziped = false;
                AndmoreLogger.error(FileUtil.class, "Error extracting file: " + file.getAbsolutePath() + " to " //$NON-NLS-1$ //$NON-NLS-2$
                        + extractDestination, t);
            } finally {
                try {
                    if (input != null) {
                        input.close();
                    }
                    if (output != null) {
                        output.close();
                    }
                } catch (Throwable t) {
                    // do nothing
                }
                subMonitor.worked(1);
            }
        }
    }
    return unziped;

}

From source file:org.eclipse.cdt.make.internal.ui.dnd.MakeTargetDndUtil.java

License:Open Source License

/**
 * Copy/move one make target to the specified container.
 *
 * @param makeTarget - make target.//  w  w w. j  a v a  2s.  c  o  m
 * @param container - container to copy/move to.
 * @param operation - copying operation. Should be one of
 *        {@link org.eclipse.swt.dnd.DND} operations.
 * @param shell - shell to display user warnings.
 * @param offerOverwriteDialog - whether overwrite dialog is provided.
 * @throws CoreException on the failure of {@link IMakeTargetManager} or
 *         {@link IMakeTarget} operation.
 *
 * @see DND#DROP_NONE
 * @see DND#DROP_COPY
 * @see DND#DROP_MOVE
 * @see DND#DROP_LINK
 * @see DND#DROP_DEFAULT
 */
public static void copyOneTarget(IMakeTarget makeTarget, IContainer container, final int operation, Shell shell,
        boolean offerOverwriteDialog) throws CoreException {

    IMakeTargetManager makeTargetManager = MakeCorePlugin.getDefault().getTargetManager();
    IMakeTarget exists = makeTargetManager.findTarget(container, makeTarget.getName());
    if (exists != null) {
        int userAnswer = IDialogConstants.CANCEL_ID;
        if (offerOverwriteDialog) {
            userAnswer = overwriteMakeTargetDialog(makeTarget.getName(), shell);
        } else {
            userAnswer = RENAME_ID;
        }
        if (userAnswer == IDialogConstants.YES_ID || userAnswer == IDialogConstants.YES_TO_ALL_ID) {
            copyTargetData(makeTarget, exists);
            if (operation == DND.DROP_MOVE) {
                makeTargetManager.removeTarget(makeTarget);
            }
        } else if (userAnswer == RENAME_ID || userAnswer == RENAME_TO_ALL_ID) {
            String name = generateUniqueName(makeTarget.getName(), container);
            IMakeTarget newMakeTarget = cloneTarget(name, makeTarget, container.getProject());
            newMakeTarget.setContainer(container);
            int dialogReturnCode = Window.OK;
            if (userAnswer == RENAME_ID) {
                MakeTargetDialog dialog;
                try {
                    dialog = new MakeTargetDialog(shell, newMakeTarget);
                    dialogReturnCode = dialog.open();
                } catch (CoreException e) {
                    MakeUIPlugin.errorDialog(shell,
                            MakeUIPlugin.getResourceString("AddBuildTargetAction.exception.internal"), //$NON-NLS-1$
                            e.toString(), e);
                }
            } else if (userAnswer == RENAME_TO_ALL_ID) {
                makeTargetManager.addTarget(container, newMakeTarget);
            }
            if (operation == DND.DROP_MOVE && dialogReturnCode != Window.CANCEL) {
                makeTargetManager.removeTarget(makeTarget);
            }
        }
    } else {
        makeTargetManager.addTarget(container,
                cloneTarget(makeTarget.getName(), makeTarget, container.getProject()));
        if (operation == DND.DROP_MOVE) {
            makeTargetManager.removeTarget(makeTarget);
        }
    }
}

From source file:org.eclipse.cdt.make.internal.ui.dnd.MakeTargetDndUtil.java

License:Open Source License

/**
 * Overwrite Make Target dialog./*from   w  w  w  . j  a  va 2s  .  co m*/
 *
 * @param name - name of make target to display to a user.
 * @param shell - shell where to display the dialog.
 *
 * @return user's answer.
 */
private static int overwriteMakeTargetDialog(String name, Shell shell) {

    if (lastUserAnswer == IDialogConstants.YES_TO_ALL_ID || lastUserAnswer == IDialogConstants.NO_TO_ALL_ID
            || lastUserAnswer == RENAME_TO_ALL_ID) {

        return lastUserAnswer;
    }

    String labels[] = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
            MakeUIPlugin.getResourceString("MakeTargetDnD.button.rename"), //$NON-NLS-1$
            IDialogConstants.CANCEL_LABEL, };

    String title = MakeUIPlugin.getResourceString("MakeTargetDnD.title.overwriteTargetConfirm"); //$NON-NLS-1$
    String question = MessageFormat.format(
            MakeUIPlugin.getResourceString("MakeTargetDnD.message.overwriteTargetConfirm"), //$NON-NLS-1$
            new Object[] { name });
    String toggleApplyToAll = MakeUIPlugin.getResourceString("MakeTargetDnD.toggle.applyToAll"); //$NON-NLS-1$

    MessageDialogWithToggle dialog = new MessageDialogWithToggle(shell, title, null, question,
            MessageDialog.QUESTION, labels, 0, toggleApplyToAll, false);

    try {
        dialog.open();
        lastUserAnswer = dialog.getReturnCode();
        boolean toAll = dialog.getToggleState();
        if (toAll && lastUserAnswer == IDialogConstants.YES_ID) {
            lastUserAnswer = IDialogConstants.YES_TO_ALL_ID;
        } else if (toAll && lastUserAnswer == IDialogConstants.NO_ID) {
            lastUserAnswer = IDialogConstants.NO_TO_ALL_ID;
        } else if (toAll && lastUserAnswer == RENAME_ID) {
            lastUserAnswer = RENAME_TO_ALL_ID;
        }
    } catch (SWTException e) {
        MakeUIPlugin.log(e);
        lastUserAnswer = IDialogConstants.CANCEL_ID;
    }

    if (lastUserAnswer == SWT.DEFAULT) {
        // A window close returns SWT.DEFAULT, which has to be
        // mapped to a cancel
        lastUserAnswer = IDialogConstants.CANCEL_ID;
    }
    return lastUserAnswer;
}

From source file:org.eclipse.rcptt.ui.actions.edit.PasteAction.java

License:Open Source License

/**
 * Implementation of method defined on <code>IAction</code>.
 *//*from   ww w  .  jav  a  2  s  . c  om*/
@Override
public void run() {
    if (LaunchUtils.hasLaunchedTestCases()) {
        MessageDialog.openWarning(shell, Messages.PasteAction_ErrorDialogTitle,
                Messages.PasteAction_ErrorDialogMsg);
        return;
    }
    if (!RefactoringSaveHelper.checkDirtyEditors(shell)) {
        return;
    }
    // try a resource transfer
    ResourceTransfer resTransfer = ResourceTransfer.getInstance();
    IResource[] resourceData = (IResource[]) clipboard.getContents(resTransfer);

    if (resourceData != null && resourceData.length > 0) {
        if (resourceData[0].getType() == IResource.PROJECT) {
            // enablement checks for all projects
            for (int i = 0; i < resourceData.length; i++) {
                CopyProjectOperation operation = new CopyProjectOperation(this.shell);
                operation.copyProject((IProject) resourceData[i]);
            }
        } else {
            // enablement should ensure that we always have access to a
            // container
            IContainer container = getContainer();

            try {
                WriteAccessChecker writeAccessChecker = new WriteAccessChecker(this.shell);
                if (!writeAccessChecker.makeResourceWritable(container)) {
                    return;
                }
            } catch (CoreException e) {
                Q7UIPlugin.log(e);
            }

            final List<IQ7NamedElement> namedElements = new ArrayList<IQ7NamedElement>();
            List<IResource> normalResources = new ArrayList<IResource>();
            for (IResource resource : resourceData) {
                if (resource instanceof IFile) {
                    IQ7NamedElement namedElement = (IQ7NamedElement) RcpttCore.create((IFile) resource);
                    if (namedElement != null) {
                        namedElements.add(namedElement);
                        continue;
                    }
                }
                normalResources.add(resource);
            }
            // paste named elements, if resources was pasted normally
            IQ7NamedElement[] elements = namedElements.toArray(new IQ7NamedElement[namedElements.size()]);
            Map<IQ7NamedElement, IFile> map = RcpttCore.getInstance().getCopyDestinationMap(elements,
                    container);

            if (normalResources.size() > 0) {
                Q7CopyFilesAndFoldersOperation operation = new Q7CopyFilesAndFoldersOperation(this.shell) {
                    protected org.eclipse.ui.ide.undo.AbstractWorkspaceOperation getUndoableCopyOrMoveOperation(
                            IResource[] resources, boolean renamed, final IPath... destinationPath) {
                        if (renamed) {
                            return new Q7ResourceCopyOperation(resources, destinationPath,
                                    IDEWorkbenchMessages.CopyFilesAndFoldersOperation_copyTitle, namedElements);
                        } else {
                            List<IPath> dests = new ArrayList<IPath>();
                            for (IResource res : resources) {
                                dests.add(destinationPath[0].append(res.getName()));
                            }
                            return new Q7ResourceCopyOperation(resources, destinationPath[0],
                                    IDEWorkbenchMessages.CopyFilesAndFoldersOperation_copyTitle, namedElements,
                                    dests.toArray(new IPath[dests.size()]));
                        }
                    };
                };
                IResource[] result = operation.copyResources(
                        normalResources.toArray(new IResource[normalResources.size()]), container);
                if (result.length == 0) {
                    // a problem was occurred
                    return;
                }
                if (namedElements.size() != elements.length) {
                    // Update elements
                    elements = namedElements.toArray(new IQ7NamedElement[namedElements.size()]);
                }
            }

            Map<IQ7NamedElement, String> newNames = new HashMap<IQ7NamedElement, String>();
            Set<String> names = CollectNames(container);
            Set<IPath> filesSkip = new HashSet<IPath>();
            List<IQ7NamedElement> skipElements = new ArrayList<IQ7NamedElement>();

            boolean isSameDestination = isDestinationSameAsSource(resourceData, container);
            int overwrite = IDialogConstants.NO_ID;
            IWorkspaceRoot workspaceRoot = container.getWorkspace().getRoot();

            for (Map.Entry<IQ7NamedElement, IFile> e : map.entrySet()) {
                if (e.getValue().exists()) {
                    if (isSameDestination) {
                        try {
                            RenameDialog dialog = new RenameDialog(shell, e.getKey().getElementName(), names,
                                    e.getValue(), Messages.PasteAction_DialogTitle, filesSkip,
                                    Messages.PasteAction_DialogNewNameProposal);
                            if (dialog.open() == RenameDialog.OK) {
                                newNames.put(e.getKey(), dialog.getResultName());
                                names.add(dialog.getResultName());
                                IPath newFilePath = dialog.getNewFileName();
                                filesSkip.add(newFilePath);
                                map.put(e.getKey(),
                                        ResourcesPlugin.getWorkspace().getRoot().getFile(newFilePath));
                            } else {
                                return; // Cancel operation
                            }
                        } catch (ModelException e2) {
                            Q7UIPlugin.log(e2);
                        }
                    } else {
                        if (overwrite != IDialogConstants.YES_TO_ALL_ID) {
                            IResource source = e.getKey().getResource();
                            IResource destination = workspaceRoot.findMember(e.getValue().getFullPath());
                            overwrite = checkOverwrite(source, destination);
                            if (overwrite == IDialogConstants.NO_ID) {
                                skipElements.add(e.getKey());
                            }
                            if (overwrite == IDialogConstants.CANCEL_ID) {
                                return; // Cancel operation
                            }
                        }
                    }
                }
            }

            // remove skipped from copied elements
            if (skipElements.size() > 0) {
                for (IQ7NamedElement element : skipElements) {
                    namedElements.remove(element);
                    newNames.remove(element);
                    map.remove(element);
                }
                elements = namedElements.toArray(new IQ7NamedElement[namedElements.size()]);
            }

            // Check and update file name
            try {
                RcpttCore.getInstance().copy(elements, map, newNames);
            } catch (CoreException e) {
                Q7UIPlugin.log(e);
            }
        }
        return;
    }

    // try a file transfer
    FileTransfer fileTransfer = FileTransfer.getInstance();
    String[] fileData = (String[]) clipboard.getContents(fileTransfer);

    if (fileData != null) {
        // enablement should ensure that we always have access to a
        // container
        IContainer container = getContainer();

        CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(this.shell);
        operation.copyFiles(fileData, container);
    }
}

From source file:org.eclipse.rcptt.ui.actions.edit.PasteAction.java

License:Open Source License

/**
 * Check if the user wishes to overwrite the supplied resource or all
 * resources. Copied from//from w  w  w .ja  v  a2  s  .  c om
 * org.eclipse.ui.actions.CopyFilesAndFoldersOperation.
 * 
 * @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 };

            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(shell,
                    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()];
            }
        }
    };
    shell.getDisplay().syncExec(query);
    return result[0];
}

From source file:org.eclipse.rcptt.ui.actions.edit.Q7CopyFilesAndFoldersOperation.java

License:Open Source License

/**
 * Check if the user wishes to overwrite the supplied resource or all
 * resources.//from   www.  j  a v  a 2 s . c  o  m
 * 
 * @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() {
        @SuppressWarnings("restriction")
        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(
                            org.eclipse.ui.internal.ide.IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteMergeQuestion,
                            destination.getFullPath().makeRelative());
                } else {
                    if (destination.isLinked()) {
                        message = NLS.bind(
                                org.eclipse.ui.internal.ide.IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteNoMergeLinkQuestion,
                                destination.getFullPath().makeRelative());
                    } else {
                        message = NLS.bind(
                                org.eclipse.ui.internal.ide.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[] {
                        org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils.getLocationText(destination),
                        org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils
                                .getDateStringValue(destination),
                        org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils.getLocationText(source),
                        org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils.getDateStringValue(source) };
                message = NLS.bind(
                        org.eclipse.ui.internal.ide.IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteWithDetailsQuestion,
                        bindings);
            }
            MessageDialog dialog = new MessageDialog(messageShell,
                    org.eclipse.ui.internal.ide.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.rcptt.ui.actions.edit.Q7CopyFilesAndFoldersOperation.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  ww w .j  ava  2  s. c o 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
 */
@SuppressWarnings({ "restriction", "rawtypes", "unchecked" })
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(
                    org.eclipse.ui.internal.ide.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.sirius.common.ui.tools.api.dialog.SiriusMessageDialogWithToggle.java

License:Open Source License

/**
 * Attempt to find a standard JFace button id that matches the specified
 * button label. If no match can be found, use the default id provided.
 * /*www  . j a  va  2  s .co m*/
 * Overridden to investigate the provided buttons.
 * 
 * @param buttonLabel
 *            the button label whose id is sought
 * @param defaultId
 *            the id to use for the button if there is no standard id
 * @return the id for the specified button label
 */
// CHECKSTYLE:OFF
private int mapButtonLabelToButtonID(String buttonLabel, int defaultId) {
    // CHECKSTYLE:OON
    // Not pretty but does the job...
    if (IDialogConstants.OK_LABEL.equals(buttonLabel)) {
        return IDialogConstants.OK_ID;
    }

    if (IDialogConstants.YES_LABEL.equals(buttonLabel)) {
        return IDialogConstants.YES_ID;
    }

    if (IDialogConstants.NO_LABEL.equals(buttonLabel)) {
        return IDialogConstants.NO_ID;
    }

    if (IDialogConstants.CANCEL_LABEL.equals(buttonLabel)) {
        return IDialogConstants.CANCEL_ID;
    }

    if (IDialogConstants.YES_TO_ALL_LABEL.equals(buttonLabel)) {
        return IDialogConstants.YES_TO_ALL_ID;
    }

    if (IDialogConstants.SKIP_LABEL.equals(buttonLabel)) {
        return IDialogConstants.SKIP_ID;
    }

    if (IDialogConstants.STOP_LABEL.equals(buttonLabel)) {
        return IDialogConstants.STOP_ID;
    }

    if (IDialogConstants.ABORT_LABEL.equals(buttonLabel)) {
        return IDialogConstants.ABORT_ID;
    }

    if (IDialogConstants.RETRY_LABEL.equals(buttonLabel)) {
        return IDialogConstants.RETRY_ID;
    }

    if (IDialogConstants.IGNORE_LABEL.equals(buttonLabel)) {
        return IDialogConstants.IGNORE_ID;
    }

    if (IDialogConstants.PROCEED_LABEL.equals(buttonLabel)) {
        return IDialogConstants.PROCEED_ID;
    }

    if (IDialogConstants.OPEN_LABEL.equals(buttonLabel)) {
        return IDialogConstants.OPEN_ID;
    }

    if (IDialogConstants.CLOSE_LABEL.equals(buttonLabel)) {
        return IDialogConstants.CLOSE_ID;
    }

    if (IDialogConstants.BACK_LABEL.equals(buttonLabel)) {
        return IDialogConstants.BACK_ID;
    }

    if (IDialogConstants.NEXT_LABEL.equals(buttonLabel)) {
        return IDialogConstants.NEXT_ID;
    }

    if (IDialogConstants.FINISH_LABEL.equals(buttonLabel)) {
        return IDialogConstants.FINISH_ID;
    }

    if (IDialogConstants.HELP_LABEL.equals(buttonLabel)) {
        return IDialogConstants.HELP_ID;
    }

    if (IDialogConstants.NO_TO_ALL_LABEL.equals(buttonLabel)) {
        return IDialogConstants.NO_TO_ALL_ID;
    }

    if (IDialogConstants.SHOW_DETAILS_LABEL.equals(buttonLabel)) {
        return IDialogConstants.DETAILS_ID;
    }

    if (IDialogConstants.HIDE_DETAILS_LABEL.equals(buttonLabel)) {
        return IDialogConstants.DETAILS_ID;
    }

    for (String providedButton : buttonsMap.keySet()) {
        if (providedButton.equals(buttonLabel)) {
            return buttonsMap.get(providedButton);
        }
    }

    // No XXX_LABEL in IDialogConstants for these. Unlikely
    // they would be used in a message dialog though.
    // public int SELECT_ALL_ID = 18;
    // public int DESELECT_ALL_ID = 19;
    // public int SELECT_TYPES_ID = 20;

    return defaultId;
}