Search in sources :

Example 41 with ColumnLabelProvider

use of org.eclipse.jface.viewers.ColumnLabelProvider 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)

Aggregations

ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)41 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)28 Composite (org.eclipse.swt.widgets.Composite)16 Image (org.eclipse.swt.graphics.Image)13 TableViewer (org.eclipse.jface.viewers.TableViewer)11 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)10 GridData (org.eclipse.swt.layout.GridData)10 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)9 ColumnPixelData (org.eclipse.jface.viewers.ColumnPixelData)8 ArrayList (java.util.ArrayList)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 TreeViewer (org.eclipse.jface.viewers.TreeViewer)7 TreeViewerColumn (org.eclipse.jface.viewers.TreeViewerColumn)7 GridLayout (org.eclipse.swt.layout.GridLayout)7 Table (org.eclipse.swt.widgets.Table)7 Text (org.eclipse.swt.widgets.Text)6 ControlEvent (org.eclipse.swt.events.ControlEvent)5 ControlListener (org.eclipse.swt.events.ControlListener)5 DatabaseModelBean (net.heartsome.cat.common.bean.DatabaseModelBean)4 Viewer (org.eclipse.jface.viewers.Viewer)4