use of org.eclipse.swt.dnd.TransferData in project Pydev by fabioz.
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
*/
@Override
protected boolean updateSelection(IStructuredSelection selection) {
if (!super.updateSelection(selection)) {
return false;
}
final IResource[][] clipboardData = new IResource[1][];
shell.getDisplay().syncExec(new Runnable() {
@Override
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<? extends IResource> selectedResources = getSelectedResources();
if (selectedResources.size() > 1) {
for (int i = 0; i < selectedResources.size(); i++) {
IResource resource = 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) {
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.swt.dnd.TransferData in project netxms-ocilib by stevemqeen.
the class ScriptEditorView method canPaste.
/**
* Check if paste action can work
*
* @return
*/
private boolean canPaste() {
Clipboard cb = new Clipboard(Display.getCurrent());
TransferData[] available = cb.getAvailableTypes();
boolean enabled = false;
for (int i = 0; i < available.length; i++) {
if (TextTransfer.getInstance().isSupportedType(available[i])) {
enabled = true;
break;
}
}
cb.dispose();
return enabled;
}
use of org.eclipse.swt.dnd.TransferData in project netxms-ocilib by stevemqeen.
the class AgentFileManager method enableDropSupport.
/**
* Enable drop support in object tree
*/
public // SubtreeType infrastructure
void enableDropSupport() {
final Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, new ViewerDropAdapter(viewer) {
@Override
public boolean performDrop(Object data) {
IStructuredSelection selection = (IStructuredSelection) data;
List<?> movableSelection = selection.toList();
for (int i = 0; i < movableSelection.size(); i++) {
AgentFile movableObject = (AgentFile) movableSelection.get(i);
moveFile((AgentFile) getCurrentTarget(), movableObject);
}
return true;
}
@Override
public boolean validateDrop(Object target, int operation, TransferData transferType) {
if ((target == null) || !LocalSelectionTransfer.getTransfer().isSupportedType(transferType))
return false;
IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
if (selection.isEmpty())
return false;
for (final Object object : selection.toList()) {
if (!(object instanceof AgentFile))
return false;
}
if (!(target instanceof AgentFile)) {
return false;
} else {
if (!((AgentFile) target).isDirectory()) {
return false;
}
}
return true;
}
});
}
use of org.eclipse.swt.dnd.TransferData in project netxms-ocilib by stevemqeen.
the class PredefinedMap method addDropSupport.
/**
* Add drop support
*/
private void addDropSupport() {
final Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, new ViewerDropAdapter(viewer) {
private int x;
private int y;
@SuppressWarnings("rawtypes")
@Override
public boolean validateDrop(Object target, int operation, TransferData transferType) {
if (!LocalSelectionTransfer.getTransfer().isSupportedType(transferType))
return false;
IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
Iterator it = selection.iterator();
while (it.hasNext()) {
Object object = it.next();
if (!((object instanceof AbstractObject) && ((AbstractObject) object).isAllowedOnMap()))
return false;
}
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean performDrop(Object data) {
IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
addObjectsFromList(selection.toList(), viewer.getControl().toControl(x, y));
return true;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.viewers.ViewerDropAdapter#dropAccept(org.eclipse
* .swt.dnd.DropTargetEvent)
*/
@Override
public void dropAccept(DropTargetEvent event) {
x = event.x;
y = event.y;
super.dropAccept(event);
}
});
}
use of org.eclipse.swt.dnd.TransferData in project netxms-ocilib by stevemqeen.
the class ObjectTree method enableDropSupport.
/**
* Enable drop support in object tree
*/
public // SubtreeType infrastructure
void enableDropSupport(// SubtreeType infrastructure
final ObjectBrowser obj) {
final Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
objectTree.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, new ViewerDropAdapter(objectTree) {
@Override
public boolean performDrop(Object data) {
TreeSelection selection = (TreeSelection) data;
List<?> movableSelection = selection.toList();
for (int i = 0; i < movableSelection.size(); i++) {
AbstractObject movableObject = (AbstractObject) movableSelection.get(i);
TreePath path = selection.getPaths()[0];
AbstractObject parent = (AbstractObject) path.getSegment(path.getSegmentCount() - 2);
obj.performObjectMove((AbstractObject) getCurrentTarget(), parent, movableObject);
}
return true;
}
@Override
public boolean validateDrop(Object target, int operation, TransferData transferType) {
if ((target == null) || !LocalSelectionTransfer.getTransfer().isSupportedType(transferType))
return false;
IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
if (selection.isEmpty())
return false;
for (final Object object : selection.toList()) {
SubtreeType subtree = null;
if ((object instanceof AbstractObject)) {
if (obj.isValidSelectionForMove(SubtreeType.INFRASTRUCTURE))
subtree = SubtreeType.INFRASTRUCTURE;
else if (obj.isValidSelectionForMove(SubtreeType.TEMPLATES))
subtree = SubtreeType.TEMPLATES;
else if (obj.isValidSelectionForMove(SubtreeType.BUSINESS_SERVICES))
subtree = SubtreeType.BUSINESS_SERVICES;
else if (obj.isValidSelectionForMove(SubtreeType.DASHBOARDS))
subtree = SubtreeType.DASHBOARDS;
else if (obj.isValidSelectionForMove(SubtreeType.MAPS))
subtree = SubtreeType.MAPS;
else if (obj.isValidSelectionForMove(SubtreeType.POLICIES))
subtree = SubtreeType.POLICIES;
}
if (subtree == null)
return false;
Set<Integer> filter;
switch(subtree) {
case INFRASTRUCTURE:
filter = ObjectSelectionDialog.createContainerSelectionFilter();
break;
case TEMPLATES:
filter = ObjectSelectionDialog.createTemplateGroupSelectionFilter();
break;
case BUSINESS_SERVICES:
filter = ObjectSelectionDialog.createBusinessServiceSelectionFilter();
break;
case DASHBOARDS:
filter = ObjectSelectionDialog.createDashboardSelectionFilter();
break;
case MAPS:
filter = ObjectSelectionDialog.createNetworkMapGroupsSelectionFilter();
break;
case POLICIES:
filter = ObjectSelectionDialog.createPolicyGroupSelectionFilter();
break;
default:
filter = null;
break;
}
if ((filter == null) || !filter.contains(((AbstractObject) target).getObjectClass()) || target.equals(object))
return false;
}
return true;
}
});
}
Aggregations