]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Publish OntologicalRequirementTracker as LifeCycleProcess 13/913/3
authorAntti Villberg <antti.villberg@semantum.fi>
Mon, 4 Sep 2017 17:08:18 +0000 (20:08 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 4 Sep 2017 19:42:06 +0000 (22:42 +0300)
refs #7462

Change-Id: Id29b225c3e7556a3afc5c4df54ed3a87a48c7908

bundles/org.simantics.modeling.ontology/graph/Modeling.pgraph
bundles/org.simantics.modeling/scl/Simantics/Misc.scl
bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java

index 2d3c38d65e1d98a8db9d2ed7ee82b08ec6e6bf40..a45e7419cb19c38363b330c0d5c1db4dad7146f1 100644 (file)
@@ -496,6 +496,14 @@ MOD.DependencyTrackingProcess : MOD.LifeCycleProcess
     "LifeCycleContext -> <Proc> ()"
      
 
+MOD.OntologicalRequirementTracker <T MOD.LifeCycleProcess
+  @MOD.sclAssertion MOD.LifeCycleProcess.load
+    """\x -> trackOntologicalRequirements"""
+    "LifeCycleContext -> <Proc> ()"
+  @MOD.sclAssertion MOD.LifeCycleProcess.unload
+    """\x -> untrackOntologicalRequirements"""
+    "LifeCycleContext -> <Proc> ()"
+
 MOD.EditorContribution <T L0.Entity
   --> MOD.EditorContribution.canHandle ==> "Resource -> <ReadGraph> Boolean" <R L0.HasProperty : L0.FunctionalRelation 
   --> MOD.EditorContribution.editorId --> L0.String <R L0.HasProperty : L0.FunctionalRelation 
index c00c564e839fb8d662134c0821e78baaa0f51689..1ab714b789b9e635eb8ec8ab874daddfff8b1449 100644 (file)
@@ -148,5 +148,7 @@ importJava "org.simantics.modeling.LifeCycleContext" where
 importJava "org.simantics.modeling.ModelingUtils" where
     trackDependencies :: <Proc> ()
     untrackDependencies :: <Proc> ()
+    trackOntologicalRequirements :: <Proc> ()
+    untrackOntologicalRequirements :: <Proc> ()
     
     
\ No newline at end of file
index 81505e0bc89863a8594cc6dc31e8fc874d6229ab..e0551eb3e76df1a7193d6e0f4ffcbd85b0715173 100644 (file)
@@ -61,13 +61,17 @@ import org.simantics.databoard.serialization.SerializationException;
 import org.simantics.databoard.type.Datatype;
 import org.simantics.databoard.util.URIStringUtils;
 import org.simantics.datatypes.literal.GUID;
+import org.simantics.db.MetadataI;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.RequestProcessor;
 import org.simantics.db.Resource;
+import org.simantics.db.Session;
 import org.simantics.db.Statement;
 import org.simantics.db.WriteGraph;
+import org.simantics.db.common.Indexing;
 import org.simantics.db.common.NamedResource;
 import org.simantics.db.common.QueryMemoryWatcher;
+import org.simantics.db.common.changeset.GenericChangeListener;
 import org.simantics.db.common.primitiverequest.IsInstanceOf;
 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
 import org.simantics.db.common.procedure.adapter.TransientCacheListener;
@@ -93,6 +97,8 @@ import org.simantics.db.layer0.adapter.Instances;
 import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor;
 import org.simantics.db.layer0.adapter.impl.EntityInstances.QueryIndex;
 import org.simantics.db.layer0.adapter.impl.ImportAdvisorFactory;
+import org.simantics.db.layer0.genericrelation.DependenciesRelation.DependencyChangesRequest;
+import org.simantics.db.layer0.genericrelation.DependencyChanges;
 import org.simantics.db.layer0.genericrelation.IndexedRelations;
 import org.simantics.db.layer0.migration.MigrationUtils;
 import org.simantics.db.layer0.request.ActivateModel;
@@ -117,6 +123,7 @@ import org.simantics.db.layer0.variable.Variables;
 import org.simantics.db.request.Read;
 import org.simantics.db.service.ClusterControl;
 import org.simantics.db.service.CollectionSupport;
+import org.simantics.db.service.GraphChangeListenerSupport;
 import org.simantics.db.service.QueryControl;
 import org.simantics.db.service.VirtualGraphSupport;
 import org.simantics.diagram.stubs.DiagramResource;
@@ -139,6 +146,7 @@ import org.simantics.layer0.Layer0;
 import org.simantics.layer0.utils.direct.GraphUtils;
 import org.simantics.modeling.adapters.ChangeInformation;
 import org.simantics.modeling.template2d.ontology.Template2dResource;
+import org.simantics.modeling.utils.OntologicalRequirementTracker;
 import org.simantics.operation.Layer0X;
 import org.simantics.project.ontology.ProjectResource;
 import org.simantics.scenegraph.profile.ProfileUtils;
@@ -631,6 +639,46 @@ public class ModelingUtils {
 
        }
 
+    public static void trackOntologicalRequirements() {
+        Session session = Simantics.getSession();
+        GraphChangeListenerSupport changeListenerSupport = session.getService(GraphChangeListenerSupport.class);
+        changeListenerSupport.addMetadataListener( OntologicalRequirementListener.getInstance() );
+    }
+
+    public static void untrackOntologicalRequirements() {
+        Session session = Simantics.getSession();
+        GraphChangeListenerSupport changeListenerSupport = session.getService(GraphChangeListenerSupport.class);
+        changeListenerSupport.removeMetadataListener( OntologicalRequirementListener.getInstance() );
+    }
+
+    public static class OntologicalRequirementListener extends GenericChangeListener<DependencyChangesRequest, DependencyChanges> {
+
+        private static OntologicalRequirementListener INSTANCE;
+
+        public static OntologicalRequirementListener getInstance() {
+            if(INSTANCE == null) {
+                INSTANCE = new OntologicalRequirementListener();
+            }
+            return INSTANCE;
+        }
+
+        private OntologicalRequirementListener() {
+        }
+
+        private OntologicalRequirementTracker changeInformationUpdater = new OntologicalRequirementTracker();
+
+        @Override
+        public boolean preEventRequest() {
+            return !Indexing.isDependenciesIndexingDisabled();
+        }
+
+        @Override
+        public void onEvent(ReadGraph graph, MetadataI metadata, DependencyChanges event) throws DatabaseException {
+            changeInformationUpdater.update(graph, metadata, event);
+        }
+
+    }
+
     public static void removeIndex(WriteGraph graph, Resource model) throws DatabaseException {
         Layer0X L0X = Layer0X.getInstance(graph);
         IndexedRelations ir = graph.getService(IndexedRelations.class);