Search in sources :

Example 1 with CopyFilesAndFoldersOperation

use of org.eclipse.ui.actions.CopyFilesAndFoldersOperation in project translationstudio8 by heartsome.

the class ResourceDropAdapterAssistant method validateTarget.

/**
	 * Ensures that the drop target meets certain criteria
	 */
private IStatus validateTarget(Object target, TransferData transferType, int dropOperation) {
    if (!(target instanceof IResource)) {
        return WorkbenchNavigatorPlugin.createInfoStatus(WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_targetMustBeResource);
    }
    IResource resource = (IResource) target;
    if (!resource.isAccessible()) {
        return WorkbenchNavigatorPlugin.createErrorStatus(WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_canNotDropIntoClosedProject);
    }
    IContainer destination = getActualTarget(resource);
    if (destination.getType() == IResource.ROOT) {
        return WorkbenchNavigatorPlugin.createErrorStatus(WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_resourcesCanNotBeSiblings);
    }
    String message = null;
    // drag within Eclipse?
    if (LocalSelectionTransfer.getTransfer().isSupportedType(transferType)) {
        IResource[] selectedResources = getSelectedResources();
        if (selectedResources.length == 0) {
            message = WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_dropOperationErrorOther;
        } else {
            CopyFilesAndFoldersOperation operation;
            if ((dropOperation == DND.DROP_COPY) || (dropOperation == DND.DROP_LINK)) {
                operation = new CopyFilesAndFoldersOperation(getShell());
                if (operation.validateDestination(destination, selectedResources) != null) {
                    operation.setVirtualFolders(true);
                    message = operation.validateDestination(destination, selectedResources);
                }
            } else {
                operation = new MoveFilesAndFoldersOperation(getShell());
                if (operation.validateDestination(destination, selectedResources) != null) {
                    operation.setVirtualFolders(true);
                    message = operation.validateDestination(destination, selectedResources);
                }
            }
        }
    } else // file import?
    if (FileTransfer.getInstance().isSupportedType(transferType)) {
        String[] sourceNames = (String[]) FileTransfer.getInstance().nativeToJava(transferType);
        if (sourceNames == null) {
            // source names will be null on Linux. Use empty names to do
            // destination validation.
            // Fixes bug 29778
            sourceNames = new String[0];
        }
        CopyFilesAndFoldersOperation copyOperation = new CopyFilesAndFoldersOperation(getShell());
        message = copyOperation.validateImportDestination(destination, sourceNames);
    }
    if (message != null) {
        return WorkbenchNavigatorPlugin.createErrorStatus(message);
    }
    return Status.OK_STATUS;
}
Also used : MoveFilesAndFoldersOperation(org.eclipse.ui.actions.MoveFilesAndFoldersOperation) IContainer(org.eclipse.core.resources.IContainer) CopyFilesAndFoldersOperation(org.eclipse.ui.actions.CopyFilesAndFoldersOperation) IResource(org.eclipse.core.resources.IResource)

Example 2 with CopyFilesAndFoldersOperation

use of org.eclipse.ui.actions.CopyFilesAndFoldersOperation in project translationstudio8 by heartsome.

the class ResourceDropAdapterAssistant method validateDrop.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#validateDrop(java.lang.Object,
	 *      int, org.eclipse.swt.dnd.TransferData)
	 */
public IStatus validateDrop(Object target, int aDropOperation, TransferData transferType) {
    if (!(target instanceof IResource)) {
        return WorkbenchNavigatorPlugin.createStatus(IStatus.INFO, 0, WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_targetMustBeResource, null);
    }
    IResource resource = (IResource) target;
    if (!resource.isAccessible()) {
        return WorkbenchNavigatorPlugin.createErrorStatus(0, WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_canNotDropIntoClosedProject, null);
    }
    IContainer destination = getActualTarget(resource);
    if (destination.getType() == IResource.ROOT) {
        return WorkbenchNavigatorPlugin.createErrorStatus(0, WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_resourcesCanNotBeSiblings, null);
    }
    String message = null;
    // drag within Eclipse?
    if (LocalSelectionTransfer.getTransfer().isSupportedType(transferType)) {
        IResource[] selectedResources = getSelectedResources();
        boolean bProjectDrop = false;
        for (int iRes = 0; iRes < selectedResources.length; iRes++) {
            IResource res = selectedResources[iRes];
            if (res instanceof IProject) {
                bProjectDrop = true;
            }
        }
        if (bProjectDrop) {
            // drop of projects not supported on other IResources
            // "Path for project must have only one segment."
            message = WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_canNotDropProjectIntoProject;
        } else {
            if (selectedResources.length == 0) {
                message = WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_dropOperationErrorOther;
            } else {
                CopyFilesAndFoldersOperation operation;
                if (aDropOperation == DND.DROP_COPY) {
                    if (Policy.DEBUG_DND) {
                        System.out.println(//$NON-NLS-1$
                        "ResourceDropAdapterAssistant.validateDrop validating COPY.");
                    }
                    operation = new CopyFilesAndFoldersOperation(getShell());
                } else {
                    if (Policy.DEBUG_DND) {
                        System.out.println(//$NON-NLS-1$
                        "ResourceDropAdapterAssistant.validateDrop validating MOVE.");
                    }
                    operation = new MoveFilesAndFoldersOperation(getShell());
                }
                if (operation.validateDestination(destination, selectedResources) != null) {
                    operation.setVirtualFolders(true);
                    message = operation.validateDestination(destination, selectedResources);
                }
            }
        }
    } else // file import?
    if (FileTransfer.getInstance().isSupportedType(transferType)) {
        String[] sourceNames = (String[]) FileTransfer.getInstance().nativeToJava(transferType);
        if (sourceNames == null) {
            // source names will be null on Linux. Use empty names to do
            // destination validation.
            // Fixes bug 29778
            sourceNames = new String[0];
        }
        CopyFilesAndFoldersOperation copyOperation = new CopyFilesAndFoldersOperation(getShell());
        message = copyOperation.validateImportDestination(destination, sourceNames);
    }
    if (message != null) {
        return WorkbenchNavigatorPlugin.createErrorStatus(0, message, null);
    }
    return Status.OK_STATUS;
}
Also used : MoveFilesAndFoldersOperation(org.eclipse.ui.actions.MoveFilesAndFoldersOperation) IContainer(org.eclipse.core.resources.IContainer) CopyFilesAndFoldersOperation(org.eclipse.ui.actions.CopyFilesAndFoldersOperation) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 3 with CopyFilesAndFoldersOperation

