file Selected/selecting elements, Navigation Listener in jython scripts

8 years 9 months ago #2175 by chm
Hi jmfavre,

The navigation service you found should have worked, but it seems it is badly initalized in Modelio 2.2.x and only 'fireNavigate' is working... :(
However, it would not have been the appropriate answer for you, as you only get the result of our 'navigation event', i.e. when we set a specific selection programmaticaly.

There is no service in Modelio giving the current selection, but it is possible to rely on the RCP platform it is based on. Here is your code sample:
from org.eclipse.ui import ISelectionListener
from org.eclipse.ui import PlatformUI

# define the listener
class SimpleNavigationListener(ISelectionListener):
  def selectionChanged(self,part,selection):
    print "eclipse selection is ",selection
    # warning: this selection often contains IAdaptable instead of IElement

# create a listener
myListener = SimpleNavigationListener()
# register it
selectionservice = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService()
selectionservice.addSelectionListener(myListener)
# from here something should be displayed if as we select some elements

# the code below works. We can select an element (here the root).
navservice = Modelio.getInstance().getNavigationService() 
navservice.fireNavigate(Modelio.getInstance().getModelingSession().getModel().getRoot())

Hope this helps,


CHM
The following user(s) said Thank You: jmfavre

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

8 years 9 months ago - 8 years 9 months ago #2177 by jmfavre
Thank you very much for this detailed answer. With eclipse selection this is working properly now, although it returns adapters as mentionned. I will check how to filter elements and post the answer here ;)

Just for the record, it seems that modelio selection listener interface does not work either in Modelio 3.0. Here is the code adapted.
from org.modelio.api.app.navigation import INavigationListener
from org.modelio.api.modelio import Modelio
# define the listener
class SimpleNavigationListener(INavigationListener):
  def navigateTo(self,target):
    print "selected element is ",target.getName()
# create a listener
myListener = SimpleNavigationListener()
# register it
navservice = Modelio.getInstance().getNavigationService()
navservice.addNavigationListener(myListener)
imports are added (see next thread)

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

8 years 9 months ago #2180 by chm
Thank you for the script, I'll check it on Modelio 3 as soon as possible.

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

8 years 9 months ago #2192 by jmfavre
Bonjour,
I've just realized that the "fireNavigate" method do not work either on modelio 3.
Just create a class "MyClass" and try the code below:
print "Assuming that there is a class MyClass in the project"
from org.modelio.metamodel.uml.statik import Class
from org.modelio.api.modelio import Modelio
x = Modelio.getInstance().getModelingSession().findByAtt(Class,"Name","MyClass")
Modelio.getInstance().getNavigationService().fireNavigate(x[0])
print "the class MyClass should be selected now (but is not...)"

I've finished to port the "AdvancedSearch" script to V3, but the select in model explorer feature do not work :dry:

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

8 years 9 months ago #2195 by chm
Hello,

you were right, both navigation listener and fire were broken in 3.0.00. :(

However, they will be working in 3.0.01, which should be out soon.

Sorry for the inconvenience.
The following user(s) said Thank You: andy

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

8 years 8 months ago - 8 years 8 months ago #2292 by jmfavre
Hi,
Still with my selection problems.

With modelio 3.0.1 the code below still do not work.
class SimpleNavigationListener(INavigationListener):
  def navigateTo(self,target):
    print "selection has changed to",target
Modelio.getInstance().getNavigationService().addNavigationListener(SimpleNavigationListener())
Is it because there are two methods with the same name in the Java interface? This might be the cause. I'm not sure if we can solve this problem in jython. Any idea?

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

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