Search in sources :

Example 1 with NamedObjectId

use of org.yamcs.protobuf.Yamcs.NamedObjectId in project yamcs-studio by yamcs.

the class ParameterCatalogue method processMetaParameters.

public synchronized void processMetaParameters(List<ParameterInfo> metaParameters) {
    log.info(String.format("Loaded %d parameters", metaParameters.size()));
    this.metaParameters = new ArrayList<>(metaParameters);
    this.metaParameters.sort((p1, p2) -> {
        return p1.getQualifiedName().compareTo(p2.getQualifiedName());
    });
    for (ParameterInfo p : this.metaParameters) {
        NamedObjectId id = NamedObjectId.newBuilder().setName(p.getQualifiedName()).build();
        parametersById.put(id, p);
        // Update unit index
        if (p != null && p.hasType() && p.getType().getUnitSetCount() > 0) {
            String combinedUnit = p.getType().getUnitSet(0).getUnit();
            for (int i = 1; i < p.getType().getUnitSetCount(); i++) {
                combinedUnit += " " + p.getType().getUnitSet(i).getUnit();
            }
            unitsById.put(id, combinedUnit);
        }
    }
    parameterListeners.forEach(ParameterListener::mdbUpdated);
}
Also used : ParameterInfo(org.yamcs.protobuf.Mdb.ParameterInfo) NamedObjectId(org.yamcs.protobuf.Yamcs.NamedObjectId)

Example 2 with NamedObjectId

use of org.yamcs.protobuf.Yamcs.NamedObjectId in project yamcs-studio by yamcs.

the class StackedCommand method buildCommandFromSource.

public static StackedCommand buildCommandFromSource(String commandSource) throws Exception {
    StackedCommand result = new StackedCommand();
    // <CommandAlias>()
    if (commandSource == null)
        throw new Exception("No Source attached to this command");
    commandSource = commandSource.trim();
    if (commandSource.isEmpty())
        throw new Exception("No Source attached to this command");
    int indexStartOfArguments = commandSource.indexOf("(");
    int indexStopOfArguments = commandSource.lastIndexOf(")");
    String commandArguments = commandSource.substring(indexStartOfArguments + 1, indexStopOfArguments);
    commandArguments = commandArguments.replaceAll("[\n]", "");
    String commandAlias = commandSource.substring(0, indexStartOfArguments);
    // Retrieve meta command and selected namespace
    CommandInfo commandInfo = null;
    String selectedAlias = "";
    for (CommandInfo ci : CommandingCatalogue.getInstance().getMetaCommands()) {
        for (NamedObjectId noi : ci.getAliasList()) {
            String alias = noi.getNamespace() + "/" + noi.getName();
            if (alias.equals(commandAlias)) {
                commandInfo = ci;
                selectedAlias = alias;
                break;
            }
        }
    }
    if (commandInfo == null)
        throw new Exception("Unable to retrieved this command in the MDB");
    result.setMetaCommand(commandInfo);
    result.setSelectedAliase(selectedAlias);
    // Retrieve arguments assignment
    // TODO: write formal source grammar
    String[] commandArgumentsTab = commandArguments.split(",");
    for (String commandArgument : commandArgumentsTab) {
        if (commandArgument == null || commandArgument.isEmpty())
            continue;
        String[] components = commandArgument.split(":");
        String argument = components[0].trim();
        String value = components[1].trim();
        boolean foundArgument = false;
        for (ArgumentInfo ai : commandInfo.getArgumentList()) {
            foundArgument = ai.getName().toUpperCase().equals(argument.toUpperCase());
            if (foundArgument) {
                if (value.startsWith("\"") && value.endsWith("\""))
                    value = value.substring(1, value.length() - 1);
                result.addAssignment(ai, value);
                break;
            }
        }
        if (!foundArgument)
            throw new Exception("Argument " + argument + " is not part of the command definition");
    }
    return result;
}
Also used : CommandInfo(org.yamcs.protobuf.Mdb.CommandInfo) StyledString(org.eclipse.jface.viewers.StyledString) NamedObjectId(org.yamcs.protobuf.Yamcs.NamedObjectId) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ArgumentInfo(org.yamcs.protobuf.Mdb.ArgumentInfo)

