use of org.eclipse.swt.dnd.TransferData in project erlide_eclipse by erlang.
the class MoveFunctionDropHandler method handleDrop.
@Override
public IStatus handleDrop(final CommonDropAdapter dropAdapter, final DropTargetEvent dropTargetEvent, final Object target) {
// get the source data
final TransferData td = dropAdapter.getCurrentTransfer();
final ISelection sel = (ISelection) LocalSelectionTransfer.getTransfer().nativeToJava(td);
final TreeSelection s = (TreeSelection) sel;
try {
GlobalParameters.setSelection(s);
} catch (final WranglerException e1) {
e1.printStackTrace();
}
// get the target data
String moduleName;
IFile file;
if (target instanceof IFile) {
file = (IFile) target;
} else {
file = (IFile) ((IErlElement) target).getResource();
}
moduleName = file.getName();
moduleName = moduleName.substring(0, moduleName.lastIndexOf("."));
final MoveFunctionRefactoring refactoring = new MoveFunctionRefactoring();
refactoring.setUserInput(moduleName);
final RefactoringWizard wizard = new DefaultWranglerRefactoringWizard(refactoring, RefactoringWizard.DIALOG_BASED_USER_INTERFACE, new ArrayList<WranglerPage>());
final Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
final RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
try {
op.run(shell, refactoring.getName());
} catch (final Exception e) {
ErlLogger.error(e);
}
return Status.OK_STATUS;
}
use of org.eclipse.swt.dnd.TransferData in project netxms by netxms.
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 by netxms.
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 by netxms.
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) {
int operation = 0;
@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, operation == DND.DROP_MOVE ? true : false);
}
return true;
}
@Override
public boolean validateDrop(Object target, int operation, TransferData transferType) {
this.operation = operation;
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;
}
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:
if (object instanceof DashboardGroup)
filter = ObjectSelectionDialog.createDashboardGroupSelectionFilter();
else
filter = ObjectSelectionDialog.createDashboardSelectionFilter();
break;
case MAPS:
filter = ObjectSelectionDialog.createNetworkMapGroupsSelectionFilter();
break;
default:
filter = null;
break;
}
if ((filter == null) || !filter.contains(((AbstractObject) target).getObjectClass()) || target.equals(object))
return false;
}
return true;
}
});
}
use of org.eclipse.swt.dnd.TransferData in project portfolio by buchen.
the class EditReportingPeriodsDialog method setupDnD.
private void setupDnD() {
Transfer[] types = new Transfer[] { LocalSelectionTransfer.getTransfer() };
tableViewer.addDragSupport(DND.DROP_MOVE, types, new DragSourceAdapter() {
@Override
public void dragSetData(DragSourceEvent event) {
IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
event.doit = (selection.size() < tableViewer.getTable().getItemCount());
if (event.doit) {
LocalSelectionTransfer.getTransfer().setSelection(selection);
LocalSelectionTransfer.getTransfer().setSelectionSetTime(event.time & 0xFFFFFFFFL);
}
}
});
tableViewer.addDropSupport(DND.DROP_MOVE, types, new ViewerDropAdapter(tableViewer) {
@Override
public boolean validateDrop(Object target, int operation, TransferData transferType) {
return true;
}
@Override
public boolean performDrop(Object data) {
IStructuredSelection selection = (IStructuredSelection) data;
List<ReportingPeriod> movedItems = new ArrayList<>();
for (Object o : selection.toList()) movedItems.add((ReportingPeriod) o);
periods.removeAll(movedItems);
Object destination = getCurrentTarget();
int index = periods.indexOf(destination);
if (index >= 0) {
int location = getCurrentLocation();
if (location == ViewerDropAdapter.LOCATION_ON || location == ViewerDropAdapter.LOCATION_AFTER)
index++;
periods.addAll(index, movedItems);
}
tableViewer.refresh();
return true;
}
});
}
Aggregations