question-circle Using diagram customization service in jython? e.g. IDiagramCustomizer

8 years 8 months ago - 8 years 8 months ago #2301 by jmfavre
Hi,
I'm trying to make some modelio customization from jython. Jython scriptng is wonderful as this allows to interactively try things, to avoid the real burden of using eclipse, packaging, reloading the module, and so on. In that context (and in the context of a course where students will have to interact with the API), I'm trying to look at all elements of the API and see whether each API interface and function can be used without the context of a module or not.

I've realized that one can do more in jython that what is said in the documentation. And want actually to do everything in jython if possible.
I will contribute the slides to the community when finished (I'm developping little example just like in the API guide but using jython).

I'm currently playing the IDiagramService and more particularily IDiagramCustomizer.

The code below register such customizer, but do not actually work as hopped :-( I guess that some action should be done so that the registration actually take place or better said the customizer are processed. Is there a reasonably easy way to do this (e.g. by calling a java method from the modelio framework or acting directly at eclipse/gef level)?

Thanks
# Before to execute the code
# (1) Create a stereotype "MyDiagram" in the local module
# (2) Create a class diagram with this stereotype
# This code create a diagram customizer palette
class MyDiagramCustomizer(IDiagramCustomizer):
     def fillPalette(palette):
         print "nothing will be in this palette"
     def keepBasePalette():
         print "the base palette will not be there"
         return False
stereotype= Modelio.getInstance().getModelingSession().findByAtt(Stereotype,"Name","MyDiagram")[0]
theDiagramService().registerDiagramCustomization( stereotype, Metamodel.getMClass(ClassDiagram),MyDiagramCustomizer() ) 

# after executing this code one could expect (a prori) that opening the
# diagram stereotyped with "MyDiagram" would display the message on the console
# and should an empty palette. This is not the case, no message, regular palette. 

oooppss, please move the message to "Script" thread :oops:

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

8 years 8 months ago #2304 by pan
Topic moved!
The following user(s) said Thank You: jmfavre

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

8 years 8 months ago #2305 by chm
Thanks pan. ;)


Hi jmfavre,

looks like your code has a few errors (you forgot adding 'self'), works for me with this one:
# Before to execute the code
# (1) Create a stereotype "MyDiagram" in the local module
# (2) Create a class diagram with this stereotype
# This code create a diagram customizer palette
class MyDiagramCustomizer(IDiagramCustomizer):
     def fillPalette(self, palette):
         print "nothing will be in this palette"
     def keepBasePalette(self):
         print "the base palette will not be there"
         return False
stereotype= Modelio.getInstance().getModelingSession().findByAtt(Stereotype,"Name","MyDiagram")[0]
Modelio.getInstance().getDiagramService().registerDiagramCustomization( stereotype, Metamodel.getMClass(ClassDiagram),MyDiagramCustomizer() ) 

# after executing this code one could expect (a prori) that opening the
# diagram stereotyped with "MyDiagram" would display the message on the console
# and should an empty palette. This is not the case, no message, regular palette. 

I've realized that one can do more in jython that what is said in the documentation. And want actually to do everything in jython if possible.


Is it written somewhere that jython can't do things? Afaik, you're supposed to have access to everything a module has access to, with exactly the same API...

Anyway, having more examples is always good, thank you for wanting to help the community! B)

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 8 months ago - 8 years 8 months ago #2311 by jmfavre
:oops:
Thank you!!! This was some night code and I missed my "self" ;-)

Is it written somewhere that jython can't do things? Afaik, you're supposed to have access to everything a module has access to, with exactly the same API...


I'm refering here to the page "macro vs. module" but I will create a separated thread as this is a quite interesting topic per see.

Thanks again!

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

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