« Back

Different relation names between multiple objects

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Different relation names between multiple objects
community relation documentation
Answer
3/27/14 12:14 PM
I have a large number of classes that I need to relate to each other. Each relation has a different name which should be displayed (e.g. the relation name between classes "tactic" and "strategy" is "implement" but not vice versa). Due to a large number of classes, I don't want to define every singe relation class because of the mess it may create in the modelling tool. Is there a way to define a "generic" relation class which would mandatory require you to choose a relation name to be displayed (e.g. from an enumeration list) based on the classes that we want to connect? If no, are there any other workarounds for it?

RE: Different relation names between multiple objects
Answer
11/4/13 11:18 AM as a reply to Natalia Sudakova.
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.