org.eclipse.ui.actions.CopyFilesAndFoldersOperation Java Examples

The following examples show how to use org.eclipse.ui.actions.CopyFilesAndFoldersOperation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NavigatorResourceDropAssistant.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Performs a drop using the FileTransfer transfer type.
 */
private IStatus performFileDrop(final CommonDropAdapter anAdapter, final Object data) {
	final int currentOperation = anAdapter.getCurrentOperation();
	final MultiStatus problems =
			new MultiStatus(PlatformUI.PLUGIN_ID, 0, WorkbenchNavigatorMessages.DropAdapter_problemImporting, null);
	mergeStatus(problems,
			validateTarget(anAdapter.getCurrentTarget(), anAdapter.getCurrentTransfer(), currentOperation));

	final IContainer target = getActualTarget(ResourceManager.getResource(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(() -> {
		getShell().forceActive();
		new CopyFilesAndFoldersOperation(getShell()).copyOrLinkFiles(names, target, currentOperation);
	});
	return problems;
}
 
Example #2
Source File: ResourceDropAdapterAssistant.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: ResourceDropAdapterAssistant.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: PyResourceDropAdapterAssistant.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Performs a resource copy
 */
private IStatus performResourceCopy(CommonDropAdapter dropAdapter, Shell shell, IResource[] sources) {
    MultiStatus problems = new MultiStatus(PlatformUI.PLUGIN_ID, 1,
            WorkbenchNavigatorMessages.DropAdapter_problemsMoving, null);
    mergeStatus(
            problems,
            validateTarget(getCurrentTarget(dropAdapter), dropAdapter.getCurrentTransfer(),
                    dropAdapter.getCurrentOperation()));

    IContainer target = getActualTarget((IResource) getCurrentTarget(dropAdapter));
    CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(shell);
    IResource[] copiedResources = operation.copyResources(sources, target);
    if (copiedResources.length > 0) {
        PythonPathHelper.updatePyPath(copiedResources, target, PythonPathHelper.OPERATION_COPY);
    }

    return problems;
}
 
Example #5
Source File: PyResourceDropAdapterAssistant.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Performs a drop using the FileTransfer transfer type.
 */
private IStatus performFileDrop(CommonDropAdapter anAdapter, Object data) {
    data = getActual(data);
    MultiStatus problems = new MultiStatus(PlatformUI.PLUGIN_ID, 0,
            WorkbenchNavigatorMessages.DropAdapter_problemImporting, null);
    mergeStatus(
            problems,
            validateTarget(getCurrentTarget(anAdapter), anAdapter.getCurrentTransfer(),
                    anAdapter.getCurrentOperation()));

    final IContainer target = getActualTarget((IResource) getCurrentTarget(anAdapter));
    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() {
        @Override
        public void run() {
            getShell().forceActive();
            CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(getShell());
            operation.copyFiles(names, target);
        }
    });
    return problems;
}
 
Example #6
Source File: PasteAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void paste(IJavaElement[] javaElements, IResource[] resources, IWorkingSet[] selectedWorkingSets, TransferData[] availableTypes) throws JavaModelException {
	String[] fileData= getClipboardFiles(availableTypes);
	if (fileData == null)
		return;

	IContainer container= getAsContainer(getTarget(javaElements, resources));
	if (container == null)
		return;

	new CopyFilesAndFoldersOperation(getShell()).copyFiles(fileData, container);
}
 
Example #7
Source File: FileTransferDropAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean performDrop(final Object data) {
	try {
		final int currentOperation= getCurrentOperation();

		if (data == null || !(data instanceof String[]) || currentOperation != DND.DROP_COPY)
			return false;

		final IContainer target= getActualTarget(getCurrentTarget());
		if (target == null)
			return false;

		// Run the import operation asynchronously.
		// Otherwise the drag source (e.g., Windows Explorer) will be blocked
		// while the operation executes. Fixes bug 35796.
		Display.getCurrent().asyncExec(new Runnable() {
			public void run() {
				getShell().forceActive();
				new CopyFilesAndFoldersOperation(getShell()).copyOrLinkFiles((String[])data, target, currentOperation);
			}
		});

		return true;
	} catch (JavaModelException e) {
		String title= PackagesMessages.DropAdapter_errorTitle;
		String message= PackagesMessages.DropAdapter_errorMessage;
		ExceptionHandler.handle(e, getShell(), title, message);
		return false;
	}
}
 
Example #8
Source File: ProjectExplorerDropAdapterAssistant.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public IStatus handleDrop(CommonDropAdapter dropAdapter,
		DropTargetEvent event, Object target) {

	try {
		// drop in folder
		if (target instanceof IXdsFolderContainer || 
				target instanceof IProject || 
				target instanceof IContainer ||
				(dropAdapter.getCurrentOperation() == DND.DROP_COPY && (
						target instanceof IFile ||
						target instanceof IXdsResource))) {

			final Object data= event.data;
			if (data == null) {
				return Status.CANCEL_STATUS;
			}
			final IContainer destination= getDestination(target);
			if (destination == null) {
				return Status.CANCEL_STATUS;
			}
			IResource[] resources = null;
			TransferData currentTransfer = dropAdapter.getCurrentTransfer();
			final int dropOperation = dropAdapter.getCurrentOperation();
			if (LocalSelectionTransfer.getTransfer().isSupportedType(
					currentTransfer)) {
				resources = getSelectedResources();
			} else if (ResourceTransfer.getInstance().isSupportedType(
					currentTransfer)) {
				resources = (IResource[]) event.data;
			}
			if (FileTransfer.getInstance().isSupportedType(currentTransfer)) {
				final String[] names = (String[]) data;
				// Run the import operation asynchronously. 
				// Otherwise the drag source (e.g., Windows Explorer) will be blocked 
				Display.getCurrent().asyncExec(new Runnable() {
					public void run() {
						getShell().forceActive();
						CopyFilesAndFoldersOperation op= new CopyFilesAndFoldersOperation(getShell());
						op.copyOrLinkFiles(names, destination, dropOperation);
					}
				});
			} else if (event.detail == DND.DROP_COPY || event.detail == DND.DROP_LINK) {
				return performResourceCopy(dropAdapter, getShell(), resources);
			} else {
				ReadOnlyStateChecker checker = new ReadOnlyStateChecker(
					getShell(), 
					"Move Resource Action",	//$NON-NLS-1$
					"Move Resource Action");//$NON-NLS-1$	
				resources = checker.checkReadOnlyResources(resources);
				MoveFilesAndFoldersOperation operation = new MoveFilesAndFoldersOperation(getShell());
				operation.copyResources(resources, destination);
			}
			return Status.OK_STATUS;
		}
	} 
	finally {
		// The drag source listener must not perform any operation
		// since this drop adapter did the remove of the source even
		// if we moved something.
		event.detail= DND.DROP_NONE;
	}
	return Status.CANCEL_STATUS;
}
 
Example #9
Source File: ProjectExplorerDropAdapterAssistant.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Performs a resource copy.
 * Cloned from ResourceDropAdapterAssistant to support linked resources (bug 319405).
 */
private IStatus performResourceCopy(CommonDropAdapter dropAdapter,
		Shell shell, IResource[] sources) {
	IContainer target = getDestination(dropAdapter.getCurrentTarget());
	if (target == null) {
		return Status.CANCEL_STATUS;
	}
	
	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);
	// if the target is a virtual folder and all sources are files, then
	// 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) {
			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 Status.CANCEL_STATUS;
		} else
			operation.copyResources(sources, target);
	}

	return Status.OK_STATUS;
}
 
Example #10
Source File: ResourceDropAdapterAssistant.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
	 * 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);
		// if the target is a virtual folder and all sources are files, then
		// 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;
	}
 
Example #11
Source File: ResourceDropAdapterAssistant.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
	 * 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);
		// if the target is a virtual folder and all sources are files, then
		// 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;
	}