use of org.eclipse.swt.dnd.DropTarget in project tdi-studio-se by Talend.
the class DragDropManager method addDropSupport.
public void addDropSupport(final Control control, final IDragDropDelegate delegate) {
// Create the drop target
DropTarget dropTarget = new DropTarget(control, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT);
dropTarget.setTransfer(types);
dropTarget.addDropListener(new DropTargetAdapter() {
@Override
public void dragEnter(DropTargetEvent event) {
if (event.detail == DND.DROP_COPY && !delegate.isDropAllowed(currentSelectionText)) {
event.detail = DND.DROP_NONE;
return;
}
if (event.detail == DND.DROP_DEFAULT) {
event.detail = DND.DROP_MOVE;
}
// Allow dropping text only
for (int i = 0, n = event.dataTypes.length; i < n; i++) {
if (TextTransfer.getInstance().isSupportedType(event.dataTypes[i])) {
event.currentDataType = event.dataTypes[i];
}
}
}
@Override
public void dragLeave(DropTargetEvent event) {
event.detail = DND.DROP_NONE;
}
@Override
public void dragOver(DropTargetEvent event) {
event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
}
@Override
public void drop(DropTargetEvent event) {
if (!delegate.isDropAllowed(currentSelectionText)) {
event.detail = DND.DROP_NONE;
return;
}
if (TextTransfer.getInstance().isSupportedType(event.currentDataType)) {
// Get the dropped data
String data = (String) event.data;
Point point = new Point(event.x, event.y);
delegate.onDropItems(data, point);
dropped = true;
}
}
});
}
use of org.eclipse.swt.dnd.DropTarget in project tdi-studio-se by Talend.
the class SchemasTreeDnD method addDragAndDrop.
public void addDragAndDrop() {
// drag
DragSource source = new DragSource(getTree(), operations);
source.setTransfer(transferTypes);
source.addDragListener(new TreeDragSourceEffect(getTree()));
// drop
DropTarget target = new DropTarget(getTree(), operations);
target.setTransfer(transferTypes);
target.addDropListener(new TreeDropTargetEffect(getTree()) {
private SchemasKeyData source;
@Override
public void dragEnter(DropTargetEvent event) {
super.dragEnter(event);
Widget item = event.item;
if (item != null) {
TreeItem treeItem = (TreeItem) event.item;
Object data = treeItem.getData();
if (data != null && data instanceof SchemasKeyData) {
this.source = (SchemasKeyData) data;
event.feedback = DND.FEEDBACK_EXPAND;
return;
}
}
event.detail = DND.DROP_NONE;
}
@Override
public void drop(DropTargetEvent event) {
super.drop(event);
if (event.item != null && source != null) {
TreeItem item = (TreeItem) event.item;
Object data = item.getData();
if (data != null && data instanceof SchemasKeyData) {
SchemasKeyData target = (SchemasKeyData) data;
target.addChild(source);
schemaTreeViewer.refresh();
}
}
source = null;
}
});
}
use of org.eclipse.swt.dnd.DropTarget in project tdi-studio-se by Talend.
the class DragAndDropForWebService method createDropTarget.
/**
*
* create DropTarget.
*/
private void createDropTarget(DropTargetListener targetListener) {
if (dropTarget != null) {
dropTarget.dispose();
}
dropTarget = new DropTarget(draggableControl, DND.DROP_DEFAULT | DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK);
dropTarget.setTransfer(new Transfer[] { TableEntriesTransfer.getInstance() });
dropTarget.addDropListener(targetListener);
}
use of org.eclipse.swt.dnd.DropTarget in project cubrid-manager by CUBRID.
the class RunSQLFileDialogDNDController method registerDropTarget.
/**
* register drag source and DB tree target
*/
public void registerDropTarget() {
synchronized (this) {
DropTarget target = new DropTarget(dialog.getDatabaseTableComp(), 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) {
addDatabase();
}
});
}
}
use of org.eclipse.swt.dnd.DropTarget in project cubrid-manager by CUBRID.
the class ERDNDController method registerDropTarget.
public void registerDropTarget() {
synchronized (this) {
DropTarget dropTt = new DropTarget(editor.getGraphicalControl(), DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK);
dropTt.setTransfer(new Transfer[] { TextTransfer.getInstance() });
dropTt.addDropListener(new DropTargetAdapter() {
@Override
public void drop(DropTargetEvent event) {
int scrolledH = editor.getVerticalScrollHeight();
int scrolledW = editor.getHorizontalScrollWidth();
List<SchemaInfo> schemaInfoList = getSelectedSchemaInfos();
// this event x, y is full screen's
int erdXPoint = event.x - getAppXPoint() - getNavigatorPaneWidth() - 15;
int erdYPoint = event.y - getAppYPoint() - 160;
// 160 is the distance between ERD canvas top and the CM/CQB
// app top
addTables(schemaInfoList, erdXPoint + scrolledW, erdYPoint + scrolledH);
}
});
}
}
Aggregations