use of org.eclipse.xtext.parsetree.impl.bug305397.Element in project JMRI by JMRI.
the class JmriUserPreferencesManager method readPreferencesState.
private void readPreferencesState() {
Element element = this.readElement(CLASSPREFS_ELEMENT, CLASSPREFS_NAMESPACE);
if (element != null) {
element.getChildren("preferences").stream().forEach((preferences) -> {
String clazz = preferences.getAttributeValue("class");
log.debug("Reading class preferences for \"{}\"", clazz);
preferences.getChildren("multipleChoice").stream().forEach((mc) -> {
mc.getChildren("option").stream().forEach((option) -> {
int value = 0;
try {
option.getAttribute("value").getIntValue();
} catch (DataConversionException ex) {
log.error("failed to convert positional attribute");
}
this.setMultipleChoiceOption(clazz, option.getAttributeValue("item"), value);
});
});
preferences.getChildren("reminderPrompts").stream().forEach((rp) -> {
rp.getChildren("reminder").stream().forEach((reminder) -> {
log.debug("Setting preferences state \"true\" for \"{}\", \"{}\"", clazz, reminder.getText());
this.setPreferenceState(clazz, reminder.getText(), true);
});
});
});
}
}
use of org.eclipse.xtext.parsetree.impl.bug305397.Element in project JMRI by JMRI.
the class JmriUserPreferencesManager method saveWindowDetails.
private void saveWindowDetails() {
this.setChangeMade(false);
if (this.allowSave) {
if (!windowDetails.isEmpty()) {
Element element = new Element(WINDOWS_ELEMENT, WINDOWS_NAMESPACE);
for (Entry<String, WindowLocations> entry : windowDetails.entrySet()) {
Element window = new Element("window");
window.setAttribute("class", entry.getKey());
if (entry.getValue().saveLocation) {
try {
window.setAttribute("locX", Double.toString(entry.getValue().getLocation().getX()));
window.setAttribute("locY", Double.toString(entry.getValue().getLocation().getY()));
} catch (NullPointerException ex) {
// Expected if the location has not been set or the window is open
}
}
if (entry.getValue().saveSize) {
try {
double height = entry.getValue().getSize().getHeight();
double width = entry.getValue().getSize().getWidth();
// Do not save the width or height if set to zero
if (!(height == 0.0 && width == 0.0)) {
window.setAttribute("width", Double.toString(width));
window.setAttribute("height", Double.toString(height));
}
} catch (NullPointerException ex) {
// Expected if the size has not been set or the window is open
}
}
if (!entry.getValue().parameters.isEmpty()) {
Element properties = new Element("properties");
entry.getValue().parameters.entrySet().stream().map((property) -> {
Element propertyElement = new Element("property");
propertyElement.addContent(new Element("key").setText(property.getKey()));
Object value = property.getValue();
if (value != null) {
propertyElement.addContent(new Element("value").setAttribute("class", value.getClass().getName()).setText(value.toString()));
}
return propertyElement;
}).forEach((propertyElement) -> {
properties.addContent(propertyElement);
});
window.addContent(properties);
}
element.addContent(window);
}
this.saveElement(element);
this.resetChangeMade();
}
}
}
use of org.eclipse.xtext.parsetree.impl.bug305397.Element in project JMRI by JMRI.
the class AbstractReporterManagerConfigXML method loadReporters.
/**
* Utility method to load the individual Reporter objects. If there's no
* additional info needed for a specific Reporter type, invoke this with the
* parent of the set of Reporter elements.
*
* @param reporters Element containing the Reporter elements to load.
* @return true if successful
*/
@SuppressWarnings("unchecked")
public boolean loadReporters(Element reporters) {
boolean result = true;
List<Element> reporterList = reporters.getChildren("reporter");
if (log.isDebugEnabled()) {
log.debug("Found " + reporterList.size() + " reporters");
}
ReporterManager tm = InstanceManager.getDefault(jmri.ReporterManager.class);
for (int i = 0; i < reporterList.size(); i++) {
String sysName = getSystemName(reporterList.get(i));
if (sysName == null) {
log.warn("unexpected null in systemName " + reporterList.get(i) + " " + reporterList.get(i).getAttributes());
result = false;
break;
}
String userName = getUserName(reporterList.get(i));
if (log.isDebugEnabled()) {
log.debug("create Reporter: (" + sysName + ")(" + (userName == null ? "<null>" : userName) + ")");
}
Reporter r = tm.newReporter(sysName, userName);
loadCommon(r, reporterList.get(i));
}
return result;
}
use of org.eclipse.xtext.parsetree.impl.bug305397.Element in project JMRI by JMRI.
the class AbstractSensorManagerConfigXML method loadSensors.
/**
* Utility method to load the individual Sensor objects. If there's no
* additional info needed for a specific sensor type, invoke this with the
* parent of the set of Sensor elements.
*
* @param sensors Element containing the Sensor elements to load.
* @return true if succeeded
*/
@SuppressWarnings("unchecked")
public boolean loadSensors(Element sensors) throws jmri.configurexml.JmriConfigureXmlException {
boolean result = true;
List<Element> sensorList = sensors.getChildren("sensor");
if (log.isDebugEnabled()) {
log.debug("Found " + sensorList.size() + " sensors");
}
SensorManager tm = InstanceManager.sensorManagerInstance();
long goingActive = 0L;
long goingInActive = 0L;
if (sensors.getChild("globalDebounceTimers") != null) {
Element timer = sensors.getChild("globalDebounceTimers");
try {
if (timer.getChild("goingActive") != null) {
String active = timer.getChild("goingActive").getText();
goingActive = Long.valueOf(active);
tm.setDefaultSensorDebounceGoingActive(goingActive);
}
} catch (NumberFormatException ex) {
log.error(ex.toString());
}
try {
if (timer.getChild("goingInActive") != null) {
String inActive = timer.getChild("goingInActive").getText();
goingInActive = Long.valueOf(inActive);
tm.setDefaultSensorDebounceGoingInActive(goingInActive);
}
} catch (NumberFormatException ex) {
log.error(ex.toString());
}
}
for (int i = 0; i < sensorList.size(); i++) {
String sysName = getSystemName(sensorList.get(i));
if (sysName == null) {
handleException("Unexpected missing system name while loading sensors", null, null, null, null);
result = false;
break;
}
boolean inverted = false;
String userName = getUserName(sensorList.get(i));
checkNameNormalization(sysName, userName, tm);
if (sensorList.get(i).getAttribute("inverted") != null) {
if (sensorList.get(i).getAttribute("inverted").getValue().equals("true")) {
inverted = true;
}
}
if (log.isDebugEnabled()) {
log.debug("create sensor: (" + sysName + ")");
}
Sensor s;
try {
s = tm.newSensor(sysName, userName);
} catch (IllegalArgumentException e) {
handleException("Could not create sensor", null, sysName, userName, null);
result = false;
continue;
}
// load common parts
loadCommon(s, sensorList.get(i));
if (sensorList.get(i).getChild("debounceTimers") != null) {
Element timer = sensorList.get(i).getChild("debounceTimers");
try {
if (timer.getChild("goingActive") != null) {
String active = timer.getChild("goingActive").getText();
s.setSensorDebounceGoingActiveTimer(Long.valueOf(active));
}
} catch (NumberFormatException ex) {
log.error(ex.toString());
}
try {
if (timer.getChild("goingInActive") != null) {
String inActive = timer.getChild("goingInActive").getText();
s.setSensorDebounceGoingInActiveTimer(Long.valueOf(inActive));
}
} catch (NumberFormatException ex) {
log.error(ex.toString());
}
}
if (sensorList.get(i).getChild("useGlobalDebounceTimer") != null) {
if (sensorList.get(i).getChild("useGlobalDebounceTimer").getText().equals("yes")) {
s.useDefaultTimerSettings(true);
}
}
s.setInverted(inverted);
if (sensorList.get(i).getChild("pullResistance") != null) {
String pull = sensorList.get(i).getChild("pullResistance").getText();
log.debug("setting pull to {} for sensor {}", pull, s);
s.setPullResistance(jmri.Sensor.PullResistance.getByShortName(pull));
}
}
return result;
}
use of org.eclipse.xtext.parsetree.impl.bug305397.Element in project JMRI by JMRI.
the class AbstractSensorManagerConfigXML method store.
public Element store(Object o, Element sensors) {
setStoreElementClass(sensors);
SensorManager tm = (SensorManager) o;
if (tm.getDefaultSensorDebounceGoingActive() > 0 || tm.getDefaultSensorDebounceGoingInActive() > 0) {
Element elem = new Element("globalDebounceTimers");
elem.addContent(new Element("goingActive").addContent(String.valueOf(tm.getDefaultSensorDebounceGoingActive())));
elem.addContent(new Element("goingInActive").addContent(String.valueOf(tm.getDefaultSensorDebounceGoingInActive())));
sensors.addContent(elem);
}
java.util.Iterator<String> iter = tm.getSystemNameList().iterator();
// don't return an element if there are not sensors to include
if (!iter.hasNext()) {
return null;
}
// store the sensors
while (iter.hasNext()) {
String sname = iter.next();
log.debug("system name is " + sname);
Sensor s = tm.getBySystemName(sname);
String inverted = s.getInverted() ? "true" : "false";
Element elem = new Element("sensor").setAttribute("inverted", inverted);
elem.addContent(new Element("systemName").addContent(sname));
log.debug("store sensor " + sname);
if (s.useDefaultTimerSettings()) {
elem.addContent(new Element("useGlobalDebounceTimer").addContent("yes"));
} else {
if (s.getSensorDebounceGoingActiveTimer() > 0 || s.getSensorDebounceGoingInActiveTimer() > 0) {
Element timer = new Element("debounceTimers");
timer.addContent(new Element("goingActive").addContent(String.valueOf(s.getSensorDebounceGoingActiveTimer())));
timer.addContent(new Element("goingInActive").addContent(String.valueOf(s.getSensorDebounceGoingInActiveTimer())));
elem.addContent(timer);
}
}
if (tm.isPullResistanceConfigurable()) {
// store the sensor's value for pull resistance.
elem.addContent(new Element("pullResistance").addContent(s.getPullResistance().getShortName()));
}
// store common part
storeCommon(s, elem);
sensors.addContent(elem);
}
return sensors;
}
Aggregations