A solution we recommend is implementing an event handler for the event "CreateRelationInstance", that allows selecting a specific entry from a list of possible names for the newly created connector. In our example, we have defined a relation class named "any2any", which can connect any two instances of any class.
The implementation of the event handler is as follows:
1ON_EVENT "CreateRelationInstance"
2{
3 # global variables of the event handler
4 # relationinstanceid connector ID
5 # relationclassid class ID of the connector
6 # frominstanceid ID of the outcoming objects to the variable frominstanceid
7 # toinstanceid ID of the target objects to the variable
8 # componentid the model ID
9 SET idConnectorID: (relationinstanceid)
10 SET idRelationClassID: (relationclassid)
11
12 CC "Core" GET_CLASS_NAME classid: (idRelationClassID)
13 # --> RESULT ecode: intValue classname: strValue isrel: intValue
14 SET sRelationClassName: (classname)
15 IF (sRelationClassName = "any2any") {
16 #define the string separating the entries
17 SET sTokenSeparator: "@"
18 #define the string containing the entries or build it dynamically
19 SET sEntries: "implement@annotate@extend"
20 CC "AdoScript" LISTBOX entries: (sEntries) toksep: (sTokenSeparator) title: "Connector name selection..." boxtext: "Please select the name of the connector."
21 # --> RESULT endbutton: strValue selection: strValue
22 IF (endbutton = "ok") {
23 SET sSelectedName: (selection)
24 CC "Core" SET_ATTR_VAL objid: (idConnectorID) attrname: "Name" val: (sSelectedName)
25 # --> RESULT ecode: intValue
26 }
27 }
28}
The definition of the relation class "any2any" also needs defining an attribute "Name" of type STRING and including it in the attribute representation.