use of org.eclipse.swt.dnd.DragSourceListener in project pentaho-kettle by pentaho.
the class RepositoryExplorerDialog method open.
public RepositoryObjectReference open() {
debug = "opening repository explorer";
try {
debug = "open new independent shell";
Shell parent = getParent();
Display display = parent.getDisplay();
shell = new Shell(display, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
props.setLook(shell);
shell.setImage(GUIResource.getInstance().getImageFolderConnections());
shell.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Title") + rep.getName() + "]");
FormLayout formLayout = new FormLayout();
formLayout.marginWidth = Const.FORM_MARGIN;
formLayout.marginHeight = Const.FORM_MARGIN;
shell.setLayout(formLayout);
// Add a small toolbar to expand/collapse all items
//
ToolBar treeTb = new ToolBar(shell, SWT.HORIZONTAL | SWT.FLAT);
props.setLook(treeTb);
fdTreeTb = new FormData();
fdTreeTb.left = new FormAttachment(0, 0);
fdTreeTb.top = new FormAttachment(0, 0);
treeTb.setLayoutData(fdTreeTb);
// Add the items...
//
exportToXML = new ToolItem(treeTb, SWT.PUSH);
exportToXML.setImage(GUIResource.getInstance().getImageExport());
exportToXML.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ExportToXML.Label"));
exportToXML.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ExportToXML.Tooltip"));
importFromXML = new ToolItem(treeTb, SWT.PUSH);
importFromXML.setImage(GUIResource.getInstance().getImageImport());
importFromXML.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ImportFromXML.Label"));
importFromXML.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ImportFromXML.Tooltip"));
new ToolItem(treeTb, SWT.SEPARATOR);
showHideDeleted = new ToolItem(treeTb, SWT.PUSH);
showHideDeleted.setImage(GUIResource.getInstance().getImageShowDeleted());
showHideDeleted.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ShowDeleted.Label"));
showHideDeleted.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ShowDeleted.Tooltip"));
showHideDeleted.setEnabled(rep.getRepositoryMeta().getRepositoryCapabilities().supportsRevisions());
new ToolItem(treeTb, SWT.SEPARATOR);
expandAll = new ToolItem(treeTb, SWT.PUSH);
expandAll.setImage(GUIResource.getInstance().getImageExpandAll());
expandAll.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ExpandAll.Label"));
expandAll.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ExpandAll.Tooltip"));
collapseAll = new ToolItem(treeTb, SWT.PUSH);
collapseAll.setImage(GUIResource.getInstance().getImageCollapseAll());
collapseAll.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.CollapseAll.Label"));
collapseAll.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.CollapseAll.Tooltip"));
// Tree
wTree = new Tree(shell, SWT.MULTI | SWT.BORDER);
wTree.setHeaderVisible(true);
props.setLook(wTree);
// Add some columns to it as well...
nameColumn = new TreeColumn(wTree, SWT.LEFT);
nameColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.Name"));
nameColumn.setWidth(350);
nameColumn.setAlignment(10);
nameColumn.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
setSort(0);
}
});
// No sorting on the type column just yet.
typeColumn = new TreeColumn(wTree, SWT.LEFT);
typeColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.Type"));
typeColumn.setWidth(100);
typeColumn.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
setSort(1);
}
});
userColumn = new TreeColumn(wTree, SWT.LEFT);
userColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.User"));
userColumn.setWidth(100);
userColumn.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
setSort(2);
}
});
changedColumn = new TreeColumn(wTree, SWT.LEFT);
changedColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.Changed"));
changedColumn.setWidth(120);
changedColumn.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
setSort(3);
}
});
descriptionColumn = new TreeColumn(wTree, SWT.LEFT);
descriptionColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.Description"));
descriptionColumn.setWidth(120);
descriptionColumn.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
setSort(4);
}
});
lockColumn = new TreeColumn(wTree, SWT.LEFT);
lockColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.LockMessage"));
lockColumn.setWidth(120);
lockColumn.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
setSort(5);
}
});
// Add a memory to the tree.
TreeMemory.addTreeListener(wTree, STRING_REPOSITORY_EXPLORER_TREE_NAME);
// Buttons
wOK = new Button(shell, SWT.PUSH);
wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
FormData fdTree = new FormData();
int margin = 10;
// To the right of the label
fdTree.left = new FormAttachment(0, 0);
fdTree.top = new FormAttachment(treeTb, 0);
fdTree.right = new FormAttachment(100, 0);
fdTree.bottom = new FormAttachment(100, -50);
wTree.setLayoutData(fdTree);
BaseStepDialog.positionBottomButtons(shell, new Button[] { wOK }, margin, null);
// Add listeners
wOK.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
close();
}
});
wTree.addMenuDetectListener(new MenuDetectListener() {
@Override
public void menuDetected(MenuDetectEvent e) {
setTreeMenu();
}
});
wTree.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
if (e.button == 1) {
// left double click!
doDoubleClick();
}
}
});
wTree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
// F2 --> rename...
if (e.keyCode == SWT.F2) {
if (!readonly) {
renameInTree();
}
}
// F5 --> refresh...
if (e.keyCode == SWT.F5) {
refreshTree();
}
}
});
expandAll.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
expandAllItems(wTree.getItems(), true);
}
});
collapseAll.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
expandAllItems(wTree.getItems(), false);
}
});
importFromXML.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
importAll();
}
});
exportToXML.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
exportAll(null);
}
});
showHideDeleted.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
includeDeleted = !includeDeleted;
if (includeDeleted) {
showHideDeleted.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.HideDeleted.Label"));
showHideDeleted.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.HideDeleted.Tooltip"));
} else {
showHideDeleted.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ShowDeleted.Label"));
showHideDeleted.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ShowDeleted.Tooltip"));
}
refreshTree();
}
});
// Drag & Drop
Transfer[] ttypes = new Transfer[] { TextTransfer.getInstance() };
DragSource ddSource = new DragSource(wTree, DND.DROP_MOVE);
ddSource.setTransfer(ttypes);
ddSource.addDragListener(new DragSourceListener() {
@Override
public void dragStart(DragSourceEvent event) {
debug = "drag start";
event.doit = true;
}
@Override
public void dragSetData(DragSourceEvent event) {
debug = "drag set data";
event.data = "";
event.doit = false;
TreeItem[] ti = wTree.getSelection();
if (ti.length >= 1) {
int cat = getItemCategory(ti[0]);
//
if (cat == ITEM_CATEGORY_TRANSFORMATION) {
debug = "drag set: drag around transformation";
RepositoryDirectoryInterface repdir = getDirectory(ti[0]);
if (repdir != null) {
//
// Pass info as a piece of XML
//
String xml = XMLHandler.getXMLHeader();
xml += "<dragdrop>" + Const.CR;
xml += " " + XMLHandler.addTagValue("directory", repdir.getPath());
xml += " " + XMLHandler.addTagValue("transformation", ti[0].getText());
xml += "</dragdrop>" + Const.CR;
event.data = xml;
event.doit = true;
}
} else if (cat == ITEM_CATEGORY_JOB) {
debug = "drag set: drag around job";
RepositoryDirectoryInterface repdir = getDirectory(ti[0]);
if (repdir != null) {
//
// Pass info as a piece of XML
//
String xml = XMLHandler.getXMLHeader();
xml += "<dragdrop>" + Const.CR;
xml += " " + XMLHandler.addTagValue("directory", repdir.getPath());
xml += " " + XMLHandler.addTagValue("job", ti[0].getText());
xml += "</dragdrop>" + Const.CR;
event.data = xml;
event.doit = true;
}
} else {
debug = "do nothing";
String xml = XMLHandler.getXMLHeader();
xml += "<dragdrop>" + Const.CR;
xml += "</dragdrop>" + Const.CR;
event.data = xml;
event.doit = true;
}
}
}
@Override
public void dragFinished(DragSourceEvent event) {
}
});
DropTarget ddTarget = new DropTarget(wTree, DND.DROP_MOVE);
ddTarget.setTransfer(ttypes);
ddTarget.addDropListener(new DropTargetListener() {
@Override
public void dragEnter(DropTargetEvent event) {
}
@Override
public void dragLeave(DropTargetEvent event) {
debug = "drag leave";
}
@Override
public void dragOperationChanged(DropTargetEvent event) {
}
@Override
public void dragOver(DropTargetEvent event) {
debug = "drag over";
}
@Override
public void drop(DropTargetEvent event) {
try {
debug = "Drop item in tree";
if (event.data == null) {
// no data to copy, indicate failure in event.detail
event.detail = DND.DROP_NONE;
return;
}
// event.feedback = DND.FEEDBACK_NONE;
TreeItem ti = (TreeItem) event.item;
if (ti != null) {
debug = "Get category";
int category = getItemCategory(ti);
if (category == ITEM_CATEGORY_TRANSFORMATION_DIRECTORY || category == ITEM_CATEGORY_TRANSFORMATION) {
debug = "Get directory";
RepositoryDirectoryInterface repdir = getDirectory(ti);
if (repdir != null) {
event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
if (moveTransformation((String) event.data, repdir)) {
refreshTree();
} else {
MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Move.UnableToMove.Message"));
mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Move.UnableToMove.Title"));
mb.open();
}
}
} else if (category == ITEM_CATEGORY_JOB_DIRECTORY || category == ITEM_CATEGORY_JOB) {
debug = "Get directory";
RepositoryDirectoryInterface repdir = getDirectory(ti);
if (repdir != null) {
event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
if (moveJob((String) event.data, repdir)) {
refreshTree();
} else {
MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Job.Move.UnableToMove.Message"));
mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Job.Move.UnableToMove.Title"));
mb.open();
}
}
} else {
MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Move.SorryOneItemAtATime.Message"));
mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Move.SorryOneItemAtATime.Title"));
mb.open();
}
}
} catch (Throwable e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Drop.UnexpectedError.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Drop.UnexpectedError.Message1") + debug + "]" + Const.CR + BaseMessages.getString(PKG, "RepositoryExplorerDialog.Drop.UnexpectedError.Message2"), e);
}
}
@Override
public void dropAccept(DropTargetEvent event) {
debug = "drop accept";
}
});
// Detect X or ALT-F4 or something that kills this window...
shell.addShellListener(new ShellAdapter() {
@Override
public void shellClosed(ShellEvent e) {
close();
}
});
debug = "set screen size and position";
BaseStepDialog.setSize(shell, 400, 480, true);
// refreshes too.
setSort(0);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
} catch (Throwable e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Main.UnexpectedError.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Main.UnexpectedError.Message1") + debug + "]" + Const.CR + BaseMessages.getString(PKG, "RepositoryExplorerDialog.Main.UnexpectedError.Message2") + Const.CR + BaseMessages.getString(PKG, "RepositoryExplorerDialog.Main.UnexpectedError.Message3"), e);
}
return lastOpened;
}
use of org.eclipse.swt.dnd.DragSourceListener in project pentaho-kettle by pentaho.
the class SpoonTreeDelegate method addDragSourceToTree.
public void addDragSourceToTree(final Tree tree, final Tree selectionTree, final Tree coreObjectsTree) {
// Drag & Drop for steps
Transfer[] ttypes = new Transfer[] { XMLTransfer.getInstance() };
DragSource ddSource = new DragSource(tree, DND.DROP_MOVE);
ddSource.setTransfer(ttypes);
ddSource.addDragListener(new DragSourceListener() {
public void dragStart(DragSourceEvent event) {
TreeSelection[] treeObjects = getTreeObjects(tree, selectionTree, coreObjectsTree);
if (treeObjects.length == 0) {
event.doit = false;
return;
}
spoon.hideToolTips();
TreeSelection treeObject = treeObjects[0];
Object object = treeObject.getSelection();
TransMeta transMeta = spoon.getActiveTransformation();
if (object instanceof StepMeta || object instanceof PluginInterface || (object instanceof DatabaseMeta && transMeta != null) || object instanceof TransHopMeta || object instanceof JobEntryCopy) {
event.doit = true;
} else {
event.doit = false;
}
}
public void dragSetData(DragSourceEvent event) {
TreeSelection[] treeObjects = getTreeObjects(tree, selectionTree, coreObjectsTree);
if (treeObjects.length == 0) {
event.doit = false;
return;
}
int type = 0;
String id = null;
String data = null;
TreeSelection treeObject = treeObjects[0];
Object object = treeObject.getSelection();
if (object instanceof StepMeta) {
StepMeta stepMeta = (StepMeta) object;
type = DragAndDropContainer.TYPE_STEP;
// name of the step.
data = stepMeta.getName();
} else if (object instanceof PluginInterface) {
PluginInterface plugin = (PluginInterface) object;
Class<? extends PluginTypeInterface> pluginType = plugin.getPluginType();
if (Const.classIsOrExtends(pluginType, StepPluginType.class)) {
type = DragAndDropContainer.TYPE_BASE_STEP_TYPE;
id = plugin.getIds()[0];
// Step type name
data = plugin.getName();
} else {
type = DragAndDropContainer.TYPE_BASE_JOB_ENTRY;
// job entry type name
data = plugin.getName();
if (treeObject.getItemText().equals(JobMeta.createStartEntry().getName())) {
data = treeObject.getItemText();
} else if (treeObject.getItemText().equals(JobMeta.createDummyEntry().getName())) {
data = treeObject.getItemText();
}
}
} else if (object instanceof DatabaseMeta) {
DatabaseMeta databaseMeta = (DatabaseMeta) object;
type = DragAndDropContainer.TYPE_DATABASE_CONNECTION;
data = databaseMeta.getName();
} else if (object instanceof TransHopMeta) {
TransHopMeta hop = (TransHopMeta) object;
type = DragAndDropContainer.TYPE_TRANS_HOP;
// nothing for really ;-)
data = hop.toString();
} else if (object instanceof JobEntryCopy) {
JobEntryCopy jobEntryCopy = (JobEntryCopy) object;
type = DragAndDropContainer.TYPE_JOB_ENTRY;
// name of the job entry.
data = jobEntryCopy.getName();
} else {
event.doit = false;
// ignore anything else you drag.
return;
}
event.data = new DragAndDropContainer(type, data, id);
}
public void dragFinished(DragSourceEvent event) {
}
});
}
use of org.eclipse.swt.dnd.DragSourceListener in project tdq-studio-se by Talend.
the class AnalysisColumnNominalIntervalTreeViewer method addSourceDND.
/**
* DOC bZhou Comment method "addSourceDND".
*
* @param newTree
*/
private void addSourceDND(final Tree newTree) {
final LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
Transfer[] types = new Transfer[] { transfer };
int operations = DND.DROP_COPY | DND.DROP_MOVE;
final DragSource source = new DragSource(newTree, operations);
source.setTransfer(types);
final TreeItem[] dragSourceItem = new TreeItem[1];
source.addDragListener(new DragSourceListener() {
public void dragStart(DragSourceEvent event) {
TreeItem[] selection = newTree.getSelection();
dragSourceItem[0] = selection[0];
if (selection.length > 0) {
event.doit = true;
transfer.setSelection(new StructuredSelection(selection[0].getData(COLUMN_INDICATOR_KEY)));
getColumnSetMultiValueList().remove(selection[0].getData(COLUMN_INDICATOR_KEY));
} else {
event.doit = false;
}
}
public void dragSetData(DragSourceEvent event) {
event.data = dragSourceItem[0];
}
public void dragFinished(DragSourceEvent event) {
if (event.detail == DND.DROP_MOVE) {
removeItemBranch(dragSourceItem[0]);
tree.forceFocus();
}
dragSourceItem[0] = null;
}
});
}
use of org.eclipse.swt.dnd.DragSourceListener 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.DragSourceListener in project tdi-studio-se by Talend.
the class HL7Message2SchemaDragAndDropHandler method createDragSource.
private void createDragSource() {
if (dragSource != null) {
dragSource.dispose();
}
dragSource = new DragSource(linker.getTree(), DND.DROP_DEFAULT | DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK);
dragSource.setTransfer(new Transfer[] { SegmentTransfer.getInstance() });
DragSourceListener sourceListener = new TreeDragSourceListener();
dragSource.addDragListener(sourceListener);
}
Aggregations