Just as with the editor, it is a good practice to obtain and to store a reference to the properties and parameters in the initHandler method, which is the first method called in the Handler; this way you can easily get and set their values in any of the other methods. shapeProp = ((DtScalarVariable)component.getProperty("Shape")); materialProp = ((DtScalarVariable)component.getProperty("Material")); thicknessParam=((DtScalarVariable)component.getParameter("Thickness")); In the modelChanged method you will monitor for any changes to the predefined parameters to make sure the user is not corrupting the necessary inputs and outputs. In Isight 2017 there is no way to set permissions on parameter changes; thus, you are allowed to make changes that should typically be disallowed. The modelChanged method allows your component to react to those and possibly correct them immediately. Alternatively, these code be handled in the validate method as well. // Only interested in Variable events for my component DtComponent eventComp = event.getParentCompForEvent(); if (eventComp == myComponent && dtme instanceof Variable) { Variable eVar = (Variable)dtme; Variable rootVar = VariableUtil.getRootVariable(eVar); String rootVarName = rootVar.getName(); // if one of our predefined parameter names changes, change it back if (event.getChangeType() == DtModelEvent.CHANGED_VARNAME) { String oldName = (String)event.getOldValue(); String newName = VariableUtil.getVariablePathAsString(eVar); if (oldName.equals("Dimensions")) { ((DtVariable)eVar).setName("Dimensions"); } else if (oldName.equals("Area")) { ((DtVariable)eVar).setName("Area"); } else if (oldName.equals("Volume")) { ((DtVariable)eVar).setName("Volume"); } else if (oldName.equals("Weight")) { ((DtVariable)eVar).setName("Weight"); } } // if a pre-defined parameter is deleted, add it back if (event.getEventType() == DtModelEvent.ELEMENT_REMOVED) { String varName = eVar.getName(); DtVariable dtVar = (DtVariable)eVar; if (varName.equals("Dimensions") || varName.equals("Area") || varName.equals("Weight") || varName.equals("Volume")) { myComponent.addParameter(dtVar); } } // if a pre-defined parameter is changed to an inappropriate type if (event.getChangeType() == DtModelEvent.CHANGED_TYPE) { String varName = eVar.getName(); DtVariable dtVar = (DtVariable)eVar; if (varName.equals("Dimensions")) { dtVar.setMode(Variable.MODE_INPUT); } else if (varName.equals("Area") || varName.equals("Weight") || varName.equals("Volume")) { dtVar.setMode(Variable.MODE_OUTPUT); } } In the validate method you will ensure that the dimensions are properly specified for the selected shape and that a thickness has been specified for the plate. public void validate(java.util.List validationList) throws SDKException { try { String name = myComponent.getName(); MetaModel myMM = myComponent.getMetaModel(); // warn if no application specified if (shapeProp.getValueObj().getAsString().length() == 0) { validationList.add(new ValidationResult(ValidationEvent.SEVERITY_WARNING, myComponent, new IString(CLASS, 0, "{0}: No shape specified for the plate", name), "shape")); } if (materialProp.getValueObj().getAsString().length() == 0) { validationList.add(new ValidationResult(ValidationEvent.SEVERITY_WARNING, myComponent, new IString(CLASS, 0, "{0}: No material specified for the plate", name), "material"));\ if (thicknessParam.getValueObj().getAsString().length() == 0) { validationList.add(new ValidationResult(ValidationEvent.SEVERITY_WARNING, myComponent, new IString(CLASS, 0, "{0}: No thickness specified for the plate", name), "thickness")); } } catch (Exception e) { throw new SDKException(e, e.getMessage()); } } The complete code for the editor for this Plate component can be found in Component Development Reference. If your component requires interaction with files that must be made known to Isight (e.g., to be passed to/from other components), you will most likely need to represent them using File Parameters. For more information on programming with file parameters, see File Parameters Reference. |