use of org.eclipse.ui.actions.CopyFilesAndFoldersOperation in project translationstudio8 by heartsome.

the class ResourceDropAdapterAssistant method performResourceCopy.

/**
	 * Performs a resource copy
	 */
private IStatus performResourceCopy(CommonDropAdapter dropAdapter, Shell shell, IResource[] sources) {
    MultiStatus problems = new MultiStatus(PlatformUI.PLUGIN_ID, 1, WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_problemsMoving, null);
    mergeStatus(problems, validateTarget(dropAdapter.getCurrentTarget(), dropAdapter.getCurrentTransfer(), dropAdapter.getCurrentOperation()));
    IContainer target = getActualTarget((IResource) dropAdapter.getCurrentTarget());
    boolean shouldLinkAutomatically = false;
    if (target.isVirtual()) {
        shouldLinkAutomatically = true;
        for (int i = 0; i < sources.length; i++) {
            if ((sources[i].getType() != IResource.FILE) && (sources[i].getLocation() != null)) {
                // If the source is a folder, but the location is null (a
                // broken link, for example),
                // we still generate a link automatically (the best option).
                shouldLinkAutomatically = false;
                break;
            }
        }
    }
    CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(shell);
    // automatically create links
    if (shouldLinkAutomatically) {
        operation.setCreateLinks(true);
        operation.copyResources(sources, target);
    } else {
        //			boolean allSourceAreLinksOrVirtualFolders = true;
        //			for (int i = 0; i < sources.length; i++) {
        //				if (!sources[i].isVirtual() && !sources[i].isLinked()) {
        //					allSourceAreLinksOrVirtualFolders = false;
        //					break;
        //				}
        //			}
        //			// if all sources are either links or groups, copy then normally,
        //			// don't show the dialog
        //			if (!allSourceAreLinksOrVirtualFolders) {
        //				IPreferenceStore store= IDEWorkbenchPlugin.getDefault().getPreferenceStore();
        //				String dndPreference= store.getString(target.isVirtual() ? IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_VIRTUAL_FOLDER_MODE : IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE);
        //
        //				if (dndPreference.equals(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_PROMPT)) {
        //					ImportTypeDialog dialog = new ImportTypeDialog(getShell(), dropAdapter.getCurrentOperation(), sources, target);
        //					dialog.setResource(target);
        //					if (dialog.open() == Window.OK) {
        //						if (dialog.getSelection() == ImportTypeDialog.IMPORT_VIRTUAL_FOLDERS_AND_LINKS)
        //							operation.setVirtualFolders(true);
        //						if (dialog.getSelection() == ImportTypeDialog.IMPORT_LINK)
        //							operation.setCreateLinks(true);
        //						if (dialog.getVariable() != null)
        //							operation.setRelativeVariable(dialog.getVariable());
        //						operation.copyResources(sources, target);
        //					} else
        //						return problems;
        //				}
        //				else
        //					operation.copyResources(sources, target);
        //			} else
        operation.copyResources(sources, target);
    }
    return problems;
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IContainer(org.eclipse.core.resources.IContainer) CopyFilesAndFoldersOperation(org.eclipse.ui.actions.CopyFilesAndFoldersOperation)

Example 4 with CopyFilesAndFoldersOperation

use of org.eclipse.ui.actions.CopyFilesAndFoldersOperation in project sling by apache.

the class JcrNode method pasteFromClipboard.

/**
     * Paste from the clipboard to this (container) node.
     * <p>
     * Copyright Note: The code of this method was ported from eclipse'
     * PasteAction, which due to visibility restrictions was not reusable.
     * <p>
     * @param clipboard
     */
public void pasteFromClipboard(Clipboard clipboard) {
    if (!canBePastedTo(clipboard)) {
        // should not occur due to 'canBePastedTo' check done by 
        // corresponding action - checking here nevertheless
        MessageDialog.openInformation(null, "Cannot paste", "No applicable node (type) for pasting found.");
        return;
    }
    Repository repository = ServerUtil.getDefaultRepository(getProject());
    NodeTypeRegistry ntManager = (repository == null) ? null : repository.getNodeTypeRegistry();
    if (ntManager == null) {
        MessageDialog.openWarning(null, "Cannot paste", "Cannot paste if corresponding server is not started");
        return;
    }
    // try the resource transfer
    IResource[] resourceData = (IResource[]) clipboard.getContents(ResourceTransfer.getInstance());
    if (resourceData != null && resourceData.length > 0) {
        if (resourceData[0].getType() == IResource.PROJECT) {
            // do not support project pasting onto a jcr node
            MessageDialog.openInformation(null, "Cannot paste project(s)", "Pasting of a project onto a (JCR) node is not possible");
            return;
        } else {
            CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(null);
            operation.copyResources(resourceData, getDropContainer());
        }
        return;
    }
    // try the file transfer
    String[] fileData = (String[]) clipboard.getContents(FileTransfer.getInstance());
    if (fileData != null) {
        CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(null);
        operation.copyFiles(fileData, getDropContainer());
        return;
    }
    // then try the text transfer
    String text = (String) clipboard.getContents(TextTransfer.getInstance());
    if ((text != null) && (this.domElement != null)) {
        try {
            Document document = TolerantXMLParser.parse(text, "pasted from clipboard");
            this.domElement.addNode(document.getRootElement());
            this.underlying.save();
        } catch (IOException e) {
            MessageDialog.openError(null, "Could not paste from clipboard", "Exception encountered while pasting from clipboard: " + e);
            Activator.getDefault().getPluginLogger().error("Error pasting from clipboard: " + e, e);
        }
    }
}
Also used : Repository(org.apache.sling.ide.transport.Repository) NodeTypeRegistry(org.apache.sling.ide.transport.NodeTypeRegistry) IOException(java.io.IOException) Document(de.pdark.decentxml.Document) CopyFilesAndFoldersOperation(org.eclipse.ui.actions.CopyFilesAndFoldersOperation) IResource(org.eclipse.core.resources.IResource)

Example 5 with CopyFilesAndFoldersOperation

use of org.eclipse.ui.actions.CopyFilesAndFoldersOperation in project translationstudio8 by heartsome.

the class ResourceDropAdapterAssistant method performFileDrop.

/**
	 * Performs a drop using the FileTransfer transfer type.
	 */
private IStatus performFileDrop(final CommonDropAdapter anAdapter, Object data) {
    final int currentOperation = anAdapter.getCurrentOperation();
    MultiStatus problems = new MultiStatus(PlatformUI.PLUGIN_ID, 0, WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_problemImporting, null);
    mergeStatus(problems, validateTarget(anAdapter.getCurrentTarget(), anAdapter.getCurrentTransfer(), currentOperation));
    final IContainer target = getActualTarget((IResource) anAdapter.getCurrentTarget());
    final String[] names = (String[]) data;
    // Run the import operation asynchronously.
    // Otherwise the drag source (e.g., Windows Explorer) will be blocked
    // while the operation executes. Fixes bug 16478.
    Display.getCurrent().asyncExec(new Runnable() {

        public void run() {
            getShell().forceActive();
            new CopyFilesAndFoldersOperation(getShell()).copyOrLinkFiles(names, target, currentOperation);
        }
    });
    return problems;
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) MultiStatus(org.eclipse.core.runtime.MultiStatus) IContainer(org.eclipse.core.resources.IContainer) CopyFilesAndFoldersOperation(org.eclipse.ui.actions.CopyFilesAndFoldersOperation)

Aggregations

CopyFilesAndFoldersOperation (org.eclipse.ui.actions.CopyFilesAndFoldersOperation)7 IContainer (org.eclipse.core.resources.IContainer)6 IResource (org.eclipse.core.resources.IResource)4 MultiStatus (org.eclipse.core.runtime.MultiStatus)3 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)2 MoveFilesAndFoldersOperation (org.eclipse.ui.actions.MoveFilesAndFoldersOperation)2 Document (de.pdark.decentxml.Document)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 NodeTypeRegistry (org.apache.sling.ide.transport.NodeTypeRegistry)1 Repository (org.apache.sling.ide.transport.Repository)1 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 PerformRefactoringOperation (org.eclipse.ltk.core.refactoring.PerformRefactoringOperation)1 Refactoring (org.eclipse.ltk.core.refactoring.Refactoring)1 RefactoringContribution (org.eclipse.ltk.core.refactoring.RefactoringContribution)1 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)1