use of org.yamcs.protobuf.Mdb.ArgumentInfo in project yamcs-studio by yamcs.
the class ExportCommandStackHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// Get current command stack
Collection<StackedCommand> scs = org.yamcs.studio.commanding.stack.CommandStack.getInstance().getCommands();
if (scs == null || scs.isEmpty()) {
MessageDialog.openError(Display.getCurrent().getActiveShell(), "Export Command Stack", "Current command stack is empty. No command to export.");
return null;
}
FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
dialog.setFilterExtensions(new String[] { "*.xml" });
// dialog.setFilterPath("c:\\temp");
String exportFile = dialog.open();
System.out.println("export file choosen: " + exportFile);
if (exportFile == null) {
// cancelled
return null;
}
// Build model
org.yamcs.studio.commanding.stack.xml.CommandStack exportCommandStack = new org.yamcs.studio.commanding.stack.xml.CommandStack();
List<org.yamcs.studio.commanding.stack.xml.CommandStack.Command> exportedCommands = exportCommandStack.getCommand();
for (StackedCommand sc : scs) {
org.yamcs.studio.commanding.stack.xml.CommandStack.Command c = new org.yamcs.studio.commanding.stack.xml.CommandStack.Command();
c.setQualifiedName(sc.getMetaCommand().getQualifiedName());
c.setSelectedAlias(sc.getSelectedAlias());
c.setComment(sc.getComment());
exportedCommands.add(c);
List<CommandArgument> cas = c.getCommandArgument();
Iterator<Entry<ArgumentInfo, String>> it = sc.getAssignments().entrySet().iterator();
while (it.hasNext()) {
Map.Entry<ArgumentInfo, String> pair = it.next();
String argName = pair.getKey().getName();
String argValue = pair.getValue();
CommandArgument ca = new CommandArgument();
ca.setArgumentName(argName);
ca.setArgumentValue(argValue);
cas.add(ca);
}
}
// Write model to file
try {
File file = new File(exportFile);
JAXBContext jaxbContext = JAXBContext.newInstance(org.yamcs.studio.commanding.stack.xml.CommandStack.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(exportCommandStack, file);
jaxbMarshaller.marshal(exportCommandStack, System.out);
} catch (Exception e) {
MessageDialog.openError(Display.getCurrent().getActiveShell(), "Export Command Stack", "Unable to perform command stack export.\nDetails:" + e.getMessage());
return null;
}
MessageDialog.openInformation(Display.getCurrent().getActiveShell(), "Export Command Stack", "Command stack exported successfully.");
return null;
}
Aggregations