Search in sources :

Example 16 with DropTargetListener

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;
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) PVTuple(org.csstudio.opibuilder.script.PVTuple) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) DropTarget(org.eclipse.swt.dnd.DropTarget) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 17 with DropTargetListener

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);
        }
    });
}
Also used : SWTError(org.eclipse.swt.SWTError) StyledText(org.eclipse.swt.custom.StyledText) Table(org.eclipse.swt.widgets.Table) TreeItem(org.eclipse.swt.widgets.TreeItem) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) Point(org.eclipse.swt.graphics.Point) TableColumn(org.eclipse.swt.widgets.TableColumn) Point(org.eclipse.swt.graphics.Point) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) Button(org.eclipse.swt.widgets.Button) Tree(org.eclipse.swt.widgets.Tree) List(org.eclipse.swt.widgets.List) DropTarget(org.eclipse.swt.dnd.DropTarget)

Example 18 with DropTargetListener

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
        }
    });
}
Also used : DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DropTarget(org.eclipse.swt.dnd.DropTarget)

Example 19 with DropTargetListener

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);
}
Also used : CommonViewer(org.eclipse.ui.navigator.CommonViewer) TableItem(org.eclipse.swt.widgets.TableItem) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBColumnRepNode(org.talend.dq.nodes.DBColumnRepNode) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DropTarget(org.eclipse.swt.dnd.DropTarget) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) TableDropTargetEffect(org.eclipse.swt.dnd.TableDropTargetEffect)

Example 20 with DropTargetListener

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);
}
Also used : CommonViewer(org.eclipse.ui.navigator.CommonViewer) TreeItem(org.eclipse.swt.widgets.TreeItem) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RuleRepNode(org.talend.dq.nodes.RuleRepNode) TreeDropTargetEffect(org.eclipse.swt.dnd.TreeDropTargetEffect) DBTableRepNode(org.talend.dq.nodes.DBTableRepNode) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) DropTarget(org.eclipse.swt.dnd.DropTarget) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) DBViewRepNode(org.talend.dq.nodes.DBViewRepNode) NamedColumnSet(orgomg.cwm.resource.relational.NamedColumnSet)

Aggregations

DropTargetListener (org.eclipse.swt.dnd.DropTargetListener)25 DropTarget (org.eclipse.swt.dnd.DropTarget)22 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)19 Transfer (org.eclipse.swt.dnd.Transfer)11 TransferDropTargetListener (org.eclipse.jface.util.TransferDropTargetListener)6 DragSource (org.eclipse.swt.dnd.DragSource)6 DragSourceEvent (org.eclipse.swt.dnd.DragSourceEvent)6 TextTransfer (org.eclipse.swt.dnd.TextTransfer)6 LocalSelectionTransfer (org.eclipse.jface.util.LocalSelectionTransfer)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 DragSourceListener (org.eclipse.swt.dnd.DragSourceListener)5 Point (org.eclipse.swt.graphics.Point)5 Button (org.eclipse.swt.widgets.Button)5 TreeItem (org.eclipse.swt.widgets.TreeItem)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 FormAttachment (org.eclipse.swt.layout.FormAttachment)4 GridData (org.eclipse.swt.layout.GridData)4 SashForm (org.eclipse.swt.custom.SashForm)3 StyledText (org.eclipse.swt.custom.StyledText)3