use of org.eclipse.ui.part.ResourceTransfer in project translationstudio8 by heartsome.
the class PasteAction method updateSelection.
/**
* The <code>PasteAction</code> implementation of this
* <code>SelectionListenerAction</code> method enables this action if
* a resource compatible with what is on the clipboard is selected.
*
* -Clipboard must have IResource or java.io.File
* -Projects can always be pasted if they are open
* -Workspace folder may not be copied into itself
* -Files and folders may be pasted to a single selected folder in open
* project or multiple selected files in the same folder
*/
protected boolean updateSelection(IStructuredSelection selection) {
if (!super.updateSelection(selection)) {
return false;
}
final IResource[][] clipboardData = new IResource[1][];
shell.getDisplay().syncExec(new Runnable() {
public void run() {
// clipboard must have resources or files
ResourceTransfer resTransfer = ResourceTransfer.getInstance();
clipboardData[0] = (IResource[]) clipboard.getContents(resTransfer);
}
});
IResource[] resourceData = clipboardData[0];
boolean isProjectRes = resourceData != null && resourceData.length > 0 && resourceData[0].getType() == IResource.PROJECT;
if (isProjectRes) {
for (int i = 0; i < resourceData.length; i++) {
// can paste open projects regardless of selection
if (resourceData[i].getType() != IResource.PROJECT || ((IProject) resourceData[i]).isOpen() == false) {
return false;
}
}
return true;
}
if (getSelectedNonResources().size() > 0) {
return false;
}
IResource targetResource = getTarget();
// or selection is empty
if (targetResource == null) {
return false;
}
// can paste files and folders to a single selection (file, folder,
// open project) or multiple file selection with the same parent
List selectedResources = getSelectedResources();
if (selectedResources.size() > 1) {
for (int i = 0; i < selectedResources.size(); i++) {
IResource resource = (IResource) selectedResources.get(i);
if (resource.getType() != IResource.FILE) {
return false;
}
if (!targetResource.equals(resource.getParent())) {
return false;
}
}
}
if (resourceData != null) {
// linked resources can only be pasted into projects
if (isLinked(resourceData) && targetResource.getType() != IResource.PROJECT && targetResource.getType() != IResource.FOLDER) {
return false;
}
if (targetResource.getType() == IResource.FOLDER) {
// don't try to copy folder to self
for (int i = 0; i < resourceData.length; i++) {
if (targetResource.equals(resourceData[i])) {
return false;
}
}
}
return true;
}
TransferData[] transfers = clipboard.getAvailableTypes();
FileTransfer fileTransfer = FileTransfer.getInstance();
for (int i = 0; i < transfers.length; i++) {
if (fileTransfer.isSupportedType(transfers[i])) {
return true;
}
}
return false;
}
use of org.eclipse.ui.part.ResourceTransfer in project translationstudio8 by heartsome.
the class PasteAction method run.
/**
* Implementation of method defined on <code>IAction</code>.
*/
public void run() {
// 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();
CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(this.shell);
operation.copyResources(resourceData, container);
}
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);
}
}
Aggregations