Search in sources :

Example 1 with CommandInfo

use of org.yamcs.protobuf.Mdb.CommandInfo in project yamcs-studio by yamcs.

the class CommandingCatalogue method processMetaCommands.

public synchronized void processMetaCommands(List<CommandInfo> metaCommands) {
    this.metaCommands = new ArrayList<>(metaCommands);
    this.metaCommands.sort((p1, p2) -> {
        return p1.getQualifiedName().compareTo(p2.getQualifiedName());
    });
    for (CommandInfo cmd : this.metaCommands) {
        commandsByQualifiedName.put(cmd.getQualifiedName(), cmd);
    }
}
Also used : CommandInfo(org.yamcs.protobuf.Mdb.CommandInfo)

Example 2 with CommandInfo

use of org.yamcs.protobuf.Mdb.CommandInfo in project yamcs-studio by yamcs.

the class ImportCommandStackHandler method parseCommandStack.

public List<StackedCommand> parseCommandStack(String fileName) {
    try {
        final JAXBContext jc = JAXBContext.newInstance(org.yamcs.studio.commanding.stack.xml.CommandStack.class);
        final Unmarshaller unmarshaller = jc.createUnmarshaller();
        final org.yamcs.studio.commanding.stack.xml.CommandStack commandStack = (org.yamcs.studio.commanding.stack.xml.CommandStack) unmarshaller.unmarshal(new FileReader(fileName));
        List<StackedCommand> importedStack = new LinkedList<StackedCommand>();
        for (CommandStack.Command c : commandStack.getCommand()) {
            StackedCommand sc = new StackedCommand();
            CommandInfo mc = CommandingCatalogue.getInstance().getCommandInfo(c.getQualifiedName());
            if (mc == null) {
                MessageDialog.openError(Display.getCurrent().getActiveShell(), "Import Command Stack", "Command " + c.getQualifiedName() + " does not exist in MDB.");
                return null;
            }
            sc.setMetaCommand(mc);
            sc.setSelectedAliase(c.getSelectedAlias());
            sc.setComment(c.getComment());
            for (CommandArgument ca : c.getCommandArgument()) {
                ArgumentInfo a = getArgumentFromYamcs(mc, ca.getArgumentName());
                if (a == null) {
                    MessageDialog.openError(Display.getCurrent().getActiveShell(), "Import Command Stack", "In command " + c.getQualifiedName() + ", argument " + ca.getArgumentName() + " does not exist in MDB.");
                    return null;
                }
                sc.addAssignment(a, ca.getArgumentValue());
            }
            importedStack.add(sc);
        }
        return importedStack;
    } catch (Exception e) {
        log.log(Level.SEVERE, "Unable to load command stack for importation. Check the XML file is correct. Details:\n" + e.toString());
        MessageDialog.openError(Display.getCurrent().getActiveShell(), "Import Command Stack", "Unable to load command stack for importation. Check the XML file is correct. Details:\n" + e.toString());
        return null;
    }
}
Also used : CommandStack(org.yamcs.studio.commanding.stack.xml.CommandStack) CommandArgument(org.yamcs.studio.commanding.stack.xml.CommandStack.Command.CommandArgument) JAXBContext(javax.xml.bind.JAXBContext) LinkedList(java.util.LinkedList) ExecutionException(org.eclipse.core.commands.ExecutionException) CommandInfo(org.yamcs.protobuf.Mdb.CommandInfo) CommandStack(org.yamcs.studio.commanding.stack.xml.CommandStack) FileReader(java.io.FileReader) Unmarshaller(javax.xml.bind.Unmarshaller) ArgumentInfo(org.yamcs.protobuf.Mdb.ArgumentInfo)

Example 3 with CommandInfo

use of org.yamcs.protobuf.Mdb.CommandInfo in project yamcs-studio by yamcs.

the class StackedCommand method getEffectiveAssignments.

public Collection<TelecommandArgument> getEffectiveAssignments() {
    // We want this to be top-down, as-defined in mdb
    Map<String, TelecommandArgument> argumentsByName = new LinkedHashMap<>();
    List<CommandInfo> hierarchy = new ArrayList<>();
    hierarchy.add(meta);
    CommandInfo base = meta;
    while (base.getBaseCommand() != null) {
        base = base.getBaseCommand();
        hierarchy.add(0, base);
    }
    // From parent to child. Children can override initial values (= defaults)
    for (CommandInfo cmd : hierarchy) {
        // Set all values, even if null initial value. This gives us consistent ordering
        for (ArgumentInfo argument : cmd.getArgumentList()) {
            String name = argument.getName();
            String value = argument.hasInitialValue() ? argument.getInitialValue() : null;
            boolean editable = true;
            argumentsByName.put(name, new TelecommandArgument(name, value, editable));
        }
        // TODO this should return an empty list in yamcs. Not null
        if (cmd.getArgumentAssignmentList() != null)
            for (ArgumentAssignmentInfo argumentAssignment : cmd.getArgumentAssignmentList()) {
                String name = argumentAssignment.getName();
                String value = argumentAssignment.getValue();
                boolean editable = (cmd == meta);
                argumentsByName.put(name, new TelecommandArgument(name, value, editable));
            }
    }
    return argumentsByName.values();
}
Also used : CommandInfo(org.yamcs.protobuf.Mdb.CommandInfo) ArrayList(java.util.ArrayList) StyledString(org.eclipse.jface.viewers.StyledString) ArgumentAssignmentInfo(org.yamcs.protobuf.Mdb.ArgumentAssignmentInfo) ArgumentInfo(org.yamcs.protobuf.Mdb.ArgumentInfo) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with CommandInfo

use of org.yamcs.protobuf.Mdb.CommandInfo 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 5 with CommandInfo

use of org.yamcs.protobuf.Mdb.CommandInfo 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)

Aggregations

CommandInfo (org.yamcs.protobuf.Mdb.CommandInfo)7 NamedObjectId (org.yamcs.protobuf.Yamcs.NamedObjectId)4 ArrayList (java.util.ArrayList)3 ArgumentInfo (org.yamcs.protobuf.Mdb.ArgumentInfo)3 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)2 ColumnPixelData (org.eclipse.jface.viewers.ColumnPixelData)2 StyledString (org.eclipse.jface.viewers.StyledString)2 TreeViewerColumn (org.eclipse.jface.viewers.TreeViewerColumn)2 FileReader (java.io.FileReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 TreeColumnLayout (org.eclipse.jface.layout.TreeColumnLayout)1 LocalResourceManager (org.eclipse.jface.resource.LocalResourceManager)1 ResourceManager (org.eclipse.jface.resource.ResourceManager)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1