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);
}
use of net.sourceforge.usbdm.deviceEditor.model.AliasPlaceholderModel in project usbdm-eclipse-plugins by podonoghue.
the class ParseMenuXML method parseAliasOption.
/**
* Parse <aliasOption> 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);
}
Aggregations