Search in sources :

Example 1 with VariableModel

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;
}
Also used : BooleanVariable(net.sourceforge.usbdm.deviceEditor.information.BooleanVariable) PinListVariable(net.sourceforge.usbdm.deviceEditor.information.PinListVariable) DoubleVariable(net.sourceforge.usbdm.deviceEditor.information.DoubleVariable) ChoiceVariable(net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable) IrqVariable(net.sourceforge.usbdm.deviceEditor.information.IrqVariable) StringVariable(net.sourceforge.usbdm.deviceEditor.information.StringVariable) IndexedCategoryVariable(net.sourceforge.usbdm.deviceEditor.information.IndexedCategoryVariable) Variable(net.sourceforge.usbdm.deviceEditor.information.Variable) BitmaskVariable(net.sourceforge.usbdm.deviceEditor.information.BitmaskVariable) LongVariable(net.sourceforge.usbdm.deviceEditor.information.LongVariable) NumericListVariable(net.sourceforge.usbdm.deviceEditor.information.NumericListVariable) VariableModel(net.sourceforge.usbdm.deviceEditor.model.VariableModel) UsbdmException(net.sourceforge.usbdm.jni.UsbdmException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with VariableModel

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;
}
Also used : BooleanVariable(net.sourceforge.usbdm.deviceEditor.information.BooleanVariable) PinListVariable(net.sourceforge.usbdm.deviceEditor.information.PinListVariable) DoubleVariable(net.sourceforge.usbdm.deviceEditor.information.DoubleVariable) ChoiceVariable(net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable) IrqVariable(net.sourceforge.usbdm.deviceEditor.information.IrqVariable) StringVariable(net.sourceforge.usbdm.deviceEditor.information.StringVariable) IndexedCategoryVariable(net.sourceforge.usbdm.deviceEditor.information.IndexedCategoryVariable) Variable(net.sourceforge.usbdm.deviceEditor.information.Variable) BitmaskVariable(net.sourceforge.usbdm.deviceEditor.information.BitmaskVariable) LongVariable(net.sourceforge.usbdm.deviceEditor.information.LongVariable) NumericListVariable(net.sourceforge.usbdm.deviceEditor.information.NumericListVariable) VariableModel(net.sourceforge.usbdm.deviceEditor.model.VariableModel)

Aggregations

BitmaskVariable (net.sourceforge.usbdm.deviceEditor.information.BitmaskVariable)2 BooleanVariable (net.sourceforge.usbdm.deviceEditor.information.BooleanVariable)2 ChoiceVariable (net.sourceforge.usbdm.deviceEditor.information.ChoiceVariable)2 DoubleVariable (net.sourceforge.usbdm.deviceEditor.information.DoubleVariable)2 IndexedCategoryVariable (net.sourceforge.usbdm.deviceEditor.information.IndexedCategoryVariable)2 IrqVariable (net.sourceforge.usbdm.deviceEditor.information.IrqVariable)2 LongVariable (net.sourceforge.usbdm.deviceEditor.information.LongVariable)2 NumericListVariable (net.sourceforge.usbdm.deviceEditor.information.NumericListVariable)2 PinListVariable (net.sourceforge.usbdm.deviceEditor.information.PinListVariable)2 StringVariable (net.sourceforge.usbdm.deviceEditor.information.StringVariable)2 Variable (net.sourceforge.usbdm.deviceEditor.information.Variable)2 VariableModel (net.sourceforge.usbdm.deviceEditor.model.VariableModel)2 FileNotFoundException (java.io.FileNotFoundException)1 UsbdmException (net.sourceforge.usbdm.jni.UsbdmException)1