Search in sources :

Example 1 with InstanceFilter

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;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) InstanceFilter(org.yamcs.client.InstanceFilter) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) ArrayList(java.util.ArrayList) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Aggregations

ArrayList (java.util.ArrayList)1 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 ColumnPixelData (org.eclipse.jface.viewers.ColumnPixelData)1 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 InstanceFilter (org.yamcs.client.InstanceFilter)1