[cooja] plugins/VariableWatcher: Fixed xml config save/load

This commit is contained in:
Enrico Joerns 2014-08-27 18:46:08 +02:00
parent 16d94780e9
commit e77c01d586

View file

@ -558,7 +558,7 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
@Override @Override
public Collection<Element> getConfigXML() { public Collection<Element> getConfigXML() {
// Return currently watched variable and type // Return currently watched variable and type
Vector<Element> config = new Vector<Element>(); Vector<Element> config = new Vector<>();
Element element; Element element;
@ -568,56 +568,33 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
config.add(element); config.add(element);
// Selected variable type // Selected variable type
if (varTypeCombo.getSelectedIndex() == BYTE_INDEX) { element = new Element("vartype");
element = new Element("vartype"); element.setText(String.valueOf(varTypeCombo.getSelectedIndex()));
element.setText("byte"); config.add(element);
config.add(element);
} else if (varTypeCombo.getSelectedIndex() == INT_INDEX) { // Selected output format
element = new Element("vartype"); element = new Element("varformat");
element.setText("int"); element.setText(String.valueOf(varDispCombo.getSelectedIndex()));
config.add(element); config.add(element);
} else if (varTypeCombo.getSelectedIndex() == ARRAY_INDEX) {
element = new Element("vartype");
element.setText("array");
config.add(element);
element = new Element("array_length");
element.setText(varLength.getValue().toString());
config.add(element);
} else if (varTypeCombo.getSelectedIndex() == CHAR_ARRAY_INDEX) {
element = new Element("vartype");
element.setText("chararray");
config.add(element);
element = new Element("array_length");
element.setText(varLength.getValue().toString());
config.add(element);
}
return config; return config;
} }
@Override @Override
public boolean setConfigXML(Collection<Element> configXML, boolean visAvailable) { public boolean setConfigXML(Collection<Element> configXML, boolean visAvailable) {
updateNumberOfValues();
for (Element element : configXML) { for (Element element : configXML) {
if (element.getName().equals("varname")) { switch (element.getName()) {
varNameCombo.setSelectedItem(element.getText()); case "varname":
} else if (element.getName().equals("vartype")) { varNameCombo.setSelectedItem(element.getText());
if (element.getText().equals("byte")) { break;
varTypeCombo.setSelectedIndex(BYTE_INDEX); case "vartype":
} else if (element.getText().equals("int")) { varTypeCombo.setSelectedIndex(Integer.parseInt(element.getText()));
varTypeCombo.setSelectedIndex(INT_INDEX); break;
} else if (element.getText().equals("array")) { case "varformat":
varTypeCombo.setSelectedIndex(ARRAY_INDEX); varDispCombo.setSelectedIndex(Integer.parseInt(element.getText()));
} else if (element.getText().equals("chararray")) { break;
varTypeCombo.setSelectedIndex(CHAR_ARRAY_INDEX);
lengthPane.setVisible(true);
}
} else if (element.getName().equals("array_length")) {
int nrValues = Integer.parseInt(element.getText());
updateNumberOfValues();
} }
} }
updateNumberOfValues();
return true; return true;
} }