Search in sources :

Example 41 with Element

use of org.eclipse.xtext.parsetree.reconstr.bug302128.Element in project JMRI by JMRI.

the class PaneProgPaneTest method testPaneWrite.

@Test
public void testPaneWrite() {
    Assume.assumeFalse(GraphicsEnvironment.isHeadless());
    log.debug("testPaneWrite starts");
    // initialize the system
    // 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", "2").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("default", "20").setAttribute("label", "Start voltage").addContent(new Element("decVal"));
    Element el1 = new Element("variable").setAttribute("CV", "3").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("default", "30").setAttribute("label", "Primary Address").addContent(new Element("decVal"));
    varModel.setRow(0, el0);
    varModel.setRow(1, el1);
    log.debug("Two elements loaded");
    //        PaneProgPane progPane = new PaneProgPane("name", pane1, cvModel, varModel, null);
    PaneProgPane progPane = new PaneProgPane(pFrame, "name", pane1, cvModel, icvModel, varModel, null, null);
    p.resetCv(2, -1);
    p.resetCv(3, -1);
    // test by invoking
    progPane.writeAllButton.setSelected(true);
    // wait for reply (normally, done by callback; will check that later)
    JUnitUtil.waitFor(() -> {
        return !progPane.isBusy();
    }, "progPane.isBusy");
    Assert.assertEquals("CV 2 value ", 20, p.getCvVal(2));
    Assert.assertEquals("CV 3 value ", 30, p.getCvVal(3));
    log.debug("testPaneWrite ends ok");
}
Also used : IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel) CvTableModel(jmri.jmrit.symbolicprog.CvTableModel) VariableTableModel(jmri.jmrit.symbolicprog.VariableTableModel) Element(org.jdom2.Element) JLabel(javax.swing.JLabel) RosterEntry(jmri.jmrit.roster.RosterEntry) IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel) Test(org.junit.Test)

Example 42 with Element

use of org.eclipse.xtext.parsetree.reconstr.bug302128.Element in project JMRI by JMRI.

the class PaneProgPaneTest method testPaneReadOpCount.

// test counting of read operations needed
@Test
public void testPaneReadOpCount() {
    Assume.assumeFalse(GraphicsEnvironment.isHeadless());
    log.debug("testPaneReadOpCount starts");
    // initialize the system
    // 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);
    // have to add a couple of defined variables
    int row = 0;
    // note these +have+ to be on this pane, e.g. named in setupDoc
    Element el0 = new Element("variable").setAttribute("CV", "1").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("label", "Start voltage").addContent(new Element("decVal"));
    varModel.setRow(row++, el0);
    Element el1 = new Element("variable").setAttribute("CV", "1").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("label", "Primary Address").addContent(new Element("decVal"));
    varModel.setRow(row++, el1);
    Element el2 = new Element("variable").setAttribute("CV", "67").setAttribute("label", "Normal direction of motion").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").addContent(new Element("speedTableVal"));
    varModel.setRow(row++, el2);
    Element el3 = new Element("variable").setAttribute("CV", "68").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("label", "Address").addContent(new Element("decVal"));
    varModel.setRow(row++, el3);
    PaneProgPane progPane = new PaneProgPane(pFrame, "name", pane1, cvModel, icvModel, varModel, null, null);
    // start actual testing
    Assert.assertEquals("number of all CVs to read ", 29, progPane.countOpsNeeded(true, false));
    Assert.assertEquals("number of all CVs to write ", 29, progPane.countOpsNeeded(false, false));
    Assert.assertEquals("number of changed CVs to read ", 0, progPane.countOpsNeeded(true, true));
    Assert.assertEquals("number of changed CVs to write ", 0, progPane.countOpsNeeded(false, true));
    // mark some as needing to be written
    (cvModel.allCvMap().get("1")).setValue(12);
    Assert.assertEquals("modified all CVs to read ", 29, progPane.countOpsNeeded(true, false));
    Assert.assertEquals("modified all CVs to write ", 29, progPane.countOpsNeeded(false, false));
    Assert.assertEquals("modified changed CVs to read ", 1, progPane.countOpsNeeded(true, true));
    Assert.assertEquals("modified changed CVs to write ", 1, progPane.countOpsNeeded(false, true));
    (cvModel.allCvMap().get("69")).setValue(12);
    // careful - might change more than one CV!
    Assert.assertEquals("spdtbl all CVs to read ", 29, progPane.countOpsNeeded(true, false));
    Assert.assertEquals("spdtbl all CVs to write ", 29, progPane.countOpsNeeded(false, false));
    Assert.assertEquals("spdtbl changed CVs to read ", 2, progPane.countOpsNeeded(true, true));
    Assert.assertEquals("spdtbl changed CVs to write ", 2, progPane.countOpsNeeded(false, true));
    log.debug("testPaneReadOpCount ends ok");
}
Also used : IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel) CvTableModel(jmri.jmrit.symbolicprog.CvTableModel) VariableTableModel(jmri.jmrit.symbolicprog.VariableTableModel) Element(org.jdom2.Element) JLabel(javax.swing.JLabel) RosterEntry(jmri.jmrit.roster.RosterEntry) IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel) Test(org.junit.Test)

