Hi George,
You are right, I'm showing the attributes as a compartment within an Entity.
An Entity provides some kind of context. Within that context only certain values (more concrete: mappings) are allowed. After adding a AfdAttribute to an Entity the user can set properties of the AfdAttribute, a.o. the property Mapping. Using a UITypeConverter I display a dropdown showing only allowed Mappings within the context of the Entity. The user selects a Mapping from the dropdown and on the dropdown click event I read the selected Mapping. A mapping has a type, e.g. string, int etc. Using the type of the selected Mapping I can derive the corresponding AfdAttribute, e.g. AfdTextAttribute for a string type Mapping. Then I create the corresponding subtype of AfdAttribute and replace the current AfdAttribute with the newly created attribute.
The last part in code (AfdPropertyDescriptor is the class representing a mapping): private void SetAttribute(System.ComponentModel.ITypeDescriptorContext context, AfdPropertyDescriptor propDesc) { ElementPropertyDescriptor descriptor = context.PropertyDescriptor as ElementPropertyDescriptor; ModelElement element = descriptor.ModelElement; AfdEntity container = ((AfdAttribute)element).AfdAttributeContainer; using (Transaction t = container.Store.TransactionManager.BeginTransaction("Change AfdAttribute")) { AfdAttribute atttribute = CreateAttribute(container.Store, propDesc, (AfdAttribute)element); int index = container.AfdAttributes.IndexOf((AfdAttribute)element); container.AfdAttributes.ReplaceAt(index, atttribute); t.Commit(); } }
After replacing the AfdAttribute I would like to update the propertygrid to display the properties of the new AfdAttribute type, something like: propertyGrid.SelectedObject = attribute.
Regards, Ronald |