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;
}
Aggregations