Example 3 with NamedObjectId

use of org.yamcs.protobuf.Yamcs.NamedObjectId 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 4 with NamedObjectId

use of org.yamcs.protobuf.Yamcs.NamedObjectId in project yamcs-studio by yamcs.

the class AddToStackWizardPage1 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;
    composite.setLayout(gl);
    // add filter box
    Text searchbox = new Text(composite, SWT.SEARCH | SWT.BORDER | SWT.ICON_CANCEL);
    searchbox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // build tree table
    ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources(), composite);
    level1Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level1s.png"));
    level2Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level2s.png"));
    level3Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level3s.png"));
    level4Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level4s.png"));
    level5Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level5s.png"));
    Composite tableWrapper = new Composite(composite, SWT.NONE);
    tcl = new TreeColumnLayout();
    tableWrapper.setLayoutData(new GridData(GridData.FILL_BOTH));
    tableWrapper.setLayout(tcl);
    commandsTreeTable = new TreeViewer(tableWrapper, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    commandsTreeTable.getTree().setHeaderVisible(true);
    commandsTreeTable.getTree().setLinesVisible(false);
    // column xtce path
    TreeViewerColumn pathColumn = new TreeViewerColumn(commandsTreeTable, SWT.NONE);
    pathColumn.getColumn().setText(COL_PATH);
    pathColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            CommandInfo cmd = (CommandInfo) element;
            return cmd.getName();
        }
    });
    tcl.setColumnData(pathColumn.getColumn(), new ColumnPixelData(COLUMN_WIDTH));
    // column significance
    TreeViewerColumn significanceColumn = new TreeViewerColumn(commandsTreeTable, SWT.NONE);
    significanceColumn.getColumn().setText(COL_SIGN);
    significanceColumn.getColumn().setToolTipText("Significance Level");
    significanceColumn.getColumn().setAlignment(SWT.CENTER);
    significanceColumn.setLabelProvider(new CenteredImageLabelProvider() {

        @Override
        public Image getImage(Object element) {
            CommandInfo cmd = (CommandInfo) element;
            if (cmd.getSignificance() == null)
                return null;
            switch(cmd.getSignificance().getConsequenceLevel()) {
                case WATCH:
                    return level1Image;
                case WARNING:
                    return level2Image;
                case DISTRESS:
                    return level3Image;
                case CRITICAL:
                    return level4Image;
                case SEVERE:
                    return level5Image;
                default:
                    return null;
            }
        }
    });
    tcl.setColumnData(significanceColumn.getColumn(), new ColumnPixelData(40));
    // column qualified name
    TreeViewerColumn nameColumn = new TreeViewerColumn(commandsTreeTable, SWT.NONE);
    nameColumn.getColumn().setText(COL_QNAME);
    nameColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            CommandInfo cmd = (CommandInfo) element;
            if (cmd.getAbstract()) {
                // show a blank line if the command is abstract
                return "";
            }
            return cmd.getQualifiedName();
        }
    });
    tcl.setColumnData(nameColumn.getColumn(), new ColumnPixelData(COLUMN_WIDTH));
    // on item selection update significance message and page completion status
    commandsTreeTable.addSelectionChangedListener(evt -> {
        IStructuredSelection sel = (IStructuredSelection) evt.getSelection();
        if (sel.isEmpty()) {
            setMessage(null);
            return;
        }
        CommandInfo cmd = (CommandInfo) sel.getFirstElement();
        setMessage(getMessage(cmd));
        command.setMetaCommand(cmd);
        command.setSelectedAliase(cmd.getQualifiedName());
        setPageComplete(!cmd.getAbstract());
    });
    CommandTreeContentProvider commandTreeContentProvider = new CommandTreeContentProvider();
    commandsTreeTable.setContentProvider(commandTreeContentProvider);
    // load command list
    Collection<CommandInfo> commandInfos = new ArrayList<>();
    CommandingCatalogue.getInstance().getMetaCommands().forEach(cmd -> {
        // add aliases columns
        for (NamedObjectId alias : cmd.getAliasList()) {
            String namespace = alias.getNamespace();
            if (!namespaces.contains(namespace) && !namespace.startsWith("/")) {
                namespaces.add(namespace);
                addAliasColumn(namespace);
            }
        }
        commandInfos.add(cmd);
    });
    commandsTreeTable.setInput(commandInfos);
    commandsTreeTable.expandAll();
    // with a small hack to display full data on the first column
    for (TreeColumn tc : commandsTreeTable.getTree().getColumns()) tc.pack();
    pathColumn.getColumn().setWidth(pathColumn.getColumn().getWidth() + 11 * commandTreeContentProvider.nbLevels);
    for (TreeColumn tc : commandsTreeTable.getTree().getColumns()) {
        if (tc.getWidth() > COLUMN_MAX_WIDTH)
            tc.setWidth(COLUMN_MAX_WIDTH);
    }
    // filter
    CommandInfoTreeViewerFilter filter = new CommandInfoTreeViewerFilter(commandTreeContentProvider);
    commandsTreeTable.addFilter(filter);
    searchbox.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent ke) {
            filter.setSearchTerm(searchbox.getText());
            commandsTreeTable.refresh();
            commandsTreeTable.expandAll();
        }
    });
    commandsTreeTable.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object o1, Object o2) {
            CommandInfo c1 = (CommandInfo) o1;
            CommandInfo c2 = (CommandInfo) o2;
            return c1.getQualifiedName().compareTo(c2.getQualifiedName());
        }
    });
}
Also used : LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) TreeViewer(org.eclipse.jface.viewers.TreeViewer) KeyAdapter(org.eclipse.swt.events.KeyAdapter) ArrayList(java.util.ArrayList) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) KeyEvent(org.eclipse.swt.events.KeyEvent) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) Text(org.eclipse.swt.widgets.Text) ResourceManager(org.eclipse.jface.resource.ResourceManager) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) CenteredImageLabelProvider(org.yamcs.studio.core.ui.utils.CenteredImageLabelProvider) CommandInfo(org.yamcs.protobuf.Mdb.CommandInfo) GridData(org.eclipse.swt.layout.GridData) NamedObjectId(org.yamcs.protobuf.Yamcs.NamedObjectId)

