use of org.eclipse.xtext.parsetree.impl.bug305397.Element in project JMRI by JMRI.
the class JTreeUtil method treeFromElement.
/**
* @param main Element to be processed
* @param wi WindowInterface to be passed to the nodes in the tree
* @param context Blind context Object passed to the nodes in the tree
* @return a mutable tree node
*/
static DefaultMutableTreeNode treeFromElement(Element main, WindowInterface wi, Object context) {
String name = "<none>";
Element e = main.getChild("name");
if (e != null) {
name = e.getText();
}
DefaultMutableTreeNode node = new DefaultMutableTreeNode(name);
node.setUserObject(actionFromNode(main, wi, context));
main.getChildren("node").stream().forEach((child) -> {
node.add(treeFromElement((Element) child, wi, context));
});
return node;
}
use of org.eclipse.xtext.parsetree.impl.bug305397.Element in project JMRI by JMRI.
the class SwitchboardServlet method getXmlPanel.
@Override
protected String getXmlPanel(String name) {
log.debug("Getting {} for {}", getPanelType(), name);
try {
SwitchboardEditor editor = (SwitchboardEditor) getEditor(name);
Element panel = new Element("panel");
JFrame frame = editor.getTargetFrame();
panel.setAttribute("name", name);
panel.setAttribute("height", Integer.toString(frame.getContentPane().getHeight()));
panel.setAttribute("width", Integer.toString(frame.getContentPane().getWidth()));
panel.setAttribute("panelheight", Integer.toString(editor.getTargetPanel().getHeight()));
panel.setAttribute("panelwidth", Integer.toString(editor.getTargetPanel().getWidth()));
// add more properties
panel.setAttribute("showtooltips", (editor.showTooltip()) ? "yes" : "no");
panel.setAttribute("controlling", (editor.allControlling()) ? "yes" : "no");
panel.setAttribute("hideunconnected", (editor.hideUnconnected()) ? "yes" : "no");
panel.setAttribute("rangemin", Integer.toString(editor.getPanelMenuRangeMin()));
panel.setAttribute("rangemax", Integer.toString(editor.getPanelMenuRangeMax()));
panel.setAttribute("type", editor.getSwitchType());
panel.setAttribute("connection", editor.getSwitchManu());
panel.setAttribute("shape", editor.getSwitchShape());
panel.setAttribute("columns", Integer.toString(editor.getColumns()));
panel.setAttribute("defaulttextcolor", editor.getDefaultTextColor());
log.debug("webserver Switchboard attribs ready");
Element bgColor = new Element("backgroundColor");
if (editor.getBackgroundColor() == null) {
// set to light grey
bgColor.setAttribute("red", Integer.toString(192));
bgColor.setAttribute("green", Integer.toString(192));
bgColor.setAttribute("blue", Integer.toString(192));
} else {
bgColor.setAttribute("red", Integer.toString(editor.getBackgroundColor().getRed()));
bgColor.setAttribute("green", Integer.toString(editor.getBackgroundColor().getGreen()));
bgColor.setAttribute("blue", Integer.toString(editor.getBackgroundColor().getBlue()));
}
panel.addContent(bgColor);
Element text = new Element("text");
text.setAttribute("color", editor.getDefaultTextColor());
text.setAttribute("content", "For now, Switchboards only present buttons in JMRI WebServer.");
panel.addContent(text);
// include switches, Bug: how to delete the old ones?
// call method in SwitchboardEditor
List<BeanSwitch> _switches = editor.getSwitches();
log.debug("SwbServlet N switches: {}", _switches.size());
for (BeanSwitch sub : _switches) {
if (sub != null) {
try {
Element e = ConfigXmlManager.elementFromObject(sub);
if (e != null) {
log.debug("element name: {}", e.getName());
// }
try {
e.setAttribute("label", sub.getNameString());
e.setAttribute(JSON.ID, sub.getNamedBean().getSystemName());
if (sub.getNamedBean() == null) {
e.setAttribute("connected", "false");
log.debug("switch {} NOT connected", sub.getNameString());
} else {
// activate click action via class
e.setAttribute("connected", "true");
}
} catch (NullPointerException ex) {
if (sub.getNamedBean() == null) {
log.debug("{} {} does not have an associated NamedBean", e.getName(), e.getAttribute(JSON.NAME));
} else {
log.debug("{} {} does not have a SystemName", e.getName(), e.getAttribute(JSON.NAME));
}
}
// read shared attribs
e.setAttribute("textcolor", editor.getDefaultTextColor());
e.setAttribute("type", editor.getSwitchType());
e.setAttribute("connection", editor.getSwitchManu());
e.setAttribute("shape", editor.getSwitchShape());
e.setAttribute("columns", Integer.toString(editor.getColumns()));
// process and add
parsePortableURIs(e);
panel.addContent(e);
}
} catch (Exception ex) {
log.error("Error reading xml panel element: " + ex, ex);
}
}
}
Document doc = new Document(panel);
XMLOutputter out = new XMLOutputter();
out.setFormat(Format.getPrettyFormat().setLineSeparator(System.getProperty("line.separator")).setTextMode(Format.TextMode.TRIM));
return out.outputString(doc);
} catch (NullPointerException ex) {
log.warn("Requested Switchboard [" + name + "] does not exist.");
return "ERROR Requested Switchboard [" + name + "] does not exist.";
}
}
use of org.eclipse.xtext.parsetree.impl.bug305397.Element in project JMRI by JMRI.
the class ControlPanelServlet method getXmlPanel.
@Override
protected String getXmlPanel(String name) {
log.debug("Getting {} for {}", getPanelType(), name);
try {
ControlPanelEditor editor = (ControlPanelEditor) getEditor(name);
Element panel = new Element("panel");
JFrame frame = editor.getTargetFrame();
panel.setAttribute("name", name);
panel.setAttribute("height", Integer.toString(frame.getContentPane().getHeight()));
panel.setAttribute("width", Integer.toString(frame.getContentPane().getWidth()));
panel.setAttribute("panelheight", Integer.toString(editor.getTargetPanel().getHeight()));
panel.setAttribute("panelwidth", Integer.toString(editor.getTargetPanel().getWidth()));
panel.setAttribute("showtooltips", (editor.showTooltip()) ? "yes" : "no");
panel.setAttribute("controlling", (editor.allControlling()) ? "yes" : "no");
if (editor.getBackgroundColor() != null) {
Element color = new Element("backgroundColor");
color.setAttribute("red", Integer.toString(editor.getBackgroundColor().getRed()));
color.setAttribute("green", Integer.toString(editor.getBackgroundColor().getGreen()));
color.setAttribute("blue", Integer.toString(editor.getBackgroundColor().getBlue()));
panel.addContent(color);
}
// include contents
List<Positionable> contents = editor.getContents();
log.debug("N elements: {}", contents.size());
for (Positionable sub : contents) {
if (sub != null) {
try {
Element e = ConfigXmlManager.elementFromObject(sub);
if (e != null) {
if ("signalmasticon".equals(e.getName())) {
//insert icon details into signalmast
e.addContent(getSignalMastIconsElement(e.getAttributeValue("signalmast")));
}
try {
e.setAttribute(JSON.ID, sub.getNamedBean().getSystemName());
} catch (NullPointerException ex) {
if (sub.getNamedBean() == null) {
log.debug("{} {} does not have an associated NamedBean", e.getName(), e.getAttribute(JSON.NAME));
} else {
log.debug("{} {} does not have a SystemName", e.getName(), e.getAttribute(JSON.NAME));
}
}
parsePortableURIs(e);
panel.addContent(e);
}
} catch (Exception ex) {
log.error("Error storing panel element: " + ex, ex);
}
}
}
Document doc = new Document(panel);
XMLOutputter out = new XMLOutputter();
out.setFormat(Format.getPrettyFormat().setLineSeparator(System.getProperty("line.separator")).setTextMode(Format.TextMode.TRIM));
return out.outputString(doc);
} catch (NullPointerException ex) {
log.warn("Requested ControlPanel [" + name + "] does not exist.");
return "ERROR Requested panel [" + name + "] does not exist.";
}
}
use of org.eclipse.xtext.parsetree.impl.bug305397.Element in project JMRI by JMRI.
the class PaneProgPaneTest method testVarListFill.
// test storage of programming info in list
@Test
public void testVarListFill() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
// make sure XML document is ready
setupDoc();
PaneProgFrame pFrame = new PaneProgFrame(null, new RosterEntry(), "test frame", "programmers/Basic.xml", p, false) {
// dummy implementations
@Override
protected JPanel getModePane() {
return null;
}
};
CvTableModel cvModel = new CvTableModel(new JLabel(), p);
IndexedCvTableModel icvModel = new IndexedCvTableModel(new JLabel(), p);
String[] args = { "CV", "Name" };
VariableTableModel varModel = new VariableTableModel(null, args, cvModel, icvModel);
log.debug("VariableTableModel ctor complete");
// have to add a couple of defined variables
Element el0 = new Element("variable").setAttribute("CV", "17").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("label", "Start voltage").addContent(new Element("longAddressVal"));
log.debug("First element created");
varModel.setRow(0, el0);
log.debug("First element loaded");
Element el1 = new Element("variable").setAttribute("CV", "17").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("label", "Primary Address").addContent(new Element("decVal"));
log.debug("Second element created");
varModel.setRow(1, el1);
log.debug("Two elements loaded");
// test by invoking
PaneProgPane pane = new PaneProgPane(pFrame, "name", pane1, cvModel, icvModel, varModel, null, null);
assertEquals("variable list length", 2, pane.varList.size());
assertEquals("1st variable index ", Integer.valueOf(1), pane.varList.get(0));
assertEquals("2nd variable index ", Integer.valueOf(0), pane.varList.get(1));
}
use of org.eclipse.xtext.parsetree.impl.bug305397.Element in project JMRI by JMRI.
the class PaneProgPaneTest method testVariables.
// test specifying variables in columns
@Test
public void testVariables() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
// make sure XML document is ready
setupDoc();
PaneProgFrame pFrame = new PaneProgFrame(null, new RosterEntry(), "test frame", "programmers/Basic.xml", p, false) {
// dummy implementations
@Override
protected JPanel getModePane() {
return null;
}
};
CvTableModel cvModel = new CvTableModel(new JLabel(), p);
IndexedCvTableModel icvModel = new IndexedCvTableModel(new JLabel(), p);
String[] args = { "CV", "Name" };
VariableTableModel varModel = new VariableTableModel(null, args, cvModel, icvModel);
log.debug("VariableTableModel ctor complete");
// create test object with special implementation of the newVariable(String) operation
varCount = 0;
PaneProgPane pane = new PaneProgPane(pFrame, "name", pane1, cvModel, icvModel, varModel, null, null) {
@Override
public void newVariable(Element e, JComponent p, GridBagLayout g, GridBagConstraints c, boolean a) {
varCount++;
}
};
assertNotNull("exists", pane);
assertEquals("variable defn count", 7, varCount);
}
Aggregations