Context Menu for Generic Table

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

Context Menu for Generic Table

Postby dustin.waguespack@gdit.com » Fri May 07, 2021 2:39 pm

I am trying to add an action to the context menu (the menu which pops up on right-click) of a "Generic Table" diagram. This is the class I am using. It is nearly a straight copy/paste of the example DiagramConfigurator.java file provided in the openApi/examples/simpleconfigurators file from the No Install version of Cameo Enterprise Architect.

Code: Select all
public class DiagramMenuActions {

  DiagramMenuActions(ActionsConfiguratorsManager manager) {
    manager.addDiagramContextConfigurator(DiagramType.GENERIC_TABLE, new DiagramConfigurator(new DiagramExampleAction()));
  }


  class DiagramConfigurator implements DiagramContextAMConfigurator, AMConfigurator {
    private final DefaultDiagramAction action;

    DiagramConfigurator(DefaultDiagramAction action) {
      this.action = action;
    }

    @Override
    public void configure(ActionsManager manager, DiagramPresentationElement diagram, PresentationElement[] selected, PresentationElement requestor) {
      final ActionsCategory category = new MDActionsCategory();
      category.addAction(action);
      manager.addCategory(category);
    }

    @Override
    public void configure(ActionsManager manager) {
      if (manager.getActionFor(action.getID()) == null) {
        ActionsCategory category = (ActionsCategory) manager.getActionFor(ActionsID.CLASS_DIAGRAM_ELEMENTS);
        if (category != null) {
          category.addAction(action);
        }
      }

    }

    @Override
    public int getPriority() {
      return AMConfigurator.MEDIUM_PRIORITY;
    }

  }


  class DiagramExampleAction extends DefaultDiagramAction {

    public DiagramExampleAction() {
      super("Test", "Test", null, null);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
      System.out.println("Performing action from diagram.");
    }

  }
}


The action does not appear in the context menu when I right click on a Generic Table diagram or any components of the diagram.
It works fine if DiagramType.GENERIC_TABLE is changed to, say, DiagramType.UML_ANY_DIAGRAM, in which case my action appears in the context menu of nearly every other diagram type.
Hoping someone can tell me what is wrong with my code or provide an example of a working Generic Table context menu context configurator class.
dustin.waguespack@gdit.com
Forum Newbie
Forum Newbie
 
Posts: 5
Posts Rating:0
Joined: Thu Mar 11, 2021 1:36 pm

Re: Context Menu for Generic Table

Postby dustin.waguespack@gdit.com » Tue May 11, 2021 1:00 pm

I now know that Cameo provides a set of three jars for a "Diagram Table plugin", namely, commons-lang3-3.4.jar, diagramtable.jar, and diagramtable_api.jar. I have learned from another post in this forum that these three jars must be added to the classpath in order to build features which provide interactivity with the Generic Table object. However, when I add these jars to the classpath and launch Cameo, the Diagram Table plugin fails to start along with a few other plugins which depend on the Diagram Table plugin. Here is one of the logged plugin failures
Code: Select all
Can not start Model migration framework v1.0 Reason: Required plugin "com.nomagic.magicdraw.diagramtable" not found


Can anyone provide instructions for how to successfully include these needed jars into the classpath in a way that does not prevent the Diagram Table plugin from loading?
dustin.waguespack@gdit.com
Forum Newbie
Forum Newbie
 
Posts: 5
Posts Rating:0
Joined: Thu Mar 11, 2021 1:36 pm

Re: Context Menu for Generic Table

Postby dustin.waguespack@gdit.com » Tue May 11, 2021 1:13 pm

Solved: For anyone following the saga. The Diagram Table plugin depends on the "Legend plugin" which is found in the com.nomagic.magicdraw.legend.LegendPlugin folder. The two jars provided in this folder, legend.jar and legend_api.jar, must also be included in the classpath.
dustin.waguespack@gdit.com
Forum Newbie
Forum Newbie
 
Posts: 5
Posts Rating:0
Joined: Thu Mar 11, 2021 1:36 pm


Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 0 guests