Search in sources :

Example 71 with TableColumnLayout

use of org.eclipse.jface.layout.TableColumnLayout in project yamcs-studio by yamcs.

the class SwitchProcessorDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    var area = (Composite) super.createDialogArea(parent);
    var composite = new Composite(area, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    composite.setLayout(new GridLayout());
    var tableWrapper = new Composite(composite, SWT.NONE);
    var tcl = new TableColumnLayout();
    tableWrapper.setLayoutData(new GridData(GridData.FILL_BOTH));
    tableWrapper.setLayout(tcl);
    processorsTable = new TableViewer(tableWrapper, SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION);
    processorsTable.getTable().setHeaderVisible(true);
    processorsTable.getTable().setLinesVisible(true);
    var instanceColumn = new TableViewerColumn(processorsTable, SWT.NONE);
    instanceColumn.getColumn().setText("Instance");
    instanceColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            var info = (ProcessorInfo) element;
            return info.getInstance();
        }
    });
    tcl.setColumnData(instanceColumn.getColumn(), new ColumnPixelData(100));
    var nameColumn = new TableViewerColumn(processorsTable, SWT.NONE);
    nameColumn.getColumn().setText("Processor");
    nameColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            var info = (ProcessorInfo) element;
            return info.getName();
        }
    });
    tcl.setColumnData(nameColumn.getColumn(), new ColumnWeightData(100));
    var typeColumn = new TableViewerColumn(processorsTable, SWT.NONE);
    typeColumn.getColumn().setText("Type");
    typeColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            var info = (ProcessorInfo) element;
            return info.getType();
        }
    });
    tcl.setColumnData(typeColumn.getColumn(), new ColumnPixelData(100));
    processorsTable.setContentProvider(ArrayContentProvider.getInstance());
    processorsTable.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    processorsTable.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            if (e1 == null || e2 == null) {
                return 0;
            }
            var p1 = (ProcessorInfo) e1;
            var p2 = (ProcessorInfo) e2;
            var c = p1.getInstance().compareTo(p2.getInstance());
            return (c != 0) ? c : p1.getName().compareTo(p2.getName());
        }
    });
    processorsTable.addSelectionChangedListener(event -> {
        var okButton = getButton(IDialogConstants.OK_ID);
        okButton.setEnabled(!event.getSelection().isEmpty());
    });
    var client = YamcsPlugin.getYamcsClient();
    var filter = new InstanceFilter();
    filter.setState(InstanceState.RUNNING);
    client.listInstances(filter).whenComplete((response, exc) -> {
        parent.getDisplay().asyncExec(() -> {
            if (exc == null) {
                var processors = new ArrayList<ProcessorInfo>();
                for (var instance : response.getInstancesList()) {
                    processors.addAll(instance.getProcessorsList());
                }
                processorsTable.setInput(processors);
            }
        });
    });
    return composite;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) InstanceFilter(org.yamcs.client.InstanceFilter) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) ArrayList(java.util.ArrayList) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 72 with TableColumnLayout

use of org.eclipse.jface.layout.TableColumnLayout in project yamcs-studio by yamcs.

the class PredefinedFontsFieldEditor method createTableControl.

private void createTableControl(Composite parent) {
    var tableWrapper = new Composite(parent, SWT.NONE);
    tableWrapper.setLayoutData(new GridData(GridData.FILL_BOTH));
    var tcl = new TableColumnLayout();
    tableWrapper.setLayout(tcl);
    tableViewer = new TableViewer(tableWrapper, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    tableViewer.setContentProvider(ArrayContentProvider.getInstance());
    tableViewer.getTable().setHeaderVisible(true);
    tableViewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            var f1 = (OPIFont) e1;
            var f2 = (OPIFont) e2;
            return f1.getFontMacroName().compareToIgnoreCase(f2.getFontMacroName());
        }
    });
    var textColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    textColumn.getColumn().setText("Name");
    textColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            var font = (OPIFont) element;
            return font.getFontMacroName();
        }
    });
    tcl.setColumnData(textColumn.getColumn(), new ColumnWeightData(100, true));
    var descColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    descColumn.getColumn().setText("Font");
    descColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            var font = (OPIFont) element;
            return StringConverter.asString(font.getRawFontData());
        }
    });
    tcl.setColumnData(descColumn.getColumn(), new ColumnWeightData(200, true));
    tableViewer.getTable().addListener(SWT.Selection, evt -> {
        updatePreviewFont();
        updateButtonStatus();
    });
    tableViewer.getTable().addListener(SWT.MouseDoubleClick, e -> {
        var item = tableViewer.getTable().getItem(new Point(e.x, e.y));
        if (item == null) {
            return;
        }
        var bounds = item.getBounds();
        var isClickOnCheckbox = e.x < bounds.x;
        if (isClickOnCheckbox) {
            return;
        }
        var selectedFont = getSelectedFont();
        editFont(selectedFont);
        updatePreviewFont();
        updateButtonStatus();
    });
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) Point(org.eclipse.swt.graphics.Point) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 73 with TableColumnLayout

use of org.eclipse.jface.layout.TableColumnLayout in project yamcs-studio by yamcs.

the class PredefinedColorsFieldEditor method createTableControl.

