⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 copyfilesandfoldersoperation.java

📁 Python Development Environment (Python IDE plugin for Eclipse). Features editor, code completion, re
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        // failure.
        IStatus status = op.getStatus();
        if (!status.isOK()) {
            if (errorStatus == null) {
                errorStatus = new MultiStatus(PlatformUI.PLUGIN_ID,
                        IStatus.ERROR, getProblemsMessage(), null);
            }
            errorStatus.merge(status);
        }
    }

    /**
     * Records the core exception to be displayed to the user once the action is
     * finished.
     * 
     * @param error
     *            a <code>CoreException</code>
     */
    private void recordError(CoreException error) {
        if (errorStatus == null) {
            errorStatus = new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.ERROR,
                    getProblemsMessage(), error);
        }

        errorStatus.merge(error.getStatus());
    }

    /**
     * Checks whether the destination is valid for copying the source resources.
     * <p>
     * Note this method is for internal use only. It is not API.
     * </p>
     * 
     * @param destination
     *            the destination container
     * @param sourceResources
     *            the source resources
     * @return an error message, or <code>null</code> if the path is valid
     */
    public String validateDestination(IContainer destination,
            IResource[] sourceResources) {
        if (!isAccessible(destination)) {
            return IDEWorkbenchMessages.CopyFilesAndFoldersOperation_destinationAccessError;
        }
        IContainer firstParent = null;
        URI destinationLocation = destination.getLocationURI();
        for (int i = 0; i < sourceResources.length; i++) {
            IResource sourceResource = sourceResources[i];
            if (firstParent == null) {
                firstParent = sourceResource.getParent();
            } else if (firstParent.equals(sourceResource.getParent()) == false) {
                // Resources must have common parent. Fixes bug 33398.
                return IDEWorkbenchMessages.CopyFilesAndFoldersOperation_parentNotEqual;
            }

            URI sourceLocation = sourceResource.getLocationURI();
            if (sourceLocation == null) {
                if (sourceResource.isLinked()) {
                    // Don't allow copying linked resources with undefined path
                    // variables. See bug 28754.
                    return NLS
                            .bind(
                                    IDEWorkbenchMessages.CopyFilesAndFoldersOperation_missingPathVariable,
                                    sourceResource.getName());
                }
                return NLS
                        .bind(
                                IDEWorkbenchMessages.CopyFilesAndFoldersOperation_resourceDeleted,
                                sourceResource.getName());

            }
            if (sourceLocation.equals(destinationLocation)) {
                return NLS
                        .bind(
                                IDEWorkbenchMessages.CopyFilesAndFoldersOperation_sameSourceAndDest,
                                sourceResource.getName());
            }
            // is the source a parent of the destination?
            if (new Path(sourceLocation.toString()).isPrefixOf(new Path(
                    destinationLocation.toString()))) {
                return IDEWorkbenchMessages.CopyFilesAndFoldersOperation_destinationDescendentError;
            }

            String linkedResourceMessage = validateLinkedResource(destination,
                    sourceResource);
            if (linkedResourceMessage != null) {
                return linkedResourceMessage;
            }
        }
        return null;
    }


    /**
     * Validates that the given source resources can be copied to the
     * destination as decided by the VCM provider.
     * 
     * @param destination
     *            copy destination
     * @param sourceResources
     *            source resources
     * @return <code>true</code> all files passed validation or there were no
     *         files to validate. <code>false</code> one or more files did not
     *         pass validation.
     */
    private boolean validateEdit(IContainer destination,
            IResource[] sourceResources) {
        ArrayList copyFiles = new ArrayList();

        collectExistingReadonlyFiles(destination.getFullPath(),
                sourceResources, copyFiles);
        if (copyFiles.size() > 0) {
            IFile[] files = (IFile[]) copyFiles.toArray(new IFile[copyFiles
                    .size()]);
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            IStatus status = workspace.validateEdit(files, messageShell);

            canceled = status.isOK() == false;
            return status.isOK();
        }
        return true;
    }

    /**
     * Checks whether the destination is valid for copying the source files.
     * <p>
     * Note this method is for internal use only. It is not API.
     * </p>
     * 
     * @param destination
     *            the destination container
     * @param sourceNames
     *            the source file names
     * @return an error message, or <code>null</code> if the path is valid
     */
    public String validateImportDestination(IContainer destination,
            String[] sourceNames) {

        IFileStore[] stores = new IFileStore[sourceNames.length];
        for (int i = 0; i < sourceNames.length; i++) {
            IFileStore store = IDEResourceInfoUtils
                    .getFileStore(sourceNames[i]);
            if (store == null) {
                return NLS
                        .bind(
                                IDEWorkbenchMessages.CopyFilesAndFoldersOperation_infoNotFound,
                                sourceNames[i]);
            }
            stores[i] = store;
        }
        return validateImportDestinationInternal(destination, stores);

    }

    /**
     * Checks whether the destination is valid for copying the source file
     * stores.
     * <p>
     * Note this method is for internal use only. It is not API.
     * </p>
     * <p>
     * TODO Bug 117804. This method has been renamed to avoid a bug in the
     * Eclipse compiler with regards to visibility and type resolution when
     * linking.
     * </p>
     * 
     * @param destination
     *            the destination container
     * @param sourceStores
     *            the source IFileStore
     * @return an error message, or <code>null</code> if the path is valid
     */
    private String validateImportDestinationInternal(IContainer destination,
            IFileStore[] sourceStores) {
        if (!isAccessible(destination)) 
            return IDEWorkbenchMessages.CopyFilesAndFoldersOperation_destinationAccessError;
        

        IFileStore destinationStore;
        try {
            destinationStore = EFS.getStore(destination.getLocationURI());
        } catch (CoreException exception) {
            IDEWorkbenchPlugin.log(exception.getLocalizedMessage(), exception);
            return NLS
                    .bind(
                            IDEWorkbenchMessages.CopyFilesAndFoldersOperation_internalError,
                            exception.getLocalizedMessage());
        }
        for (int i = 0; i < sourceStores.length; i++) {
            IFileStore sourceStore = sourceStores[i];
            IFileStore sourceParentStore = sourceStore.getParent();

            if (sourceStore != null) {
                if (destinationStore.equals(sourceStore)
                        || (sourceParentStore != null && destinationStore
                                .equals(sourceParentStore))) {
                    return NLS
                            .bind(
                                    IDEWorkbenchMessages.CopyFilesAndFoldersOperation_importSameSourceAndDest,
                                    sourceStore.getName());
                }
                // work around bug 16202. replacement for
                // sourcePath.isPrefixOf(destinationPath)
                IFileStore destinationParent = destinationStore.getParent();
                if (sourceStore.isParentOf(destinationParent)) {
                    return IDEWorkbenchMessages.CopyFilesAndFoldersOperation_destinationDescendentError;
                }

            }
        }
        return null;
    }

    /**
     * Check if the destination is valid for the given source resource.
     * 
     * @param destination
     *            destination container of the operation
     * @param source
     *            source resource
     * @return String error message or null if the destination is valid
     */
    private String validateLinkedResource(IContainer destination,
            IResource source) {
        if (source.isLinked() == false) {
            return null;
        }
        IWorkspace workspace = destination.getWorkspace();
        IResource linkHandle = createLinkedResourceHandle(destination, source);
        IStatus locationStatus = workspace.validateLinkLocation(linkHandle,
                source.getRawLocation());

        if (locationStatus.getSeverity() == IStatus.ERROR) {
            return locationStatus.getMessage();
        }
        IPath sourceLocation = source.getLocation();
        if (source.getProject().equals(destination.getProject()) == false
                && source.getType() == IResource.FOLDER
                && sourceLocation != null) {
            // prevent merging linked folders that point to the same
            // file system folder
            try {
                IResource[] members = destination.members();
                for (int j = 0; j < members.length; j++) {
                    if (sourceLocation.equals(members[j].getLocation())
                            && source.getName().equals(members[j].getName())) {
                        return NLS
                                .bind(
                                        IDEWorkbenchMessages.CopyFilesAndFoldersOperation_sameSourceAndDest,
                                        source.getName());
                    }
                }
            } catch (CoreException exception) {
                displayError(NLS
                        .bind(
                                IDEWorkbenchMessages.CopyFilesAndFoldersOperation_internalError,
                                exception.getMessage()));
            }
        }
        return null;
    }

    /**
     * Returns whether moving all of the given source resources to the given
     * destination container could be done without causing name collisions.
     * 
     * @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()]);
    }

    private void copyResources(final IResource[] resources,
            final IPath destinationPath, final IResource[][] copiedResources,
            IProgressMonitor monitor) {
        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -