use of org.eclipse.swt.dnd.URLTransfer 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.URLTransfer in project statecharts by Yakindu.
the class ExampleDropTargetInstaller method registerWithExistingTarget.
protected void registerWithExistingTarget(DropTarget target) {
Transfer[] transfers = target.getTransfer();
boolean exists = false;
if (transfers != null) {
for (Transfer transfer : transfers) {
if (transfer instanceof URLTransfer) {
exists = true;
break;
}
}
if (!exists) {
Transfer[] newTransfers = new Transfer[transfers.length + 1];
System.arraycopy(transfers, 0, newTransfers, 0, transfers.length);
newTransfers[transfers.length] = URLTransfer.getInstance();
target.setTransfer(newTransfers);
}
}
}
use of org.eclipse.swt.dnd.URLTransfer in project epp.mpc by eclipse.
the class MarketplaceDropAdapter method registerWithExistingTarget.
private void registerWithExistingTarget(DropTarget target) {
Transfer[] transfers = target.getTransfer();
boolean exists = false;
if (transfers != null) {
for (Transfer transfer : transfers) {
if (transfer instanceof URLTransfer) {
exists = true;
break;
}
}
if (!exists) {
Transfer[] newTransfers = new Transfer[transfers.length + 1];
System.arraycopy(transfers, 0, newTransfers, 0, transfers.length);
newTransfers[transfers.length] = URLTransfer.getInstance();
target.setTransfer(newTransfers);
}
}
}
use of org.eclipse.swt.dnd.URLTransfer in project egit by eclipse.
the class GitCloneDropAdapter method registerWithExistingTarget.
private void registerWithExistingTarget(DropTarget target) {
Transfer[] transfers = target.getTransfer();
if (transfers != null) {
for (Transfer transfer : transfers) {
if (transfer instanceof URLTransfer) {
return;
}
}
Transfer[] newTransfers = new Transfer[transfers.length + 1];
System.arraycopy(transfers, 0, newTransfers, 0, transfers.length);
newTransfers[transfers.length] = URLTransfer.getInstance();
target.setTransfer(newTransfers);
}
}
Aggregations