use of org.eclipse.wst.xml.ui.internal.dnd.DragNodeCommand in project webtools.sourceediting by eclipse.
the class XMLTableTreeViewer method createDropTargetListener.
private DropTargetListener createDropTargetListener() {
return new DropTargetListener() {
public void dragEnter(DropTargetEvent event) {
}
public void dragLeave(DropTargetEvent event) {
}
public void dragOperationChanged(DropTargetEvent event) {
}
public void drop(DropTargetEvent event) {
if (event.operations != DND.DROP_NONE && LocalSelectionTransfer.getTransfer().getSelection() instanceof IStructuredSelection) {
dragOver(event);
IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
if (selection != null && !selection.isEmpty() && event.item != null && event.item.getData() != null) {
/*
* the command uses these numbers instead of the
* feedback constants (even though it converts in
* the other direction as well)
*/
float feedbackFloat = getHeightInItem(event);
final DragNodeCommand command = new DragNodeCommand(event.item.getData(), feedbackFloat, event.operations, event.detail, selection.toList(), XMLTableTreeViewer.this);
if (command != null && command.canExecute()) {
SafeRunnable.run(new SafeRunnable() {
public void run() throws Exception {
command.execute();
}
});
}
}
}
}
public void dropAccept(DropTargetEvent event) {
}
public void dragOver(DropTargetEvent event) {
event.feedback = DND.FEEDBACK_SELECT;
float feedbackFloat = getHeightInItem(event);
if (feedbackFloat > 0.75) {
event.feedback = DND.FEEDBACK_INSERT_AFTER;
} else if (feedbackFloat < 0.25) {
event.feedback = DND.FEEDBACK_INSERT_BEFORE;
}
event.feedback |= DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL;
if (getLocalNodeSelection(event) == null) {
event.detail = DND.DROP_NONE;
}
}
private IStructuredSelection getLocalNodeSelection(DropTargetEvent event) {
IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
if (selection != null && !selection.isEmpty()) {
for (Iterator i = selection.iterator(); i.hasNext(); ) {
Object node = i.next();
if (node instanceof Node) {
return selection;
}
}
}
return null;
}
private float getHeightInItem(DropTargetEvent event) {
if (event.item == null)
return .5f;
if (event.item instanceof TreeItem) {
TreeItem treeItem = (TreeItem) event.item;
Control control = treeItem.getParent();
Point point = control.toControl(new Point(event.x, event.y));
Rectangle bounds = treeItem.getBounds();
return (float) (point.y - bounds.y) / (float) bounds.height;
} else if (event.item instanceof TableItem) {
TableItem tableItem = (TableItem) event.item;
Control control = tableItem.getParent();
Point point = control.toControl(new Point(event.x, event.y));
Rectangle bounds = tableItem.getBounds(0);
return (float) (point.y - bounds.y) / (float) bounds.height;
} else {
return 0.0F;
}
}
};
}
use of org.eclipse.wst.xml.ui.internal.dnd.DragNodeCommand in project webtools.sourceediting by eclipse.
the class AbstractXMLContentOutlineConfiguration method getTransferDropTargetListeners.
/*
* (non-Javadoc)
*
* @see org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration#getTransferDropTargetListeners(org.eclipse.jface.viewers.TreeViewer)
*/
public TransferDropTargetListener[] getTransferDropTargetListeners(final TreeViewer treeViewer) {
if (fTransferDropTargetListeners == null) {
fTransferDropTargetListeners = new TransferDropTargetListener[] { new TransferDropTargetListener() {
public void dragEnter(DropTargetEvent event) {
}
public void dragLeave(DropTargetEvent event) {
}
public void dragOperationChanged(DropTargetEvent event) {
}
public void dragOver(DropTargetEvent event) {
event.feedback = DND.FEEDBACK_SELECT;
float feedbackFloat = getHeightInItem(event);
if (feedbackFloat > 0.75) {
event.feedback = DND.FEEDBACK_INSERT_AFTER;
} else if (feedbackFloat < 0.25) {
event.feedback = DND.FEEDBACK_INSERT_BEFORE;
}
event.feedback |= DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL;
}
public void drop(DropTargetEvent event) {
if (event.operations != DND.DROP_NONE && LocalSelectionTransfer.getTransfer().getSelection() != null && !LocalSelectionTransfer.getTransfer().getSelection().isEmpty()) {
IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
if (selection != null && !selection.isEmpty() && event.item != null && event.item.getData() != null) {
/*
* the command uses these numbers instead of the
* feedback constants (even though it converts in
* the other direction as well)
*/
float feedbackFloat = getHeightInItem(event);
final DragNodeCommand command = new DragNodeCommand(event.item.getData(), feedbackFloat, event.operations, event.detail, selection.toList(), treeViewer);
if (command != null && command.canExecute()) {
SafeRunnable.run(new SafeRunnable() {
public void run() throws Exception {
command.execute();
}
});
}
}
}
}
public void dropAccept(DropTargetEvent event) {
}
private float getHeightInItem(DropTargetEvent event) {
if (event.item == null)
return .5f;
if (event.item instanceof TreeItem) {
TreeItem treeItem = (TreeItem) event.item;
Control control = treeItem.getParent();
Point point = control.toControl(new Point(event.x, event.y));
Rectangle bounds = treeItem.getBounds();
return (float) (point.y - bounds.y) / (float) bounds.height;
} else if (event.item instanceof TableItem) {
TableItem tableItem = (TableItem) event.item;
Control control = tableItem.getParent();
Point point = control.toControl(new Point(event.x, event.y));
Rectangle bounds = tableItem.getBounds(0);
return (float) (point.y - bounds.y) / (float) bounds.height;
} else {
return 0.0F;
}
}
public Transfer getTransfer() {
return LocalSelectionTransfer.getTransfer();
}
public boolean isEnabled(DropTargetEvent event) {
return getTransfer().isSupportedType(event.currentDataType);
}
} };
}
return fTransferDropTargetListeners;
}
Aggregations