Search in sources :

Example 31 with ColumnPixelData

use of org.eclipse.jface.viewers.ColumnPixelData in project eclipse.platform.text by eclipse.

the class ColumnLayout method computeTableSize.

private Point computeTableSize(Table table, int wHint, int hHint) {
    Point result = table.computeSize(wHint, hHint);
    int width = 0;
    int size = columns.size();
    for (int i = 0; i < size; ++i) {
        ColumnLayoutData layoutData = columns.get(i);
        if (layoutData instanceof ColumnPixelData) {
            ColumnPixelData col = (ColumnPixelData) layoutData;
            width += col.width;
            if (col.addTrim) {
                width += COLUMN_TRIM;
            }
        } else if (layoutData instanceof ColumnWeightData) {
            ColumnWeightData col = (ColumnWeightData) layoutData;
            width += col.minimumWidth;
        } else {
            // $NON-NLS-1$
            Assert.isTrue(false, "Unknown column layout data");
        }
    }
    if (width > result.x)
        result.x = width;
    return result;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ColumnLayoutData(org.eclipse.jface.viewers.ColumnLayoutData) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 32 with ColumnPixelData

use of org.eclipse.jface.viewers.ColumnPixelData in project eclipse.platform.text by eclipse.

the class ColumnLayout method layoutTable.

private void layoutTable(final Table table, final int width, final Rectangle area, final boolean increase) {
    final TableColumn[] tableColumns = table.getColumns();
    final int size = Math.min(columns.size(), tableColumns.length);
    final int[] widths = new int[size];
    final int[] weightIteration = new int[size];
    int numberOfWeightColumns = 0;
    int fixedWidth = 0;
    int minWeightWidth = 0;
    int totalWeight = 0;
    // First calc space occupied by fixed columns
    for (int i = 0; i < size; i++) {
        ColumnLayoutData col = columns.get(i);
        if (col instanceof ColumnPixelData) {
            ColumnPixelData cpd = (ColumnPixelData) col;
            int pixels = cpd.width;
            if (cpd.addTrim) {
                pixels += COLUMN_TRIM;
            }
            widths[i] = pixels;
            fixedWidth += pixels;
        } else if (col instanceof ColumnWeightData) {
            ColumnWeightData cw = (ColumnWeightData) col;
            weightIteration[numberOfWeightColumns] = i;
            numberOfWeightColumns++;
            totalWeight += cw.weight;
            minWeightWidth += cw.minimumWidth;
            widths[i] = cw.minimumWidth;
        } else {
            // $NON-NLS-1$
            Assert.isTrue(false, "Unknown column layout data");
        }
    }
    // Do we have columns that have a weight?
    final int restIncludingMinWidths = width - fixedWidth;
    final int rest = restIncludingMinWidths - minWeightWidth;
    if (numberOfWeightColumns > 0 && rest > 0) {
        // Modify the weights to reflect what each column already
        // has due to its minimum. Otherwise, columns with low
        // minimums get discriminated.
        int totalWantedPixels = 0;
        final int[] wantedPixels = new int[numberOfWeightColumns];
        for (int i = 0; i < numberOfWeightColumns; i++) {
            ColumnWeightData cw = (ColumnWeightData) columns.get(weightIteration[i]);
            wantedPixels[i] = totalWeight == 0 ? 0 : cw.weight * restIncludingMinWidths / totalWeight;
            totalWantedPixels += wantedPixels[i];
        }
        // Now distribute the rest to the columns with weight.
        int totalDistributed = 0;
        for (int i = 0; i < numberOfWeightColumns; ++i) {
            int pixels = totalWantedPixels == 0 ? 0 : wantedPixels[i] * rest / totalWantedPixels;
            totalDistributed += pixels;
            widths[weightIteration[i]] += pixels;
        }
        // Distribute any remaining pixels to columns with weight.
        int diff = rest - totalDistributed;
        for (int i = 0; diff > 0; i = ((i + 1) % numberOfWeightColumns)) {
            ++widths[weightIteration[i]];
            --diff;
        }
    }
    if (increase) {
        table.setSize(area.width, area.height);
    }
    for (int i = 0; i < size; i++) {
        tableColumns[i].setWidth(widths[i]);
    }
    if (!increase) {
        table.setSize(area.width, area.height);
    }
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ColumnLayoutData(org.eclipse.jface.viewers.ColumnLayoutData) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) TableColumn(org.eclipse.swt.widgets.TableColumn) Point(org.eclipse.swt.graphics.Point)

Example 33 with ColumnPixelData

use of org.eclipse.jface.viewers.ColumnPixelData in project yamcs-studio by yamcs.

the class CommandHistoryView method processCommandHistoryEntry.

public void processCommandHistoryEntry(CommandHistoryEntry cmdhistEntry) {
    // Maybe we need to update structure
    for (CommandHistoryAttribute attr : cmdhistEntry.getAttrList()) {
        if (IGNORED_ATTRIBUTES.contains(attr.getName()))
            continue;
        String shortName = CommandHistoryRecordContentProvider.toHumanReadableName(attr);
        if (!dynamicColumns.contains(shortName)) {
            TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.LEFT);
            column.getColumn().setText(shortName);
            column.getColumn().addSelectionListener(getSelectionAdapter(column.getColumn()));
            column.setLabelProvider(new ColumnLabelProvider() {

                @Override
                public String getText(Object element) {
                    return ((CommandHistoryRecord) element).getTextForColumn(shortName, showRelativeTime);
                }

                @Override
                public String getToolTipText(Object element) {
                    return ((CommandHistoryRecord) element).getTooltipForColumn(shortName);
                }

                @Override
                public Image getImage(Object element) {
                    String imgLoc = ((CommandHistoryRecord) element).getImageForColumn(shortName);
                    if (CommandHistoryRecordContentProvider.GREEN.equals(imgLoc))
                        return greenBubble;
                    else if (CommandHistoryRecordContentProvider.RED.equals(imgLoc))
                        return redBubble;
                    else
                        return null;
                }
            });
            dynamicColumns.add(shortName);
            tableLayout.addColumnData(new ColumnPixelData(90));
            column.getColumn().setWidth(90);
            column.getColumn().addControlListener(new ControlListener() {

                @Override
                public void controlMoved(ControlEvent e) {
                }

                @Override
                public void controlResized(ControlEvent e) {
                    checkMinWidth(column.getColumn());
                }
            });
        }
    }
    // Now add content
    tableContentProvider.processCommandHistoryEntry(cmdhistEntry);
    updateSummaryLine();
}
Also used : ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) ControlListener(org.eclipse.swt.events.ControlListener) Image(org.eclipse.swt.graphics.Image) ControlEvent(org.eclipse.swt.events.ControlEvent) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) CommandHistoryAttribute(org.yamcs.protobuf.Commanding.CommandHistoryAttribute)

