Search in sources :

Example 56 with TableColumnLayout

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

the class ConnectionsDialog method createServerPanel.

private Composite createServerPanel(Composite parent, ResourceManager resourceManager) {
    Composite serverPanel = new Composite(parent, SWT.NONE);
    GridData gd = new GridData(GridData.FILL_BOTH);
    serverPanel.setLayoutData(gd);
    TableColumnLayout tcl = new TableColumnLayout();
    serverPanel.setLayout(tcl);
    Image serverImage = resourceManager.createImage(RCPUtils.getImageDescriptor(ConnectionsDialog.class, "icons/obj16/server.gif"));
    connViewer = new TableViewer(serverPanel, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    connViewer.getTable().setHeaderVisible(true);
    connViewer.getTable().setLinesVisible(false);
    TableViewerColumn nameColumn = new TableViewerColumn(connViewer, SWT.NONE);
    nameColumn.getColumn().setText("Connection Name");
    nameColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public Image getImage(Object element) {
            return serverImage;
        }

        @Override
        public String getText(Object element) {
            YamcsConfiguration conf = (YamcsConfiguration) element;
            return conf.getName();
        }
    });
    tcl.setColumnData(nameColumn.getColumn(), new ColumnWeightData(400));
    connViewer.setContentProvider(new ArrayContentProvider());
    connViewer.addSelectionChangedListener(evt -> {
        IStructuredSelection sel = (IStructuredSelection) evt.getSelection();
        if (sel.getFirstElement() != null) {
            YamcsConfiguration conf = (YamcsConfiguration) sel.getFirstElement();
            yamcsInstanceText.setText(forceString(conf.getInstance()));
            yamcsUserText.setText(forceString(conf.getUser()));
            yamcsPasswordText.setText(forceString(conf.getPassword()));
            savePasswordButton.setSelection(conf.isSavePassword());
            yamcsPrimaryHostText.setText(forceString(conf.getPrimaryHost()));
            yamcsPrimaryPortText.setText(forceString(conf.getPrimaryPort()));
            yamcsFailoverHostText.setText(forceString(conf.getFailoverHost()));
            yamcsFailoverPortText.setText(forceString(conf.getFailoverPort()));
            nameText.setText(forceString(conf.getName()));
            updateState();
        }
    });
    connViewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object o1, Object o2) {
            YamcsConfiguration c1 = (YamcsConfiguration) o1;
            YamcsConfiguration c2 = (YamcsConfiguration) o2;
            if (c1.getName() != null && c2.getName() != null)
                return c1.getName().compareTo(c2.getName());
            else
                return 0;
        }
    });
    return serverPanel;
}
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) TextUtils.forceString(org.yamcs.studio.core.ui.utils.TextUtils.forceString) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 57 with TableColumnLayout

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

the class ThemeColorBlock method createMasterPart.

