use of org.yamcs.protobuf.Mdb.ParameterInfo in project yamcs-studio by yamcs.
the class AddParameterPage method createControl.
@Override
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
setControl(composite);
GridLayout gl = new GridLayout();
gl.marginHeight = 0;
gl.marginWidth = 0;
gl.numColumns = 2;
gl.makeColumnsEqualWidth = false;
composite.setLayout(gl);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite tableWrapper1 = new Composite(composite, SWT.NONE);
contentProvider = new ParameterContentProvider();
trcl = new TreeColumnLayout();
tableWrapper1.setLayoutData(new GridData(GridData.FILL_BOTH));
tableWrapper1.setLayout(trcl);
namespaceTable = new TreeViewer(tableWrapper1, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
namespaceTable.getTree().setHeaderVisible(true);
namespaceTable.getTree().setLinesVisible(true);
// column container
TreeViewerColumn pathColumn = new TreeViewerColumn(namespaceTable, SWT.NONE);
pathColumn.getColumn().setText(COL_NAMESPACE);
pathColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
String namespace = (String) element;
return namespace;
}
});
trcl.setColumnData(pathColumn.getColumn(), new ColumnPixelData(COLUMN_WIDTH));
namespaceTable.addSelectionChangedListener(evt -> {
IStructuredSelection sel = (IStructuredSelection) evt.getSelection();
if (sel.isEmpty()) {
contentProvider.setNamespace(null);
return;
}
contentProvider.setNamespace((String) sel.getFirstElement());
});
namespaceTable.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
IStructuredSelection sel = new IStructuredSelection() {
@Override
public boolean isEmpty() {
return false;
}
@Override
public List toList() {
return Arrays.asList(contentProvider.getElements(event));
}
@Override
public Object[] toArray() {
return contentProvider.getElements(event);
}
@Override
public int size() {
return contentProvider.getElements(event).length;
}
@Override
public Iterator iterator() {
return Arrays.asList(contentProvider.getElements(event)).iterator();
}
@Override
public Object getFirstElement() {
return null;
}
};
parameterTable.setSelection(sel);
}
});
namespaceTable.setContentProvider(new NamespaceContentProvider());
namespaceTable.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object o1, Object o2) {
String n1 = (String) o1;
String n2 = (String) o2;
return n1.compareTo(n2);
}
});
Composite tableWrapper2 = new Composite(composite, SWT.NONE);
tcl = new TableColumnLayout();
tableWrapper2.setLayoutData(new GridData(GridData.FILL_BOTH));
tableWrapper2.setLayout(tcl);
parameterTable = new TableViewer(tableWrapper2, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
parameterTable.getTable().setHeaderVisible(true);
parameterTable.getTable().setLinesVisible(true);
TableViewerColumn nameColumn = new TableViewerColumn(parameterTable, SWT.NONE);
nameColumn.getColumn().setText(COL_NAME);
nameColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ParameterInfo obj = (ParameterInfo) element;
return obj.getQualifiedName();
}
});
tcl.setColumnData(nameColumn.getColumn(), new ColumnPixelData(COLUMN_WIDTH));
parameterTable.addSelectionChangedListener(evt -> {
IStructuredSelection sel = (IStructuredSelection) evt.getSelection();
if (sel.isEmpty()) {
setParameter(new ArrayList<>());
return;
}
List<ParameterInfo> parameters = new ArrayList<>();
for (Object obj : sel.toArray()) {
parameters.add((ParameterInfo) obj);
}
setParameter(parameters);
setPageComplete(true);
});
parameterTable.setContentProvider(contentProvider);
parameterTable.setInput(contentProvider);
ParameterCatalogue.getInstance().getMetaParameters().forEach(pmtr -> {
for (NamedObjectId alias : pmtr.getAliasList()) {
String namespace = alias.getNamespace();
if (!namespace.startsWith("/"))
return;
if (!parameterInfos.containsKey(namespace)) {
parameterInfos.put(namespace, new ArrayList<>());
}
parameterInfos.get(namespace).add(pmtr);
String parentns = namespace.substring(0, namespace.lastIndexOf("/"));
while (!parentns.isEmpty()) {
if (!parameterInfos.containsKey(parentns)) {
parameterInfos.put(parentns, new ArrayList<>());
}
parentns = parentns.substring(0, parentns.lastIndexOf("/"));
}
}
});
namespaceTable.setInput(parameterInfos.keySet());
parameterTable.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object o1, Object o2) {
ParameterInfo n1 = (ParameterInfo) o1;
ParameterInfo n2 = (ParameterInfo) o2;
return n1.getQualifiedName().compareTo(n2.getQualifiedName());
}
});
}
use of org.yamcs.protobuf.Mdb.ParameterInfo in project yamcs-studio by yamcs.
the class AlphaNumericEditor method loadData.
private List<ParameterInfo> loadData() {
try {
List<ParameterInfo> info = new ArrayList<>();
BufferedReader reader = new BufferedReader(new InputStreamReader(input.getFile().getContents()));
String line;
while ((line = reader.readLine()) != null) {
for (ParameterInfo meta : ParameterCatalogue.getInstance().getMetaParameters()) {
if (line.contains(meta.getQualifiedName()))
info.add(meta);
}
}
return info;
} catch (IOException | CoreException e) {
log.log(Level.SEVERE, "Could not read parameter list", e);
return null;
}
}
use of org.yamcs.protobuf.Mdb.ParameterInfo in project yamcs-studio by yamcs.
the class ParameterTableViewer method clear.
public void clear() {
for (ParameterInfo info : readers.keySet()) {
PVCatalogue.getInstance().unregister(readers.get(info));
}
readers.clear();
contentProvider.clearAll();
refresh();
}
use of org.yamcs.protobuf.Mdb.ParameterInfo in project yamcs-studio by yamcs.
the class ParameterTableViewer method addFixedColumns.
private void addFixedColumns(TableColumnLayout tcl) {
TableViewerColumn nameColumn = new TableViewerColumn(this, SWT.LEFT);
nameColumn.getColumn().setText(COL_NAME);
tcl.setColumnData(nameColumn.getColumn(), new ColumnWeightData(40));
nameColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ParameterInfo cnt = (ParameterInfo) element;
return cnt.getQualifiedName();
}
});
TableViewerColumn engValueColumn = new TableViewerColumn(this, SWT.RIGHT);
engValueColumn.getColumn().setText(COL_ENG);
tcl.setColumnData(engValueColumn.getColumn(), new ColumnWeightData(10));
engValueColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ParameterReader reader = readers.get(element);
if (reader == null || reader.getValue() == null)
return "-";
ParameterValue value = reader.getValue();
return String.valueOf(getValue(value.getEngValue()));
}
});
TableViewerColumn rawValueColumn = new TableViewerColumn(this, SWT.RIGHT);
rawValueColumn.getColumn().setText(COL_RAW);
tcl.setColumnData(rawValueColumn.getColumn(), new ColumnWeightData(10));
rawValueColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ParameterReader reader = readers.get(element);
if (reader == null || reader.getValue() == null)
return "-";
ParameterValue value = reader.getValue();
return String.valueOf(getValue(value.getRawValue()));
}
});
TableViewerColumn gentimeValueColumn = new TableViewerColumn(this, SWT.LEFT);
gentimeValueColumn.getColumn().setText(COL_TIME);
tcl.setColumnData(gentimeValueColumn.getColumn(), new ColumnWeightData(20));
gentimeValueColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ParameterReader reader = readers.get(element);
if (reader == null || reader.getValue() == null)
return "-";
ParameterValue value = reader.getValue();
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
Date time = new Date(value.getGenerationTime());
String strDate = sdfDate.format(time);
return strDate;
}
});
TableViewerColumn aqutimeValueColumn = new TableViewerColumn(this, SWT.LEFT);
aqutimeValueColumn.getColumn().setText(COL_AQU_TIME);
tcl.setColumnData(aqutimeValueColumn.getColumn(), new ColumnWeightData(20));
aqutimeValueColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ParameterReader reader = readers.get(element);
if (reader == null || reader.getValue() == null)
return "-";
ParameterValue value = reader.getValue();
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
Date time = new Date(value.getAcquisitionTime());
String strDate = sdfDate.format(time);
return strDate;
}
});
// Common properties to all columns
List<TableViewerColumn> columns = new ArrayList<>();
columns.add(nameColumn);
columns.add(engValueColumn);
columns.add(rawValueColumn);
columns.add(gentimeValueColumn);
columns.add(aqutimeValueColumn);
for (TableViewerColumn column : columns) {
// prevent resize to 0
column.getColumn().addControlListener(new ControlListener() {
@Override
public void controlMoved(ControlEvent e) {
}
@Override
public void controlResized(ControlEvent e) {
if (column.getColumn().getWidth() < 5)
column.getColumn().setWidth(5);
}
});
}
}
use of org.yamcs.protobuf.Mdb.ParameterInfo in project yamcs-studio by yamcs.
the class ParameterTableViewer method restoreParameters.
public void restoreParameters() {
clear();
for (ParameterInfo info : contentProvider.getInitial()) {
addParameter(info);
}
refresh();
}
Aggregations