Example 5 with NamedObjectId

use of org.yamcs.protobuf.Yamcs.NamedObjectId in project yamcs-studio by yamcs.

the class AddToStackWizardPage1 method addAliasColumn.

// Add dynamically columns for each alias of a command
private void addAliasColumn(String namespace) {
    TreeViewerColumn aliasColumn = new TreeViewerColumn(commandsTreeTable, SWT.NONE);
    aliasColumn.getColumn().setText(namespace);
    aliasColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            CommandInfo cmd = (CommandInfo) element;
            if (cmd.getAbstract()) {
                // show a blank line if the command is abstract
                return "";
            }
            List<NamedObjectId> aliases = cmd.getAliasList();
            for (NamedObjectId aliase : aliases) {
                if (aliase.getNamespace().equals(namespace))
                    return aliase.getName();
            }
            return "";
        }
    });
    tcl.setColumnData(aliasColumn.getColumn(), new ColumnPixelData(COLUMN_WIDTH));
}
Also used : ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) CommandInfo(org.yamcs.protobuf.Mdb.CommandInfo) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) ArrayList(java.util.ArrayList) List(java.util.List) NamedObjectId(org.yamcs.protobuf.Yamcs.NamedObjectId) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn)

Aggregations

NamedObjectId (org.yamcs.protobuf.Yamcs.NamedObjectId)12 ArrayList (java.util.ArrayList)4 CommandInfo (org.yamcs.protobuf.Mdb.CommandInfo)4 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)3 ColumnPixelData (org.eclipse.jface.viewers.ColumnPixelData)3 TreeViewerColumn (org.eclipse.jface.viewers.TreeViewerColumn)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 List (java.util.List)2 TreeColumnLayout (org.eclipse.jface.layout.TreeColumnLayout)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2 Viewer (org.eclipse.jface.viewers.Viewer)2 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)2 Text (org.eclipse.swt.widgets.Text)2 ParameterInfo (org.yamcs.protobuf.Mdb.ParameterInfo)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 GradientPaint (java.awt.GradientPaint)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1