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;
}
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;
}
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;
}
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);
}
}
}
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;
}
Aggregations