use of org.eclipse.swt.dnd.DragSource in project tdi-studio-se by Talend.
the class DragDropManager method addDragSupport.
public void addDragSupport(final Control control, final IDragDropDelegate delegate) {
DragSource dragSource = new DragSource(control, DND.DROP_MOVE | DND.DROP_COPY);
dragSource.setTransfer(types);
dragSource.addDragListener(new DragSourceAdapter() {
@Override
public void dragStart(DragSourceEvent event) {
currentSelectionText = delegate.getDragItemsAsText();
dropped = false;
}
@Override
public void dragSetData(DragSourceEvent event) {
// Get the selected items in the drag source
event.data = currentSelectionText;
}
@Override
public void dragFinished(DragSourceEvent event) {
if (event.detail == DND.DROP_MOVE && dropped) {
// remove selection
delegate.removeDragItems(currentSelectionText);
}
}
});
}
use of org.eclipse.swt.dnd.DragSource in project cubrid-manager by CUBRID.
the class CubridNavigatorView method addDragDropSupport.
/**
* Add the drag drop support of tree.
*
* @param tree the tree need to drag and drop.
*/
protected void addDragDropSupport(final Tree tree) {
// Define 'Transfer Type', 'Operation'
Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
int operations = DND.DROP_MOVE | DND.DROP_COPY;
// DragSource
final DragSource source = new DragSource(tree, operations);
source.setTransfer(types);
source.addDragListener(new DragSourceListener() {
public void dragStart(DragSourceEvent event) {
event.doit = false;
if (!dataSupportDND(tree.getSelection())) {
return;
}
event.doit = true;
}
public void dragSetData(DragSourceEvent event) {
event.data = ((ICubridNode) tree.getSelection()[0].getData()).getLabel();
}
public void dragFinished(DragSourceEvent event) {
}
});
addTreeDropTarget(tree);
String perspectiveId = PerspectiveManager.getInstance().getCurrentPerspectiveId();
// DropTarget for query editor.
QueryEditorDNDController.registerDragSource(perspectiveId, tv);
// DropTarget for multiple query
MultiDBQueryDNDController.registerDragSource(perspectiveId, tv);
// DropTarget for Run SQL file
RunSQLFileDialogDNDController.registerDragSource(perspectiveId, tv);
//DropTarget for ERD
ERDNDController.registerDragSource(perspectiveId, tv);
}
use of org.eclipse.swt.dnd.DragSource in project eclipse.platform.swt by eclipse.
the class DNDExample method createDragSource.
private void createDragSource() {
if (dragSource != null)
dragSource.dispose();
dragSource = new DragSource(dragControl, dragOperation);
dragSource.setTransfer(dragTypes);
dragSource.addDragListener(new DragSourceListener() {
@Override
public void dragFinished(org.eclipse.swt.dnd.DragSourceEvent event) {
dragConsole.append(">>dragFinished\n");
printEvent(event);
dragDataText = dragDataRTF = dragDataHTML = dragDataURL = null;
dragDataFiles = null;
if (event.detail == DND.DROP_MOVE) {
switch(dragControlType) {
case BUTTON_CHECK:
case BUTTON_TOGGLE:
case BUTTON_RADIO:
{
Button b = (Button) dragControl;
b.setText("");
break;
}
case STYLED_TEXT:
{
StyledText text = (StyledText) dragControl;
text.insert("");
break;
}
case TABLE:
{
Table table = (Table) dragControl;
TableItem[] items = table.getSelection();
for (TableItem item : items) {
item.dispose();
}
break;
}
case TEXT:
{
Text text = (Text) dragControl;
text.insert("");
break;
}
case TREE:
{
Tree tree = (Tree) dragControl;
TreeItem[] items = tree.getSelection();
for (TreeItem item : items) {
item.dispose();
}
break;
}
case CANVAS:
{
dragControl.setData("STRINGS", null);
dragControl.redraw();
break;
}
case LABEL:
{
Label label = (Label) dragControl;
label.setText("");
break;
}
case LIST:
{
List list = (List) dragControl;
int[] indices = list.getSelectionIndices();
list.remove(indices);
break;
}
case COMBO:
{
Combo combo = (Combo) dragControl;
combo.setText("");
break;
}
}
}
}
@Override
public void dragSetData(org.eclipse.swt.dnd.DragSourceEvent event) {
dragConsole.append(">>dragSetData\n");
printEvent(event);
if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
event.data = dragDataText;
}
if (RTFTransfer.getInstance().isSupportedType(event.dataType)) {
event.data = dragDataRTF;
}
if (HTMLTransfer.getInstance().isSupportedType(event.dataType)) {
event.data = dragDataHTML;
}
if (URLTransfer.getInstance().isSupportedType(event.dataType)) {
event.data = dragDataURL;
}
if (FileTransfer.getInstance().isSupportedType(event.dataType)) {
event.data = dragDataFiles;
}
}
@Override
public void dragStart(org.eclipse.swt.dnd.DragSourceEvent event) {
dragConsole.append(">>dragStart\n");
printEvent(event);
dragDataFiles = fileList.getItems();
switch(dragControlType) {
case BUTTON_CHECK:
case BUTTON_TOGGLE:
case BUTTON_RADIO:
{
Button b = (Button) dragControl;
dragDataText = b.getSelection() ? "true" : "false";
break;
}
case STYLED_TEXT:
{
StyledText text = (StyledText) dragControl;
String s = text.getSelectionText();
if (s.length() == 0) {
event.doit = false;
} else {
dragDataText = s;
}
break;
}
case TABLE:
{
Table table = (Table) dragControl;
TableItem[] items = table.getSelection();
if (items.length == 0) {
event.doit = false;
} else {
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < items.length; i++) {
buffer.append(items[i].getText());
if (items.length > 1 && i < items.length - 1) {
buffer.append("\n");
}
}
dragDataText = buffer.toString();
}
break;
}
case TEXT:
{
Text text = (Text) dragControl;
String s = text.getSelectionText();
if (s.length() == 0) {
event.doit = false;
} else {
dragDataText = s;
}
break;
}
case TREE:
{
Tree tree = (Tree) dragControl;
TreeItem[] items = tree.getSelection();
if (items.length == 0) {
event.doit = false;
} else {
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < items.length; i++) {
buffer.append(items[i].getText());
if (items.length > 1 && i < items.length - 1) {
buffer.append("\n");
}
}
dragDataText = buffer.toString();
}
break;
}
case CANVAS:
{
String[] strings = (String[]) dragControl.getData("STRINGS");
if (strings == null || strings.length == 0) {
event.doit = false;
} else {
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < strings.length; i++) {
buffer.append(strings[i]);
if (strings.length > 1 && i < strings.length - 1) {
buffer.append("\n");
}
}
dragDataText = buffer.toString();
}
break;
}
case LABEL:
{
Label label = (Label) dragControl;
String string = label.getText();
if (string.length() == 0) {
event.doit = false;
} else {
dragDataText = string;
}
break;
}
case LIST:
{
List list = (List) dragControl;
String[] selection = list.getSelection();
if (selection.length == 0) {
event.doit = false;
} else {
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < selection.length; i++) {
buffer.append(selection[i]);
if (selection.length > 1 && i < selection.length - 1) {
buffer.append("\n");
}
}
dragDataText = buffer.toString();
}
break;
}
case COMBO:
{
Combo combo = (Combo) dragControl;
String string = combo.getText();
Point selection = combo.getSelection();
if (selection.x == selection.y) {
event.doit = false;
} else {
dragDataText = string.substring(selection.x, selection.y);
}
break;
}
default:
throw new SWTError(SWT.ERROR_NOT_IMPLEMENTED);
}
if (dragDataText != null) {
dragDataRTF = "{\\rtf1{\\colortbl;\\red255\\green0\\blue0;}\\cf1\\b " + dragDataText + "}";
dragDataHTML = "<b>" + dragDataText + "</b>";
dragDataURL = "http://" + dragDataText.replace(' ', '.');
try {
new URL(dragDataURL);
} catch (MalformedURLException e) {
dragDataURL = null;
}
}
for (Transfer dragType : dragTypes) {
if (dragType instanceof TextTransfer && dragDataText == null) {
event.doit = false;
}
if (dragType instanceof RTFTransfer && dragDataRTF == null) {
event.doit = false;
}
if (dragType instanceof HTMLTransfer && dragDataHTML == null) {
event.doit = false;
}
if (dragType instanceof URLTransfer && dragDataURL == null) {
event.doit = false;
}
if (dragType instanceof FileTransfer && (dragDataFiles == null || dragDataFiles.length == 0)) {
event.doit = false;
}
}
}
});
}
use of org.eclipse.swt.dnd.DragSource in project eclipse.platform.swt by eclipse.
the class FileViewer method createTableDragSource.
/**
* Creates the Drag & Drop DragSource for items being dragged from the table.
*
* @return the DragSource for the table
*/
private DragSource createTableDragSource(final Table table) {
DragSource dragSource = new DragSource(table, DND.DROP_MOVE | DND.DROP_COPY);
dragSource.setTransfer(FileTransfer.getInstance());
dragSource.addDragListener(new DragSourceListener() {
TableItem[] dndSelection = null;
String[] sourceNames = null;
@Override
public void dragStart(DragSourceEvent event) {
dndSelection = table.getSelection();
sourceNames = null;
event.doit = dndSelection.length > 0;
isDragging = true;
}
@Override
public void dragFinished(DragSourceEvent event) {
dragSourceHandleDragFinished(event, sourceNames);
dndSelection = null;
sourceNames = null;
isDragging = false;
handleDeferredRefresh();
}
@Override
public void dragSetData(DragSourceEvent event) {
if (dndSelection == null || dndSelection.length == 0)
return;
if (!FileTransfer.getInstance().isSupportedType(event.dataType))
return;
sourceNames = new String[dndSelection.length];
for (int i = 0; i < dndSelection.length; i++) {
File file = (File) dndSelection[i].getData(TABLEITEMDATA_FILE);
sourceNames[i] = file.getAbsolutePath();
}
event.data = sourceNames;
}
});
return dragSource;
}
use of org.eclipse.swt.dnd.DragSource in project eclipse.platform.swt by eclipse.
the class Bug307441_DnDOverlappingControls method setDragSource.
public static void setDragSource(final Label label) {
int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK;
final DragSource source = new DragSource(label, operations);
source.setTransfer(new Transfer[] { URLTransfer.getInstance() });
source.addDragListener(new DragSourceListener() {
@Override
public void dragStart(DragSourceEvent e) {
}
@Override
public void dragSetData(DragSourceEvent e) {
e.data = label.getText();
}
@Override
public void dragFinished(DragSourceEvent event) {
}
});
}
Aggregations