From: Antti Villberg Date: Fri, 10 Mar 2017 09:12:37 +0000 (+0200) Subject: Use single available diagram profile by default X-Git-Tag: v1.28.0~63 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=3dea4df51b8252fe7cc5f1219e77444eac24bab8;p=simantics%2Fplatform.git Use single available diagram profile by default Use single available diagram profile if no other information is available refs #7079 Change-Id: Ib195bdacac5a3e25bf62c540e6480b907ff043a0 --- diff --git a/bundles/org.simantics.scenegraph.profile/META-INF/MANIFEST.MF b/bundles/org.simantics.scenegraph.profile/META-INF/MANIFEST.MF index 085f5cd15..ba17d92ec 100644 --- a/bundles/org.simantics.scenegraph.profile/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.scenegraph.profile/META-INF/MANIFEST.MF @@ -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 index 000000000..3c3276aad --- /dev/null +++ b/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/request/AvailableProfiles.java @@ -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>{ + + protected AvailableProfiles(Resource runtimeDiagram) { + super(runtimeDiagram); + } + + @Override + public List 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 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 diff --git a/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/request/RuntimeProfileActiveEntryResources.java b/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/request/RuntimeProfileActiveEntryResources.java index 762ee12bd..5686024b0 100644 --- a/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/request/RuntimeProfileActiveEntryResources.java +++ b/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/request/RuntimeProfileActiveEntryResources.java @@ -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 result = new ArrayList(); Resource activeProfile = graph.getPossibleObject(resource, DIA.RuntimeDiagram_HasRuntimeProfile); - if (activeProfile == null) - return result; + if (activeProfile == null) { + + List 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)