]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Variable optimizations for documents (Simupedia) 55/2455/3
authorAntti Villberg <antti.villberg@semantum.fi>
Tue, 13 Nov 2018 05:59:50 +0000 (07:59 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 13 Nov 2018 08:48:09 +0000 (08:48 +0000)
* Added ProxyVariableSupport - a mechanism to re-parent a Variable

gitlab #169

Change-Id: I2852ef1895003a7b1735e1fa2505ac20d6a8ba46

bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyVariableSupport.java [new file with mode: 0644]
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyVariables.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java

diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyVariableSupport.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyVariableSupport.java
new file mode 100644 (file)
index 0000000..225bef5
--- /dev/null
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2018 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:
+ *     Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.layer0.variable;
+
+import org.simantics.db.ReadGraph;
+
+/**
+ * Allows attaching a variable under another one to create custom hierarchies
+ * from existing variables.
+ * 
+ * @author Antti Villberg
+ * @since 1.36.0
+ */
+public interface ProxyVariableSupport {
+
+    Variable attachTo(ReadGraph graph, Variable parent);
+    Variable attachToRenamed(ReadGraph graph, Variable parent, String name);
+
+}
index db552650b09c7098074bfd069b954a9b5d80ca15..ddfe108cb713a409f1da67df7e688748bdb94606 100644 (file)
@@ -2,9 +2,29 @@ package org.simantics.db.layer0.variable;
 
 import org.simantics.db.ReadGraph;
 import org.simantics.db.exception.DatabaseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ProxyVariables {
-       
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(ProxyVariables.class);
+
+    public static Variable tryToOwn(ReadGraph graph, Variable parent, Variable variable) {
+        if (variable instanceof ProxyVariableSupport) {
+            ProxyVariableSupport pvs = (ProxyVariableSupport) variable;
+            return pvs.attachTo(graph, parent);
+        }
+        return null;
+    }
+
+    public static Variable tryToOwnRenamed(ReadGraph graph, Variable parent, Variable variable, String name) {
+        if (variable instanceof ProxyVariableSupport) {
+            ProxyVariableSupport pvs = (ProxyVariableSupport) variable;
+            return pvs.attachToRenamed(graph, parent, name);
+        }
+        return null;
+    }
+
        public static Variable inputVariable(ReadGraph graph, Variable context) throws DatabaseException {
        Variable session = graph.syncRequest(new ProxySessionRequest(context));
        if(session == null) return null;
@@ -52,7 +72,7 @@ public class ProxyVariables {
                        return input;
                }
         } catch (Throwable t) {
-            t.printStackTrace();
+            LOGGER.error("proxySessionVariable failed", t);
             return null;
         }
 
@@ -72,7 +92,7 @@ public class ProxyVariables {
                }
                
         } catch (Throwable t) {
-            t.printStackTrace();
+            LOGGER.error("proxyVariableBase failed", t);
             return null;
         }
 
@@ -108,7 +128,7 @@ public class ProxyVariables {
                }
                
         } catch (Throwable t) {
-            t.printStackTrace();
+            LOGGER.error("proxyVariableRoot failed", t);
             return null;
         }
 
@@ -118,5 +138,4 @@ public class ProxyVariables {
        return proxyVariableRoot(graph, variable) != null;
     }
 
-    
 }
index b784754bfa69ce8187999cb78af598506552c45d..bd0184e86af9f413931f512d223b6be1e234dcf7 100644 (file)
@@ -12,7 +12,6 @@ import org.simantics.db.Resource;
 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
 import org.simantics.db.exception.AssumptionException;
 import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.exception.VariableException;
 import org.simantics.db.layer0.exception.InvalidVariableException;
 import org.simantics.db.layer0.function.All;
 import org.simantics.db.layer0.request.ClassificationsRequest;
@@ -24,7 +23,7 @@ import org.simantics.db.layer0.variable.Variables.Role;
 import org.simantics.layer0.Layer0;
 import org.simantics.simulator.variable.exceptions.NodeManagerException;
 
-public class StandardGraphChildVariable extends AbstractChildVariable {
+public class StandardGraphChildVariable extends AbstractChildVariable implements ProxyVariableSupport {
 
        /*
         * Extension points
@@ -335,5 +334,20 @@ public class StandardGraphChildVariable extends AbstractChildVariable {
     public Resource getPossiblePredicateResource(ReadGraph graph) throws DatabaseException {
        return null;
     }
-       
+
+    @Override
+    public Variable attachTo(ReadGraph graph, Variable parent) {
+        return new StandardGraphChildVariable(parent, node, resource);
+    }
+
+    @Override
+    public Variable attachToRenamed(ReadGraph graph, Variable parent, String name) {
+        return new StandardGraphChildVariable(parent, node, resource) {
+            @Override
+            public String getName(ReadGraph graph) throws DatabaseException {
+                return name;
+            }
+        };
+    }
+
 }