use of org.eclipse.swt.dnd.DropTarget in project cubrid-manager by CUBRID.
the class MultiDBQueryDNDController method registerDropTarget.
/**
* register drag source and DB tree target
*/
public void registerDropTarget() {
synchronized (this) {
DropTarget target = new DropTarget(multiDBQueryComposite, 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) {
setTreeSelectedItems();
}
});
}
}
use of org.eclipse.swt.dnd.DropTarget in project cubrid-manager by CUBRID.
the class QueryEditorDNDController method registerDropTarget.
/**
* register drag source and text editor target
*
* @param combinedQueryComposite CombinedQueryEditorComposite
*/
public void registerDropTarget(CombinedQueryEditorComposite combinedQueryComposite) {
synchronized (this) {
DropTarget sqlTarget = new DropTarget(combinedQueryComposite.getSqlEditorComp().getText(), DND.DROP_MOVE);
sqlTarget.setTransfer(new Transfer[] { TextTransfer.getInstance() });
sqlTarget.addDropListener(new DropTargetAdapter() {
public void drop(DropTargetEvent event) {
replaceSql();
}
});
}
}
use of org.eclipse.swt.dnd.DropTarget in project cogtool by cogtool.
the class ProjectUI method setUpDragAndDrop.
// See http://www.eclipse.org/articles/Article-SWT-DND/DND-in-SWT.html
// for more documentation of SWT drag-and-drop support.
protected void setUpDragAndDrop() {
DragSource treeAsSource = new DragSource(tree, DND.DROP_MOVE | DND.DROP_COPY);
TaskDnDTransfer taskTransfer = TaskDnDTransfer.getInstance();
TaskAppDnDTransfer taskAppTransfer = TaskAppDnDTransfer.getInstance();
Transfer[] types = new Transfer[] { taskTransfer, taskAppTransfer };
treeAsSource.setTransfer(types);
// DropSourceEvent fields:
// dataType:
// the Transfer type of the data the target prefers to receive;
// useful in dragSetData
// detail:
// the operation the target performed; one of:
// DROP_MOVE - move from source to target; remove from source
// DROP_COPY - copy the source to target; leave the source
// DROP_LINK - create a link of the source at the target
// useful in dragFinished in case the source needs to be removed
// doit:
// in dragStart, determines if the operation should proceed
// in dragFinished, may be set to indicate if the operation succeeded
// image:
// may be set to the Image displayed during drag
// x, y: position within the Tree
DragSourceListener srcListener = new TreeDragSourceEffect(tree) {
@Override
public void dragStart(DragSourceEvent evt) {
// If the Transfer type cannot be determined until the drag
// starts, the setTransfer() call can be invoked here.
// Set evt.doit to false here if action is inappropriate.
// Reset, just in case no drag-and-drop should happen
currentDnDSource = null;
// Must be in first column!
TreeColumn column = findColumn(evt.x);
TreeItem row = tree.getItem(new Point(evt.x, evt.y));
if ((column != null) && (column.getData() == null)) {
if ((row != null) && (row.getData() != null)) {
if (((AUndertaking) row.getData()).isSpawned()) {
evt.doit = false;
return;
}
}
if (selection.getSelectedTaskCount() == 0) {
if (row != null) {
selection.setSelectedItem(row);
currentDnDSource = tree;
currentDnDColumn = 0;
}
} else {
currentDnDSource = tree;
currentDnDColumn = 0;
}
} else {
// Must be in cell with a valid TaskApplication!
if ((column != null) && (column.getData() != null)) {
if ((row != null) && (row.getData() != null)) {
Design design = (Design) column.getData();
AUndertaking task = (AUndertaking) row.getData();
TaskApplication taskApp = project.getTaskApplication(task, design);
if (taskApp != null) {
if (!taskApp.getDemonstration().isEditable()) {
evt.doit = false;
return;
}
// set some highlighting of the source cell
selection.setSelectedCell(row, column);
contextSelection.setSelectedDesign(design);
contextSelection.addSelectedTask(task);
currentDnDRow = row;
currentDnDSource = tree;
currentDnDColumn = tree.indexOf(column);
// do not do superclass work!
return;
}
}
}
evt.doit = false;
}
super.dragStart(evt);
}
@Override
public void dragSetData(DragSourceEvent evt) {
// Based on the requested Transfer data type, set evt.data
// if (taskTransfer.isSupportedType(evt.dataType)) {
// evt.data = "This is the requested data";
// }
super.dragSetData(evt);
}
@Override
public void dragFinished(DragSourceEvent evt) {
// Operation was performed by the drop target; clean up
// If needed, evt.detail should be the operation performed.
super.dragFinished(evt);
currentDnDSource = null;
currentDnDColumn = -1;
currentDnDRow = null;
currentDndTaskAppDropRow = null;
}
};
treeAsSource.addDragListener(srcListener);
DropTarget treeAsTarget = new DropTarget(tree, DND.DROP_MOVE | DND.DROP_COPY);
treeAsTarget.setTransfer(types);
// DropTargetEvent fields:
// currentDataType:
// the Transfer type of the data the target prefers to receive;
// can be set -- see the method comments below
// dataTypes:
// the array of Transfer types the source can "send"
// detail:
// the operation the user is trying to perform; one of:
// DROP_MOVE - move from source to target; remove from source
// DROP_COPY - copy the source to target; leave the source
// DROP_LINK - create a link of the source at the target
// DROP_DEFAULT - indicator that target must choose operation
// DROP_NONE - indicator that user is trying an unsupported op
// may be set to the operation the target feels is correct
// (thus, if initially DEFAULT, then the operation that would be
// performed; if initially DEFAULT and not changed, it will appear
// to the user as a MOVE -- also, set to NONE if target determines
// operation is not permitted)
// feedback:
// bitwise OR'ing of feedback effects displayed to the user;
// can be set using the following constants:
// FEEDBACK_SELECT - item under cursor is selected
// FEEDBACK_SCROLL - allows scrolling to make items visible
// FEEDBACK_EXPAND - allows tree items to be expanded
// FEEDBACK_INSERT_BEFORE - insertion mark before item under cursor
// FEEDBACK_INSERT_AFTER - insertion mark after item under cursor
// FEEDBACK_NONE - no feedback
// item:
// TreeItem or TableItem under the cursor, if applicable
// operations:
// bitwise OR'ing of the operations that the DragSource can support
treeAsTarget.addDropListener(new TreeDropTargetEffect(tree) {
protected static final int DRAG_FEEDBACK = DND.FEEDBACK_EXPAND | DND.FEEDBACK_INSERT_BEFORE | DND.FEEDBACK_SCROLL;
protected static final int DRAG_APP_FEEDBACK = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL;
protected int requestedOp = DND.DROP_MOVE;
@Override
public void dragEnter(DropTargetEvent evt) {
// Set evt.detail to DND.DROP_NONE when the operation is a no-op
// or if the presented type is unacceptable. Other choices
// that make sense: DND.DROP_MOVE, DND.DROP_COPY
// evt.currentDataType is the type preferred by the target.
// evt.dataTypes contains types provided by the source.
super.dragEnter(evt);
if (currentDnDSource != getControl()) {
evt.detail = DND.DROP_NONE;
} else {
requestedOp = evt.detail;
}
}
@Override
public void dragLeave(DropTargetEvent evt) {
if (currentDndTaskAppDropRow != null) {
currentDndTaskAppDropRow.setBackground(currentDnDColumn, ProjectUIModel.unselectedTaskBackgroundColor);
}
super.dragLeave(evt);
}
@Override
public void dragOperationChanged(DropTargetEvent evt) {
// change evt.currentDataType if desired here.
if ((evt.detail != DND.DROP_MOVE) && (evt.detail != DND.DROP_COPY)) {
evt.detail = DND.DROP_NONE;
}
requestedOp = evt.detail;
super.dragOperationChanged(evt);
}
@Override
public void dragOver(DropTargetEvent evt) {
if (currentDndTaskAppDropRow != null) {
currentDndTaskAppDropRow.setBackground(currentDnDColumn, ProjectUIModel.unselectedTaskBackgroundColor);
}
Point toTreeEvtLoc = tree.toControl(evt.x, evt.y);
//System.out.println("dragOver; set feedback here?");
if (currentDnDSource != getControl()) {
evt.detail = DND.DROP_NONE;
evt.feedback = DND.FEEDBACK_NONE;
} else if (currentDnDColumn == 0) {
// Moving tasks
evt.feedback = DRAG_FEEDBACK;
evt.detail = requestedOp;
TreeItem row = tree.getItem(toTreeEvtLoc);
if ((row != null) && (row.getData() != null)) {
if (((AUndertaking) row.getData()).isSpawned()) {
evt.detail = DND.DROP_NONE;
evt.feedback = DND.FEEDBACK_NONE;
}
}
} else {
// Moving task applications
evt.feedback = DRAG_APP_FEEDBACK;
TreeColumn column = findColumn(toTreeEvtLoc.x);
if (column == null) {
evt.detail = DND.DROP_NONE;
} else {
Design design = (Design) column.getData();
if (design != contextSelection.getSelectedDesign()) {
evt.detail = DND.DROP_NONE;
} else {
TreeItem row = tree.getItem(toTreeEvtLoc);
if ((row == null) || (row.getData() == null)) {
evt.detail = DND.DROP_NONE;
} else {
AUndertaking task = (AUndertaking) row.getData();
if (task.isTaskGroup() || task.isSpawned() || contextSelection.isTaskSelected(task)) {
evt.detail = DND.DROP_NONE;
} else {
evt.detail = requestedOp;
currentDndTaskAppDropRow = row;
currentDndTaskAppDropRow.setBackground(currentDnDColumn, CONTEXT_COLOR);
}
}
}
}
}
super.dragOver(evt);
}
@Override
public void dropAccept(DropTargetEvent evt) {
// Can change evt.detail if desired here.
// Provide one last chance to define the type of data that
// will be returned in the drop event; thus, change
// evt.currentDataType if desired here
super.dropAccept(evt);
}
@Override
public void drop(DropTargetEvent evt) {
// When the drop operation is completed, update the
// evt.detail field with the operation performed.
// Do the operation!
AUndertaking beforeTask = null;
if (evt.item != null) {
beforeTask = (AUndertaking) evt.item.getData();
}
if (requestedOp == DND.DROP_COPY) {
if (currentDnDColumn == 0) {
ProjectUI.ChangeTaskPositionParms parms = new ProjectUI.ChangeTaskPositionParms(selection, beforeTask, true);
if (performAction(ProjectLID.DuplicateTaskFull, parms, true)) {
evt.detail = DND.DROP_COPY;
}
} else {
AUndertaking fromTask = (AUndertaking) currentDnDRow.getData();
AUndertaking toTask = (AUndertaking) currentDndTaskAppDropRow.getData();
TreeColumn column = tree.getColumn(currentDnDColumn);
Design design = (Design) column.getData();
ProjectUI.MoveCopyTaskApplicationParms parms = new ProjectUI.MoveCopyTaskApplicationParms(fromTask, toTask, design);
selection.setSelectedCell(currentDndTaskAppDropRow, column);
if (performAction(ProjectLID.DuplicateTaskApplication, parms, true)) {
uiModel.redisplayAllResults();
evt.detail = DND.DROP_COPY;
}
}
} else if (requestedOp == DND.DROP_MOVE) {
if (currentDnDColumn == 0) {
ProjectUI.ChangeTaskPositionParms parms = new ProjectUI.ChangeTaskPositionParms(selection, beforeTask, false);
if (performAction(ProjectLID.ChangeTaskPosition, parms, true)) {
evt.detail = DND.DROP_MOVE;
}
} else {
AUndertaking fromTask = (AUndertaking) currentDnDRow.getData();
AUndertaking toTask = (AUndertaking) currentDndTaskAppDropRow.getData();
TreeColumn column = tree.getColumn(currentDnDColumn);
Design design = (Design) column.getData();
ProjectUI.MoveCopyTaskApplicationParms parms = new ProjectUI.MoveCopyTaskApplicationParms(fromTask, toTask, design);
selection.setSelectedCell(currentDndTaskAppDropRow, column);
if (performAction(ProjectLID.MoveTaskApplication, parms, true)) {
uiModel.redisplayAllResults();
evt.detail = DND.DROP_MOVE;
}
}
}
super.drop(evt);
}
});
}
use of org.eclipse.swt.dnd.DropTarget in project cubrid-manager by CUBRID.
the class QueryEditorDNDController method addTableDropTarget.
/**
* register result table target, connect drag target with drag source
*
* @param table Table
*/
public void addTableDropTarget(Table table) {
DropTarget resultTarget = new DropTarget(table, DND.DROP_MOVE);
resultTarget.setTransfer(new Transfer[] { TextTransfer.getInstance() });
resultTarget.addDropListener(new DropTargetAdapter() {
public void drop(DropTargetEvent event) {
boolean isSuccess = replaceSql();
if (isSuccess) {
editor.getRunItem().notifyListeners(SWT.Selection, new Event());
}
}
});
}
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);
}
}
});
}
Aggregations