Search in sources :

Example 1 with SectionModel

use of net.sourceforge.usbdm.deviceEditor.model.SectionModel in project usbdm-eclipse-plugins by podonoghue.

the class ParseMenuXML method parseSectionsOrOther.

/**
 * Parse: <br>
 *    &lt;peripheralPage&gt;<br>
 *    &lt;list&gt;<br>
 *    &lt;section&gt;<br>
 *    &lt;fragment&gt;<br>
 *
 * @param menuElement
 *
 * @throws Exception
 */
private BaseModel parseSectionsOrOther(BaseModel parent, Element element) throws Exception {
    String name = element.getAttribute("name");
    if (name.equalsIgnoreCase("_instance")) {
        name = fProvider.getName();
    }
    // String description = element.getAttribute("description");
    String toolTip = getToolTip(element);
    BaseModel model = null;
    if (element.getTagName() == "fragment") {
        /*
          * Parse fragment as if it was a continuation of the parent elements
          * This handles fragments that just include a href= include a <peripheralPage>
          */
        for (Node subNode = element.getFirstChild(); subNode != null; subNode = subNode.getNextSibling()) {
            if (subNode.getNodeType() != Node.ELEMENT_NODE) {
                continue;
            }
            model = parseSectionsOrOther(parent, (Element) subNode);
        }
    } else if (element.getTagName() == "section") {
        model = new SectionModel(parent, name, toolTip);
        parseSectionsOrOtherContents(model, element);
    } else if (element.getTagName() == "list") {
        BaseModel tModel = new ListModel(parent, name);
        parseSectionsOrOtherContents(tModel, element);
        parent.addChild(tModel);
    } else {
        throw new Exception("Expected <section> or <list>, found = \'" + element.getTagName() + "\'");
    }
    return model;
}
Also used : BaseModel(net.sourceforge.usbdm.deviceEditor.model.BaseModel) SectionModel(net.sourceforge.usbdm.deviceEditor.model.SectionModel) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) UsbdmException(net.sourceforge.usbdm.jni.UsbdmException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with SectionModel

use of net.sourceforge.usbdm.deviceEditor.model.SectionModel in project usbdm-eclipse-plugins by podonoghue.

the class TabbedEditor method setModel.

public void setModel(BaseModel model) {
    if (fPeripheralPageModel == model) {
        return;
    }
    fPeripheralPageModel = (TabModel) model;
    fTabFolder.setToolTipText(fPeripheralPageModel.getToolTip());
    for (CTabItem c : fTabFolder.getItems()) {
        c.dispose();
    }
    ArrayList<Object> children = fPeripheralPageModel.getChildren();
    if ((children.size() == 1) && (children.get(0) instanceof TreeViewModel)) {
    }
    for (Object child : fPeripheralPageModel.getChildren()) {
        BaseModel pageModel = (BaseModel) child;
        CTabItem tabItem = new CTabItem(fTabFolder, SWT.NONE);
        tabItem.setText(pageModel.getName());
        tabItem.setToolTipText(pageModel.getToolTip());
        if (pageModel instanceof TreeViewModel) {
            TreeEditor treeEditor = new TreeEditor() {

                @Override
                protected TreeColumnInformation[] getColumnInformation(TreeViewer viewer) {
                    final TreeColumnInformation[] fColumnInformation = { new TreeColumnInformation("Property", 350, new NameColumnLabelProvider(), null), new TreeColumnInformation("Value", 450, new ValueColumnLabelProvider(), new ValueColumnEditingSupport(viewer)), new TreeColumnInformation("Description", 500, new DescriptionColumnLabelProvider(), new DescriptionColumnEditingSupport(viewer)) };
                    return fColumnInformation;
                }
            };
            tabItem.setControl(treeEditor.createControl(fTabFolder));
            treeEditor.setModel((TreeViewModel) pageModel);
        } else if (pageModel instanceof SectionModel) {
            SectionEditor sectionEditor = new SectionEditor();
            tabItem.setControl(sectionEditor.createControl(fTabFolder));
            sectionEditor.setModel(pageModel);
        } else {
            System.err.println("other");
        }
    }
    fTabFolder.setSelection(0);
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) CTabItem(org.eclipse.swt.custom.CTabItem) BaseModel(net.sourceforge.usbdm.deviceEditor.model.BaseModel) SectionModel(net.sourceforge.usbdm.deviceEditor.model.SectionModel) TreeViewModel(net.sourceforge.usbdm.deviceEditor.model.TreeViewModel)

Example 3 with SectionModel

use of net.sourceforge.usbdm.deviceEditor.model.SectionModel in project usbdm-eclipse-plugins by podonoghue.

the class ParseMenuXML method parseSectionsOrOtherContents.

/**
 * Parse: <br>
 *    &lt;peripheralPage&gt;<br>
 *    &lt;list&gt;<br>
 *    &lt;section&gt;<br>
 *    &lt;fragment&gt;<br>
 *
 * @param menuElement
 *
 * @throws Exception
 */
private BaseModel parseSectionsOrOtherContents(BaseModel parent, Element topElement) throws Exception {
    String name = topElement.getAttribute("name");
    if (name.equalsIgnoreCase("_instance")) {
        name = fProvider.getName();
    }
    // String tagName = topElement.getTagName();
    // System.err.println("parseSectionsOrOther(<" + tagName + " name="+ name + ">)");
    // String description = topElement.getAttribute("description");
    String toolTip = getToolTip(topElement);
    BaseModel model = null;
    for (Node node = topElement.getFirstChild(); node != null; node = node.getNextSibling()) {
        if (node.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }
        Element element = (Element) node;
        String tagName = element.getTagName();
        // System.err.println("AT " + element.getTagName());
        if (tagName == "fragment") {
            /*
             * Parse fragment as if it was a continuation of the parent elements
             */
            parseSectionsOrOtherContents(parent, element);
        } else if (tagName == "section") {
            if (model != null) {
                throw new Exception("Multiple top-level elements found " + tagName);
            }
            model = new SectionModel(parent, name, toolTip);
            parseSectionsOrOther(model, element);
        } else if (tagName == "list") {
            BaseModel tModel = new ListModel(parent, name);
            parseSectionsOrOther(tModel, element);
            parent.addChild(tModel);
        } else {
            parseChildModel(parent, element);
        }
    }
    return model;
}
Also used : BaseModel(net.sourceforge.usbdm.deviceEditor.model.BaseModel) SectionModel(net.sourceforge.usbdm.deviceEditor.model.SectionModel) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) UsbdmException(net.sourceforge.usbdm.jni.UsbdmException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

BaseModel (net.sourceforge.usbdm.deviceEditor.model.BaseModel)3 SectionModel (net.sourceforge.usbdm.deviceEditor.model.SectionModel)3 FileNotFoundException (java.io.FileNotFoundException)2 UsbdmException (net.sourceforge.usbdm.jni.UsbdmException)2 Element (org.w3c.dom.Element)2 Node (org.w3c.dom.Node)2 TreeViewModel (net.sourceforge.usbdm.deviceEditor.model.TreeViewModel)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 CTabItem (org.eclipse.swt.custom.CTabItem)1