use of apps.startup.ScriptButtonModel in project JMRI by JMRI.
the class ScriptButtonModelXml method store.
/**
* Default implementation for storing the model contents
*
* @param o Object to store, of type PerformActonModel
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
// NOI18N
Element element = new Element("perform");
// NOI18N
element.setAttribute("name", ((StartupModel) o).getName());
// NOI18N
element.setAttribute("type", "Button");
// NOI18N
element.setAttribute("class", this.getClass().getName());
// NOI18N
Element property = new Element("property");
// NOI18N
property.setAttribute("name", "script");
property.setAttribute("value", FileUtil.getPortableFilename(((ScriptButtonModel) o).getScript()));
element.addContent(property);
return element;
}
use of apps.startup.ScriptButtonModel in project JMRI by JMRI.
the class ScriptButtonModelXml method load.
@Override
public boolean load(Element shared, Element perNode) throws JmriException {
// Should the script engines be pre-loaded here?
boolean result = false;
ScriptButtonModel model = new ScriptButtonModel();
// NOI18N
model.setName(shared.getAttribute("name").getValue());
for (Element child : shared.getChildren("property")) {
// NOI18N
if (// NOI18N
child.getAttributeValue("name").equals("script") && child.getAttributeValue("value") != null) {
// NOI18N
// NOI18N
String script = child.getAttributeValue("value");
try {
model.setScript(FileUtil.getFile(script));
result = true;
} catch (FileNotFoundException ex) {
model.addException(new InitializationException(Bundle.getMessage(Locale.ENGLISH, "ScriptButtonModel.ScriptNotFound", script), Bundle.getMessage("ScriptButtonModel.ScriptNotFound", script), ex));
log.error("Unable to create button for script {}", script);
}
}
}
// store the model
InstanceManager.getDefault(StartupActionsManager.class).addAction(model);
return result;
}
Aggregations