Example 43 with Element

use of org.eclipse.xtext.parsetree.reconstr.bug302128.Element in project JMRI by JMRI.

the class PaneProgPaneTest method testColumn.

// test creating columns in a pane
@Test
public void testColumn() {
    Assume.assumeFalse(GraphicsEnvironment.isHeadless());
    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);
    log.debug("CvTableModel ctor complete");
    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 newColumn(String) operation
    colCount = 0;
    PaneProgPane pane = new PaneProgPane(pFrame, "name", pane1, cvModel, icvModel, varModel, null, null) {

        @Override
        public JPanel newColumn(Element e, boolean a, Element el) {
            colCount++;
            return new JPanel();
        }
    };
    assertNotNull("exists", pane);
    assertEquals("column count", 2, colCount);
}
Also used : IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel) CvTableModel(jmri.jmrit.symbolicprog.CvTableModel) VariableTableModel(jmri.jmrit.symbolicprog.VariableTableModel) JPanel(javax.swing.JPanel) Element(org.jdom2.Element) JLabel(javax.swing.JLabel) RosterEntry(jmri.jmrit.roster.RosterEntry) IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel) Test(org.junit.Test)

Example 44 with Element

use of org.eclipse.xtext.parsetree.reconstr.bug302128.Element in project JMRI by JMRI.

the class VariableTableModelTest method testVarEnumVar.

// Check creating an enumvar with various groupings
public void testVarEnumVar() {
    String[] args = { "CV", "Name" };
    VariableTableModel t = new VariableTableModel(null, args, new CvTableModel(null, p), null);
    // create a JDOM tree with just some elements
    Element root = new Element("decoder-config");
    Document doc = new Document(root);
    doc.setDocType(new DocType("decoder-config", "decoder-config.dtd"));
    // add some elements
    Element el0;
    root.addContent(// the sites information here lists all relevant
    new Element("decoder").addContent(new Element("variables").addContent(el0 = new Element("variable").setAttribute("CV", "99").setAttribute("label", "Enum Sample").setAttribute("mask", "VVVVVVVV").setAttribute("readOnly", "").addContent(new Element("enumVal").addContent(new Element("enumChoice").setAttribute("choice", "V0")).addContent(new Element("enumChoice").setAttribute("choice", "V1")).addContent(new Element("enumChoiceGroup").addContent(new Element("enumChoice").setAttribute("choice", "V2")).addContent(new Element("enumChoice").setAttribute("choice", "V3"))).addContent(new Element("enumChoice").setAttribute("choice", "V4"))))));
    // end of adding contents
    // and test reading this
    t.setRow(0, el0);
    // check
    Assert.assertEquals("name of variable 1", "Enum Sample", t.getLabel(0));
    EnumVariableValue ev = (EnumVariableValue) t.getVariable(t.findVarIndex("Enum Sample"));
    ev.setValue(1);
    Assert.assertEquals("value 1", "V1", ev.getTextValue());
    ev.setValue(2);
    Assert.assertEquals("value 2", "V2", ev.getTextValue());
    ev.setValue(3);
    Assert.assertEquals("value 3", "V3", ev.getTextValue());
    ev.setValue(4);
    Assert.assertEquals("value 4", "V4", ev.getTextValue());
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) DocType(org.jdom2.DocType)

Example 45 with Element

use of org.eclipse.xtext.parsetree.reconstr.bug302128.Element in project JMRI by JMRI.

the class VariableTableModelTest method testVarTableLoadFileComplex.

// Check can read complex file
public void testVarTableLoadFileComplex() throws Exception {
    String[] args = { "CV", "Name" };
    VariableTableModel t = new VariableTableModel(null, args, new CvTableModel(null, p), null);
    // create a JDOM tree from file
    XmlFile file = new XmlFile() {
    };
    Element root = file.rootFromName("xml/decoders//QSI_ver9.xml");
    // add the contents
    Element el0 = root.getChild("decoder").getChild("variables");
    int i = 0;
    for (Element v : el0.getChildren("variable")) {
        t.setRow(i++, v);
    }
// fault is failure to reach the end, e.g. throw message or exception
}
Also used : XmlFile(jmri.jmrit.XmlFile) Element(org.jdom2.Element)

Aggregations

Element (org.jdom2.Element)829 Attribute (org.jdom2.Attribute)76 Document (org.jdom2.Document)75 Test (org.junit.Test)70 File (java.io.File)53 ArrayList (java.util.ArrayList)45 JDOMException (org.jdom2.JDOMException)37 IOException (java.io.IOException)34 HashMap (java.util.HashMap)28 NamedIcon (jmri.jmrit.catalog.NamedIcon)27 List (java.util.List)26 XmlFile (jmri.jmrit.XmlFile)24 SAXBuilder (org.jdom2.input.SAXBuilder)21 Turnout (jmri.Turnout)20 DataConversionException (org.jdom2.DataConversionException)20 DocType (org.jdom2.DocType)19 Editor (jmri.jmrit.display.Editor)18 XMLOutputter (org.jdom2.output.XMLOutputter)18 Namespace (org.jdom2.Namespace)17 Point (java.awt.Point)15