Bug 441618 - JavaExternalAction gets only 1 element as selection
Summary: JavaExternalAction gets only 1 element as selection
Status: NEW
Alias: None
Product: Sirius
Classification: Modeling
Component: Diagram (show other bugs)
Version: 1.0.0M7   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: triaged
Depends on:
Blocks:
 
Reported: 2014-08-12 13:20 EDT by Stefan Schulz CLA
Modified: 2014-08-13 05:13 EDT (History)
2 users (show)

See Also:


Attachments
Example project reproducing the bug (11.83 KB, application/zip)
2014-08-12 13:20 EDT, Stefan Schulz CLA
no flags Details
New release of sample independant of EcoreTools (13.27 KB, application/x-zip-compressed)
2014-08-13 04:38 EDT, Esteban DUGUEPEROUX CLA
no flags Details
ExternalJavaAction used as menu item and as model operation in tool and menu (13.22 KB, application/x-zip-compressed)
2014-08-13 05:13 EDT, Maxime Porhel CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Schulz CLA 2014-08-12 13:20:24 EDT
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/
Comment 1 Esteban DUGUEPEROUX CLA 2014-08-13 04:36:15 EDT
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.
Comment 2 Esteban DUGUEPEROUX CLA 2014-08-13 04:38:51 EDT
Created attachment 245943 [details]
New release of sample independant of EcoreTools

I have attached another release of your sample independant of EcoreTools.
Comment 3 Esteban DUGUEPEROUX CLA 2014-08-13 05:05:38 EDT
As a work-around you can retreive the selection by calling :

org.eclipse.sirius.common.ui.tools.api.util.EclipseUIUtil.getActiveEditor().getSelection();
Comment 4 Maxime Porhel CLA 2014-08-13 05:13:19 EDT
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.