]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Support opening multiple selected objects from same diagram 44/2944/1
authorjsimomaa <jani.simomaa@gmail.com>
Wed, 12 Jun 2019 09:17:34 +0000 (12:17 +0300)
committerjsimomaa <jani.simomaa@gmail.com>
Wed, 12 Jun 2019 09:17:34 +0000 (12:17 +0300)
gitlab #304

Change-Id: I3a0c8b8ca9d01c672ba311f09b7faf9e7dfdc5fa

bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/OpenDiagramFromConfigurationAdapter.java

index 8c052561e2340ed051d5989836742d0684083e0f..0ca3b1b04406861467b845013717710ff5c45788 100644 (file)
@@ -13,6 +13,8 @@ package org.simantics.modeling.ui.diagramEditor;
 
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
 
 import org.eclipse.ui.PlatformUI;
 import org.simantics.Simantics;
@@ -103,16 +105,21 @@ public class OpenDiagramFromConfigurationAdapter extends AbstractResourceEditorA
         Resource diagram = ComponentUtils.getPossibleCompositeDiagram(graph, r);
         if(diagram != null) return diagram;
         
-        if(selectedObjects.size() == 1) {
-               Object o = selectedObjects.iterator().next();
-               if(o instanceof Resource) {
-                       Resource res = (Resource)o;
-                       if(graph.isInstanceOf(res, DIA.Element)) {
-                               return graph.getPossibleObject(res, L0.PartOf);
-                       }
-               }
+        // TODO: what if the selected objects are from different diagrams?
+        if (selectedObjects.size() > 0) {
+            Set<Resource> diagrams = new HashSet<>();
+            for (Object o : selectedObjects) {
+                if (o instanceof Resource) {
+                    Resource res = (Resource)o;
+                    if (graph.isInstanceOf(res, DIA.Element)) {
+                        diagrams.add(graph.getPossibleObject(res, L0.PartOf));
+                    }
+                }
+            }
+            if (diagrams.size() == 1) {
+                return diagrams.iterator().next();
+            }
         }
-        
         return null;
 
     }