Search in sources :

Example 1 with AliasPlaceholderModel

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

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

the class ParseMenuXML method parseAliasOption.

/**
 * Parse &lt;aliasOption&gt; element<br>
 *
 * @param stringElement
 * @throws Exception
 */
private void parseAliasOption(BaseModel parent, Element stringElement) throws Exception {
    // Key and name are interchangeable
    // Name is an IDREF and can be used for validation checks within the file.
    // Key is used to refer to an external variable without validation error
    // DisplayName is used for GUI (model)
    String name = stringElement.getAttribute("name");
    String key = stringElement.getAttribute("key");
    String displayName = stringElement.getAttribute("displayName");
    String description = stringElement.getAttribute("description");
    String toolTip = getToolTip(stringElement);
    String indexSuffix = "";
    indexSuffix = "[" + Integer.toString(fIndex) + "]";
    if (!key.isEmpty() && !name.isEmpty()) {
        throw new Exception("Both name and key provided for <alias>, key='" + key + "', name='" + name + "'");
    }
    if (key.isEmpty()) {
        key = name;
    }
    if (key.isEmpty()) {
        throw new Exception("Alias requires either name or key " + displayName);
    }
    key = substituteKey(key);
    key = key.replaceAll("\\.$", indexSuffix);
    key = fProvider.makeKey(key);
    boolean isConstant = Boolean.valueOf(stringElement.getAttribute("constant"));
    boolean isOptional = Boolean.valueOf(stringElement.getAttribute("optional"));
    AliasPlaceholderModel placeholderModel = new AliasPlaceholderModel(parent, displayName, description);
    placeholderModel.setkey(key);
    placeholderModel.setConstant(isConstant);
    placeholderModel.setOptional(isOptional);
    placeholderModel.setToolTip(toolTip);
}
Also used : UsbdmException(net.sourceforge.usbdm.jni.UsbdmException) FileNotFoundException(java.io.FileNotFoundException) AliasPlaceholderModel(net.sourceforge.usbdm.deviceEditor.model.AliasPlaceholderModel)

Aggregations

AliasPlaceholderModel (net.sourceforge.usbdm.deviceEditor.model.AliasPlaceholderModel)2 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 BaseModel (net.sourceforge.usbdm.deviceEditor.model.BaseModel)1 UsbdmException (net.sourceforge.usbdm.jni.UsbdmException)1