Search in sources :

Example 1 with BaseModel

use of net.sourceforge.usbdm.deviceEditor.model.BaseModel 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 BaseModel

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

the class ParseMenuXML method parseChildModel.

/**
 * Parse element containing: <ul>
 *   <li> &lt;fragment&gt; referencing only elements below
 *   <li> &lt;intOption&gt;
 *   <li> &lt;bitmaskOption&gt;
 *   <li> &lt;floatOption&gt;
 *   <li> &lt;binaryOption&gt;
 *   <li> &lt;irqOption&gt;
 *   <li> &lt;choiceOption&gt;
 *   <li> &lt;stringOption&gt;
 *   <li> &lt;numericListOption&gt;
 *   <li> &lt;pinListOption&gt;
 *   <li> &lt;aliasOption&gt;
 *   <li> &lt;constant&gt;
 *   <li> &lt;section&gt;
 *   <li> &lt;signals&gt;
 *   <li> Control items...
 *</ul>
 *
 * Elements found are added as children of the parentModel
 *
 * @param  parentModel  Model to attach children to
 * @param  menuElement  Menu element to parse
 *
 * @throws Exception
 */
void parseChildModel(BaseModel parentModel, Element element) throws Exception {
    String tagName = element.getTagName();
    String name = element.getAttribute("name");
    String toolTip = getToolTip(element);
    // System.err.println("parseChildModel(): " + tagName + ", " + element.getAttribute("name"));
    if (tagName == "fragment") {
        parseChildModels(parentModel, element);
    } else if (tagName == "category") {
        BaseModel model = new CategoryModel(parentModel, name, toolTip);
        parseChildModels(model, element);
    } else if (tagName == "indexedCategory") {
        parseIndexedCategoryOption(parentModel, element);
    } else if (tagName == "intOption") {
        parseLongOption(parentModel, element);
    } else if (tagName == "bitmaskOption") {
        parseBitmaskOption(parentModel, element);
    } else if (tagName == "floatOption") {
        parseDoubleOption(parentModel, element);
    } else if (tagName == "binaryOption") {
        parseBinaryOption(parentModel, element);
    } else if (tagName == "irqOption") {
        parseIrqOption(parentModel, element);
    } else if (tagName == "choiceOption") {
        parseChoiceOption(parentModel, element);
    } else if (tagName == "stringOption") {
        parseStringOption(parentModel, element);
    } else if (tagName == "numericListOption") {
        parseNumericListOption(parentModel, element);
    } else if (tagName == "pinListOption") {
        parsePinListOption(parentModel, element);
    } else if (tagName == "aliasOption") {
        parseAliasOption(parentModel, element);
    } else if (tagName == "constant") {
        parseConstant(parentModel, element);
    } else if (tagName == "section") {
        BaseModel model = new ParametersModel(parentModel, name, toolTip);
        parseChildModels(model, element);
    } else if (tagName == "list") {
        BaseModel model = new ListModel(parentModel, name);
        parseSectionsOrOther(model, element);
    } else if (tagName == "signals") {
        parseSignalsOption(parentModel, element);
    } else {
        parseControlItem(element);
    }
}
Also used : BaseModel(net.sourceforge.usbdm.deviceEditor.model.BaseModel) ParametersModel(net.sourceforge.usbdm.deviceEditor.model.ParametersModel) CategoryModel(net.sourceforge.usbdm.deviceEditor.model.CategoryModel) IndexedCategoryModel(net.sourceforge.usbdm.deviceEditor.model.IndexedCategoryModel)

Example 3 with BaseModel

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

the class PeripheralWithState method getModels.

@Override
public void getModels(BaseModel parent) {
    if (fMenuData == null) {
        return;
    }
    createSignalModel();
    BaseModel model = fMenuData.getRootModel();
    if (model != null) {
        model.setParent(parent);
    }
}
Also used : BaseModel(net.sourceforge.usbdm.deviceEditor.model.BaseModel)

Example 4 with BaseModel

use of net.sourceforge.usbdm.deviceEditor.model.BaseModel 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 5 with BaseModel

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

the class BaseLabelProvider method getStyledText.

@Override
public StyledString getStyledText(Object element) {
    if (!(element instanceof BaseModel)) {
        return new StyledString("");
    }
    BaseModel baseModel = (BaseModel) element;
    String text = getText(baseModel);
    if ((text == null) || (text.length() == 0)) {
        return new StyledString("");
    }
    if (!baseModel.isEnabled()) {
        return new StyledString(text, DISABLED_STYLER);
    }
    if (baseModel.isError()) {
        return new StyledString(text, ERROR_STYLER);
    }
    if (baseModel.isWarning()) {
        return new StyledString(text, WARNING_STYLER);
    }
    if (baseModel.isUnassigned()) {
        return new StyledString(text, DISABLED_STYLER);
    }
    if (baseModel.hasChildren()) {
        return new StyledString(text, CATEGORY_STYLER);
    }
    return new StyledString(text, DEFAULT_STYLER);
}
Also used : BaseModel(net.sourceforge.usbdm.deviceEditor.model.BaseModel) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

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