Search in sources :

Example 6 with ParameterInfo

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());
        }
    });
}
Also used : TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) ParameterInfo(org.yamcs.protobuf.Mdb.ParameterInfo) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) GridData(org.eclipse.swt.layout.GridData) NamedObjectId(org.yamcs.protobuf.Yamcs.NamedObjectId) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 7 with ParameterInfo

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;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) ParameterInfo(org.yamcs.protobuf.Mdb.ParameterInfo) IOException(java.io.IOException)

Example 8 with ParameterInfo

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();
}
Also used : ParameterInfo(org.yamcs.protobuf.Mdb.ParameterInfo)

Example 9 with ParameterInfo

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);
            }
        });
    }
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ParameterValue(org.yamcs.protobuf.Pvalue.ParameterValue) ArrayList(java.util.ArrayList) ParameterInfo(org.yamcs.protobuf.Mdb.ParameterInfo) Date(java.util.Date) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) SimpleDateFormat(java.text.SimpleDateFormat) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 10 with ParameterInfo

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();
}
Also used : ParameterInfo(org.yamcs.protobuf.Mdb.ParameterInfo)

Aggregations

ParameterInfo (org.yamcs.protobuf.Mdb.ParameterInfo)14 ArrayList (java.util.ArrayList)4 PVConnectionInfo (org.yamcs.studio.css.core.pvmanager.PVConnectionInfo)3 IOException (java.io.IOException)2 List (java.util.List)2 CoreException (org.eclipse.core.runtime.CoreException)2 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)2 NamedObjectId (org.yamcs.protobuf.Yamcs.NamedObjectId)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Collections (java.util.Collections)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Level (java.util.logging.Level)1