use of org.eclipse.swt.dnd.DropTargetListener in project yamcs-studio by yamcs.
the class PVTupleTableEditor method createPVTupleListTableViewer.
/**
* Creates and configures a {@link TableViewer}.
*
* @param parent
* The parent for the table
* @return The {@link TableViewer}
*/
private TableViewer createPVTupleListTableViewer(final Composite parent) {
final TableViewer viewer = new TableViewer(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
viewer.getTable().setLinesVisible(true);
viewer.getTable().setHeaderVisible(true);
final TableViewerColumn numColumn = new TableViewerColumn(viewer, SWT.NONE);
numColumn.getColumn().setText("#");
numColumn.getColumn().setMoveable(false);
numColumn.getColumn().setWidth(50);
final TableViewerColumn pvColumn = new TableViewerColumn(viewer, SWT.NONE);
pvColumn.getColumn().setText("PV Name");
pvColumn.getColumn().setMoveable(false);
pvColumn.getColumn().setWidth(220);
pvColumn.setEditingSupport(new PVColumnEditingSupport(viewer, viewer.getTable()));
final TableViewerColumn TrigColumn = new TableViewerColumn(viewer, SWT.NONE);
TrigColumn.getColumn().setText("Trigger");
TrigColumn.getColumn().setMoveable(false);
TrigColumn.getColumn().pack();
TrigColumn.setEditingSupport(new TriggerColumnEditingSupport(viewer, viewer.getTable()));
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new PVTupleLabelProvider(pvTupleList));
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(final SelectionChangedEvent event) {
refreshToolbarOnSelection();
}
});
viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
DropTarget target = new DropTarget(viewer.getControl(), DND.DROP_MOVE | DND.DROP_COPY);
target.setTransfer(new Transfer[] { TextTransfer.getInstance() });
target.addDropListener(new DropTargetListener() {
@Override
public void dragEnter(DropTargetEvent event) {
}
@Override
public void dragLeave(DropTargetEvent event) {
}
@Override
public void dragOperationChanged(DropTargetEvent event) {
}
@Override
public void dragOver(DropTargetEvent event) {
}
@Override
public void drop(DropTargetEvent event) {
if (event == null || !(event.data instanceof String))
return;
String txt = (String) event.data;
String[] names = txt.split("[\r\n]+");
PVTuple[] tuples = new PVTuple[names.length];
int i = 0;
for (String name : names) {
tuples[i] = new PVTuple(name, true);
pvTupleList.add(tuples[i]);
i++;
}
refreshTableViewerFromAction(tuples);
}
@Override
public void dropAccept(DropTargetEvent event) {
}
});
return viewer;
}
use of org.eclipse.swt.dnd.DropTargetListener 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.DropTargetListener 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
}
});
}
use of org.eclipse.swt.dnd.DropTargetListener in project tdq-studio-se by Talend.
the class ColumnViewerDND method installDND.
/**
* DOC xqliu Comment method "installDND". bug 8791 2009-08-31.
*
* @param myTable
*/
public static void installDND(final Table targetControl) {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
DQRespositoryView findView = (DQRespositoryView) activePage.findView(DQRespositoryView.ID);
final CommonViewer commonViewer = findView.getCommonViewer();
final LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
int operations = DND.DROP_COPY | DND.DROP_MOVE;
Transfer[] transfers = new Transfer[] { transfer };
DropTarget dropTarget = new DropTarget(targetControl, operations);
dropTarget.setTransfer(transfers);
DropTargetListener dndListener = new TableDropTargetEffect(targetControl) {
ISelectionReceiver receiver = null;
@Override
public void dragEnter(DropTargetEvent event) {
super.dragEnter(event);
IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
Object object = selection.getFirstElement();
// MOD klliu 2011-03-08 bug 19286
if (object instanceof DBColumnRepNode) {
receiver = new ColumnReceiverTable();
}
if (receiver == null) {
event.detail = DND.DROP_NONE;
} else {
event.feedback = DND.FEEDBACK_EXPAND;
receiver.doDropValidation(event, commonViewer);
}
}
@Override
public void dragOver(DropTargetEvent event) {
if (receiver == null) {
return;
}
super.dragOver(event);
receiver.doDropValidation(event, commonViewer);
}
@Override
public void drop(DropTargetEvent event) {
if (receiver == null) {
return;
}
int index = targetControl.getItemCount();
super.drop(event);
if (event.item == null) {
index = -1;
} else {
// Widget widget = event.widget;
// Object data = event.data;
TableItem item = (TableItem) event.item;
TableItem[] items = targetControl.getItems();
for (int i = 0; i < items.length; i++) {
if (items[i] == item) {
index = i;
break;
}
}
}
receiver.drop(event, commonViewer, index);
}
};
dropTarget.addDropListener(dndListener);
}
use of org.eclipse.swt.dnd.DropTargetListener in project tdq-studio-se by Talend.
the class TableViewerDND method installDND.
/**
* DOC xqliu Comment method "installDND".
*
* @param targetControl
*/
public static void installDND(final Tree targetControl) {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
DQRespositoryView findView = (DQRespositoryView) activePage.findView(DQRespositoryView.ID);
final CommonViewer commonViewer = findView.getCommonViewer();
final LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
int operations = DND.DROP_COPY | DND.DROP_MOVE;
Transfer[] transfers = new Transfer[] { transfer };
DropTarget dropTarget = new DropTarget(targetControl, operations);
dropTarget.setTransfer(transfers);
DropTargetListener dndListener = new TreeDropTargetEffect(targetControl) {
ISelectionReceiver receiver = null;
@Override
public void dragEnter(DropTargetEvent event) {
super.dragEnter(event);
IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
Object object = selection.getFirstElement();
if (object instanceof RuleRepNode) {
receiver = new DQRuleReceiver();
}
if (object instanceof NamedColumnSet) {
receiver = new TableReceiver();
}
if (object instanceof DBTableRepNode) {
receiver = new TableReceiver();
}
if (object instanceof DBViewRepNode) {
receiver = new TableReceiver();
}
if (receiver == null) {
event.detail = DND.DROP_NONE;
} else {
event.feedback = DND.FEEDBACK_EXPAND;
receiver.doDropValidation(event, commonViewer);
}
}
@Override
public void dragOver(DropTargetEvent event) {
super.dragOver(event);
if (receiver != null) {
receiver.doDropValidation(event, commonViewer);
}
}
@Override
public void drop(DropTargetEvent event) {
int index = targetControl.getItemCount();
super.drop(event);
if (event.item == null) {
// TreeItem item = new TreeItem(targetControl, SWT.NONE);
// item.setText(texts);
// item.setText(text);
} else {
TreeItem item = (TreeItem) event.item;
TreeItem[] items = targetControl.getItems();
for (int i = 0; i < items.length; i++) {
if (items[i] == item) {
index = i;
break;
}
}
}
if (receiver != null) {
receiver.drop(event, commonViewer, index);
}
}
};
dropTarget.addDropListener(dndListener);
}
Aggregations