]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Refactoring of simulator toolkit 64/2364/2
authorAntti Villberg <antti.villberg@semantum.fi>
Fri, 26 Oct 2018 11:54:42 +0000 (14:54 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Sat, 27 Oct 2018 20:51:48 +0000 (20:51 +0000)
gitlab #162

Change-Id: Id68f68667a1ad5840eccbd53a4b8ec81483c0cdb

35 files changed:
bundles/org.simantics.document.server/src/org/simantics/document/server/state/StateNodeManager.java
bundles/org.simantics.document.server/src/org/simantics/document/server/state/StateSessionManager.java
bundles/org.simantics.jdbc/src/org/simantics/jdbc/variable/JDBCSessionManager.java
bundles/org.simantics.simulator.toolkit.db/META-INF/MANIFEST.MF
bundles/org.simantics.simulator.toolkit.db/src/org/simantics/simulator/toolkit/db/StandardSessionManager.java
bundles/org.simantics.simulator.toolkit.db/src/org/simantics/simulator/toolkit/db/StandardVariableManagerVariableBuilder.java [new file with mode: 0644]
bundles/org.simantics.simulator.toolkit.db/src/org/simantics/simulator/toolkit/db/StandardVariableNodeManager.java [new file with mode: 0644]
bundles/org.simantics.simulator.toolkit.db/src/org/simantics/simulator/toolkit/db/StandardVariableRealm.java [new file with mode: 0644]
bundles/org.simantics.simulator.toolkit.db/src/org/simantics/simulator/toolkit/db/StandardVariableSessionManager.java [new file with mode: 0644]
bundles/org.simantics.simulator.toolkit/src/org/simantics/simulator/toolkit/StandardNodeManager.java
bundles/org.simantics.simulator.toolkit/src/org/simantics/simulator/toolkit/StandardRealm.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetBook.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetMapping.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetReferenceResolver.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetSessionManager.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/LineCommandBuilder.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/LineUpdater.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/LinesCommandBuilder.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/NullCommandBuilder.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/SheetLineComponent.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/StyleUpdater.java
bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/CommandBuilder.java
bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/ConnectionUpdateRule.java
bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/ModuleUpdateContext.java
bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/ModuleUpdaterBase.java
bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/ModuleUpdaterFactoryBase.java
bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/PropertyUpdateRule.java
bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/ReferenceResolverBase.java
bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/SynchronizationEventHandlerBase.java
bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/UpdateComponentUids.java
bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/utils/ComponentBase.java [moved from bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/ComponentBase.java with 98% similarity]
bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/utils/ComponentFactory.java [moved from bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/ComponentFactory.java with 62% similarity]
bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/utils/MappingBase.java [moved from bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/MappingBase.java with 99% similarity]
bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/utils/Solver.java [moved from bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/Solver.java with 85% similarity]
bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/utils/StateUndoContextBase.java [moved from bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/StateUndoContextBase.java with 83% similarity]

index 0b48e27220bbdf2fa130400b30857f2ad5ef2214..97bc4b1c732df93b6ce1671c8b6c6d0a9acb58a5 100644 (file)
@@ -1,9 +1,7 @@
 package org.simantics.document.server.state;
 
 import java.io.IOException;
-import java.util.Collections;
 import java.util.Map;
-import java.util.Set;
 
 import org.simantics.databoard.Bindings;
 import org.simantics.databoard.binding.Binding;
@@ -11,38 +9,19 @@ import org.simantics.databoard.binding.error.BindingConstructionException;
 import org.simantics.databoard.binding.mutable.Variant;
 import org.simantics.databoard.serialization.RuntimeSerializerConstructionException;
 import org.simantics.databoard.serialization.SerializerConstructionException;
-import org.simantics.db.layer0.variable.NodeSupport;
-import org.simantics.simulator.toolkit.StandardNodeManager;
 import org.simantics.simulator.toolkit.StandardRealm;
+import org.simantics.simulator.toolkit.db.StandardVariableNodeManager;
 import org.simantics.simulator.variable.exceptions.NodeManagerException;
 import org.slf4j.LoggerFactory;
 
-public class StateNodeManager extends StandardNodeManager<StateNode, StateNodeManagerSupport> {
+public class StateNodeManager extends StandardVariableNodeManager<StateNode, StateNodeManagerSupport> {
 
        private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(StateNodeManager.class);
 
-       private NodeSupport<StateNode> support;
-
        public StateNodeManager(StandardRealm<StateNode, StateNodeManagerSupport> realm, StateNode root) {
                super(realm, root);
        }
 
-       public void registerSupport(NodeSupport<StateNode> support) {
-               this.support = support;
-       }
-
-       @Override
-       public Set<String> getClassifications(StateNode node) throws NodeManagerException {
-               return Collections.emptySet();
-       }
-
-       @Override
-       public void refreshVariable(StateNode node) {
-               super.refreshVariable(node);
-               support.valueCache.clearExpired();
-               support.structureCache.clearExpired();
-       }
-
        public void setState(String key, Object value) {
                try {
                        getRealm().syncExec(() -> {
index 267217c2003faed937dd51d88ab94f5eb0e59af1..321141abcdfdb900f13ff340c781c08eeb06445d 100644 (file)
@@ -2,12 +2,10 @@ package org.simantics.document.server.state;
 
 import org.simantics.db.ReadGraph;
 import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.layer0.variable.NodeSupport;
-import org.simantics.simulator.toolkit.StandardNodeManager;
 import org.simantics.simulator.toolkit.StandardRealm;
-import org.simantics.simulator.toolkit.db.StandardSessionManager;
+import org.simantics.simulator.toolkit.db.StandardVariableSessionManager;
 
-public class StateSessionManager extends StandardSessionManager<StateNode, StateNodeManagerSupport> {
+public class StateSessionManager extends StandardVariableSessionManager<StateNode, StateNodeManagerSupport> {
 
        private static StateSessionManager INSTANCE;
 
@@ -28,10 +26,4 @@ public class StateSessionManager extends StandardSessionManager<StateNode, State
                return new StateRealm(engine, id);
        }
 
-       @Override
-       public void registerNodeSupport(StandardNodeManager<StateNode, StateNodeManagerSupport> manager,
-                       NodeSupport<StateNode> support) {
-               ((StateNodeManager)manager).registerSupport(support);
-       }
-
 }
index f6a6077e46d598c00b16bb2a09f1f659f54c82a2..17ffcf143cc679b7f25685069c8c9e2023ea9533 100644 (file)
@@ -21,7 +21,7 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.variable.NodeSupport;
 import org.simantics.jdbc.SimanticsJDBC;
 import org.simantics.simulator.toolkit.StandardRealm;
-import org.simantics.simulator.toolkit.db.StandardSessionManager;
+import org.simantics.simulator.toolkit.db.StandardVariableSessionManager;
 import org.simantics.simulator.variable.exceptions.NodeManagerException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -30,7 +30,7 @@ import com.impossibl.postgres.api.jdbc.PGConnection;
 import com.impossibl.postgres.api.jdbc.PGNotificationListener;
 import com.impossibl.postgres.jdbc.PGDataSource;
 
-public class JDBCSessionManager extends StandardSessionManager<JDBCNode, JDBCNodeManagerSupport> {
+public class JDBCSessionManager extends StandardVariableSessionManager<JDBCNode, JDBCNodeManagerSupport> {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(JDBCSessionManager.class);
     private static JDBCSessionManager INSTANCE = new JDBCSessionManager();
index ea7f97e6d4769e54effb7948825d09530e7499ea..982c354d0bfc3628561be70ebe216183b3af9df3 100644 (file)
@@ -5,6 +5,7 @@ Bundle-SymbolicName: org.simantics.simulator.toolkit.db
 Bundle-Version: 1.0.0.qualifier
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Require-Bundle: org.simantics.simulator.toolkit;bundle-version="1.0.0";visibility:=reexport,
- org.simantics.db.layer0;bundle-version="1.1.0"
+ org.simantics.db.layer0;bundle-version="1.1.0",
+ org.slf4j.api;bundle-version="1.7.25"
 Export-Package: org.simantics.simulator.toolkit.db
 Bundle-Vendor: Semantum Oy
index 47b6782825a731de43ac32e00dbaccaa2a0ac2ca..2ad2546a6b9573ec7b74408baacf5ce959f272c5 100644 (file)
@@ -1,130 +1,7 @@
 package org.simantics.simulator.toolkit.db;
 
-import java.util.Collection;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.simantics.db.ReadGraph;
-import org.simantics.db.WriteGraph;
-import org.simantics.db.common.request.ParametrizedPrimitiveRead;
-import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.layer0.variable.NodeSupport;
-import org.simantics.db.procedure.Listener;
-import org.simantics.simulator.toolkit.StandardNodeManager;
 import org.simantics.simulator.toolkit.StandardNodeManagerSupport;
-import org.simantics.simulator.toolkit.StandardRealm;
-
-public abstract class StandardSessionManager<Node, Engine extends StandardNodeManagerSupport<Node>> {
-
-    private ConcurrentHashMap<String, Listener<StandardRealm<Node,Engine>>> realmListeners = new ConcurrentHashMap<>();
-    private ConcurrentHashMap<String, StandardRealm<Node,Engine>> REALMS = new ConcurrentHashMap<>(); 
-    private ConcurrentHashMap<String, NodeSupport<Node>> SUPPORTS = new ConcurrentHashMap<>(); 
-
-    // Accessing Realms should be done over ParametrizedPrimitveRead for the
-    // case if a realm is destroyed and new one is created with the same id than
-    // the previously deleted one for the listeners to get discarded and new
-    // registered
-    private class RealmRequest extends ParametrizedPrimitiveRead<String, StandardRealm<Node, Engine>> {
-
-        public RealmRequest(String parameter) {
-            super(parameter);
-        }
-
-        @Override
-        public void register(ReadGraph graph, Listener<StandardRealm<Node, Engine>> procedure) {
-            StandardRealm<Node, Engine> realm = REALMS.get(parameter);
-            if (realm == null) {
-                try {
-                    realm = createRealmInner(graph, parameter);
-                } catch (DatabaseException e) {
-                    e.printStackTrace();
-                }
-            }
-
-            if(procedure.isDisposed()) {
-                procedure.execute(realm);
-                return;
-            }
-
-            Listener<StandardRealm<Node,Engine>> existing = getOrDisposeListener(parameter);
-            assert(existing == null);
-            realmListeners.put(parameter, procedure);
-            procedure.execute(realm);
-        }
-
-        private StandardRealm<Node,Engine> createRealmInner(ReadGraph graph, String id) throws DatabaseException {
-            Engine engine = createEngine(graph, id);
-            StandardRealm<Node,Engine> realm = createRealm(engine, id);
-            modifyRealms(id, realm);
-            return realm;
-        }
-    }
-
-    protected StandardSessionManager() {
-    }
-
-    private Listener<StandardRealm<Node,Engine>> getOrDisposeListener(String key) {
-        Listener<StandardRealm<Node,Engine>> listener = realmListeners.get(key);
-        if(listener != null) {
-            if(listener.isDisposed()) {
-                realmListeners.remove(key);
-            } else {
-                return listener;
-            }
-        }
-        return null;
-    }
-
-    private void modifyRealms(String key, StandardRealm<Node,Engine> realm) {
-        if(realm != null) {
-            REALMS.put(key, realm);
-        } else {
-            StandardRealm<Node, Engine> removedRealm = REALMS.remove(key);
-            if (removedRealm != null)
-                removedRealm.close();
-        }
-        Listener<StandardRealm<Node,Engine>> listener = getOrDisposeListener(key);
-        if(listener != null) {
-            listener.execute(realm);
-        }
-    }
-
-    public void registerNodeSupport(StandardNodeManager<Node,Engine> realm, NodeSupport<Node> support) {
-    
-    }
-
-    public NodeSupport<Node> getOrCreateNodeSupport(ReadGraph graph, String id) throws DatabaseException {
-        synchronized(SUPPORTS) {
-            NodeSupport<Node> result = SUPPORTS.get(id);
-            if(result == null) {
-                StandardRealm<Node,Engine> realm = getOrCreateRealm(graph, id);
-                result = new NodeSupport<Node>(realm.getNodeManager());
-                registerNodeSupport(realm.getNodeManager(), result);
-                SUPPORTS.put(id, result);
-            }
-            return result;
-        }
-    }
-
-    public StandardRealm<Node,Engine> getOrCreateRealm(ReadGraph graph, String id) throws DatabaseException {
-        synchronized(REALMS) {
-            return graph.syncRequest(new RealmRequest(id));
-        }
-    }
-
-    protected abstract Engine createEngine(ReadGraph graph, String id) throws DatabaseException;
-    protected abstract StandardRealm<Node,Engine> createRealm(Engine engine, String id);
 
-    public void removeRealm(WriteGraph graph, String id) throws DatabaseException {
-        modifyRealms(id, null);
-        // remove listeners from this realm
-        realmListeners.remove(id);
-        // if node support has been created remove it as well
-        NodeSupport<Node> support = SUPPORTS.remove(id);
-        if (support != null)
-            support.dispose();
-    }
+public abstract class StandardSessionManager<Node, Engine extends StandardNodeManagerSupport<Node>> extends StandardVariableSessionManager<Node,Engine> {
 
-    public Collection<String> getRealms() {
-        return REALMS.keySet();
-    }
 }
diff --git a/bundles/org.simantics.simulator.toolkit.db/src/org/simantics/simulator/toolkit/db/StandardVariableManagerVariableBuilder.java b/bundles/org.simantics.simulator.toolkit.db/src/org/simantics/simulator/toolkit/db/StandardVariableManagerVariableBuilder.java
new file mode 100644 (file)
index 0000000..7699a24
--- /dev/null
@@ -0,0 +1,29 @@
+package org.simantics.simulator.toolkit.db;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.NodeManagerVariableBuilder;
+import org.simantics.db.layer0.variable.NodeSupport;
+import org.simantics.simulator.toolkit.StandardNodeManager;
+
+public abstract class StandardVariableManagerVariableBuilder extends NodeManagerVariableBuilder {
+
+    @Override
+    protected Object getRoot(ReadGraph graph, NodeSupport<?> support, String sessionName) {
+        StandardNodeManager manager = (StandardNodeManager)support.manager;
+        return manager.getRoot();
+    }
+    
+    /*
+     * For compatibility reasons. Existing implementations implement getNodeSupport directly and in that case this is not needed.
+     * New implementations should not implement getNodeSupport but rather implement this.
+     */
+    protected StandardVariableSessionManager getSessionManager() {
+        throw new UnsupportedOperationException();
+    }
+    
+    protected NodeSupport<?> getNodeSupport(ReadGraph graph, String sessionName) throws DatabaseException {
+        return getSessionManager().getOrCreateNodeSupport(graph, sessionName);
+    }
+
+}
diff --git a/bundles/org.simantics.simulator.toolkit.db/src/org/simantics/simulator/toolkit/db/StandardVariableNodeManager.java b/bundles/org.simantics.simulator.toolkit.db/src/org/simantics/simulator/toolkit/db/StandardVariableNodeManager.java
new file mode 100644 (file)
index 0000000..883f809
--- /dev/null
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *     Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.simulator.toolkit.db;
+
+import org.simantics.db.layer0.variable.NodeSupport;
+import org.simantics.simulator.toolkit.StandardNodeManager;
+import org.simantics.simulator.toolkit.StandardNodeManagerSupport;
+import org.simantics.simulator.toolkit.StandardRealm;
+
+/**
+ * Adds support for Layer0 Variable interface in StandardNodeManager
+ *
+ * @author Antti Villberg
+ */
+public class StandardVariableNodeManager<Node, Engine extends StandardNodeManagerSupport<Node>> extends StandardNodeManager<Node,Engine> {
+
+    protected NodeSupport<Node> support;
+
+    public StandardVariableNodeManager(StandardRealm<Node, Engine> realm, Node root) {
+        super(realm, root);
+        this.support = new NodeSupport<>(this);
+    }
+
+/*    public void registerNodeSupport(NodeSupport<Node> support) {
+        this.support = support;
+    }
+
+
+    public void registerSupport(NodeSupport<Node> support) {
+        this.support = support;
+    }*/
+
+    @Override
+    public void refreshVariable(Node node) {
+        super.refreshVariable(node);
+        support.valueCache.clearExpired();
+        support.structureCache.clearExpired();
+    }
+
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.simulator.toolkit.db/src/org/simantics/simulator/toolkit/db/StandardVariableRealm.java b/bundles/org.simantics.simulator.toolkit.db/src/org/simantics/simulator/toolkit/db/StandardVariableRealm.java
new file mode 100644 (file)
index 0000000..6ed50d4
--- /dev/null
@@ -0,0 +1,18 @@
+package org.simantics.simulator.toolkit.db;
+
+import org.simantics.simulator.toolkit.StandardNodeManager;
+import org.simantics.simulator.toolkit.StandardNodeManagerSupport;
+import org.simantics.simulator.toolkit.StandardRealm;
+
+public abstract class StandardVariableRealm<Node, Engine extends StandardNodeManagerSupport<Node>> extends StandardRealm<Node, Engine> {
+
+    protected StandardVariableRealm(Engine engine, String id) {
+        super(engine, id);
+    }
+
+    @Override
+    protected StandardNodeManager<Node, Engine> createManager(Node root) {
+        return new StandardVariableNodeManager<Node, Engine>(this, root);
+    }
+
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.simulator.toolkit.db/src/org/simantics/simulator/toolkit/db/StandardVariableSessionManager.java b/bundles/org.simantics.simulator.toolkit.db/src/org/simantics/simulator/toolkit/db/StandardVariableSessionManager.java
new file mode 100644 (file)
index 0000000..5e824f4
--- /dev/null
@@ -0,0 +1,129 @@
+package org.simantics.simulator.toolkit.db;
+
+import java.util.Collection;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.ParametrizedPrimitiveRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.NodeSupport;
+import org.simantics.db.procedure.Listener;
+import org.simantics.simulator.toolkit.StandardNodeManagerSupport;
+import org.simantics.simulator.toolkit.StandardRealm;
+import org.simantics.simulator.variable.NodeManager;
+
+public abstract class StandardVariableSessionManager<Node, Engine extends StandardNodeManagerSupport<Node>> {
+
+    private ConcurrentHashMap<String, Listener<StandardRealm<Node,Engine>>> realmListeners = new ConcurrentHashMap<>();
+    private ConcurrentHashMap<String, StandardRealm<Node,Engine>> REALMS = new ConcurrentHashMap<>();
+    private ConcurrentHashMap<String, NodeSupport<Node>> SUPPORTS = new ConcurrentHashMap<>();
+
+    // Accessing Realms should be done over ParametrizedPrimitveRead for the
+    // case if a realm is destroyed and new one is created with the same id than
+    // the previously deleted one for the listeners to get discarded and new
+    // registered
+    private class RealmRequest extends ParametrizedPrimitiveRead<String, StandardRealm<Node, Engine>> {
+
+        public RealmRequest(String parameter) {
+            super(parameter);
+        }
+
+        @Override
+        public void register(ReadGraph graph, Listener<StandardRealm<Node, Engine>> procedure) {
+            StandardRealm<Node, Engine> realm = REALMS.get(parameter);
+            if (realm == null) {
+                try {
+                    realm = createRealmInner(graph, parameter);
+                } catch (DatabaseException e) {
+                    e.printStackTrace();
+                }
+            }
+
+            if(procedure.isDisposed()) {
+                procedure.execute(realm);
+                return;
+            }
+
+            Listener<StandardRealm<Node,Engine>> existing = getOrDisposeListener(parameter);
+            assert(existing == null);
+            realmListeners.put(parameter, procedure);
+            procedure.execute(realm);
+        }
+
+        private StandardRealm<Node,Engine> createRealmInner(ReadGraph graph, String id) throws DatabaseException {
+            Engine engine = createEngine(graph, id);
+            StandardRealm<Node,Engine> realm = createRealm(engine, id);
+            modifyRealms(id, realm);
+            return realm;
+        }
+    }
+
+    protected StandardVariableSessionManager() {
+    }
+
+    private Listener<StandardRealm<Node,Engine>> getOrDisposeListener(String key) {
+        Listener<StandardRealm<Node,Engine>> listener = realmListeners.get(key);
+        if(listener != null) {
+            if(listener.isDisposed()) {
+                realmListeners.remove(key);
+            } else {
+                return listener;
+            }
+        }
+        return null;
+    }
+
+    private void modifyRealms(String key, StandardRealm<Node,Engine> realm) {
+        if(realm != null) {
+            REALMS.put(key, realm);
+        } else {
+            StandardRealm<Node, Engine> removedRealm = REALMS.remove(key);
+            if (removedRealm != null)
+                removedRealm.close();
+        }
+        Listener<StandardRealm<Node,Engine>> listener = getOrDisposeListener(key);
+        if(listener != null) {
+            listener.execute(realm);
+        }
+    }
+
+    public NodeSupport<Node> getOrCreateNodeSupport(ReadGraph graph, String id) throws DatabaseException {
+        synchronized(SUPPORTS) {
+            NodeSupport<Node> result = SUPPORTS.get(id);
+            if(result == null) {
+                StandardRealm<Node,Engine> realm = getOrCreateRealm(graph, id);
+                NodeManager nodeManager = realm.getNodeManager();
+                if(!(nodeManager instanceof StandardVariableNodeManager))
+                    throw new DatabaseException("StandardVariableSessionManager requires an instance of  StandardVariableNodeManager, got " + nodeManager.getClass());
+                StandardVariableNodeManager svnm = (StandardVariableNodeManager)nodeManager;
+                result = svnm.support;
+                SUPPORTS.put(id, result);
+            }
+            return result;
+        }
+    }
+
+    public StandardRealm<Node,Engine> getOrCreateRealm(ReadGraph graph, String id) throws DatabaseException {
+        synchronized(REALMS) {
+            return graph.syncRequest(new RealmRequest(id));
+        }
+    }
+
+    protected abstract Engine createEngine(ReadGraph graph, String id) throws DatabaseException;
+    protected abstract StandardRealm<Node,Engine> createRealm(Engine engine, String id);
+
+    public void removeRealm(WriteGraph graph, String id) throws DatabaseException {
+        modifyRealms(id, null);
+        // remove listeners from this realm
+        realmListeners.remove(id);
+        // if node support has been created remove it as well
+        NodeSupport<Node> support = SUPPORTS.remove(id);
+        if (support != null)
+            support.dispose();
+    }
+
+    public Collection<String> getRealms() {
+        return REALMS.keySet();
+    }
+}
index 8a51fd330764959e7c62f4cc292c2ab2e36fb0c0..b8a549087fdb1c745cb6287f95b5faf7ba88a892 100644 (file)
@@ -13,6 +13,7 @@
 package org.simantics.simulator.toolkit;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -46,7 +47,7 @@ import gnu.trove.set.hash.THashSet;
  *
  * @author Antti Villberg
  */
-public abstract class StandardNodeManager<Node, Engine extends StandardNodeManagerSupport<Node>> implements NodeManager<Node> {
+public class StandardNodeManager<Node, Engine extends StandardNodeManagerSupport<Node>> implements NodeManager<Node> {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(StandardNodeManager.class);
 
@@ -424,4 +425,9 @@ public abstract class StandardNodeManager<Node, Engine extends StandardNodeManag
         listeners.clear();
     }
 
+    @Override
+    public Set<String> getClassifications(Node node) throws NodeManagerException {
+        return Collections.emptySet();
+    }
+
 }
\ No newline at end of file
index e228b603d803d86a2fa6146bccbdd51a294b57ad..8551222b22d2183b866aff466a83e35a537e8dcf 100644 (file)
@@ -46,7 +46,21 @@ abstract public class StandardRealm<Node, Engine extends StandardNodeManagerSupp
         this.nodeManager = createManager();
     }
 
-    abstract protected StandardNodeManager<Node, Engine> createManager();
+    protected StandardNodeManager<Node, Engine> createManager(Node root) {
+        return new StandardNodeManager<Node, Engine>(this, root);
+    }
+
+    protected StandardNodeManager<Node, Engine> createManager() {
+        return createManager(createRootNode());
+    }
+
+    /*
+     * For compatibility reasons. Existing implementations implement createManager() directly and in that case this is not needed.
+     * New implementations should not implement createManager() but rather implement this.
+     */
+    protected Node createRootNode() {
+        throw new UnsupportedOperationException();
+    }
 
     protected String getSCLContextKey() {
         return getClass().getSimpleName();
index 5a7dcd5ee0aae8f1f129158c284ac00cd666deba..d741d4c7abf5870958ff585a675649c9bfc6127c 100644 (file)
@@ -24,12 +24,12 @@ import org.simantics.spreadsheet.graph.synchronization.LineUpdater;
 import org.simantics.spreadsheet.graph.synchronization.NullUpdater;
 import org.simantics.spreadsheet.graph.synchronization.SheetLineComponent;
 import org.simantics.spreadsheet.graph.synchronization.StyleUpdater;
-import org.simantics.structural.synchronization.base.ComponentFactory;
-import org.simantics.structural.synchronization.base.MappingBase;
 import org.simantics.structural.synchronization.base.ModuleUpdaterBase;
 import org.simantics.structural.synchronization.base.ModuleUpdaterFactoryBase;
-import org.simantics.structural.synchronization.base.Solver;
 import org.simantics.structural.synchronization.base.SolverNameUtil;
+import org.simantics.structural.synchronization.utils.ComponentFactory;
+import org.simantics.structural.synchronization.utils.MappingBase;
+import org.simantics.structural.synchronization.utils.Solver;
 
 import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
 import it.unimi.dsi.fastutil.longs.AbstractLongList;
index 23ce1cf1166e32cbb18c28a4faac4c0ac18d0307..64079d2b0fe90c3f380cf83ff834c62996e4fc59 100644 (file)
@@ -3,10 +3,10 @@ package org.simantics.spreadsheet.graph;
 import java.io.Serializable;
 
 import org.simantics.spreadsheet.graph.synchronization.SheetLineComponent;
-import org.simantics.structural.synchronization.base.ComponentFactory;
-import org.simantics.structural.synchronization.base.MappingBase;
-import org.simantics.structural.synchronization.base.Solver;
-import org.simantics.structural.synchronization.base.StateUndoContextBase;
+import org.simantics.structural.synchronization.utils.ComponentFactory;
+import org.simantics.structural.synchronization.utils.MappingBase;
+import org.simantics.structural.synchronization.utils.Solver;
+import org.simantics.structural.synchronization.utils.StateUndoContextBase;
 
 public class SpreadsheetMapping extends MappingBase<SheetLineComponent> implements Serializable {
        
index 6428f9b83db4b9d60730ad9ca0a77d1653822d92..6c3c0b17ca9c648f5401f48d181ef6da0b5166c7 100644 (file)
@@ -2,7 +2,7 @@ package org.simantics.spreadsheet.graph;
 
 import org.simantics.spreadsheet.graph.synchronization.SheetLineComponent;
 import org.simantics.structural.synchronization.base.ReferenceResolverBase;
-import org.simantics.structural.synchronization.base.Solver;
+import org.simantics.structural.synchronization.utils.Solver;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
index 19c9948060f60787d94d99f441d920fe2653d0f0..f50463ef009f93d55bdf4dc74375c44b57d656cf 100644 (file)
@@ -19,7 +19,7 @@ import org.simantics.db.layer0.variable.ProxyVariables;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;
 import org.simantics.simulator.toolkit.StandardRealm;
-import org.simantics.simulator.toolkit.db.StandardSessionManager;
+import org.simantics.simulator.toolkit.db.StandardVariableSessionManager;
 import org.simantics.spreadsheet.graph.formula.SpreadsheetEvaluationEnvironment;
 import org.simantics.spreadsheet.graph.synchronization.SpreadsheetSynchronizationEventHandler;
 import org.simantics.spreadsheet.resource.SpreadsheetResource;
@@ -27,7 +27,7 @@ import org.simantics.structural.synchronization.Synchronizer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class SpreadsheetSessionManager extends StandardSessionManager<SheetNode, SpreadsheetBook> {
+public class SpreadsheetSessionManager extends StandardVariableSessionManager<SheetNode, SpreadsheetBook> {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(SpreadsheetSessionManager.class);
     
index 6e191436142b82b0bb148e209c63bff343da5d78..90c96cc2d017f5be51e411e1aa1f8d0fb7987f9c 100644 (file)
@@ -18,7 +18,7 @@ import org.simantics.spreadsheet.graph.parser.SheetFormulaParser;
 import org.simantics.spreadsheet.graph.parser.ast.AstArrayFormulaReference;
 import org.simantics.spreadsheet.graph.parser.ast.AstValue;
 import org.simantics.structural.synchronization.base.CommandBuilder;
-import org.simantics.structural.synchronization.base.Solver;
+import org.simantics.structural.synchronization.utils.Solver;
 
 public class LineCommandBuilder implements CommandBuilder {
        
index 3462b247f5924a5fd54075620765160883de1116..baa0851b2503006182b9cb53cc055329cfdc8fe1 100644 (file)
@@ -10,7 +10,7 @@ import org.simantics.structural.synchronization.base.CommandBuilder;
 import org.simantics.structural.synchronization.base.ModuleUpdateContext;
 import org.simantics.structural.synchronization.base.ModuleUpdaterBase;
 import org.simantics.structural.synchronization.base.PropertyUpdateRule;
-import org.simantics.structural.synchronization.base.Solver;
+import org.simantics.structural.synchronization.utils.Solver;
 
 public class LineUpdater extends ModuleUpdaterBase<SheetLineComponent> {
        
index be7f25c9e9ef324b83babd23fdfb82e59d43aadb..4cf804c2dd1cb1859591ec050c4fcc6990f160a3 100644 (file)
@@ -3,7 +3,7 @@ package org.simantics.spreadsheet.graph.synchronization;
 import org.simantics.spreadsheet.graph.SpreadsheetBook;
 import org.simantics.spreadsheet.graph.SpreadsheetLines;
 import org.simantics.structural.synchronization.base.CommandBuilder;
-import org.simantics.structural.synchronization.base.Solver;
+import org.simantics.structural.synchronization.utils.Solver;
 
 public class LinesCommandBuilder implements CommandBuilder {
        
index 6e16386f7d28bef6417ef3e707fb8c1301a3cdc0..80ed1ca13cda9743697563548b1ddb45d7f9c680 100644 (file)
@@ -1,7 +1,7 @@
 package org.simantics.spreadsheet.graph.synchronization;
 
 import org.simantics.structural.synchronization.base.CommandBuilder;
-import org.simantics.structural.synchronization.base.Solver;
+import org.simantics.structural.synchronization.utils.Solver;
 
 public class NullCommandBuilder implements CommandBuilder {
        
index c3b40737d9d2710f0ddd90e213b95e13174a83cd..5edea565fa56d00851d7d16582e09fa0fc59b651 100644 (file)
@@ -2,7 +2,7 @@ package org.simantics.spreadsheet.graph.synchronization;
 
 import java.io.Serializable;
 
-import org.simantics.structural.synchronization.base.ComponentBase;
+import org.simantics.structural.synchronization.utils.ComponentBase;
 
 import gnu.trove.map.hash.THashMap;
 import gnu.trove.procedure.TObjectProcedure;
index de5b47cc829b0edd68a35e3a63958d7f6a19d311..4451d13140a6049d3b3271d90757b4bfcf2921ce 100644 (file)
@@ -12,7 +12,7 @@ import org.simantics.structural.synchronization.base.CommandBuilder;
 import org.simantics.structural.synchronization.base.ModuleUpdateContext;
 import org.simantics.structural.synchronization.base.ModuleUpdaterBase;
 import org.simantics.structural.synchronization.base.PropertyUpdateRule;
-import org.simantics.structural.synchronization.base.Solver;
+import org.simantics.structural.synchronization.utils.Solver;
 
 public class StyleUpdater extends ModuleUpdaterBase<SheetLineComponent> {
 
index 45f2791a87beb2e39c7160af06423ee6e875e948..57b8d9a065fab77a17c892bb72b13a587f82dfc7 100644 (file)
@@ -1,5 +1,7 @@
 package org.simantics.structural.synchronization.base;
 
+import org.simantics.structural.synchronization.utils.Solver;
+
 public interface CommandBuilder {
 
        void apply(Solver solver);
index dd59baa5515a005ae8dc5bf883b7fe3f4324c8ab..144833a7ad132c1e0eda8fffe83b20a455d4d482 100644 (file)
@@ -4,6 +4,7 @@ import java.util.Collection;
 import java.util.Map;
 
 import org.simantics.databoard.binding.mutable.Variant;
+import org.simantics.structural.synchronization.utils.ComponentBase;
 
 public interface ConnectionUpdateRule<T extends ComponentBase<T>> {
 
index 1615aaf2ba35e8e4cd66c1cd009897e2005988fc..854a22d23ab055898c4f4a28dbe33698cc55913b 100644 (file)
@@ -5,6 +5,8 @@ import gnu.trove.map.hash.THashMap;
 import java.util.ArrayList;
 
 import org.simantics.databoard.binding.mutable.Variant;
+import org.simantics.structural.synchronization.utils.ComponentBase;
+import org.simantics.structural.synchronization.utils.Solver;
 
 public class ModuleUpdateContext<T extends ComponentBase<T>> {
 
index 9ec63c06167846f619da56d24f939e5603d150ad..45ea7400fbbf8682d0da92ce463cc008fdbe62d1 100644 (file)
@@ -9,6 +9,7 @@ import java.util.Map;
 import org.simantics.databoard.binding.mutable.Variant;
 import org.simantics.structural.synchronization.protocol.Connection;
 import org.simantics.structural.synchronization.protocol.SerializedVariable;
+import org.simantics.structural.synchronization.utils.ComponentBase;
 
 abstract public class ModuleUpdaterBase<T extends ComponentBase<T>> {
 
index 04320c9465b513fc6c99f4eaf4725886326c6a7d..f30527e3d29822ccfa0d18417740b39e195315b6 100644 (file)
@@ -1,6 +1,7 @@
 package org.simantics.structural.synchronization.base;
 
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.structural.synchronization.utils.ComponentBase;
 
 
 public interface ModuleUpdaterFactoryBase<T extends ComponentBase<T>> {
index 32f94c27cb7a7a9a66bed1182faf24b37dbf2069..a0b734d15c41ca96d028360d95a566c152389d22 100644 (file)
@@ -4,6 +4,7 @@ import java.util.Collection;
 import java.util.Map;
 
 import org.simantics.databoard.binding.mutable.Variant;
+import org.simantics.structural.synchronization.utils.ComponentBase;
 
 
 public interface PropertyUpdateRule<T extends ComponentBase<T>> {
index 7fabc6747f1c6fe27676fb7483bcad942b928408..33b5d9bdcf424675a281c2279892a489a9ba8ebe 100644 (file)
@@ -8,6 +8,8 @@ import java.util.Collections;
 
 import org.simantics.databoard.util.URIStringUtils;
 import org.simantics.structural.synchronization.protocol.SynchronizationEventHandler;
+import org.simantics.structural.synchronization.utils.ComponentBase;
+import org.simantics.structural.synchronization.utils.Solver;
 import org.slf4j.Logger;
 
 abstract public class ReferenceResolverBase<T extends ComponentBase<T>> {
@@ -116,7 +118,7 @@ abstract public class ReferenceResolverBase<T extends ComponentBase<T>> {
 
     private static void fullPathOfComponent(StringBuilder b, ComponentBase<?> component) {
         if(component != null) {
-            fullPathOfComponent(b, component.parent);
+            fullPathOfComponent(b, component.getParent());
             b.append("/").append(component.solverComponentName);
         }
     }
index 82dd224b6ec2f413f933a60ef5910bcbd72f1382..7be353a0222bac45db628c3655d0faded28078c7 100644 (file)
@@ -15,6 +15,10 @@ import org.simantics.structural.synchronization.protocol.Connection;
 import org.simantics.structural.synchronization.protocol.SerializedVariable;
 import org.simantics.structural.synchronization.protocol.SynchronizationEventHandler;
 import org.simantics.structural.synchronization.protocol.SynchronizationException;
+import org.simantics.structural.synchronization.utils.ComponentBase;
+import org.simantics.structural.synchronization.utils.ComponentFactory;
+import org.simantics.structural.synchronization.utils.MappingBase;
+import org.simantics.structural.synchronization.utils.Solver;
 import org.slf4j.Logger;
 
 import gnu.trove.map.hash.THashMap;
index 0c051ecef9c2445963a957adae56d5c25097239c..df63ada0525911d50cd84c636989f1fe8e30d34c 100644 (file)
@@ -5,6 +5,7 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.exception.CancelTransactionException;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.variable.Variable;
+import org.simantics.structural.synchronization.utils.ComponentBase;
 
 import gnu.trove.map.hash.THashMap;
 
@@ -1,12 +1,12 @@
-package org.simantics.structural.synchronization.base;
+package org.simantics.structural.synchronization.utils;
+
+import java.io.PrintWriter;
 
 import gnu.trove.map.hash.THashMap;
 import gnu.trove.procedure.TObjectObjectProcedure;
 import gnu.trove.procedure.TObjectProcedure;
 import gnu.trove.set.hash.THashSet;
 
-import java.io.PrintWriter;
-
 /**
  * The entry point to the mapping structure between Simantics database and a
  * designated solver. It is used to synchronize changes from Simantics to the