Community
Participate
Working Groups
Created attachment 245924 [details] Example project reproducing the bug External Java Action get only one element in their selection parameter when executed - even if there are multiple elements selected. I've attached an example viewpoint-specification project that prints the size of the selection parameter when the action is executed. Reproduction: -Run project as Eclipse Application -Make sure you have ExampleViewPoint selected for Example.aird -Open example class diagram -Add related elements if necessary (class1, class2, class3) -Select any amount of elements n (n>1) -Right-click element -> ExampleMenu -> ExampleAction -Print-out on console should be "Selection size is n", but will be "Selection size is 1" Another example: https://www.eclipse.org/forums/index.php/t/798692/
I confirm the bug. Technical explain : The IExternalJavaAction to execute is encapsulated in a ExternalJavaActionTask and this last has a CommandContext which can take only one target, i.e. the first EObject of the selection. When using the contextual menu, we execute the UndoRedoCapableEMFCommandFactory.buildOperationActionFromTool() which take only the first element of the selection. When using the generic tool, we execute the GenericToolCommandBuilder.buildCommand() which only take semantic element under the GraphicalEditPart on which we click. The fix will change many classes, beginning by CommandContext to take a list of semantic elements instead of a single one.
Created attachment 245943 [details] New release of sample independant of EcoreTools I have attached another release of your sample independant of EcoreTools.
As a work-around you can retreive the selection by calling : org.eclipse.sirius.common.ui.tools.api.util.EclipseUIUtil.getActiveEditor().getSelection();
Created attachment 245945 [details] ExternalJavaAction used as menu item and as model operation in tool and menu I have updated a new version of the reproduction case. This version adds an ExternalJavaAction used as menu item (as a tool and not as a model operation in an other tool or operation action). Note that with this action (ExampleJavaAction in the example menu), the multi selection is passed to the action. But I have detected a secondary issue: the selection can contains doublons if the user has selected several nodes with a drag selection: it select the nodes and their labels. If the external java acton is used in a tool as model operation, the selection will be unique, but the user could use a parameter to pass the selection list.