@Override
protected void createMasterPart(IManagedForm managedForm, Composite parent) {
    FormToolkit tk = managedForm.getToolkit();
    Section section = tk.createSection(parent, Section.NO_TITLE);
    section.marginWidth = 10;
    section.marginHeight = 5;
    Composite client = tk.createComposite(section, SWT.WRAP);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginWidth = 2;
    layout.marginHeight = 2;
    client.setLayout(layout);
    Composite tableWrapper = tk.createComposite(client, SWT.NONE);
    tableWrapper.setLayoutData(new GridData(GridData.FILL_VERTICAL));
    TableColumnLayout tcl = new TableColumnLayout();
    tableWrapper.setLayout(tcl);
    Table t = tk.createTable(tableWrapper, SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
    t.setHeaderVisible(false);
    t.setLinesVisible(false);
    tk.paintBordersFor(client);
    Composite buttonWrapper = tk.createComposite(client);
    buttonWrapper.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));
    GridLayout gl = new GridLayout();
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    buttonWrapper.setLayout(gl);
    Button b = tk.createButton(buttonWrapper, "Add", SWT.PUSH);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    b.setLayoutData(gd);
    b = tk.createButton(buttonWrapper, "Remove", SWT.PUSH);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    b.setLayoutData(gd);
    b = tk.createButton(buttonWrapper, "Up", SWT.PUSH);
    b.setImage(upImage);
    b.setToolTipText("Move Up");
    gd = new GridData(GridData.FILL_HORIZONTAL);
    b.setLayoutData(gd);
    b = tk.createButton(buttonWrapper, "Down", SWT.PUSH);
    b.setImage(downImage);
    b.setToolTipText("Move Down");
    gd = new GridData(GridData.FILL_HORIZONTAL);
    b.setLayoutData(gd);
    section.setClient(client);
    SectionPart spart = new SectionPart(section);
    managedForm.addPart(spart);
    TableViewer viewer = new TableViewer(t);
    viewer.setContentProvider(ArrayContentProvider.getInstance());
    viewer.addSelectionChangedListener(evt -> {
        managedForm.fireSelectionChanged(spart, evt.getSelection());
    });
    TableViewerColumn colorColumn = new TableViewerColumn(viewer, SWT.NONE);
    colorColumn.setLabelProvider(new ColorLabelProvider() {

        @Override
        public Color getColor(Object element) {
            ThemeColor color = (ThemeColor) element;
            return colorMap.get(color.getRGB());
        }

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

        @Override
        public String getText(Object element) {
            ThemeColor color = (ThemeColor) element;
            return color.getLabel();
        }
    });
    tcl.setColumnData(textColumn.getColumn(), new ColumnWeightData(200, 200, true));
    viewer.setInput(def.getColors());
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Table(org.eclipse.swt.widgets.Table) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) Composite(org.eclipse.swt.widgets.Composite) Color(org.eclipse.swt.graphics.Color) Section(org.eclipse.ui.forms.widgets.Section) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) SectionPart(org.eclipse.ui.forms.SectionPart) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ColorLabelProvider(org.yamcs.studio.core.ui.utils.ColorLabelProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 58 with TableColumnLayout

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

the class DataLinkView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    Composite tableWrapper = new Composite(parent, SWT.NONE);
    tableWrapper.setLayoutData(new GridData(GridData.FILL_BOTH));
    TableColumnLayout tcl = new TableColumnLayout();
    tableWrapper.setLayout(tcl);
    tableViewer = new DataLinkTableViewer(tableWrapper, tcl);
    contentProvider = new DataLinkTableViewerContentProvider(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();
    LinkCatalogue.getInstance().addLinkListener(this);
    YamcsPlugin.getDefault().addYamcsConnectionListener(this);
    ManagementCatalogue.getInstance().addInstanceListener(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 59 with TableColumnLayout

use of org.eclipse.jface.layout.TableColumnLayout in project org.csstudio.display.builder by kasemir.

the class SampleView method doCreatePartControl.

/**
 * {@inheritDoc}
 */
@Override
protected void doCreatePartControl(final Composite parent) {
    final GridLayout layout = new GridLayout(3, false);
    parent.setLayout(layout);
    // Item: pvs [Refresh]
    Label l = new Label(parent, 0);
    l.setText(Messages.SampleView_Item);
    l.setLayoutData(new GridData());
    items = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
    items.setLayoutData(new GridData(SWT.FILL, 0, true, false));
    items.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
            // Configure table to display samples of the selected model item
            if (items.getSelectionIndex() == 0) {
                sample_table.setInput(null);
                return;
            }
            // / Skip initial "Select item" entry
            final int selected = items.getSelectionIndex() - 1;
            int index = 0;
            for (ModelItem item : model.getItems()) {
                if (index == selected) {
                    sample_table.setInput(item);
                    return;
                }
                ++index;
            }
            Activator.getLogger().log(Level.WARNING, "Invalid item index " + selected);
        }
    });
    final Button refresh = new Button(parent, SWT.PUSH);
    refresh.setText(Messages.SampleView_Refresh);
    refresh.setToolTipText(Messages.SampleView_RefreshTT);
    refresh.setLayoutData(new GridData());
    refresh.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            // Trigger GUI update
            update(false);
        }
    });
    // Sample Table
    // TableColumnLayout requires this to be in its own container
    final Composite table_parent = new Composite(parent, 0);
    table_parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, layout.numColumns, 1));
    final TableColumnLayout table_layout = new MinSizeTableColumnLayout(10);
    table_parent.setLayout(table_layout);
    sample_table = new TableViewer(table_parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION | SWT.VIRTUAL);
    sample_table.setContentProvider(new SampleTableContentProvider());
    final Table table = sample_table.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    // Time column
    TableViewerColumn col = TableHelper.createColumn(table_layout, sample_table, Messages.TimeColumn, 90, 100);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final PlotSample sample = (PlotSample) cell.getElement();
            cell.setText(TimestampHelper.format(sample.getPosition()));
        }
    });
    // Value column
    col = TableHelper.createColumn(table_layout, sample_table, Messages.ValueColumn, 50, 100);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final PlotSample sample = (PlotSample) cell.getElement();
            cell.setText(format.format(sample.getVType()));
        }

        @Override
        public String getToolTipText(Object element) {
            final PlotSample sample = (PlotSample) element;
            final VType value = sample.getVType();
            // Show numbers in their 'natural' format which may differ from the Display settings
            if (value instanceof VStatistics) {
                final VStatistics mmd = (VStatistics) value;
                return NLS.bind(Messages.SampleView_MinMaxValueTT, new String[] { Double.toString(mmd.getAverage()), Double.toString(mmd.getMin()), Double.toString(mmd.getMax()) });
            } else if (value instanceof VNumber) {
                final VNumber dbl = (VNumber) value;
                return Double.toString(dbl.getValue().doubleValue());
            } else
                return VTypeHelper.toString(value);
        }
    });
    // Severity column
    col = TableHelper.createColumn(table_layout, sample_table, Messages.SeverityColumn, 90, 50);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final PlotSample sample = (PlotSample) cell.getElement();
            final VType value = sample.getVType();
            final AlarmSeverity severity = VTypeHelper.getSeverity(value);
            cell.setText(severity.toString());
            if (severity == AlarmSeverity.NONE) {
                cell.setBackground(null);
                return;
            }
            final Display display = cell.getControl().getDisplay();
            if (severity == AlarmSeverity.MAJOR)
                cell.setBackground(display.getSystemColor(SWT.COLOR_RED));
            else if (severity == AlarmSeverity.MINOR)
                cell.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
            else
                cell.setBackground(display.getSystemColor(SWT.COLOR_GRAY));
        }
    });
    // Status column
    col = TableHelper.createColumn(table_layout, sample_table, Messages.StatusColumn, 90, 50);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final PlotSample sample = (PlotSample) cell.getElement();
            final VType value = sample.getVType();
            cell.setText(VTypeHelper.getMessage(value));
        }
    });
    // Sample Source column
    col = TableHelper.createColumn(table_layout, sample_table, Messages.SampleView_Source, 90, 10);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final PlotSample sample = (PlotSample) cell.getElement();
            cell.setText(sample.getSource());
        }
    });
    ColumnViewerToolTipSupport.enableFor(sample_table);
    // Be ignorant of any change of the current model after this view
    // is disposed.
    parent.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            if (model != null)
                model.removeListener(model_listener);
        }
    });
}
Also used : MinSizeTableColumnLayout(org.csstudio.ui.util.MinSizeTableColumnLayout) DisposeListener(org.eclipse.swt.events.DisposeListener) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) DisposeEvent(org.eclipse.swt.events.DisposeEvent) GridLayout(org.eclipse.swt.layout.GridLayout) VType(org.diirt.vtype.VType) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) MinSizeTableColumnLayout(org.csstudio.ui.util.MinSizeTableColumnLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) VStatistics(org.diirt.vtype.VStatistics) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) Table(org.eclipse.swt.widgets.Table) AlarmSeverity(org.diirt.vtype.AlarmSeverity) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) VNumber(org.diirt.vtype.VNumber) ViewerCell(org.eclipse.jface.viewers.ViewerCell) GridData(org.eclipse.swt.layout.GridData) PlotSample(org.csstudio.trends.databrowser3.model.PlotSample) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener) Display(org.eclipse.swt.widgets.Display)

