question-circle Access to a MObject from an element of a Diagram selection

8 years 4 months ago #2605 by jaracic
For example if someone have a script that reproduces the "Select in the Explorer" command for a diagram element, it will be useful to help me in my first steps in Modelio 3 scripting.

Because by exploring (quickly, I admit...) the modelio and jface APIs (I'm not an Eclipse programmer...) it is not abvious.

Actually, If someone can tell how to access to a IDiagramGraphic object from a ISelection element it would be enough (I hope;-) )

Thanks

Joseph

Please Log in or Create an account to join the conversation.

8 years 4 months ago #2606 by pan
Hi jaracic,

Actually, it is not possible to get the IDiagramGraphic from a selection. When you select an element from a diagram, the selection is the MObject itself.
For example, if you select a Class in a diagram, the selection is the Class object (and not the associated IDiagramGrahic).

Here is a little Jython script example:
navigationService = Modelio.getInstance().getNavigationService()

if (selectedElements.size > 0):
	for element in selectedElements:
		print "Metaclass: " + element.getMClass().getName()
		navigationService.fireNavigate(element)
If you select a class C1 in a diagram it will be automatically selected in the UML explorer (like the "Select in Explorer" command).
In this example, we browse a list of elements but only the last element will be selected.

Hope this helps

Please Log in or Create an account to join the conversation.

8 years 4 months ago #2607 by jaracic
Hi pan,

Thank you for your response, very useful... because it highlights something I didn't noticed :
selectedElements variable is updated by Modelio regarding the last user selection made in the explorer OR in the diagram !!!!

Actually I thought that selection variable was for diagram selection...

cheers.
Joseph

Please Log in or Create an account to join the conversation.

8 years 4 months ago #2608 by pan

selectedElements variable is updated by Modelio regarding the last user selection made in the explorer OR in the diagram !!!!

To be more precise, the selectedElements variable represents the selected elements in the current active view.

Do not hesitate to ask more questions if you need more information about Jython scripts.

BR

Please Log in or Create an account to join the conversation.

Moderators: chmcma
Time to create page: 0.038 seconds
^ Back to Top