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;
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;
}