use of org.eclipse.swt.dnd.Transfer in project eclipse.platform.swt by eclipse.
the class Bug497705_BrowserDragDetect method setDrag.
public static void setDrag(final Browser browser) {
Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK;
final DragSource source = new DragSource(browser, operations);
source.setTransfer(types);
source.addDragListener(new DragSourceListener() {
@Override
public void dragStart(DragSourceEvent event) {
event.doit = (browser.getText().length() != 0);
// not ran.
System.out.println("Drag started");
}
@Override
public void dragSetData(DragSourceEvent event) {
event.data = browser.getText();
}
@Override
public void dragFinished(DragSourceEvent event) {
if (event.detail == DND.DROP_MOVE)
browser.setText("");
}
});
}
use of org.eclipse.swt.dnd.Transfer in project eclipse.platform.swt by eclipse.
the class DNDExample method createDragTypes.
private void createDragTypes(Composite parent) {
parent.setLayout(new GridLayout());
Button textButton = new Button(parent, SWT.CHECK);
textButton.setText("Text Transfer");
textButton.addSelectionListener(widgetSelectedAdapter(e -> {
Button b = (Button) e.widget;
if (b.getSelection()) {
addDragTransfer(TextTransfer.getInstance());
} else {
removeDragTransfer(TextTransfer.getInstance());
}
}));
Button b = new Button(parent, SWT.CHECK);
b.setText("RTF Transfer");
b.addSelectionListener(widgetSelectedAdapter(e -> {
Button b1 = (Button) e.widget;
if (b1.getSelection()) {
addDragTransfer(RTFTransfer.getInstance());
} else {
removeDragTransfer(RTFTransfer.getInstance());
}
}));
b = new Button(parent, SWT.CHECK);
b.setText("HTML Transfer");
b.addSelectionListener(widgetSelectedAdapter(e -> {
Button b2 = (Button) e.widget;
if (b2.getSelection()) {
addDragTransfer(HTMLTransfer.getInstance());
} else {
removeDragTransfer(HTMLTransfer.getInstance());
}
}));
b = new Button(parent, SWT.CHECK);
b.setText("URL Transfer");
b.addSelectionListener(widgetSelectedAdapter(e -> {
Button b3 = (Button) e.widget;
if (b3.getSelection()) {
addDragTransfer(URLTransfer.getInstance());
} else {
removeDragTransfer(URLTransfer.getInstance());
}
}));
b = new Button(parent, SWT.CHECK);
b.setText("File Transfer");
b.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
b.addSelectionListener(widgetSelectedAdapter(e -> {
Button b4 = (Button) e.widget;
if (b4.getSelection()) {
addDragTransfer(FileTransfer.getInstance());
} else {
removeDragTransfer(FileTransfer.getInstance());
}
}));
b = new Button(parent, SWT.PUSH);
b.setText("Select File(s)");
b.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
b.addSelectionListener(widgetSelectedAdapter(e -> {
FileDialog dialog = new FileDialog(fileList.getShell(), SWT.OPEN | SWT.MULTI);
String result = dialog.open();
if (result != null && result.length() > 0) {
fileList.removeAll();
String path = dialog.getFilterPath();
String[] names = dialog.getFileNames();
for (String name : names) {
fileList.add(path + File.separatorChar + name);
}
}
}));
fileList = new List(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
GridData data = new GridData();
data.grabExcessHorizontalSpace = true;
data.horizontalAlignment = GridData.FILL;
data.verticalAlignment = GridData.BEGINNING;
fileList.setLayoutData(data);
// initialize state
textButton.setSelection(true);
addDragTransfer(TextTransfer.getInstance());
}
use of org.eclipse.swt.dnd.Transfer in project eclipse.platform.swt by eclipse.
the class DNDExample method open.
public void open(Display display) {
Shell shell = new Shell(display);
shell.setText("Drag and Drop Example");
shell.setLayout(new FillLayout());
itemImage = new Image(display, DNDExample.class.getResourceAsStream("openFolder.gif"));
ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL);
Composite parent = new Composite(sc, SWT.NONE);
sc.setContent(parent);
parent.setLayout(new FormLayout());
Label dragLabel = new Label(parent, SWT.LEFT);
dragLabel.setText("Drag Source:");
Group dragWidgetGroup = new Group(parent, SWT.NONE);
dragWidgetGroup.setText("Widget");
createDragWidget(dragWidgetGroup);
Composite cLeft = new Composite(parent, SWT.NONE);
cLeft.setLayout(new GridLayout(2, false));
Group dragOperationsGroup = new Group(cLeft, SWT.NONE);
dragOperationsGroup.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1));
dragOperationsGroup.setText("Allowed Operation(s):");
createDragOperations(dragOperationsGroup);
Group dragTypesGroup = new Group(cLeft, SWT.NONE);
dragTypesGroup.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
dragTypesGroup.setText("Transfer Type(s):");
createDragTypes(dragTypesGroup);
dragConsole = new Text(cLeft, SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI);
dragConsole.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
Menu menu = new Menu(shell, SWT.POP_UP);
MenuItem item = new MenuItem(menu, SWT.PUSH);
item.setText("Clear");
item.addSelectionListener(widgetSelectedAdapter(e -> dragConsole.setText("")));
item = new MenuItem(menu, SWT.CHECK);
item.setText("Show Event detail");
item.addSelectionListener(widgetSelectedAdapter(e -> {
MenuItem eItem = (MenuItem) e.widget;
dragEventDetail = eItem.getSelection();
}));
dragConsole.setMenu(menu);
Label dropLabel = new Label(parent, SWT.LEFT);
dropLabel.setText("Drop Target:");
Group dropWidgetGroup = new Group(parent, SWT.NONE);
dropWidgetGroup.setText("Widget");
createDropWidget(dropWidgetGroup);
Composite cRight = new Composite(parent, SWT.NONE);
cRight.setLayout(new GridLayout(2, false));
Group dropOperationsGroup = new Group(cRight, SWT.NONE);
dropOperationsGroup.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 2));
dropOperationsGroup.setText("Allowed Operation(s):");
createDropOperations(dropOperationsGroup);
Group dropTypesGroup = new Group(cRight, SWT.NONE);
dropTypesGroup.setText("Transfer Type(s):");
createDropTypes(dropTypesGroup);
Group feedbackTypesGroup = new Group(cRight, SWT.NONE);
feedbackTypesGroup.setText("Feedback Type(s):");
createFeedbackTypes(feedbackTypesGroup);
dropConsole = new Text(cRight, SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI);
dropConsole.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
menu = new Menu(shell, SWT.POP_UP);
item = new MenuItem(menu, SWT.PUSH);
item.setText("Clear");
item.addSelectionListener(widgetSelectedAdapter(e -> dropConsole.setText("")));
item = new MenuItem(menu, SWT.CHECK);
item.setText("Show Event detail");
item.addSelectionListener(widgetSelectedAdapter(e -> {
MenuItem eItem = (MenuItem) e.widget;
dropEventDetail = eItem.getSelection();
}));
dropConsole.setMenu(menu);
if (dragEnabled)
createDragSource();
if (dropEnabled)
createDropTarget();
int height = 200;
FormData data = new FormData();
data.top = new FormAttachment(0, 10);
data.left = new FormAttachment(0, 10);
dragLabel.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(dragLabel, 10);
data.left = new FormAttachment(0, 10);
data.right = new FormAttachment(50, -10);
data.height = height;
dragWidgetGroup.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(dragWidgetGroup, 10);
data.left = new FormAttachment(0, 10);
data.right = new FormAttachment(50, -10);
data.bottom = new FormAttachment(100, -10);
cLeft.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(0, 10);
data.left = new FormAttachment(cLeft, 10);
dropLabel.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(dropLabel, 10);
data.left = new FormAttachment(cLeft, 10);
data.right = new FormAttachment(100, -10);
data.height = height;
dropWidgetGroup.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(dropWidgetGroup, 10);
data.left = new FormAttachment(cLeft, 10);
data.right = new FormAttachment(100, -10);
data.bottom = new FormAttachment(100, -10);
cRight.setLayoutData(data);
sc.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT));
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
Rectangle monitorArea = shell.getMonitor().getClientArea();
shell.setSize(Math.min(size.x, monitorArea.width - 20), Math.min(size.y, monitorArea.height - 20));
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
itemImage.dispose();
}
use of org.eclipse.swt.dnd.Transfer in project eclipse.platform.swt by eclipse.
the class DNDExample method removeDragTransfer.
private void removeDragTransfer(Transfer transfer) {
if (dragTypes.length == 1) {
dragTypes = new Transfer[0];
} else {
int index = -1;
for (int i = 0; i < dragTypes.length; i++) {
if (dragTypes[i] == transfer) {
index = i;
break;
}
}
if (index == -1)
return;
Transfer[] newTypes = new Transfer[dragTypes.length - 1];
System.arraycopy(dragTypes, 0, newTypes, 0, index);
System.arraycopy(dragTypes, index + 1, newTypes, index, dragTypes.length - index - 1);
dragTypes = newTypes;
}
if (dragSource != null) {
dragSource.setTransfer(dragTypes);
}
}
use of org.eclipse.swt.dnd.Transfer in project vorto by eclipse.
the class DatatypeTreeViewer method init.
@Override
protected void init() {
super.init();
int operations = DND.DROP_COPY | DND.DROP_MOVE;
Transfer[] transferTypes = new Transfer[] { LocalSelectionTransfer.getTransfer() };
treeViewer.addDragSupport(operations, transferTypes, new ModelDragListener(treeViewer));
treeViewer.addDropSupport(operations, transferTypes, ModelDropListenerFactory.datatypeViewPartDropListener(treeViewer, localModelWorkspace));
}
Aggregations