Search in sources :

Example 6 with BaseModel

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

the class SectionEditor method setModel.

public void setModel(BaseModel model) {
    if (fSectionModel == model) {
        return;
    }
    fSectionModel = (SectionModel) model;
    for (Object child : fSectionModel.getChildren()) {
        BaseModel pageModel = (BaseModel) child;
        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", 550, new DescriptionColumnLabelProvider(), new DescriptionColumnEditingSupport(viewer)) };
                    return fColumnInformation;
                }
            };
            Control treeControl = treeEditor.createControl(tabArea);
            treeControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
            treeEditor.setModel((TreeViewModel) pageModel);
        } else if (pageModel instanceof TabModel) {
            TabbedEditor tabEditor = new TabbedEditor();
            Control treeControl = tabEditor.createControl(tabArea);
            treeControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
            tabEditor.setModel(pageModel);
        }
    }
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) Control(org.eclipse.swt.widgets.Control) BaseModel(net.sourceforge.usbdm.deviceEditor.model.BaseModel) GridData(org.eclipse.swt.layout.GridData) TreeViewModel(net.sourceforge.usbdm.deviceEditor.model.TreeViewModel) TabModel(net.sourceforge.usbdm.deviceEditor.model.TabModel)

Example 7 with BaseModel

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

the class ParseMenuXML method instantiateAliases.

/**
 * Visits all nodes of the model and instantiates any aliases
 *
 * @param  provider  Provider to look up variables
 * @param  parent    Root of the model tree to visit
 *
 * @throws Exception
 */
static void instantiateAliases(VariableProvider provider, BaseModel parent) throws Exception {
    if ((parent == null) || (parent.getChildren() == null)) {
        return;
    }
    ArrayList<Object> children = parent.getChildren();
    ArrayList<Object> deletedChildren = new ArrayList<Object>();
    for (int index = 0; index < children.size(); index++) {
        Object model = children.get(index);
        if (model instanceof AliasPlaceholderModel) {
            BaseModel newModel = createModelFromAlias(provider, parent, (AliasPlaceholderModel) model);
            if (newModel == null) {
                // Variable not found and model is optional - delete placeholder
                deletedChildren.add(model);
            } else {
                // Replace placeholder with new model
                children.set(index, newModel);
                newModel.setParentOnly(parent);
            }
        } else {
            instantiateAliases(provider, (BaseModel) model);
        }
    }
    // Remove deleted children
    children.removeAll(deletedChildren);
}
Also used : BaseModel(net.sourceforge.usbdm.deviceEditor.model.BaseModel) ArrayList(java.util.ArrayList) AliasPlaceholderModel(net.sourceforge.usbdm.deviceEditor.model.AliasPlaceholderModel)

Example 8 with BaseModel

use of net.sourceforge.usbdm.deviceEditor.model.BaseModel 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)8 SectionModel (net.sourceforge.usbdm.deviceEditor.model.SectionModel)3 FileNotFoundException (java.io.FileNotFoundException)2 TreeViewModel (net.sourceforge.usbdm.deviceEditor.model.TreeViewModel)2 UsbdmException (net.sourceforge.usbdm.jni.UsbdmException)2 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2 Element (org.w3c.dom.Element)2 Node (org.w3c.dom.Node)2 ArrayList (java.util.ArrayList)1 AliasPlaceholderModel (net.sourceforge.usbdm.deviceEditor.model.AliasPlaceholderModel)1 CategoryModel (net.sourceforge.usbdm.deviceEditor.model.CategoryModel)1 IndexedCategoryModel (net.sourceforge.usbdm.deviceEditor.model.IndexedCategoryModel)1 ParametersModel (net.sourceforge.usbdm.deviceEditor.model.ParametersModel)1 TabModel (net.sourceforge.usbdm.deviceEditor.model.TabModel)1 StyledString (org.eclipse.jface.viewers.StyledString)1 CTabItem (org.eclipse.swt.custom.CTabItem)1 GridData (org.eclipse.swt.layout.GridData)1 Control (org.eclipse.swt.widgets.Control)1