Duh! InitializeShapeFields is only invoked once!
Beware!!!
The method InitializeShapeFields appears in each shape class that is generated by the DSL tools. However, this method is only invoked ONCE per shape. It is due to this code
///
<summary>
/// Per-class ShapeFields for this shape.
/// </summary>
public override global::System.Collections.Generic.IList<DslDiagrams::ShapeField> ShapeFields
{
get
{
if (shapeFields == null)
{
shapeFields = CreateShapeFields();
}
return shapeFields;
}
}
Note what the comment says. It says "/// Per-class ShapeFields for this shape." Thus, a static collection is being initialized by a member method.
Thus, if you are rolling your own shape fields and expect them to work correctly, make sure you know that the shape field won't be a per shape instance. It will be a per class instance. Thus, you will need to incorporate the appropriate logic for ensuring that your shape field will correctly.
For example, in our DSL, we have a "hyperlink field" which when clicked on pops up an in-place grid editor. The grid derives its data from the model element linked to the shape element on which our "hyperlink field" is parented. Oops! We initially wrote the implementation assuming that there would be one field per shape element. However, the fix was not hard. The field
DiagramItem
item = e.HitDiagramItem;
where e is the DiagramEventArgs passed to the OnClick method is what we needed.