use of org.eclipse.swt.dnd.DropTarget in project cubrid-manager by CUBRID.
the class CubridNavigatorView method addTreeDropTarget.
/**
* Add drop target
*
* @param tree Tree
*/
private void addTreeDropTarget(final Tree tree) {
// DropTarget for tree
Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
int operations = DND.DROP_MOVE | DND.DROP_COPY;
DropTarget target = new DropTarget(tree, operations);
target.setTransfer(types);
target.addDropListener(new DropTargetAdapter() {
/**
* Drag item enter the tree items
*/
public void dragEnter(DropTargetEvent event) {
TreeItem[] selectedItems = tree.getSelection();
//do not support multi DROP_COPY
if (event.detail == DND.DROP_COPY && selectedItems.length > 1) {
event.detail = DND.DROP_NONE;
event.feedback = DND.FEEDBACK_NONE;
}
}
/**
* When drag operation change, check whether to support this operation
*/
public void dragOperationChanged(DropTargetEvent event) {
dragEnter(event);
}
/**
* Drag item over the tree items.
*/
public void dragOver(DropTargetEvent event) {
event.feedback = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL;
if (event.item == null) {
event.feedback = DND.FEEDBACK_NONE;
return;
}
//do not support multi DROP_COPY
TreeItem[] selectedItems = tree.getSelection();
if (event.detail == DND.DROP_COPY && selectedItems.length > 1) {
event.feedback = DND.FEEDBACK_NONE;
return;
}
//Target TreeItem
TreeItem targetTreeItem = (TreeItem) event.item;
ICubridNode data = (ICubridNode) targetTreeItem.getData();
if (dataSupportDragOver(data)) {
if (data instanceof CubridGroupNode) {
event.feedback |= DND.FEEDBACK_SELECT;
return;
}
//Convert drop coordinate from Display to Tree
Point pt = Display.getCurrent().map(null, tree, event.x, event.y);
Rectangle bounds = targetTreeItem.getBounds();
if (pt.y < (bounds.y + bounds.height / 2)) {
event.feedback |= DND.FEEDBACK_INSERT_BEFORE;
} else {
//if (pt.y > bounds.y + 2 * bounds.height / 3)
event.feedback |= DND.FEEDBACK_INSERT_AFTER;
}
} else {
event.feedback = DND.FEEDBACK_NONE;
}
}
public void drop(DropTargetEvent event) {
if (event.data == null) {
event.detail = DND.DROP_NONE;
return;
}
TreeItem[] selectedItems = tree.getSelection();
if (event.detail == DND.DROP_COPY && selectedItems.length > 1) {
event.detail = DND.DROP_NONE;
return;
}
final int dropOperation = event.detail;
ICubridNode dropNode = null;
boolean insertBefore = false;
if (event.item == null) {
List<CubridGroupNode> allGroup = getGroupNodeManager().getAllGroupNodes();
dropNode = allGroup.get(allGroup.size() - 1);
} else {
//Move under a TreeItem node
TreeItem dropItem = (TreeItem) event.item;
dropNode = (ICubridNode) dropItem.getData();
Point pt = Display.getCurrent().map(null, tree, event.x, event.y);
Rectangle bounds = dropItem.getBounds();
if (pt.y < bounds.y + bounds.height / 2) {
insertBefore = true;
}
}
CubridDnDNodeHandler handler = getCubridDnDNodeHandler();
boolean isSuccess = false;
if (insertBefore) {
for (TreeItem si : selectedItems) {
ICubridNode dragNode = (ICubridNode) si.getData();
isSuccess = handler.handle(dragNode, dropNode, insertBefore, dropOperation) || isSuccess;
}
} else {
for (int i = selectedItems.length - 1; i >= 0; i--) {
TreeItem si = selectedItems[i];
ICubridNode dragNode = (ICubridNode) si.getData();
isSuccess = handler.handle(dragNode, dropNode, insertBefore, dropOperation) || isSuccess;
}
}
if (isSuccess) {
Object[] objs = tv.getExpandedElements();
setTreeInput();
tv.setExpandedElements(objs);
}
}
});
}
use of org.eclipse.swt.dnd.DropTarget in project cubrid-manager by CUBRID.
the class UnifyHostConfigDialogDNDController method registerDropTarget.
/**
* register drag source and DB tree target
*/
public void registerDropTarget() {
synchronized (this) {
DropTarget target = new DropTarget(dialog.getTableComposite(), DND.DROP_MOVE);
target.setTransfer(new Transfer[] { TextTransfer.getInstance() });
target.addDropListener(new DropTargetAdapter() {
/**
* @see org.eclipse.swt.dnd.DropTargetAdapter#drop(org.eclipse.swt.dnd.DropTargetEvent)
* @param event the information associated with the drop event
*/
public void drop(DropTargetEvent event) {
addHost();
}
});
}
}
use of org.eclipse.swt.dnd.DropTarget in project tdi-studio-se by Talend.
the class DropTargetOperationListener method addControl.
/**
* DOC amaumont Comment method "addControl".
*
* @param outputTablesZoneView
*/
public void addControl(Control control) {
DropTarget dropTarget = new DropTarget(control, authorizedOperations);
dropTarget.setTransfer(authorizedTransfers);
dropTarget.addDropListener(dropTargetListener);
}
use of org.eclipse.swt.dnd.DropTarget in project tdi-studio-se by Talend.
the class SchemaXMLDragAndDropHandler method createDropTarget.
/**
*
* create DropTarget.
*/
private void createDropTarget() {
if (loopDropTarget != null) {
loopDropTarget.dispose();
}
loopDropTarget = new DropTarget(linker.getTarget(), DND.DROP_DEFAULT | DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK);
loopDropTarget.setTransfer(new Transfer[] { LocalDataTransfer.getInstance() });
DropTargetListener targetListener = new TableDropTargetListener();
loopDropTarget.addDropListener(targetListener);
}
use of org.eclipse.swt.dnd.DropTarget in project tdi-studio-se by Talend.
the class Schema2XMLDragAndDropHandler method createDropTarget.
/**
*
* create DropTarget.
*/
private void createDropTarget() {
if (loopDropTarget != null) {
loopDropTarget.dispose();
}
loopDropTarget = new DropTarget(linker.getTarget(), DND.DROP_DEFAULT | DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK);
loopDropTarget.setTransfer(new Transfer[] { LocalDataTransfer.getInstance() });
DropTargetListener targetListener = new TableDropTargetListener();
loopDropTarget.addDropListener(targetListener);
}
Aggregations