Example 60 with TableColumnLayout

use of org.eclipse.jface.layout.TableColumnLayout in project org.csstudio.display.builder by kasemir.

the class ArchiveListGUI method createGUI.

/**
 * Create GUI elements
 *  @param parent Parent widget
 */
private void createGUI(final Composite parent) {
    final GridLayout layout = new GridLayout(3, false);
    parent.setLayout(layout);
    // URL:  ___urls___  [info]
    Label l;
    l = new Label(parent, 0);
    l.setText(Messages.Search_URL);
    l.setLayoutData(new GridData());
    urls = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
    urls.setToolTipText(Messages.Search_URL_TT);
    for (ArchiveServerURL url : server_urls) urls.add(url.getDisplayName());
    urls.setLayoutData(new GridData(SWT.FILL, 0, true, false));
    if (urls.getItemCount() <= 0) {
        urls.add(Messages.ArchiveListGUI_NoArchives);
        urls.setEnabled(false);
    }
    urls.select(0);
    info = new Button(parent, SWT.PUSH);
    info.setText(Messages.ArchiveServerInfo);
    info.setToolTipText(Messages.ArchiveServerInfoTT);
    info.setEnabled(false);
    // Table for archives, displaying array of ArchiveDataSource entries
    // TableColumnLayout requires table in its own container
    final Composite table_parent = new Composite(parent, 0);
    table_parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, layout.numColumns, 1));
    final TableColumnLayout table_layout = new MinSizeTableColumnLayout(10);
    table_parent.setLayout(table_layout);
    archive_table = new TableViewer(table_parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    archive_table.setContentProvider(new ArrayContentProvider());
    TableViewerColumn col = TableHelper.createColumn(table_layout, archive_table, Messages.ArchiveName, 150, 100);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ArchiveDataSource archive = (ArchiveDataSource) cell.getElement();
            cell.setText(archive.getName());
        }
    });
    new TableColumnSortHelper<ArchiveDataSource>(archive_table, col) {

        @Override
        public int compare(final ArchiveDataSource item1, final ArchiveDataSource item2) {
            return item1.getName().compareTo(item2.getName());
        }
    };
    col = TableHelper.createColumn(table_layout, archive_table, Messages.ArchiveDescription, 50, 100);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ArchiveDataSource archive = (ArchiveDataSource) cell.getElement();
            cell.setText(archive.getDescription());
        }
    });
    new TableColumnSortHelper<ArchiveDataSource>(archive_table, col) {

        @Override
        public int compare(final ArchiveDataSource item1, final ArchiveDataSource item2) {
            return item1.getDescription().compareTo(item2.getDescription());
        }
    };
    col = TableHelper.createColumn(table_layout, archive_table, Messages.ArchiveKey, 35, 5);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ArchiveDataSource archive = (ArchiveDataSource) cell.getElement();
            cell.setText(Integer.toString(archive.getKey()));
        }
    });
    new TableColumnSortHelper<ArchiveDataSource>(archive_table, col) {

        @Override
        public int compare(final ArchiveDataSource item1, final ArchiveDataSource item2) {
            return item1.getKey() - item2.getKey();
        }
    };
    final Table table = archive_table.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
}
Also used : MinSizeTableColumnLayout(org.csstudio.ui.util.MinSizeTableColumnLayout) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ArchiveServerURL(org.csstudio.trends.databrowser3.preferences.ArchiveServerURL) Label(org.eclipse.swt.widgets.Label) ArchiveDataSource(org.csstudio.trends.databrowser3.model.ArchiveDataSource) Combo(org.eclipse.swt.widgets.Combo) ViewerCell(org.eclipse.jface.viewers.ViewerCell) GridLayout(org.eclipse.swt.layout.GridLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) MinSizeTableColumnLayout(org.csstudio.ui.util.MinSizeTableColumnLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) TableColumnSortHelper(org.csstudio.apputil.ui.swt.TableColumnSortHelper) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider)

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