Concept's Properties
Hi,
In our domain model we need to be able to allow the end user to define a variable number of name/value pairs for a single concept's property. For example, we need to support a model element that contains a custom property field that the user can specify multiple entries for such as isrootelement/true, generatecode/false, etc. To achieve this I would like to have a value property field on the model element that when selected allows the user to pop up a window that enables them to enter multiple name/value pairs into a grid. What approach would you recommend to achieve this (e.g. VSIP, GAT)?
Cheers
Susan Entwisle
Hi Susan
I can only think of a workaround, which would be to invent and domain class A with two value propeties: a string and a boolean. Then embed this beneath the domain class B whose elements you want to have multiple entries for these properties.
Then, in the explorer, you can create a B, then create 1 or more A's bested beneath that B. When you select one of those A's you can use the properties grid to enter the string e.g. isrootelement, and the corresponding value, e.g. true.
This will work without any coding.
You may be able to write custom code that creates and populates the A's through a custom editor tied to an entry in the properties grid, but I'll have to ask one of the devs in the team to help you out with that.
Caveat Emptor: As always, this might well change by V1 release....
If you don't want the user to have to work with this in the explorer but rather also want a property editing experience you can do the following:
You'll see the property value in the property grid as some gnarly string catenation e.g. Pair1Name|Pair1Value;Pair2Name|Pair2Value but you'll get an edit button for your custom form.
If you follow standard .Net practices and add a custom editor to the property using the CLRAttributes property. in the domain model.
e.g.
[System.ComponentModel.
Editor(typeof(YourEditorType), typeof(System.Drawing.Design.UITypeEditor))]
Then you can create an editor class that when it is OK'd creates the sub-object structure.
You'll have to set the property to be of type string and custom storage to be true.
Then in the class containing the property, override
GetValueForCustomStoredAttribute to construct the string representation from teh object graph
and
SetValueForCustomStoredAttribute to just return doing nothing.
This is how the CLRAttributes property in the DMD is constructed for example.
A further step which might work...
Double Caveat Emptor: I've haven't had time to try this one...
Don't model the name/value classes at all. just create them as simple .Net types, with an appropriate strongly-typed collection type.
Then make the type of the property a "New Simple Type" using the name and namespace of the collection.
Then add the Editor attribute to the property as before and add a TypeConvertor attribute to the collection class. The TypeConvertor for the collection should convert between it and String (in the gnarly format).
This time the editor would simply create the set of .Net objects when OK'd.
The Get and Set custom properties would now use standard .Net Convert functions to switch the storage to string which our runtime can handle.
Test Undo functionality thoroughly with either of these methods.
Hope one of these meets your needs...
Gareth
Hi Gareth,
As you mentioned, i'm using a custom UITypeEditor to pop-up a dialog and that returns a string value, i just want the string returned from my editor to be displayed on the property grid. So, what has to be done in GetValueForCustomStoredAttribute method to achieve the same.
Could you please elaborate on this ?
thanks,
Arumugam J
Hi Arumugam J,
If you're just storing a string value and your editor essentially is just a nice way to compose that complex string then you shoudln't need a custom storage at all and inthat case, you won't need to implement GetValueForCustomStoredAttribute.
You'd need to implement Get/SetValueForCustomStoredAttribute if you wanted to parse that string and maybe create some structured objects behind the scenes.