Search in sources :

Example 46 with ColumnPixelData

use of org.eclipse.jface.viewers.ColumnPixelData 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(Composite parent, TableColumnLayout tcl) {
    var 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);
    var numColumn = new TableViewerColumn(viewer, SWT.NONE);
    numColumn.getColumn().setText("#");
    tcl.setColumnData(numColumn.getColumn(), new ColumnPixelData(50));
    var pvColumn = new TableViewerColumn(viewer, SWT.NONE);
    pvColumn.getColumn().setText("PV Name");
    tcl.setColumnData(pvColumn.getColumn(), new ColumnWeightData(50));
    pvColumn.setEditingSupport(new PVColumnEditingSupport(viewer, viewer.getTable()));
    var trigColumn = new TableViewerColumn(viewer, SWT.NONE);
    trigColumn.getColumn().setText("Trigger");
    tcl.setColumnData(trigColumn.getColumn(), new ColumnPixelData(50));
    trigColumn.setEditingSupport(new TriggerColumnEditingSupport(viewer, viewer.getTable()));
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new PVTupleLabelProvider(pvTupleList));
    viewer.addSelectionChangedListener(event -> refreshToolbarOnSelection());
    viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    var 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;
            }
            var txt = (String) event.data;
            var names = txt.split("[\r\n]+");
            var tuples = new PVTuple[names.length];
            var i = 0;
            for (var 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 : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) 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)

Aggregations

ColumnPixelData (org.eclipse.jface.viewers.ColumnPixelData)46 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)21 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)17 TableLayout (org.eclipse.jface.viewers.TableLayout)16 Composite (org.eclipse.swt.widgets.Composite)16 TableViewer (org.eclipse.jface.viewers.TableViewer)15 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)14 Image (org.eclipse.swt.graphics.Image)13 GridData (org.eclipse.swt.layout.GridData)13 TableColumn (org.eclipse.swt.widgets.TableColumn)13 SelectionEvent (org.eclipse.swt.events.SelectionEvent)11 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)9 Point (org.eclipse.swt.graphics.Point)9 TreeViewerColumn (org.eclipse.jface.viewers.TreeViewerColumn)8 Table (org.eclipse.swt.widgets.Table)8 Viewer (org.eclipse.jface.viewers.Viewer)7 ArrayList (java.util.ArrayList)6 TreeColumnLayout (org.eclipse.jface.layout.TreeColumnLayout)6 GridLayout (org.eclipse.swt.layout.GridLayout)6