Search in sources :

Example 1 with ArgumentTypeInfo

use of org.yamcs.protobuf.Mdb.ArgumentTypeInfo in project yamcs-studio by yamcs.

the class ArgumentTableBuilder method createArgumentTable.

public TableViewer createArgumentTable(Composite shell) {
    Label desc = new Label(shell, SWT.NONE);
    desc.setText("Specify the command arguments:");
    desc.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    TableColumnLayout tcl = new TableColumnLayout();
    Composite argumentsComposite = new Composite(shell, SWT.NONE);
    argumentsComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    argumentsComposite.setLayout(tcl);
    argumentTable = new TableViewer(argumentsComposite, SWT.BORDER | SWT.V_SCROLL | SWT.FULL_SELECTION);
    Table table = argumentTable.getTable();
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    table.setLayoutData(gridData);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    argumentTable.setContentProvider(new ArrayContentProvider());
    // create columns
    String[] titles = { "Argument", "Eng. Type", "Range", "Value", "Default Value" };
    // argument
    TableViewerColumn column = createTableViewerColumn(argumentTable, titles[0], 0);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof ArgumentAssignement)
                return ((ArgumentAssignement) element).arg.getName();
            return super.getText(element);
        }
    });
    tcl.setColumnData(column.getColumn(), new ColumnPixelData(10));
    // eng. type
    column = createTableViewerColumn(argumentTable, titles[1], 1);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof ArgumentAssignement)
                return ((ArgumentAssignement) element).arg.getType().getEngType();
            return super.getText(element);
        }
    });
    tcl.setColumnData(column.getColumn(), new ColumnPixelData(10));
    // range
    column = createTableViewerColumn(argumentTable, titles[2], 2);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof ArgumentAssignement) {
                ArgumentTypeInfo ati = ((ArgumentAssignement) element).arg.getType();
                String format = INT.equals(ati.getEngType()) ? "%.0f" : "%f";
                String range = "";
                if (ati.hasRangeMin()) {
                    range = "[" + String.format(format, ati.getRangeMin()) + ", ";
                }
                if (ati.hasRangeMax()) {
                    range += String.format(format, ati.getRangeMax()) + "]";
                }
                return range;
            }
            return super.getText(element);
        }
    });
    tcl.setColumnData(column.getColumn(), new ColumnPixelData(0));
    // value
    column = createTableViewerColumn(argumentTable, titles[3], 3);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof ArgumentAssignement)
                return ((ArgumentAssignement) element).value;
            return super.getText(element);
        }
    });
    column.setEditingSupport(new ParameterEditingSupport(argumentTable));
    tcl.setColumnData(column.getColumn(), new ColumnPixelData(200));
    // default value
    column = createTableViewerColumn(argumentTable, titles[4], 4);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof ArgumentAssignement) {
                ArgumentAssignement aa = (ArgumentAssignement) element;
                return aa.arg.hasInitialValue() ? aa.arg.getInitialValue() : null;
            }
            return super.getText(element);
        }
    });
    tcl.setColumnData(column.getColumn(), new ColumnPixelData(200));
    return argumentTable;
}
Also used : Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ArgumentTypeInfo(org.yamcs.protobuf.Mdb.ArgumentTypeInfo) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Aggregations

TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 ColumnPixelData (org.eclipse.jface.viewers.ColumnPixelData)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)1 GridData (org.eclipse.swt.layout.GridData)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Table (org.eclipse.swt.widgets.Table)1 ArgumentTypeInfo (org.yamcs.protobuf.Mdb.ArgumentTypeInfo)1