private void createTableControl(Composite parent) {
    var tableWrapper = new Composite(parent, SWT.NONE);
    tableWrapper.setLayoutData(new GridData(GridData.FILL_BOTH));
    var tcl = new TableColumnLayout();
    tableWrapper.setLayout(tcl);
    tableViewer = new TableViewer(tableWrapper, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    tableViewer.setContentProvider(ArrayContentProvider.getInstance());
    tableViewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            var c1 = (NamedColor) e1;
            var c2 = (NamedColor) e2;
            return c1.name.compareToIgnoreCase(c2.name);
        }
    });
    var colorColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    colorColumn.setLabelProvider(new ColorLabelProvider() {

        @Override
        public Color getColor(Object element) {
            var color = (NamedColor) element;
            return colorCache.computeIfAbsent(color.rgb, resourceManager::createColor);
        }

        @Override
        public Color getBorderColor(Object element) {
            return parent.getDisplay().getSystemColor(SWT.COLOR_BLACK);
        }
    });
    tcl.setColumnData(colorColumn.getColumn(), new ColumnWeightData(50, 50, false));
    var textColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    textColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            var color = (NamedColor) element;
            return color.name;
        }
    });
    tcl.setColumnData(textColumn.getColumn(), new ColumnWeightData(200, 200, true));
    tableViewer.getTable().addListener(SWT.Selection, evt -> updateButtonStatus());
    tableViewer.getTable().addListener(SWT.MouseDoubleClick, e -> {
        var item = tableViewer.getTable().getItem(new Point(e.x, e.y));
        if (item == null) {
            return;
        }
        var bounds = item.getBounds();
        var isClickOnCheckbox = e.x < bounds.x;
        if (isClickOnCheckbox) {
            return;
        }
        var selectedRule = getSelectedColor();
        editColor(selectedRule);
        updateButtonStatus();
    });
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) Color(org.eclipse.swt.graphics.Color) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) Point(org.eclipse.swt.graphics.Point) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 74 with TableColumnLayout

use of org.eclipse.jface.layout.TableColumnLayout in project yamcs-studio by yamcs.

the class LinksView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    var tableWrapper = new Composite(parent, SWT.NONE);
    tableWrapper.setLayoutData(new GridData(GridData.FILL_BOTH));
    var tcl = new TableColumnLayout();
    tableWrapper.setLayout(tcl);
    tableViewer = new LinkTableViewer(tableWrapper, tcl);
    contentProvider = new LinkTableViewerContentProvider(tableViewer);
    tableViewer.setContentProvider(contentProvider);
    tableViewer.setInput(contentProvider);
    tableViewer.getTable().addListener(SWT.MouseDown, evt -> {
        // broke the popup menu for me.
        if (tableViewer.getCell(new Point(evt.x, evt.y)) == null) {
            tableViewer.getTable().deselectAll();
        }
    });
    if (getViewSite() != null) {
        getViewSite().setSelectionProvider(tableViewer);
    }
    // Set initial state
    tableViewer.refresh();
    YamcsPlugin.addListener(this);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) GridData(org.eclipse.swt.layout.GridData) Point(org.eclipse.swt.graphics.Point)

Example 75 with TableColumnLayout

use of org.eclipse.jface.layout.TableColumnLayout in project hale by halestudio.

the class LookupTablePage method addPreview.

// add table for the preview to the given composite
private void addPreview(Composite page) {
    tableContainer = new Composite(page, SWT.NONE);
    tableContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    TableColumnLayout layout = new TableColumnLayout();
    tableContainer.setLayout(layout);
    tableViewer = new TableViewer(tableContainer, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
    tableViewer.getTable().setLinesVisible(true);
    tableViewer.getTable().setHeaderVisible(true);
    tableViewer.setContentProvider(ArrayContentProvider.getInstance());
    sourceColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    layout.setColumnData(sourceColumn.getColumn(), new ColumnWeightData(1));
    sourceColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            @SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) element;
            return entry.getKey().getStringRepresentation();
        }
    });
    targetColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    layout.setColumnData(targetColumn.getColumn(), new ColumnWeightData(1));
    targetColumn.setLabelProvider(new StyledCellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            @SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) cell.getElement();
            if (entry.getValue() == null) {
                StyledString styledString = new StyledString("(unmapped)", StyledString.DECORATIONS_STYLER);
                cell.setText(styledString.getString());
                cell.setStyleRanges(styledString.getStyleRanges());
            } else {
                cell.setText(entry.getValue().getStringRepresentation());
                cell.setStyleRanges(null);
            }
            super.update(cell);
        }
    });
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) Composite(org.eclipse.swt.widgets.Composite) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) ViewerCell(org.eclipse.jface.viewers.ViewerCell) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Entry(java.util.Map.Entry) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) GridData(org.eclipse.swt.layout.GridData) Value(eu.esdihumboldt.hale.common.core.io.Value) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Aggregations

TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)105 Composite (org.eclipse.swt.widgets.Composite)94 TableViewer (org.eclipse.jface.viewers.TableViewer)78 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)62 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)51 GridData (org.eclipse.swt.layout.GridData)46 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)44 Table (org.eclipse.swt.widgets.Table)38 GridLayout (org.eclipse.swt.layout.GridLayout)34 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)31 Image (org.eclipse.swt.graphics.Image)28 Label (org.eclipse.swt.widgets.Label)27 Viewer (org.eclipse.jface.viewers.Viewer)25 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)23 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)22 SelectionEvent (org.eclipse.swt.events.SelectionEvent)22 Button (org.eclipse.swt.widgets.Button)21 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)18 TableColumn (org.eclipse.swt.widgets.TableColumn)18 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)17