Search in sources :

Example 1 with ArgumentInfo

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

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

the class StackedCommand method toStyledString.

public StyledString toStyledString(CommandStackView styleProvider) {
    Styler identifierStyler = styleProvider != null ? styleProvider.getIdentifierStyler(this) : null;
    Styler bracketStyler = styleProvider != null ? styleProvider.getBracketStyler(this) : null;
    Styler argNameSyler = styleProvider != null ? styleProvider.getArgNameStyler(this) : null;
    Styler errorStyler = styleProvider != null ? styleProvider.getErrorStyler(this) : null;
    Styler numberStyler = styleProvider != null ? styleProvider.getNumberStyler(this) : null;
    StyledString str = new StyledString();
    str.append(getSelectedAlias(), identifierStyler);
    str.append("(", bracketStyler);
    boolean first = true;
    for (ArgumentInfo arg : meta.getArgumentList()) {
        String value = getAssignedStringValue(arg);
        if (value == null && arg.hasInitialValue())
            continue;
        if (!first)
            str.append("\n, ", bracketStyler);
        first = false;
        str.append(arg.getName() + ": ", argNameSyler);
        if (value == null) {
            str.append("  ", errorStyler);
        } else {
            boolean needQuotationMark = ArgumentTableBuilder.STRING.equals(arg.getType().getEngType()) || ArgumentTableBuilder.ENUM.equals(arg.getType().getEngType());
            if (needQuotationMark)
                str.append("\"", isValid(arg) ? numberStyler : errorStyler);
            str.append(value, isValid(arg) ? numberStyler : errorStyler);
            if (needQuotationMark)
                str.append("\"", isValid(arg) ? numberStyler : errorStyler);
        }
    }
    str.append(")", bracketStyler);
    return str;
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Styler(org.eclipse.jface.viewers.StyledString.Styler) ArgumentInfo(org.yamcs.protobuf.Mdb.ArgumentInfo)

Example 3 with ArgumentInfo

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

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

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

the class ArgumentTableBuilder method updateCommandArguments.

public void updateCommandArguments() {
    argumentAssignements = new ArrayList<>();
    for (ArgumentInfo arg : command.getMetaCommand().getArgumentList()) {
        String value = command.getAssignedStringValue(arg);
        argumentAssignements.add(new ArgumentAssignement(arg, value == null ? "" : value));
    }
    argumentTable.setInput(argumentAssignements);
}
Also used : ArgumentInfo(org.yamcs.protobuf.Mdb.ArgumentInfo)

Aggregations

ArgumentInfo (org.yamcs.protobuf.Mdb.ArgumentInfo)6 StyledString (org.eclipse.jface.viewers.StyledString)3 CommandInfo (org.yamcs.protobuf.Mdb.CommandInfo)3 JAXBContext (javax.xml.bind.JAXBContext)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 CommandArgument (org.yamcs.studio.commanding.stack.xml.CommandStack.Command.CommandArgument)2 File (java.io.File)1 FileReader (java.io.FileReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Marshaller (javax.xml.bind.Marshaller)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 Styler (org.eclipse.jface.viewers.StyledString.Styler)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1 ArgumentAssignmentInfo (org.yamcs.protobuf.Mdb.ArgumentAssignmentInfo)1 NamedObjectId (org.yamcs.protobuf.Yamcs.NamedObjectId)1