use of org.eclipse.swt.dnd.DropTarget in project archi by archimatetool.
the class IconSection method createControls.
@Override
protected void createControls(Composite parent) {
createLabel(parent, Messages.IconSection_9, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.NONE);
final int canvasSize = IIconic.MAX_IMAGE_SIZE;
fCanvas = new Canvas(parent, SWT.BORDER);
getWidgetFactory().adapt(fCanvas);
GridData gd = new GridData(SWT.NONE, SWT.NONE, false, false);
gd.widthHint = canvasSize;
gd.heightHint = canvasSize;
fCanvas.setLayoutData(gd);
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
fCanvas.setLayout(layout);
fCanvas.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
disposeImage();
}
});
fCanvas.addListener(SWT.MouseDoubleClick, new Listener() {
@Override
public void handleEvent(Event event) {
if (!isLocked(getFirstSelectedObject())) {
chooseImage();
}
}
});
fCanvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
if (fImage != null) {
Rectangle bounds = fImage.getBounds();
int x = (canvasSize - bounds.width) / 2;
int y = (canvasSize - bounds.height) / 2;
e.gc.drawImage(fImage, x, y);
}
}
});
String tooltip = Messages.IconSection_10;
fCanvas.setToolTipText(tooltip);
DropTarget target = new DropTarget(fCanvas, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT);
target.setTransfer(new Transfer[] { FileTransfer.getInstance() });
target.addDropListener(new DropTargetAdapter() {
@Override
public void drop(DropTargetEvent event) {
if (event.data instanceof String[]) {
if (!isLocked(getFirstSelectedObject())) {
File file = new File(((String[]) event.data)[0]);
setImage(file);
}
}
}
});
// Image Button
createImageButton(parent);
// Position
createLabel(parent, Messages.IconSection_11, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER);
fComboPosition = new Combo(parent, SWT.READ_ONLY);
fComboPosition.setItems(fComboPositionItems);
gd = new GridData(SWT.NONE, SWT.NONE, false, false);
fComboPosition.setLayoutData(gd);
fComboPosition.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
CompoundCommand result = new CompoundCommand();
for (EObject iconic : getEObjects()) {
if (isAlive(iconic)) {
Command cmd = new EObjectFeatureCommand(Messages.IconSection_12, iconic, ICanvasPackage.Literals.ICONIC__IMAGE_POSITION, fComboPosition.getSelectionIndex());
if (cmd.canExecute()) {
result.add(cmd);
}
}
}
executeCommand(result.unwrap());
}
});
// Help
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
}
use of org.eclipse.swt.dnd.DropTarget in project eclipse.platform.swt by eclipse.
the class DNDExample method createDropTarget.
private void createDropTarget() {
if (dropTarget != null)
dropTarget.dispose();
dropTarget = new DropTarget(dropControl, dropOperation);
dropTarget.setTransfer(dropTypes);
dropTarget.addDropListener(new DropTargetListener() {
@Override
public void dragEnter(DropTargetEvent event) {
dropConsole.append(">>dragEnter\n");
printEvent(event);
if (event.detail == DND.DROP_DEFAULT) {
event.detail = dropDefaultOperation;
}
event.feedback = dropFeedback;
}
@Override
public void dragLeave(DropTargetEvent event) {
dropConsole.append(">>dragLeave\n");
printEvent(event);
}
@Override
public void dragOperationChanged(DropTargetEvent event) {
dropConsole.append(">>dragOperationChanged\n");
printEvent(event);
if (event.detail == DND.DROP_DEFAULT) {
event.detail = dropDefaultOperation;
}
event.feedback = dropFeedback;
}
@Override
public void dragOver(DropTargetEvent event) {
dropConsole.append(">>dragOver\n");
printEvent(event);
event.feedback = dropFeedback;
}
@Override
public void drop(DropTargetEvent event) {
dropConsole.append(">>drop\n");
printEvent(event);
String[] strings = null;
if (TextTransfer.getInstance().isSupportedType(event.currentDataType) || RTFTransfer.getInstance().isSupportedType(event.currentDataType) || HTMLTransfer.getInstance().isSupportedType(event.currentDataType) || URLTransfer.getInstance().isSupportedType(event.currentDataType)) {
strings = new String[] { (String) event.data };
}
if (FileTransfer.getInstance().isSupportedType(event.currentDataType)) {
strings = (String[]) event.data;
}
if (strings == null || strings.length == 0) {
dropConsole.append("!!Invalid data dropped");
return;
}
if (strings.length == 1 && (dropControlType == TABLE || dropControlType == TREE || dropControlType == LIST)) {
// convert string separated by "\n" into an array of strings
String string = strings[0];
int count = 0;
int offset = string.indexOf("\n", 0);
while (offset > 0) {
count++;
offset = string.indexOf("\n", offset + 1);
}
if (count > 0) {
strings = new String[count + 1];
int start = 0;
int end = string.indexOf("\n");
int index = 0;
while (start < end) {
strings[index++] = string.substring(start, end);
start = end + 1;
end = string.indexOf("\n", start);
if (end == -1)
end = string.length();
}
}
}
switch(dropControlType) {
case BUTTON_CHECK:
case BUTTON_TOGGLE:
case BUTTON_RADIO:
{
Button b = (Button) dropControl;
b.setText(strings[0]);
break;
}
case STYLED_TEXT:
{
StyledText text = (StyledText) dropControl;
for (String string : strings) {
text.insert(string);
}
break;
}
case TABLE:
{
Table table = (Table) dropControl;
Point p = event.display.map(null, table, event.x, event.y);
TableItem dropItem = table.getItem(p);
int index = dropItem == null ? table.getItemCount() : table.indexOf(dropItem);
for (String string : strings) {
TableItem item = new TableItem(table, SWT.NONE, index);
item.setText(0, string);
item.setText(1, "dropped item");
}
TableColumn[] columns = table.getColumns();
for (TableColumn column : columns) {
column.pack();
}
break;
}
case TEXT:
{
Text text = (Text) dropControl;
for (String string : strings) {
text.append(string + "\n");
}
break;
}
case TREE:
{
Tree tree = (Tree) dropControl;
Point p = event.display.map(null, tree, event.x, event.y);
TreeItem parentItem = tree.getItem(p);
for (String string : strings) {
TreeItem item = parentItem != null ? new TreeItem(parentItem, SWT.NONE) : new TreeItem(tree, SWT.NONE);
item.setText(string);
}
break;
}
case CANVAS:
{
dropControl.setData("STRINGS", strings);
dropControl.redraw();
break;
}
case LABEL:
{
Label label = (Label) dropControl;
label.setText(strings[0]);
break;
}
case LIST:
{
List list = (List) dropControl;
for (String string : strings) {
list.add(string);
}
break;
}
case COMBO:
{
Combo combo = (Combo) dropControl;
combo.setText(strings[0]);
break;
}
default:
throw new SWTError(SWT.ERROR_NOT_IMPLEMENTED);
}
}
@Override
public void dropAccept(DropTargetEvent event) {
dropConsole.append(">>dropAccept\n");
printEvent(event);
}
});
}
use of org.eclipse.swt.dnd.DropTarget in project eclipse.platform.swt by eclipse.
the class FileViewer method createTreeDropTarget.
/**
* Creates the Drag & Drop DropTarget for items being dropped onto the tree.
*
* @return the DropTarget for the tree
*/
private DropTarget createTreeDropTarget(final Tree tree) {
DropTarget dropTarget = new DropTarget(tree, DND.DROP_MOVE | DND.DROP_COPY);
dropTarget.setTransfer(FileTransfer.getInstance());
dropTarget.addDropListener(new DropTargetAdapter() {
@Override
public void dragEnter(DropTargetEvent event) {
isDropping = true;
}
@Override
public void dragLeave(DropTargetEvent event) {
isDropping = false;
handleDeferredRefresh();
}
@Override
public void dragOver(DropTargetEvent event) {
dropTargetValidate(event, getTargetFile(event));
event.feedback |= DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL;
}
@Override
public void drop(DropTargetEvent event) {
File targetFile = getTargetFile(event);
if (dropTargetValidate(event, targetFile))
dropTargetHandleDrop(event, targetFile);
}
private File getTargetFile(DropTargetEvent event) {
// Determine the target File for the drop
TreeItem item = tree.getItem(tree.toControl(new Point(event.x, event.y)));
File targetFile = null;
if (item != null) {
// We are over a particular item in the tree, use the item's file
targetFile = (File) item.getData(TREEITEMDATA_FILE);
}
return targetFile;
}
});
return dropTarget;
}
use of org.eclipse.swt.dnd.DropTarget in project eclipse.platform.swt by eclipse.
the class FileViewer method createTableDropTarget.
/**
* Creates the Drag & Drop DropTarget for items being dropped onto the table.
*
* @return the DropTarget for the table
*/
private DropTarget createTableDropTarget(final Table table) {
DropTarget dropTarget = new DropTarget(table, DND.DROP_MOVE | DND.DROP_COPY);
dropTarget.setTransfer(FileTransfer.getInstance());
dropTarget.addDropListener(new DropTargetAdapter() {
@Override
public void dragEnter(DropTargetEvent event) {
isDropping = true;
}
@Override
public void dragLeave(DropTargetEvent event) {
isDropping = false;
handleDeferredRefresh();
}
@Override
public void dragOver(DropTargetEvent event) {
dropTargetValidate(event, getTargetFile(event));
event.feedback |= DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL;
}
@Override
public void drop(DropTargetEvent event) {
File targetFile = getTargetFile(event);
if (dropTargetValidate(event, targetFile))
dropTargetHandleDrop(event, targetFile);
}
private File getTargetFile(DropTargetEvent event) {
// Determine the target File for the drop
TableItem item = table.getItem(table.toControl(new Point(event.x, event.y)));
File targetFile = null;
if (item == null) {
// If it is a COPY, we can use the table's root file.
if (event.detail == DND.DROP_COPY) {
targetFile = (File) table.getData(TABLEDATA_DIR);
}
} else {
// We are over a particular item in the table, use the item's file
targetFile = (File) item.getData(TABLEITEMDATA_FILE);
}
return targetFile;
}
});
return dropTarget;
}
use of org.eclipse.swt.dnd.DropTarget in project eclipse.platform.swt by eclipse.
the class Bug307441_DnDOverlappingControls method setDropTargetForLabel.
public static void setDropTargetForLabel(final Label control) {
int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK;
DropTarget target = new DropTarget(control, operations);
target.setTransfer(new Transfer[] { URLTransfer.getInstance() });
target.addDropListener(new DropTargetListener() {
@Override
public void dragEnter(DropTargetEvent e) {
System.out.println("dragEnter=" + control.getText());
if (e.detail == DND.DROP_NONE)
e.detail = DND.DROP_LINK;
}
@Override
public void dragOperationChanged(DropTargetEvent e) {
if (e.detail == DND.DROP_NONE)
e.detail = DND.DROP_LINK;
}
@Override
public void drop(DropTargetEvent event) {
if (event.data == null) {
event.detail = DND.DROP_NONE;
return;
}
control.setText(((String) event.data));
}
@Override
public void dragLeave(DropTargetEvent arg0) {
// TODO Auto-generated method stub
System.out.println("dragLeave=" + control.getText());
}
@Override
public void dragOver(DropTargetEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void dropAccept(DropTargetEvent arg0) {
// TODO Auto-generated method stub
}
});
}
Aggregations