use of net.sourceforge.usbdm.deviceEditor.model.VariableModel in project usbdm-eclipse-plugins by podonoghue.
the class ParseMenuXML method createModelFromAlias.
/**
* @param provider Provider to look up variables
* @param parent Parent model needed to replace child in
* @param aliasModel Information for model to instantiate
*
* @return New model created
*
* @throws Exception
*/
static BaseModel createModelFromAlias(VariableProvider provider, BaseModel parent, AliasPlaceholderModel aliasModel) throws Exception {
String key = aliasModel.getKey();
boolean isOptional = aliasModel.isOptional();
Variable variable = provider.safeGetVariable(key);
if (variable == null) {
if (!isOptional) {
throw new Exception("Alias not found for " + key + " within " + parent.getName() + ", provider = " + provider);
}
return null;
}
String description = aliasModel.getDescription();
if (!description.isEmpty()) {
if ((variable.getDescription() != null) && !variable.getDescription().isEmpty()) {
throw new Exception("Alias tries to change description for " + key);
}
variable.setDescription(description);
}
String toolTip = aliasModel.getToolTip();
if ((toolTip != null) && !toolTip.isEmpty()) {
if ((variable.getDisplayToolTip() != null) && !variable.getDisplayToolTip().isEmpty()) {
throw new Exception("Alias tries to change toolTip for " + key);
}
variable.setToolTip(toolTip);
}
VariableModel model = variable.createModel(null);
boolean isConstant = aliasModel.isConstant();
model.setConstant(isConstant);
String displayName = aliasModel.getName();
if (!displayName.isEmpty()) {
model.setName(displayName);
}
return model;
}
use of net.sourceforge.usbdm.deviceEditor.model.VariableModel in project usbdm-eclipse-plugins by podonoghue.
the class ParseMenuXML method parseCommonAttributes.
/**
* Parse attributes common to most variables<br>
* Also creates model.
* Processes the following attributes:
* <li>name
* <li>key
* <li>description
* <li>toolTip (processed)
* <li>constant
* <li>derived
* <li>derivedFrom
* <li>origin
*
* @param parent Parent for model
* @param varElement Element obtain attributes from
* @param clazz Class of variable to create
*
* @return Variable created (or existing one)
* @throws Exception
*/
private VariableModel parseCommonAttributes(BaseModel parent, Element varElement, Class<?> clazz) throws Exception {
Variable variable = createVariable(varElement, clazz);
Variable otherVariable = getDerived(varElement);
if (otherVariable != null) {
variable.setDescription(otherVariable.getDescription());
variable.setToolTip(otherVariable.getToolTip());
variable.setOrigin(otherVariable.getRawOrigin());
}
if (varElement.hasAttribute("description")) {
variable.setDescription(varElement.getAttribute("description"));
}
if (varElement.hasAttribute("toolTip")) {
variable.setToolTip(getToolTip(varElement));
}
if (varElement.hasAttribute("value")) {
// Value is used as default and initial value
String value = varElement.getAttribute("value");
variable.setValue(value);
variable.setDefault(value);
variable.setDisabledValue(value);
}
if (varElement.hasAttribute("disabledValue")) {
// Value is used as default and initial value
String value = varElement.getAttribute("disabledValue");
variable.setDisabledValue(value);
}
if (varElement.hasAttribute("origin")) {
variable.setOrigin(varElement.getAttribute("origin"));
}
if (varElement.hasAttribute("hidden")) {
// Value is used as default and initial value
if (Boolean.valueOf(varElement.getAttribute("hidden"))) {
parent = null;
}
}
variable.setDerived(Boolean.valueOf(varElement.getAttribute("derived")));
VariableModel model = variable.createModel(parent);
model.setConstant(Boolean.valueOf(varElement.getAttribute("constant")));
return model;
}
Aggregations