]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Use single available diagram profile by default 57/357/2
authorAntti Villberg <antti.villberg@semantum.fi>
Fri, 10 Mar 2017 09:12:37 +0000 (11:12 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Sat, 11 Mar 2017 05:43:15 +0000 (07:43 +0200)
Use single available diagram profile if no other information is
available

refs #7079

Change-Id: Ib195bdacac5a3e25bf62c540e6480b907ff043a0

bundles/org.simantics.scenegraph.profile/META-INF/MANIFEST.MF
bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/request/AvailableProfiles.java [new file with mode: 0644]
bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/request/RuntimeProfileActiveEntryResources.java

index 085f5cd15d011894f25fd92ea36c5eb40ac531fa..ba17d92ec4ef48bc80aeb16ba25d456667ae0b4c 100644 (file)
@@ -13,7 +13,8 @@ Require-Bundle: org.simantics.db.layer0;bundle-version="1.1.0",
  org.simantics.basicexpression;bundle-version="1.1.0",
  org.simantics.scenegraph;bundle-version="1.1.1",
  org.eclipse.core.runtime;bundle-version="3.6.0",
- org.simantics.diagram.ontology;bundle-version="1.1.1"
+ org.simantics.diagram.ontology;bundle-version="1.1.1",
+ org.simantics.db.common
 Bundle-ActivationPolicy: lazy
 Bundle-Activator: org.simantics.scenegraph.profile.impl.Activator
 Import-Package: org.simantics
diff --git a/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/request/AvailableProfiles.java b/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/request/AvailableProfiles.java
new file mode 100644 (file)
index 0000000..3c3276a
--- /dev/null
@@ -0,0 +1,51 @@
+package org.simantics.scenegraph.profile.request;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.NamedResource;
+import org.simantics.db.common.request.ResourceRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.Instances;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.layer0.Layer0;
+
+public class AvailableProfiles extends ResourceRead<List<NamedResource>>{
+
+       protected AvailableProfiles(Resource runtimeDiagram) {
+               super(runtimeDiagram);
+       }
+
+       @Override
+       public List<NamedResource> perform(ReadGraph graph) throws DatabaseException {
+               
+                 Layer0 L0 = Layer0.getInstance(graph);
+               DiagramResource DIA = DiagramResource.getInstance(graph);
+
+               String indexURI = graph.getPossibleRelatedValue(resource, DIA.RuntimeDiagram_HasModelURI);
+               if (indexURI == null)
+                   return Collections.emptyList();
+
+               Resource index = graph.getPossibleResource(indexURI);
+               if (index == null)
+                   return Collections.emptyList();
+
+               Instances query = graph.adapt(DIA.Profile, Instances.class);
+
+               ArrayList<NamedResource> result = new ArrayList<>();
+               for(Resource profile : query.find(graph, index)) {
+                       if(!graph.hasStatement(profile, L0.Abstract)) {
+                               String name = graph.getRelatedValue(profile, L0.HasName, Bindings.STRING);
+                               result.add(new NamedResource(name, profile));
+                       }
+               }
+               
+               return result;
+               
+       }
+
+}
\ No newline at end of file
index 762ee12bdd0cbf7c10c5db51fda81c7953a64e03..5686024b0c702176352e73d34e0475b84903a5e2 100644 (file)
@@ -13,9 +13,11 @@ package org.simantics.scenegraph.profile.request;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
 
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
+import org.simantics.db.common.NamedResource;
 import org.simantics.db.common.request.ResourceRead;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.diagram.stubs.DiagramResource;
@@ -35,8 +37,14 @@ public class RuntimeProfileActiveEntryResources extends ResourceRead<Collection<
 
         ArrayList<Resource> result = new ArrayList<Resource>();
         Resource activeProfile = graph.getPossibleObject(resource, DIA.RuntimeDiagram_HasRuntimeProfile);
-        if (activeProfile == null)
-            return result;
+        if (activeProfile == null) {
+               
+               List<NamedResource> available = graph.syncRequest(new AvailableProfiles(resource));
+               if(available.size() != 1) return result;
+               
+               activeProfile = available.iterator().next().getResource();
+            
+        }
 
         Resource rootEntries = graph.getPossibleObject(activeProfile, DIA.HasEntries);
         if (rootEntries == null)