use of org.yamcs.client.InstanceFilter in project yamcs-studio by yamcs.
the class SwitchProcessorDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
var area = (Composite) super.createDialogArea(parent);
var composite = new Composite(area, SWT.NONE);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
composite.setLayout(new GridLayout());
var tableWrapper = new Composite(composite, SWT.NONE);
var tcl = new TableColumnLayout();
tableWrapper.setLayoutData(new GridData(GridData.FILL_BOTH));
tableWrapper.setLayout(tcl);
processorsTable = new TableViewer(tableWrapper, SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION);
processorsTable.getTable().setHeaderVisible(true);
processorsTable.getTable().setLinesVisible(true);
var instanceColumn = new TableViewerColumn(processorsTable, SWT.NONE);
instanceColumn.getColumn().setText("Instance");
instanceColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
var info = (ProcessorInfo) element;
return info.getInstance();
}
});
tcl.setColumnData(instanceColumn.getColumn(), new ColumnPixelData(100));
var nameColumn = new TableViewerColumn(processorsTable, SWT.NONE);
nameColumn.getColumn().setText("Processor");
nameColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
var info = (ProcessorInfo) element;
return info.getName();
}
});
tcl.setColumnData(nameColumn.getColumn(), new ColumnWeightData(100));
var typeColumn = new TableViewerColumn(processorsTable, SWT.NONE);
typeColumn.getColumn().setText("Type");
typeColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
var info = (ProcessorInfo) element;
return info.getType();
}
});
tcl.setColumnData(typeColumn.getColumn(), new ColumnPixelData(100));
processorsTable.setContentProvider(ArrayContentProvider.getInstance());
processorsTable.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
processorsTable.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
if (e1 == null || e2 == null) {
return 0;
}
var p1 = (ProcessorInfo) e1;
var p2 = (ProcessorInfo) e2;
var c = p1.getInstance().compareTo(p2.getInstance());
return (c != 0) ? c : p1.getName().compareTo(p2.getName());
}
});
processorsTable.addSelectionChangedListener(event -> {
var okButton = getButton(IDialogConstants.OK_ID);
okButton.setEnabled(!event.getSelection().isEmpty());
});
var client = YamcsPlugin.getYamcsClient();
var filter = new InstanceFilter();
filter.setState(InstanceState.RUNNING);
client.listInstances(filter).whenComplete((response, exc) -> {
parent.getDisplay().asyncExec(() -> {
if (exc == null) {
var processors = new ArrayList<ProcessorInfo>();
for (var instance : response.getInstancesList()) {
processors.addAll(instance.getProcessorsList());
}
processorsTable.setInput(processors);
}
});
});
return composite;
}
Aggregations