use of org.eclipse.xtext.parsetree.impl.bug305397.Element in project JMRI by JMRI.
the class AbstractNamedBeanManagerConfigXML method loadProperties.
/**
* Load all key/value properties
*
* @param t The NamedBean being loaded
* @param elem The existing Element
*/
void loadProperties(NamedBean t, Element elem) {
Element p = elem.getChild("properties");
if (p == null) {
return;
}
for (Object next : p.getChildren("property")) {
Element e = (Element) next;
try {
Class<?> cl;
Constructor<?> ctor;
// create key string
String key = e.getChild("key").getText();
// constructed from Strings, similar to the value code below.
if (!(e.getChild("key").getAttributeValue("class") == null || e.getChild("key").getAttributeValue("class").equals("") || e.getChild("key").getAttributeValue("class").equals("java.lang.String"))) {
log.warn("NamedBean {} property key of invalid non-String type {} not supported", t.getSystemName(), e.getChild("key").getAttributeValue("class"));
}
// create value object
Object value = null;
if (e.getChild("value") != null) {
cl = Class.forName(e.getChild("value").getAttributeValue("class"));
ctor = cl.getConstructor(new Class<?>[] { String.class });
value = ctor.newInstance(new Object[] { e.getChild("value").getText() });
}
// store
t.setProperty(key, value);
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | java.lang.reflect.InvocationTargetException ex) {
log.error("Error loading properties", ex);
}
}
}
use of org.eclipse.xtext.parsetree.impl.bug305397.Element in project JMRI by JMRI.
the class JmriJTablePersistenceManager method savePreferences.
@Override
public synchronized void savePreferences(Profile profile) {
log.debug("Saving preferences (dirty={})...", this.dirty);
Element element = new Element(TABLES_ELEMENT, TABLES_NAMESPACE);
if (!this.columns.isEmpty()) {
this.columns.entrySet().stream().map((entry) -> {
Element table = new Element("table").setAttribute("name", entry.getKey());
Element columnsElement = new Element("columns");
entry.getValue().entrySet().stream().map((column) -> {
Element columnElement = new Element("column").setAttribute("name", column.getKey());
if (column.getValue().getOrder() != -1) {
columnElement.setAttribute("order", Integer.toString(column.getValue().getOrder()));
}
if (column.getValue().getWidth() != -1) {
columnElement.setAttribute("width", Integer.toString(column.getValue().getWidth()));
}
columnElement.setAttribute("hidden", Boolean.toString(column.getValue().getHidden()));
return columnElement;
}).forEach((columnElement) -> {
columnsElement.addContent(columnElement);
});
table.addContent(columnsElement);
List<SortKey> keys = this.sortKeys.get(entry.getKey());
if (keys != null) {
Element sorter = new Element(SORT_ORDER);
keys.stream().forEach((key) -> {
sorter.addContent(new Element("sortKey").setAttribute("column", Integer.toString(key.getColumn())).setAttribute(SORT_ORDER, key.getSortOrder().name()));
});
table.addContent(sorter);
}
return table;
}).forEach((table) -> {
element.addContent(table);
});
}
try {
ProfileUtils.getUserInterfaceConfiguration(ProfileManager.getDefault().getActiveProfile()).putConfigurationFragment(JDOMUtil.toW3CElement(element), false);
} catch (JDOMException ex) {
log.error("Unable to save user preferences", ex);
}
this.dirty = false;
}
use of org.eclipse.xtext.parsetree.impl.bug305397.Element in project JMRI by JMRI.
the class JMenuUtil method jMenuFromElement.
@Nonnull
static JMenu jMenuFromElement(@CheckForNull Element main, WindowInterface wi, Object context) {
boolean addSep = false;
String name = "<none>";
if (main == null) {
log.warn("Menu from element called without an element");
return new JMenu(name);
}
name = LocaleSelector.getAttribute(main, "name");
//Next statement left in if the xml file hasn't been converted
if ((name == null) || (name.equals(""))) {
if (main.getChild("name") != null) {
name = main.getChild("name").getText();
}
}
JMenu menu = new JMenu(name);
ArrayList<Integer> mnemonicList = new ArrayList<Integer>();
for (Object item : main.getChildren("node")) {
JMenuItem menuItem = null;
Element child = (Element) item;
if (child.getChildren("node").size() == 0) {
// leaf
if ((child.getText().trim()).equals("separator")) {
addSep = true;
} else {
if (!(SystemType.isMacOSX() && UIManager.getLookAndFeel().isNativeLookAndFeel() && ((child.getChild("adapter") != null && child.getChild("adapter").getText().equals("apps.gui3.TabbedPreferencesAction")) || (child.getChild("current") != null && child.getChild("current").getText().equals("quit"))))) {
if (addSep) {
menu.addSeparator();
addSep = false;
}
Action act = actionFromNode(child, wi, context);
menu.add(menuItem = new JMenuItem(act));
}
}
} else {
if (addSep) {
menu.addSeparator();
addSep = false;
}
if (child.getChild("group") != null && child.getChild("group").getText().equals("yes")) {
//A seperate method is required for creating radio button groups
menu.add(createMenuGroupFromElement(child, wi, context));
} else {
// not leaf
menu.add(menuItem = jMenuFromElement(child, wi, context));
}
}
if (menuItem != null && child.getChild("current") != null) {
setMenuItemInterAction(context, child.getChild("current").getText(), menuItem);
}
if (menuItem != null && child.getChild("mnemonic") != null) {
int mnemonic = convertStringToKeyEvent(child.getChild("mnemonic").getText());
if (mnemonicList.contains(mnemonic)) {
log.error("Menu Item '" + menuItem.getText() + "' Mnemonic '" + child.getChild("mnemonic").getText() + "' has already been assigned");
} else {
menuItem.setMnemonic(mnemonic);
mnemonicList.add(mnemonic);
}
}
}
return menu;
}
use of org.eclipse.xtext.parsetree.impl.bug305397.Element in project JMRI by JMRI.
the class JMenuUtil method loadMenu.
public static JMenu[] loadMenu(String path, WindowInterface wi, Object context) {
Element root = rootFromName(path);
int n = root.getChildren("node").size();
JMenu[] retval = new JMenu[n];
int i = 0;
ArrayList<Integer> mnemonicList = new ArrayList<Integer>();
for (Object child : root.getChildren("node")) {
JMenu menuItem = jMenuFromElement((Element) child, wi, context);
retval[i++] = menuItem;
if (((Element) child).getChild("mnemonic") != null) {
int mnemonic = convertStringToKeyEvent(((Element) child).getChild("mnemonic").getText());
if (mnemonicList.contains(mnemonic)) {
log.error("Menu item '" + menuItem.getText() + "' Mnemonic '" + ((Element) child).getChild("mnemonic").getText() + "' has already been assigned");
} else {
menuItem.setMnemonic(mnemonic);
mnemonicList.add(mnemonic);
}
}
}
return retval;
}
use of org.eclipse.xtext.parsetree.impl.bug305397.Element in project JMRI by JMRI.
the class JMenuUtil method createMenuGroupFromElement.
@Nonnull
static JMenu createMenuGroupFromElement(@CheckForNull Element main, WindowInterface wi, Object context) {
String name = "<none>";
if (main == null) {
log.warn("Menu from element called without an element");
return new JMenu(name);
}
name = LocaleSelector.getAttribute(main, "name");
//Next statement left in if the xml file hasn't been converted
if ((name == null) || (name.equals(""))) {
if (main.getChild("name") != null) {
name = main.getChild("name").getText();
}
}
JMenu menu = new JMenu(name);
ButtonGroup group = new ButtonGroup();
for (Object item : main.getChildren("node")) {
Element elem = (Element) item;
Action act = actionFromNode(elem, wi, context);
JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(act);
group.add(menuItem);
menu.add(menuItem);
if (elem.getChild("current") != null) {
setMenuItemInterAction(context, elem.getChild("current").getText(), menuItem);
}
}
return menu;
}
Aggregations