From: jsimomaa Date: Wed, 12 Jun 2019 09:17:34 +0000 (+0300) Subject: Support opening multiple selected objects from same diagram X-Git-Tag: v1.43.0~136^2~148^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F44%2F2944%2F1;p=simantics%2Fplatform.git Support opening multiple selected objects from same diagram gitlab #304 Change-Id: I3a0c8b8ca9d01c672ba311f09b7faf9e7dfdc5fa --- diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/OpenDiagramFromConfigurationAdapter.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/OpenDiagramFromConfigurationAdapter.java index 8c052561e..0ca3b1b04 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/OpenDiagramFromConfigurationAdapter.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/OpenDiagramFromConfigurationAdapter.java @@ -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 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; }