Popup menu with diagram element selected

Hello.
I wrote a script in python, which I want to be able to launch:

  • either from an element selected in the explorer,
  • or from an element selected on a diagram.

The problem is that my popup menu only appears when I right-click on an element in the explorer, but not when I right-click on an element in the diagram. Do you know why ?

here is my python file header:

# name          : Naval Group Contextual Menu
# script-type   : Python
# description   : Contextual Menu
# popup         : enableFor(org.polarsys.capella.core.data.capellacore.CapellaElement)

Is there anything that can be done to change this behavior?
thanks

Hi Emmanuel,

When you select an element on a diagram, you select the graphical element and not the semantic element. This means you will activate your menu for all graphical element of the same kind (Container, Node, Edge, …). With the magic header provided by EASE it’s not possible to make further tests to check the semantic element for instance.

To enable your menu on any element of a diagram you can use:

# popup         : enableFor(org.eclipse.sirius.diagram.DDiagramElement)

other choices for the class can be:

org.eclipse.sirius.diagram.DEdge
org.eclipse.sirius.diagram.AbstractDNode
  org.eclipse.sirius.diagram.DNode
  org.eclipse.sirius.diagram.DDiagramElementContainer
    org.eclipse.sirius.diagram.DNodeContainer
    org.eclipse.sirius.diagram.DNodeList

You will need to create three scripts one for each header that will call the main code of your initial script.

Hello.
I understand that you need to create two python scripts (i.e. two *.py files) with appropriate headers.

Example :

Diagram_NG_Menu.py

# name          : Naval Group Contextual Menu
# script-type   : Python
# description   : Contextual Menu
# popup         : enableFor(org.eclipse.sirius.diagram.DDiagramElement)
    
include('workspace://Python4Designer/utils/MyMenu.py')
if False:
    from Utils.MyMenu_XLSX import *    

MyMenu.naval_group_contextual_menu()

#=========================================================================
# FIN
#=========================================================================

and

Explorer_NG_Menu.py

# name          : Naval Group Contextual Menu
# script-type   : Python
# description   : Contextual Menu
# popup         : enableFor(org.polarsys.capella.core.data.capellacore.CapellaElement)
    
include('workspace://Python4Designer/utils/MyMenu.py')
if False:
    from Utils.MyMenu_XLSX import *    

MyMenu.naval_group_contextual_menu()

#=========================================================================
# FIN
#=========================================================================

this all works perfectly, thank you.

1 Like