Example 34 with ColumnPixelData

use of org.eclipse.jface.viewers.ColumnPixelData in project yamcs-studio by yamcs.

the class EventLogTableViewer method addFixedColumns.

private void addFixedColumns() {
    // sort listener common for all columns
    Listener sortListener = event -> {
        TableColumn column = (TableColumn) event.widget;
        // TODO should this sort logic not move up into this class? Why are columns passed?
        EventLogContentProvider contentProvider = (EventLogContentProvider) getContentProvider();
        contentProvider.sort(column);
    };
    TableViewerColumn messageColumn = new TableViewerColumn(this, SWT.NONE);
    messageColumn.getColumn().setText(COL_MESSAGE);
    messageColumn.getColumn().addListener(SWT.Selection, sortListener);
    tableLayout.addColumnData(new ColumnPixelData(300));
    TableViewerColumn sourceColumn = new TableViewerColumn(this, SWT.NONE);
    sourceColumn.getColumn().setText(COL_SOURCE);
    sourceColumn.getColumn().addListener(SWT.Selection, sortListener);
    tableLayout.addColumnData(new ColumnPixelData(150));
    TableViewerColumn generationColumn = new TableViewerColumn(this, SWT.NONE);
    generationColumn.getColumn().setText(COL_GENERATION);
    generationColumn.getColumn().addListener(SWT.Selection, sortListener);
    tableLayout.addColumnData(new ColumnPixelData(150));
    TableViewerColumn receptionColumn = new TableViewerColumn(this, SWT.NONE);
    receptionColumn.getColumn().setText(COL_RECEPTION);
    receptionColumn.getColumn().addListener(SWT.Selection, sortListener);
    tableLayout.addColumnData(new ColumnPixelData(150));
    TableViewerColumn seqNumColum = new TableViewerColumn(this, SWT.RIGHT);
    seqNumColum.getColumn().setText(COL_SEQNUM);
    seqNumColum.getColumn().addListener(SWT.Selection, sortListener);
    tableLayout.addColumnData(new ColumnPixelData(80));
    if (!EventLogPreferences.isShowSequenceNumberColumn()) {
        tableLayout.addColumnData(new ColumnPixelData(0));
        seqNumColum.getColumn().setResizable(false);
    }
    if (!EventLogPreferences.isShowGenerationColumn()) {
        tableLayout.addColumnData(new ColumnPixelData(0));
        generationColumn.getColumn().setResizable(false);
    }
    if (!EventLogPreferences.isShowReceptionColumn()) {
        tableLayout.addColumnData(new ColumnPixelData(0));
        receptionColumn.getColumn().setResizable(false);
    }
    for (TableColumn tableColumn : getTable().getColumns()) {
        tableColumn.setMoveable(true);
        // prevent resize to 0
        tableColumn.addControlListener(new ControlListener() {

            @Override
            public void controlMoved(ControlEvent e) {
            }

            @Override
            public void controlResized(ControlEvent e) {
                if (tableColumn.getWidth() < 5)
                    tableColumn.setWidth(5);
            }
        });
    }
    // TODO use IMemento or something
    // !! Keep these values in sync with EventLogViewerComparator constructor
    getTable().setSortColumn(receptionColumn.getColumn());
    getTable().setSortDirection(SWT.UP);
}
Also used : TableLayout(org.eclipse.jface.viewers.TableLayout) TableViewer(org.eclipse.jface.viewers.TableViewer) Composite(org.eclipse.swt.widgets.Composite) Listener(org.eclipse.swt.widgets.Listener) SWT(org.eclipse.swt.SWT) TableColumn(org.eclipse.swt.widgets.TableColumn) ControlListener(org.eclipse.swt.events.ControlListener) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) ControlEvent(org.eclipse.swt.events.ControlEvent) Listener(org.eclipse.swt.widgets.Listener) ControlListener(org.eclipse.swt.events.ControlListener) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 35 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)45 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)20 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)17 TableLayout (org.eclipse.jface.viewers.TableLayout)16 Composite (org.eclipse.swt.widgets.Composite)15 TableViewer (org.eclipse.jface.viewers.TableViewer)14 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)13 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)10 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)9 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 TreeViewerColumn (org.eclipse.jface.viewers.TreeViewerColumn)8 Point (org.eclipse.swt.graphics.Point)8 Table (org.eclipse.swt.widgets.Table)8 ArrayList (java.util.ArrayList)6 TreeColumnLayout (org.eclipse.jface.layout.TreeColumnLayout)6 Viewer (org.eclipse.jface.viewers.Viewer)6 GridLayout (org.eclipse.swt.layout.GridLayout)6