]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
wip
authorAntti Villberg <antti.villberg@semantum.fi>
Thu, 1 Nov 2018 06:09:30 +0000 (08:09 +0200)
committerAntti Villberg <antti.villberg@semantum.fi>
Thu, 1 Nov 2018 06:09:30 +0000 (08:09 +0200)
Change-Id: Icb7ed89f246349b0dbae93600ae029924a9e9610

22 files changed:
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/function/All.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/CompileValueRequest.java
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.debug.ui/src/org/simantics/debug/ui/VariableDebugger.java
bundles/org.simantics.document.base.ontology/graph/Components.pgraph
bundles/org.simantics.document.base.ontology/graph/Documentation.pgraph
bundles/org.simantics.document.base.ontology/graph/Properties.pgraph
bundles/org.simantics.document.server/scl/Document/All.scl
bundles/org.simantics.document.server/src/org/simantics/document/server/DocumentProperties.java [new file with mode: 0644]
bundles/org.simantics.document.server/src/org/simantics/document/server/DocumentServerUtils.java
bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java
bundles/org.simantics.document.server/src/org/simantics/document/server/request/NodeRequest.java
bundles/org.simantics.structural2/src/org/simantics/structural2/ConnectionImpl.java [new file with mode: 0644]
bundles/org.simantics.structural2/src/org/simantics/structural2/ConnectionImpl2.java
bundles/org.simantics.structural2/src/org/simantics/structural2/Functions.java
bundles/org.simantics.structural2/src/org/simantics/structural2/scl/CompileStructuralValueRequest.java
bundles/org.simantics.structural2/src/org/simantics/structural2/variables/Connection.java
bundles/org.simantics.structural2/src/org/simantics/structural2/variables/Connection2.java [new file with mode: 0644]
bundles/org.simantics.structural2/src/org/simantics/structural2/variables/ConnectionBrowser.java
bundles/org.simantics.structural2/src/org/simantics/structural2/variables/FixedConnection.java [new file with mode: 0644]
bundles/org.simantics.structural2/src/org/simantics/structural2/variables/StandardProceduralChildVariable.java

index f93023b77ccd36a6db7d44af8d9981f4a47fc983..6f6f9b3b826512b0d1b89bdf8a94a0a740e7801e 100644 (file)
@@ -1186,16 +1186,16 @@ public class All {
        return Functions.exec(graph, resource, graph, resource, context);
     }
 
-    @SCLValue(type = "ReadGraph -> Resource -> a -> b")
-    public static Object computeExpression(ReadGraph graph, Resource converter, Object context) throws DatabaseException {
-       if(context instanceof Variable) {
-            return CompileValueRequest.compileAndEvaluate(graph, (Variable)context);
-       } if (context instanceof Resource) {
-            return CompileResourceValueRequest.compileAndEvaluate(graph, (Resource)converter);
-       } else {
-               throw new IllegalStateException("Unknown context " + context);
-       }
-    }
+//    @SCLValue(type = "ReadGraph -> Resource -> a -> b")
+//    public static Object computeExpression(ReadGraph graph, Resource converter, Object context) throws DatabaseException {
+//     if(context instanceof Variable) {
+//            return CompileValueRequest.compileAndEvaluate(graph, (Variable)context);
+//     } if (context instanceof Resource) {
+//            return CompileResourceValueRequest.compileAndEvaluate(graph, (Resource)converter);
+//     } else {
+//             throw new IllegalStateException("Unknown context " + context);
+//     }
+//    }
 
     @SCLValue(type = "ReadGraph -> Resource -> a -> b")
     public static Object composedPropertyValue(ReadGraph graph, Resource converter, Object context) throws DatabaseException {
index caa60900cfbd8d99729f2cef4684e78467bf1e35..78998d289830293e21c66e9f87ce29e1d790febb 100644 (file)
@@ -52,7 +52,7 @@ public class CompileValueRequest extends AbstractExpressionCompilationRequest<Co
     public static Object compileAndEvaluate(ReadGraph graph, Variable context) throws DatabaseException {
         SCLContext sclContext = SCLContext.getCurrent();
         Object oldGraph = sclContext.get("graph");
-        try {
+        try {        
             Function1<Object,Object> exp = graph.syncRequest(new CompileValueRequest(graph, context),
                     TransientCacheListener.instance());
             sclContext.put("graph", graph);
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..9ae52c6
--- /dev/null
@@ -0,0 +1,10 @@
+package org.simantics.db.layer0.variable;
+
+import org.simantics.db.ReadGraph;
+
+public interface ProxyVariableSupport {
+
+    Variable attachTo(ReadGraph graph, Variable parent);
+    Variable attachToRenamed(ReadGraph graph, Variable parent, String name);
+    
+}
index db552650b09c7098074bfd069b954a9b5d80ca15..8fa9bf42628a3be5a29e12824cb87b5be4c61b2a 100644 (file)
@@ -4,8 +4,24 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.exception.DatabaseException;
 
 public class ProxyVariables {
-       
-       public static Variable inputVariable(ReadGraph graph, Variable context) throws DatabaseException {
+    
+    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;
        String uri = session.getPossiblePropertyValue(graph, "inputURI");
index 9c02bbe2a70806dfb8833e9b7a23a12310e7a015..08342593fe132b1b89578b645183cf52bd5239be 100644 (file)
@@ -694,7 +694,7 @@ public class VariableDebugger extends Composite {
             content.append("<table class=\"top\">\n");
             content.append("<tr><td class=\"top_key\">URI</td><td class=\"top_value\"><span id=\"uri\">").append(uri).append("</span></td></tr>\n");
             content.append("<tr><td class=\"top_key\">RVI</td><td class=\"top_value\"><span id=\"uri\">").append(rviString).append("</span></td></tr>\n");
-            content.append("<tr><td class=\"top_key\">Class</td><td class=\"top_value\"><span id=\"class\">").append(var.getClass().getCanonicalName()).append("</span></td></tr>\n");
+            content.append("<tr><td class=\"top_key\">Class</td><td class=\"top_value\"><span id=\"class\">").append(var.getClass()).append("</span></td></tr>\n");
             content.append("<tr><td class=\"top_key\">Solver node</td><td class=\"top_value\"><span id=\"class\">").append(node).append("</span></td></tr>\n");
             content.append("</table>\n");
             content.append("</div>\n");
index 099755380dc64c4ff874d8d1fe637ef97bc954f6..3eb47b3a99cb61b974d4c0825aceb135fbd3b9a7 100644 (file)
@@ -31,10 +31,6 @@ sclAttribute = COMPONENTS.sclAttribute : L0.Template
                   L0.SCLValue.expression %command
                   L0.default false
 
-DOC.SCL : L0.SCLModule
-    L0.SCLModule.definition _ : L0.String
-        @L0.loadString "scl/Code.scl"
-
 DOC.scl : L0.Template
     @template %subject %property %expression %valueType
         %subject
@@ -49,7 +45,6 @@ DOC.sclValue : L0.Template
             L0.HasValueType %valueType
 
 DOC.SCLValue <T L0.SCLValue
-  @L0.scl L0.SCLValueType.validator """\self -> compileDocumentSCLValueExpression self""" "Variable -> <ReadGraph> String"
   @L0.assert L0.ConvertsToValueWith
     DOC.Functions.sclValue : L0.ExternalValue
 
@@ -67,9 +62,7 @@ COMPONENTS.Component <T STR.Component
     @sclAttribute PROPERTIES.commands "commandList self" "[Command]"
 
 COMPONENTS.PrimitiveComponent <T COMPONENTS.Component
-    @L0.assert PROPERTIES.primitiveProperties
-      _ : L0.Value
-        L0.domainProperties FUNCTIONS.primitiveProperties
+    @L0.sclAssertion PROPERTIES.primitiveProperties "primitiveProperties" "DocumentProperties"
 
 COMPONENTS.ParentlessComponent <T COMPONENTS.PrimitiveComponent /* Component without a parent, e.g. Root, DialogBox */
 
@@ -88,7 +81,7 @@ COMPONENTS.Event <T COMPONENTS.ParentlessComponent
  
 COMPONENTS.CommandEvent <T COMPONENTS.Event
    @connectionPoint RELATIONS.data1
-   @sclAttribute PROPERTIES.dataDefinitions "dataDefinitions self" "[DataDefinition]"
+   @sclAttribute PROPERTIES.dataDefinitions "computeDataDefinitions self" "[DataDefinition]"
    @sclAttribute PROPERTIES.SCLFunction "emptyOnClick ()" "String"
 
 DOC.commandEvent : L0.Template
index 4845558ea2b21bb1a72545af5b2957f347f22496..d6cb64dbac3644d44916b9d002f7667c6075c4db 100644 (file)
@@ -12,6 +12,11 @@ Documentation = <http://www.simantics.org/Documentation-1.2> : L0.Ontology
     @L0.new
     L0.HasResourceClass "org.simantics.document.base.ontology.DocumentationResource"
 
+Documentation.SCLMain : L0.SCLModule
+    L0.SCLModule.definition """
+        include "Document/All"
+        """
+
 Documentation.connect : L0.Template
   @template %parent %relation %connection %child
     %parent
@@ -122,13 +127,12 @@ Documentation.singleData : L0.Template
     
 
 Documentation.Relations : L0.Library
+
 Documentation.Document <T Documentation.Components.Composite
     @L0.assert L0.domainChildren Documentation.Functions.inputSpaceChildren
     @L0.assert STR.Composite.namingFunction Documentation.Functions.componentNamingStrategy       
     >-- Documentation.Properties.state
-    L0.Asserts _ : L0.Assertion
-        L0.HasPredicate Documentation.Properties.state
-        L0.HasObject FUNCTIONS.state
+    @L0.sclAssertion Documentation.Properties.state "stateVariable self" "Variable"
     >-- Documentation.Properties.session
     L0.Asserts _ : L0.Assertion
         L0.HasPredicate Documentation.Properties.session
index d502e3d2f2e860ed22dbdc56340c9e44954a643d..e1c71fe976a62df8b76c3a213c51418a8dbabd34 100644 (file)
@@ -52,7 +52,7 @@ PROPERTIES.model <R L0.HasProperty : L0.FunctionalRelation
     ==> "Variable"
 
 PROPERTIES.primitiveProperties <R L0.HasProperty : L0.FunctionalRelation
-    ==> "String"
+    ==> "DocumentProperties"
 
 PROPERTIES.exists
     @defAttribute L0.Value
index 4db639f5bf2696a389669d527bae19b035978064..c6967b559a3ca1377e8e74e93711d6efff72489d 100644 (file)
@@ -2,6 +2,9 @@ import "Simantics/DB"
 import "Simantics/Variables"
 import "JavaBuiltin" as Java
 
+importJava "org.simantics.document.server.DocumentProperties" where
+    data DocumentProperties
+
 importJava "org.simantics.document.server.io.IConsole" where
     data IConsole
     addMessage :: IConsole -> String -> <Proc> ()
@@ -110,6 +113,9 @@ importJava "org.simantics.document.server.Functions" where
 
     dataDefinitions :: Variable -> <ReadGraph> [DataDefinition]
 
+    @JavaName "dataDefinitions"
+    computeDataDefinitions :: Variable -> <ReadGraph> [DataDefinition]
+    
     emptyOnClick :: () -> <ReadGraph> AbstractEventHandler
     
     writeEventHandler :: Variable -> (Variable -> (String -> Maybe String) -> <WriteGraph> String) -> <ReadGraph> AbstractEventHandler
@@ -139,6 +145,8 @@ importJava "org.simantics.document.server.Functions" where
     
     compileDocumentSCLValueExpression :: Variable -> <ReadGraph> String
     
+    primitiveProperties :: <Proc> DocumentProperties
+    
 propertyValueCached :: Serializable a => Typeable a => Variable -> String -> <ReadGraph> a
 propertyValueCached var prop = propertyValueCached_ var prop binding
     
diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/DocumentProperties.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/DocumentProperties.java
new file mode 100644 (file)
index 0000000..2951b93
--- /dev/null
@@ -0,0 +1,14 @@
+package org.simantics.document.server;
+
+import java.util.Collection;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+
+public interface DocumentProperties {
+       
+       Collection<String> getKeys(ReadGraph graph, Variable context) throws DatabaseException;
+       Object getValue(ReadGraph graph, Variable context, String key) throws DatabaseException;
+       
+}
index 5e1f5cc30e798aff45343b8f8c5f4483b6d8a9cc..c87276461e10441c4f407dc3394efd1f0113d7b5 100644 (file)
@@ -19,12 +19,10 @@ import org.simantics.db.layer0.variable.ProxyChildVariable;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;
 import org.simantics.document.base.ontology.DocumentationResource;
-import org.simantics.document.server.Functions.RootVariable;
 import org.simantics.document.server.request.NodeRequest;
 import org.simantics.document.server.request.NodeRequestUtils;
 import org.simantics.structural2.variables.Connection;
 import org.simantics.structural2.variables.VariableConnectionPointDescriptor;
-import org.simantics.utils.datastructures.Pair;
 import org.simantics.utils.strings.AlphanumComparator;
 
 public class DocumentServerUtils {
@@ -127,7 +125,7 @@ public class DocumentServerUtils {
 
        public static Variable getPossibleOtherConnectionPoint(ReadGraph graph, Variable connectionPoint, Connection conn) throws DatabaseException {
 
-               Collection<VariableConnectionPointDescriptor> descs = conn.getConnectionPointDescriptors(graph, null);
+               Collection<VariableConnectionPointDescriptor> descs = conn.getConnection2().getConnectionPointDescriptors(graph, connectionPoint.getParent(graph), null);
                if(descs.size() != 2) return null;
 
                for(VariableConnectionPointDescriptor desc : descs) {
@@ -141,7 +139,7 @@ public class DocumentServerUtils {
 
        public static Variable getPossibleChildConnectionPoint(ReadGraph graph, Variable connectionPoint, Connection conn) throws DatabaseException {
 
-               Collection<VariableConnectionPointDescriptor> descs = conn.getConnectionPointDescriptors(graph, null);
+               Collection<VariableConnectionPointDescriptor> descs = conn.getConnection2().getConnectionPointDescriptors(graph, connectionPoint.getParent(graph), null);
                if(descs.size() != 2) return null;
 
        DocumentationResource DOC = DocumentationResource.getInstance(graph);
@@ -174,7 +172,7 @@ public class DocumentServerUtils {
 
        public static Variable getPossibleCommandTriggerConnectionPoint(ReadGraph graph, Variable connectionPoint, Connection conn) throws DatabaseException {
 
-               Collection<Variable> cpts = conn.getConnectionPoints(graph, null);
+               Collection<Variable> cpts = conn.getConnection2().getConnectionPoints(graph, connectionPoint.getParent(graph), null);
 
                Variable result = null;
                
@@ -192,7 +190,7 @@ public class DocumentServerUtils {
 
        public static Collection<Variable> getPossibleOtherConnectionPoints(ReadGraph graph, Variable connectionPoint, Connection conn) throws DatabaseException {
 
-           Collection<Variable> cpts = conn.getConnectionPoints(graph, null);
+           Collection<Variable> cpts = conn.getConnection2().getConnectionPoints(graph, connectionPoint.getParent(graph), null);
            if(cpts.size() < 2) 
                return Collections.emptyList();
 
@@ -208,9 +206,14 @@ public class DocumentServerUtils {
 
                if(node == null) return "root";
                else {
-                       String uri = node.getURI(graph); 
-                       int l = uri.lastIndexOf(ProxyChildVariable.CONTEXT_END);
-                       return uri.substring(l+4);
+                   String name = node.getName(graph);
+                   if(ProxyChildVariable.CONTEXT_END.equals(name)) return "";
+                   else {
+                       String parentId = getId(graph, node.getParent(graph));
+                       if(parentId.isEmpty()) return name;
+                       else return parentId + "/" + name; 
+                   }
+                   
                }
 
        }
@@ -294,81 +297,72 @@ public class DocumentServerUtils {
                return variable.getProperties(graph, DOC.Document_AttributeRelation);
        }
        
-       public static class AttributesRequest extends VariableRead<Pair<JSONObject, Collection<Variable>>> {
-
-               public AttributesRequest(Variable variable) {
-                       super(variable);
-               }
-
-               @Override
-               public Pair<JSONObject,Collection<Variable>> perform(ReadGraph graph) throws DatabaseException {
-               ArrayList<Variable> statics = new ArrayList<Variable>();
-               DocumentationResource DOC = DocumentationResource.getInstance(graph);
-               
-               Variable primitives = variable.getProperty(graph, DOC.Properties_primitiveProperties);
-               for(Variable property : primitives.getProperties(graph)) {
-                       statics.add(property);
-                       // NO SUPPORT FOR DYNAMICS AT THIS STAGE
-               }
-               
-               JSONObject staticContent = computeStatic(graph, variable, statics);
-               
-               return new Pair<JSONObject, Collection<Variable>>(staticContent, Collections.emptyList());
-               
-               }
-               
-               JSONObject computeStatic(ReadGraph graph, Variable variable, ArrayList<Variable> statics) throws DatabaseException {
-                       
-                       JSONObject base = graph.syncRequest(new org.simantics.document.server.request.DefaultFields(variable));
-                       JSONObject object = base.clone();
-                       
-                       for(Variable attrib : statics) {
-                               String name = attrib.getName(graph);
-                               try {
-                                       if (name.equals(NodeRequest.PROPERTY_VALUE_EXCEPTIONS)) {
-                                       @SuppressWarnings("unchecked")
-                                               Map<String, Exception> exceptions = (Map<String, Exception>)DocumentServerUtils.getValue(graph, attrib);
-                                       
-                                       List<String> errorList = object.getJSONField(NodeRequest.ERRORS);
-                                           if(errorList == null)
-                                               errorList = new ArrayList<String>();
-                                           
-                                   for (Map.Entry<String, Exception> entry : exceptions.entrySet()) {
-                                       String errorMessage = NodeRequestUtils.formatErrorMessage(entry.getKey(), entry.getValue());
-                                       errorList.add(errorMessage);
-                                   }
-                                       object.addJSONField(NodeRequest.ERRORS, errorList);
-                                       
-                                   } else {
-                                               Object value = DocumentServerUtils.getValue(graph, attrib);
-                                           object.addJSONField(name, value);
-                                   }
-                               } catch (Throwable t) {
-                                   List<String> errorList = object.getJSONField(NodeRequest.ERRORS);
-                                   if(errorList == null)
-                                       errorList = new ArrayList<String>();
-                                   
-                           String errorMessage = NodeRequestUtils.formatErrorMessage(name, t);
-                           
-                                   errorList.add(errorMessage);
-                                   object.addJSONField(NodeRequest.ERRORS, errorList);
-                               }
-
-                       }
-
-                       return object;
-                       
-               }
-               
-       }
+    public static class AttributesRequest extends VariableRead<JSONObject> {
+
+        public AttributesRequest(Variable variable) {
+            super(variable);
+        }
+
+        @Override
+        public JSONObject perform(ReadGraph graph) throws DatabaseException {
+
+            DocumentationResource DOC = DocumentationResource.getInstance(graph);
+            
+            DocumentProperties properties = variable.getPropertyValue(graph, DOC.Properties_primitiveProperties); 
+            
+            return computeStatic(graph, variable, properties);
+            
+        }
+        
+        JSONObject computeStatic(ReadGraph graph, Variable variable, DocumentProperties statics) throws DatabaseException {
+            
+            JSONObject base = graph.syncRequest(new org.simantics.document.server.request.DefaultFields(variable));
+            JSONObject object = base.clone();
+            
+            for(String name : statics.getKeys(graph, variable)) {
+                try {
+                    if (name.equals(NodeRequest.PROPERTY_VALUE_EXCEPTIONS)) {
+                        @SuppressWarnings("unchecked")
+                        Map<String, Exception> exceptions = (Map<String, Exception>)statics.getValue(graph, variable, name);//(Map<String, Exception>)DocumentServerUtils.getValue(graph, attrib);
+                        
+                        List<String> errorList = object.getJSONField(NodeRequest.ERRORS);
+                        if(errorList == null)
+                            errorList = new ArrayList<String>();
+                        
+                        for (Map.Entry<String, Exception> entry : exceptions.entrySet()) {
+                            String errorMessage = NodeRequestUtils.formatErrorMessage(entry.getKey(), entry.getValue());
+                            errorList.add(errorMessage);
+                        }
+                        object.addJSONField(NodeRequest.ERRORS, errorList);
+                        
+                    } else {
+                        object.addJSONField(name, statics.getValue(graph, variable, name));
+                    }
+                } catch (Throwable t) {
+                    List<String> errorList = object.getJSONField(NodeRequest.ERRORS);
+                    if(errorList == null)
+                        errorList = new ArrayList<String>();
+                    
+                    String errorMessage = NodeRequestUtils.formatErrorMessage(name, t);
+                    
+                    errorList.add(errorMessage);
+                    object.addJSONField(NodeRequest.ERRORS, errorList);
+                }
+
+            }
+
+            return object;
+            
+        }
+        
+    }
 
        public static Collection<Variable> getDynamicAttributes(ReadGraph graph, final DocumentationResource DOC, Variable variable) throws DatabaseException {
-       Pair<JSONObject, Collection<Variable>> attribs = graph.syncRequest(new AttributesRequest(variable));
-       return attribs.second;
+        return Collections.emptyList();
        }
        
        public static Variable getPossibleDocumentRootVariable(ReadGraph graph, Variable documentPart) throws DatabaseException {
-               if(documentPart instanceof RootVariable) return documentPart;
+           if(ProxyChildVariable.CONTEXT_END.equals(documentPart.getName(graph))) return documentPart;
                Variable parent = documentPart.getParent(graph);
                if(parent == null) return null;
                return getPossibleDocumentRootVariable(graph, parent);
index aabe7b29ffd04dbcdff684dc899f11f2bde8c19f..13439c86572a31d6b762564043cac321f0f8c9fd 100644 (file)
@@ -15,7 +15,6 @@ import org.simantics.databoard.Bindings;
 import org.simantics.databoard.Datatypes;
 import org.simantics.databoard.binding.Binding;
 import org.simantics.databoard.type.Datatype;
-import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.DirectStatements;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.RequestProcessor;
@@ -25,7 +24,7 @@ import org.simantics.db.Statement;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.common.primitiverequest.Adapter;
 import org.simantics.db.common.procedure.adapter.TransientCacheListener;
-import org.simantics.db.common.request.UnaryRead;
+import org.simantics.db.common.request.BinaryRead;
 import org.simantics.db.common.request.UniqueRead;
 import org.simantics.db.common.request.WriteResultRequest;
 import org.simantics.db.common.utils.Logger;
@@ -42,15 +41,14 @@ import org.simantics.db.layer0.scl.SCLDatabaseException;
 import org.simantics.db.layer0.variable.ConstantPropertyVariable;
 import org.simantics.db.layer0.variable.ProxyChildVariable;
 import org.simantics.db.layer0.variable.ProxySessionRequest;
+import org.simantics.db.layer0.variable.ProxyVariableSupport;
 import org.simantics.db.layer0.variable.ProxyVariables;
 import org.simantics.db.layer0.variable.StandardAssertedGraphPropertyVariable;
-import org.simantics.db.layer0.variable.StandardGraphChildVariable;
 import org.simantics.db.layer0.variable.StandardGraphPropertyVariable;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.VariableMap;
 import org.simantics.db.layer0.variable.VariableMapImpl;
 import org.simantics.db.layer0.variable.Variables;
-import org.simantics.db.procedure.AsyncProcedure;
 import org.simantics.db.service.DirectQuerySupport;
 import org.simantics.document.base.ontology.DocumentationResource;
 import org.simantics.document.server.bean.Command;
@@ -107,21 +105,6 @@ public class Functions {
 
     private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(Functions.class);
     
-    private static class PrimitivePropertyStatementsProcedure implements AsyncProcedure<DirectStatements> {
-
-        public DirectStatements result;
-
-        @Override
-        public void execute(AsyncReadGraph graph, DirectStatements result) {
-            this.result = result;
-        }
-
-        @Override
-        public void exception(AsyncReadGraph graph, Throwable throwable) {
-        }
-
-    }
-
     @SCLValue(type = "VariableMap")
     public static VariableMap primitiveProperties = new VariableMapImpl() {
        private void storePropertyValueAndExceptions(ReadGraph graph, Variable parent, String name, Variable property, Map<String, Variable> map) {
@@ -229,11 +212,42 @@ public class Functions {
 
     };
 
+    static class StandardDocumentProperties implements DocumentProperties {
+
+        @Override
+        public Collection<String> getKeys(ReadGraph graph, Variable context) throws DatabaseException {
+            
+            DocumentationResource DOC = DocumentationResource.getInstance(graph);
+            StandardGraphPropertyVariable asd = new StandardGraphPropertyVariable(graph, context, DOC.Properties_primitiveProperties);
+            Map<String, Variable> ps = primitiveProperties.getVariables(graph, asd, null);
+            return ps.keySet();
+            
+        }
+
+        @Override
+        public Object getValue(ReadGraph graph, Variable context, String key) throws DatabaseException {
+            
+            DocumentationResource DOC = DocumentationResource.getInstance(graph);
+            StandardGraphPropertyVariable asd = new StandardGraphPropertyVariable(graph, context, DOC.Properties_primitiveProperties);
+            Map<String, Variable> ps = primitiveProperties.getVariables(graph, asd, null);
+            return ps.get(key).getValue(graph);
+            
+        }
+        
+    }
+    
+    public static DocumentProperties primitiveProperties() throws DatabaseException {
+        return new StandardDocumentProperties();
+    }
+    
     @SCLValue(type = "VariableMap")
     public static VariableMap inputSpaceChildren = new VariableMapImpl() {
 
         private Variable getProxy(ReadGraph graph, Variable context) throws DatabaseException {
-            Variable root = Variables.getRootVariable(graph);
+            System.err.println("getProxy " + context.getURI(graph));
+            //System.err.println("getProxy " + context.getParent(graph).getURI(graph));
+            Variable root = Variables.getVariable(graph, graph.getRootLibrary());   
+            //Variable parent = context.getParent(graph);
             return new DocumentProxyChildVariable(context, context, root, ProxyChildVariable.CONTEXT_BEGIN);
         }
 
@@ -257,7 +271,7 @@ public class Functions {
 
     };
 
-    static class DocumentProxyChildVariable extends ProxyChildVariable {
+    static class DocumentProxyChildVariable extends ProxyChildVariable implements ProxyVariableSupport {
 
         public DocumentProxyChildVariable(Variable base, Variable parent, Variable other, String name) {
             super(base, parent, other, name);
@@ -269,13 +283,17 @@ public class Functions {
         }
 
         public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException {
+            
+            System.err.println("possibleChild " + name + " for " + getURI(graph));
 
                if(CONTEXT_END.equals(name)) {
                if(other instanceof ProxyChildVariable) {
                        // The context is also a proxy - let it do the job
                     return super.getPossibleChild(graph, name);
                } else {
-                       return new RootVariable(this, base.getRepresents(graph));
+                   System.err.println("RootVariable for " + getURI(graph) + " from " + base.getURI(graph));
+                   return ProxyVariables.tryToOwnRenamed(graph, this, base, CONTEXT_END);
+                       //return new RootVariable(this, base);
                }
                }
 
@@ -283,36 +301,45 @@ public class Functions {
 
         }
 
-        public Collection<Variable> getChildren(ReadGraph graph) throws DatabaseException {
-
-            Collection<Variable> result = super.getChildren(graph);
-            if(!(base instanceof ProxyChildVariable)) {
-               result.add(new RootVariable(this, base.getRepresents(graph)));
-            }
-            return result;
-
+        @Override
+        public Variable attachTo(ReadGraph graph, Variable parent) {
+            return attachToRenamed(graph, parent, name);
+        }
+        
+        @Override
+        public Variable attachToRenamed(ReadGraph graph, Variable parent, String name) {
+            if(this.parent.equals(base))
+                return new DocumentProxyChildVariable(parent, parent, other, name);
+            else
+                return new DocumentProxyChildVariable(base, parent, other, name);
         }
 
     }
 
-    static class RootVariable extends StandardGraphChildVariable {
+    /*static class RootVariable extends ProxyVariable {
 
-        public RootVariable(DocumentProxyChildVariable parent, Resource resource) {
-            super(parent, null, resource);
+        public RootVariable(DocumentProxyChildVariable parent, Variable proxy) {
+            super(parent, proxy);
         }
 
         @Override
         public String getName(ReadGraph graph) throws DatabaseException {
             return ProxyChildVariable.CONTEXT_END;
         }
-
-        @SuppressWarnings("deprecation")
+        
         @Override
-        public Variable getNameVariable(ReadGraph graph) throws DatabaseException {
-            return new ConstantPropertyVariable(this, Variables.NAME, ProxyChildVariable.CONTEXT_END, Bindings.STRING);
+        public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException {
+            System.err.println("Root.getPossibleChild " + name + " " + getURI(graph));
+            return super.getPossibleChild(graph, name);
+        }
+        
+        @Override
+        public Collection<Variable> getChildren(ReadGraph graph) throws DatabaseException {
+            System.err.println("Root.getChildren " + getURI(graph));
+            return super.getChildren(graph);
         }
 
-    }
+    }*/
 
     @SCLValue(type = "ReadGraph -> Resource -> Variable -> Variable")
     public static Variable input(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {
@@ -1200,6 +1227,8 @@ public class Functions {
 
     public static Object getPropertyValueCached(ReadGraph graph, Variable variable, String name, Binding binding) throws DatabaseException {
        Variable property = graph.syncRequest(new VariableProperty(variable, name));
+       if(property == null)
+           System.err.println("faa");
        return graph.syncRequest(new VariableValueWithBinding<Object>(property, binding));
     }
 
@@ -1252,11 +1281,11 @@ public class Functions {
                                                return true;
                                        }
                                } else {
-                                       Variable parentCp = graph.sync(new UnaryRead<Connection, Variable>(conn) {
+                                       Variable parentCp = graph.sync(new BinaryRead<Variable, Connection, Variable>(widget, conn) {
                                    @Override
                                    public Variable perform(ReadGraph graph) throws DatabaseException {
                                        DocumentationResource DOC = DocumentationResource.getInstance(graph);
-                                       Collection<VariableConnectionPointDescriptor> descs = parameter.getConnectionPointDescriptors(graph, null);
+                                       Collection<VariableConnectionPointDescriptor> descs = parameter2.getConnection2().getConnectionPointDescriptors(graph, parameter, null);
 
                                                for(VariableConnectionPointDescriptor desc : descs) {
                                                        if (DOC.Relations_partN.equals(desc.getConnectionPointResource(graph))) {
index d9418db9947d482fecd4daf547d85359363bea5c..9367a151d6879d663698b44b4e0883528d468074 100644 (file)
@@ -1,67 +1,28 @@
 package org.simantics.document.server.request;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
 import org.simantics.db.ReadGraph;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.request.VariableRead;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.document.server.DocumentServerUtils.AttributesRequest;
 import org.simantics.document.server.JSONObject;
-import org.simantics.utils.datastructures.Pair;
 
 public class NodeRequest extends VariableRead<JSONObject> {
 
     public static final String ERRORS = "Errors";
     public static final String PROPERTY_VALUE_EXCEPTIONS = "_PropertyValueExceptions";
-    
-       public NodeRequest(Variable node) {
-               super(node);
-       }
-
-       @SuppressWarnings("unchecked")
-    @Override
-       public JSONObject perform(ReadGraph graph) throws DatabaseException {
-
-               long s = System.nanoTime();
-
-               Pair<JSONObject, Collection<Variable>> attribs = graph.syncRequest(new AttributesRequest(variable));
-
-           JSONObject staticContent = attribs.first;
-           if(attribs.second.isEmpty()) {
-
-               if(DocumentRequest.PROFILE) {
-                       long dura = System.nanoTime()-s;
-                   if(dura > DocumentRequest.PROFILE_THRESHOLD_NODEREQUEST * 1e3) {
-                       System.err.println("NodeRequest " + System.identityHashCode(this) + " in " + 1e-6*dura + "ms. " + variable.getURI(graph));
-                   }
-               }
-
-               return staticContent;
-           }
 
-           Map<String,Object> dynamicContent = graph.syncRequest(new NodeRequestDynamic(variable));
-           if(dynamicContent.isEmpty()) {
-               return staticContent;
-           }
-
-        JSONObject result = staticContent.clone();
-        result.add(dynamicContent);
+    public NodeRequest(Variable node) {
+        super(node);
+    }
 
-        if(dynamicContent.containsKey(ERRORS) || staticContent.getJSONField(ERRORS) != null) {
-            ArrayList<String> errorList = new ArrayList<>();
+    @SuppressWarnings("unchecked")
+    @Override
+    public JSONObject perform(ReadGraph graph) throws DatabaseException {
 
-            if(dynamicContent.containsKey(ERRORS))
-                errorList.addAll((List<String>)dynamicContent.get(ERRORS));
+        long s = System.nanoTime();
 
-            if(staticContent.getJSONField(ERRORS) != null)
-                errorList.addAll((List<String>)staticContent.getJSONField(ERRORS));
-
-            result.addJSONField(ERRORS, errorList);
-        }
+        JSONObject staticContent = graph.syncRequest(new AttributesRequest(variable));
 
         if(DocumentRequest.PROFILE) {
             long dura = System.nanoTime()-s;
@@ -69,8 +30,9 @@ public class NodeRequest extends VariableRead<JSONObject> {
                 System.err.println("NodeRequest " + System.identityHashCode(this) + " in " + 1e-6*dura + "ms. " + variable.getURI(graph));
             }
         }
-        
-        return result;
+
+
+        return staticContent;
 
     }
 
diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/ConnectionImpl.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/ConnectionImpl.java
new file mode 100644 (file)
index 0000000..b7f6661
--- /dev/null
@@ -0,0 +1,87 @@
+package org.simantics.structural2;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.structural2.variables.Connection;
+import org.simantics.structural2.variables.Connection2;
+import org.simantics.structural2.variables.ConnectionBrowser;
+import org.simantics.structural2.variables.VariableConnectionPointDescriptor;
+
+import gnu.trove.set.hash.THashSet;
+
+public class ConnectionImpl implements Connection {
+
+       @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((component == null) ? 0 : component.hashCode());
+        result = prime * result + ((predicate == null) ? 0 : predicate.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        ConnectionImpl other = (ConnectionImpl) obj;
+        if (component == null) {
+            if (other.component != null)
+                return false;
+        } else if (!component.equals(other.component))
+            return false;
+        if (predicate == null) {
+            if (other.predicate != null)
+                return false;
+        } else if (!predicate.equals(other.predicate))
+            return false;
+        return true;
+    }
+
+    final private Variable component;
+       final private Resource predicate;
+       
+       public ConnectionImpl(Variable component, Resource predicate) {
+           this.component = component;
+           this.predicate = predicate;
+       }
+
+    @Override
+    public Collection<Variable> getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException {
+        Set<Variable> result = new THashSet<Variable>();
+        for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, predicate, relationType)) {
+            result.add(desc.getVariable(graph));
+        }
+        return result;
+    }
+
+       @Override
+    public Collection<String> getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException {
+        Set<String> result = new THashSet<String>();
+        for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, predicate, relationType)) {
+            result.add(desc.getURI(graph));
+        }
+        return result;
+    }
+
+    @Override
+    public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph,
+            Resource relationType) throws DatabaseException {
+        return ConnectionBrowser.flatten(graph, component, predicate, relationType);
+    }
+
+    @Override
+    public Connection2 getConnection2() {
+        return new ConnectionImpl2(predicate);
+    }
+
+}
\ No newline at end of file
index e4b898a6b18cccef2d66ab26c00e0ada365594da..76af826a881dfc880c4908b081b504b32e627fe1 100644 (file)
@@ -14,23 +14,23 @@ package org.simantics.structural2;
 import java.util.Collection;
 import java.util.Set;
 
+import org.simantics.databoard.binding.error.UnsupportedOperationException;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.structural2.variables.Connection;
+import org.simantics.structural2.variables.Connection2;
 import org.simantics.structural2.variables.ConnectionBrowser;
 import org.simantics.structural2.variables.VariableConnectionPointDescriptor;
 
 import gnu.trove.set.hash.THashSet;
 
-public class ConnectionImpl2 implements Connection {
+public class ConnectionImpl2 implements Connection, Connection2 {
 
-    private final Variable component;
     private final Resource predicate;
     
-    public ConnectionImpl2(Variable component, Resource predicate) {
-        this.component = component;
+    public ConnectionImpl2(Resource predicate) {
         this.predicate = predicate;
     }
     
@@ -60,26 +60,50 @@ public class ConnectionImpl2 implements Connection {
     }
 
     @Override
-    public Collection<Variable> getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException {
-        Set<Variable> result = new THashSet<Variable>();
+    public Collection<String> getConnectionPointURIs(ReadGraph graph, Variable component, Resource relationType)
+            throws DatabaseException {
+        Set<String> result = new THashSet<String>();
         for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, predicate, relationType)) {
-            result.add(desc.getVariable(graph));
+            result.add(desc.getURI(graph));
         }
         return result;
     }
-    
+
     @Override
-    public Collection<String> getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException {
-        Set<String> result = new THashSet<String>();
+    public Collection<Variable> getConnectionPoints(ReadGraph graph, Variable component, Resource relationType)
+            throws DatabaseException {
+        Set<Variable> result = new THashSet<Variable>();
         for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, predicate, relationType)) {
-            result.add(desc.getURI(graph));
+            result.add(desc.getVariable(graph));
         }
         return result;
     }
 
     @Override
-    public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph, Resource relationType) throws DatabaseException {
+    public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph,
+            Variable component, Resource relationType) throws DatabaseException {
         return ConnectionBrowser.flatten(graph, component, predicate, relationType);
     }
 
+    @Override
+    public Collection<String> getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException {
+        throw new IllegalStateException();
+    }
+
+    @Override
+    public Collection<Variable> getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException {
+        throw new IllegalStateException();
+    }
+
+    @Override
+    public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph,
+            Resource relationType) throws DatabaseException {
+        throw new IllegalStateException();
+    }
+
+    @Override
+    public Connection2 getConnection2() {
+        return this;
+    }
+
 }
\ No newline at end of file
index d89026a79454e8e661a0967958f664460bc49085..fd4151b2e5f49e5d2ec95e9732c43800f0d03f93 100644 (file)
@@ -180,7 +180,7 @@ public class Functions {
                @Override
                public Object getValue(ReadGraph graph, Variable context) throws DatabaseException {
                        StandardGraphPropertyVariable variable = (StandardGraphPropertyVariable)context; 
-                       return new ConnectionImpl2(context.getParent(graph), variable.property.predicate);
+                       return new ConnectionImpl(context.getParent(graph), variable.property.predicate);
                }
 
                @Override
@@ -308,6 +308,82 @@ public class Functions {
                
        }
        
+    public static class StructuralChildMapOfResource extends ResourceRead<Map<String, Resource>> {
+
+        public StructuralChildMapOfResource(Resource resource) {
+            super(resource);
+        }
+
+        @Override
+        public Map<String, Resource> perform(ReadGraph graph) throws DatabaseException {
+            StructuralResource2 STR = StructuralResource2.getInstance(graph);
+            Resource type = graph.getPossibleType(resource, STR.Component);
+            if(type != null) {
+                Resource definition = graph.getPossibleObject(type, STR.IsDefinedBy);
+                if(definition != null) {
+                    Map<String, Resource> map = graph.syncRequest(new UnescapedChildMapOfResource(definition));
+                    if (!map.isEmpty())
+                        return map;
+                } 
+            }
+            Map<String, Resource> directChildren = graph.syncRequest(new UnescapedChildMapOfResource(resource));
+            return directChildren;
+        }
+
+    }
+
+    public static class StructuralChildMapOfResourceT extends ResourceRead<Map<String, Resource>> {
+
+        public StructuralChildMapOfResourceT(Resource resource) {
+            super(resource);
+        }
+
+        @Override
+        public Map<String, Resource> perform(ReadGraph graph) throws DatabaseException {
+            StructuralResource2 STR = StructuralResource2.getInstance(graph);
+            Resource definition = graph.getPossibleObject(resource, STR.IsDefinedBy);
+            if(definition != null) {
+                Map<String, Resource> map = graph.syncRequest(new UnescapedChildMapOfResource(definition));
+                if (!map.isEmpty())
+                    return map;
+            } 
+            return Collections.emptyMap();
+        }
+
+    }
+
+    static class StructuralRunChildMapOfResource extends ResourceRead<Map<String, Resource>> {
+
+        public StructuralRunChildMapOfResource(Resource resource) {
+            super(resource);
+        }
+
+        public Map<String, Resource> fromContext(ReadGraph graph, Resource context) throws DatabaseException {
+            return graph.sync(new StructuralChildMapOfResource(context));
+        }
+        
+        @Override
+        public Map<String, Resource> perform(ReadGraph graph) throws DatabaseException {
+
+            Layer0 L0 = Layer0.getInstance(graph);
+            SimulationResource SIMU = SimulationResource.getInstance(graph);
+            Resource model = graph.sync(new PossibleIndexRoot(resource));
+            if(graph.isInstanceOf(model, L0.RVIContext)) {
+                return fromContext(graph, model);
+            }
+            Resource configuration = graph.getPossibleObject(model, SIMU.HasConfiguration);
+            if(configuration != null) {
+                if(graph.isInstanceOf(configuration, L0.RVIContext)) {
+                    return fromContext(graph, configuration);
+                }
+            }
+            
+            return Collections.emptyMap();
+            
+        }
+        
+    }
+
        private static class SubstructureRequest extends VariableRead<List<SubstructureElement>> {
            public SubstructureRequest(Variable context) {
             super(context);
index 7a8eb715f26362fdc8726d680e3d485fd340d873..5c0e679c505a73ea1c48f3d7a20dda132521d924 100644 (file)
@@ -48,7 +48,7 @@ public class CompileStructuralValueRequest extends AbstractCompileStructuralValu
             sclContext.put("graph", oldGraph);
         }
     }
-    
+      
     public static Function1<Object, Object> compile(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException {
         return graph.syncRequest(new CompileStructuralValueRequest(s, o, p), TransientCacheListener.instance());
     }
index b404932e7a58c6d59bd98917c30dee81df36d788..6343be4a2c9298de9ca5abe2337a6fe8cff0e327 100644 (file)
@@ -21,5 +21,7 @@ public interface Connection {
        Collection<Variable> getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException;
        
        Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph, Resource relationType) throws DatabaseException;
-
+       
+       Connection2 getConnection2();
+       
 }
diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/Connection2.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/Connection2.java
new file mode 100644 (file)
index 0000000..0751ea2
--- /dev/null
@@ -0,0 +1,26 @@
+package org.simantics.structural2.variables;
+
+import java.util.Collection;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+
+public interface Connection2 {
+
+
+    /**
+     * Return absolute URIs of the connection points. An optional (may be null) relationType may be used
+     * to filter the returned connection points.
+     */
+    Collection<String> getConnectionPointURIs(ReadGraph graph, Variable component, Resource relationType) throws DatabaseException;
+    /**
+     * Return the connection points. An optional (may be null) relationType may be used
+     * to filter the returned connection points.
+     */
+    Collection<Variable> getConnectionPoints(ReadGraph graph, Variable component, Resource relationType) throws DatabaseException;
+    
+    Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph, Variable component, Resource relationType) throws DatabaseException;
+
+}
index b2b92039f87f4f35870c31ed0564c624a89cec75..4339049ecb95a673ec202ebbd038e1d99c660fdf 100644 (file)
@@ -36,7 +36,6 @@ import org.simantics.structural2.Functions.InterfaceResolution;
 import org.simantics.structural2.queries.ConnectionSet;
 import org.simantics.structural2.utils.StructuralUtils;
 import org.simantics.structural2.utils.StructuralUtils.StructuralComponentClass;
-import org.simantics.structural2.variables.StandardProceduralChildVariable.FixedConnection;
 import org.simantics.utils.datastructures.Pair;
 
 import gnu.trove.map.hash.THashMap;
@@ -338,14 +337,9 @@ public class ConnectionBrowser {
                
                Variable conn = child.getPossibleProperty(graph, cp);
             FixedConnection fc = (FixedConnection)conn.getValue(graph);
-            Set<VariableConnectionPointDescriptor> result = new THashSet<VariableConnectionPointDescriptor>(1+fc.cps.size());
+            Set<VariableConnectionPointDescriptor> result = new THashSet<VariableConnectionPointDescriptor>(1+fc.size());
             result.add(new ComponentConnectionDescriptor(child, cp));// (graph, STR, curConfiguration, "/" + c.name + "#" + conn.getName(graph)));
-            for(Pair<String,Resource> cpzz : fc.cps) {
-               if(cpzz.first == null) {
-                       throw new DatabaseException("Lifted connection was not resolved.");
-               }
-               result.add(new PairConnectionDescriptor(curConfiguration, cpzz));
-            }
+            fc.addConnectionDescriptors(graph, curConfiguration, result);
             return result;
             
         } else {
diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/FixedConnection.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/FixedConnection.java
new file mode 100644 (file)
index 0000000..3f5219e
--- /dev/null
@@ -0,0 +1,150 @@
+package org.simantics.structural2.variables;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.utils.datastructures.Pair;
+
+import gnu.trove.set.hash.THashSet;
+
+public class FixedConnection implements Connection, Connection2 {
+
+    final private Variable parent;
+    
+    final private Collection<Pair<String,Resource>> cps = new ArrayList<Pair<String,Resource>>();
+    
+    public FixedConnection(Variable parent) {
+        this.parent = parent;
+    }
+    
+    public void addAll(List<Pair<String,Resource>> cps) throws DatabaseException {
+        for(Pair<String,Resource> cp : cps) {
+            this.cps.add(cp);
+        }
+    }
+    
+    public int size() {
+        return cps.size();
+    }
+    
+    public void addConnectionDescriptors(ReadGraph graph, Variable curConfiguration, Collection<VariableConnectionPointDescriptor> result) throws DatabaseException {
+        for(Pair<String,Resource> cpzz : cps) {
+            // This is a connection to an interface terminal. It is handled by ConnectionBrowser in separate logic. Do not include it here.
+            if(cpzz.first == null) continue;
+            /*if(cpzz.first == null) {
+                String message = "Lifted connection was not resolved. Child = " + parent.getURI(graph);
+                throw new DatabaseException(message);
+            }*/
+            result.add(new PairConnectionDescriptor(curConfiguration, cpzz));
+        }
+    }
+    
+    @Override
+    public Collection<Variable> getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException {
+        return getConnectionPoints(graph, parent, relationType);
+    }
+    
+       @Override
+       public Collection<String> getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException {
+           return getConnectionPointURIs(graph, parent, relationType);
+               
+       }
+       
+       @Override
+       public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph, Resource relationType) throws DatabaseException {
+           return getConnectionPointDescriptors(graph, parent, relationType);
+       }
+
+    @Override
+       public int hashCode() {
+               final int prime = 31;
+               int result = 1;
+               result = prime * result + ((cps == null) ? 0 : cps.hashCode());
+               result = prime * result
+                               + ((parent == null) ? 0 : parent.hashCode());
+               return result;
+       }
+
+       @Override
+       public boolean equals(Object obj) {
+               if (this == obj)
+                       return true;
+               if (obj == null)
+                       return false;
+               if (getClass() != obj.getClass())
+                       return false;
+               FixedConnection other = (FixedConnection) obj;
+               if (cps == null) {
+                       if (other.cps != null)
+                               return false;
+               } else if (!cps.equals(other.cps))
+                       return false;
+               if (parent == null) {
+                       if (other.parent != null)
+                               return false;
+               } else if (!parent.equals(other.parent))
+                       return false;
+               return true;
+       }
+
+       @Override
+       public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph,
+               Variable parent, Resource relationType) throws DatabaseException {
+        Set<VariableConnectionPointDescriptor> result = new THashSet<VariableConnectionPointDescriptor>();
+        for(Pair<String,Resource> cp : cps) {
+            Variable component = cp.first == null ? parent : parent.getChild(graph, cp.first); 
+            Variable cp2 = component.getPossibleProperty(graph, cp.second);
+            if(cp2 != null)
+                result.addAll(ConnectionBrowser.flatten(graph, component, cp.second, relationType));
+            else
+                StandardProceduralChildVariable.LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
+        }
+        return result;
+       }
+       
+       @Override
+       public Collection<Variable> getConnectionPoints(ReadGraph graph, Variable parent, Resource relationType)
+               throws DatabaseException {
+        Set<Variable> result = new THashSet<Variable>();
+        for(Pair<String,Resource> cp : cps) {
+            Variable component = cp.first == null ? parent : parent.getChild(graph, cp.first); 
+            Variable cp2 = component.getPossibleProperty(graph, cp.second);
+            if(cp2 != null)
+                for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) {
+                    result.add(desc.getVariable(graph));
+                }
+            else
+                StandardProceduralChildVariable.LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
+        }
+        return result;
+       }
+       
+       @Override
+       public Collection<String> getConnectionPointURIs(ReadGraph graph, Variable parent, Resource relationType)
+               throws DatabaseException {
+        Set<String> result = new THashSet<String>();
+        for(Pair<String,Resource> cp : cps) {
+            Variable component = cp.first == null ? parent : parent.getChild(graph, cp.first);
+            Variable cp2 = component.getPossibleProperty(graph, cp.second);
+            if(cp2 != null)
+                for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) {
+                    result.add(desc.getURI(graph));
+                }
+            else
+                StandardProceduralChildVariable.LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
+        }
+        return result;
+       }
+
+    @Override
+    public Connection2 getConnection2() {
+        return this;
+    }
+       
+}
\ No newline at end of file
index f133adee02e3c783b7e7fe5b8dc12ef93a6a4d5a..13ef05145a818981c180b4dad865b17c6e983a57 100644 (file)
@@ -1,8 +1,5 @@
 package org.simantics.structural2.variables;
 
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.set.hash.THashSet;
-
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -39,9 +36,11 @@ import org.simantics.structural2.procedural.Terminal;
 import org.simantics.utils.datastructures.Pair;
 import org.slf4j.LoggerFactory;
 
+import gnu.trove.map.hash.THashMap;
+
 public class StandardProceduralChildVariable extends AbstractChildVariable {
 
-    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(StandardProceduralChildVariable.class);
+    static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(StandardProceduralChildVariable.class);
        /*
         * Extension points
         * 
@@ -64,103 +63,7 @@ public class StandardProceduralChildVariable extends AbstractChildVariable {
        final private Map<String, Variable> properties;
        final private List<Object> propertyIdentity;
        
-    public static class FixedConnection implements org.simantics.structural2.variables.Connection {
-
-               final public Collection<Pair<String,Resource>> cps = new ArrayList<Pair<String,Resource>>();
-        
-        final private Variable parent;
-        
-        public FixedConnection(Variable parent) {
-            this.parent = parent;
-        }
-        
-        @Override
-        public Collection<Variable> getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException {
-               
-               Set<Variable> result = new THashSet<Variable>();
-            for(Pair<String,Resource> cp : cps) {
-               Variable component = cp.first == null ? parent : parent.getChild(graph, cp.first); 
-               Variable cp2 = component.getPossibleProperty(graph, cp.second);
-               if(cp2 != null)
-                       for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) {
-                               result.add(desc.getVariable(graph));
-                       }
-                else
-                       LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
-            }
-            return result;
-            
-        }
-        
-               @Override
-               public Collection<String> getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException {
-                       
-               Set<String> result = new THashSet<String>();
-            for(Pair<String,Resource> cp : cps) {
-               Variable component = cp.first == null ? parent : parent.getChild(graph, cp.first); 
-               Variable cp2 = component.getPossibleProperty(graph, cp.second);
-               if(cp2 != null)
-                       for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) {
-                               result.add(desc.getURI(graph));
-                       }
-                else
-                       LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
-            }
-            return result;
-                       
-               }
-               
-               @Override
-               public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph, Resource relationType) throws DatabaseException {
-                       
-               Set<VariableConnectionPointDescriptor> result = new THashSet<VariableConnectionPointDescriptor>();
-            for(Pair<String,Resource> cp : cps) {
-               Variable component = cp.first == null ? parent : parent.getChild(graph, cp.first); 
-               Variable cp2 = component.getPossibleProperty(graph, cp.second);
-               if(cp2 != null)
-                       result.addAll(ConnectionBrowser.flatten(graph, component, cp.second, relationType));
-                else
-                       LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
-            }
-            return result;
-                       
-               }        
-
-        @Override
-               public int hashCode() {
-                       final int prime = 31;
-                       int result = 1;
-                       result = prime * result + ((cps == null) ? 0 : cps.hashCode());
-                       result = prime * result
-                                       + ((parent == null) ? 0 : parent.hashCode());
-                       return result;
-               }
-
-               @Override
-               public boolean equals(Object obj) {
-                       if (this == obj)
-                               return true;
-                       if (obj == null)
-                               return false;
-                       if (getClass() != obj.getClass())
-                               return false;
-                       FixedConnection other = (FixedConnection) obj;
-                       if (cps == null) {
-                               if (other.cps != null)
-                                       return false;
-                       } else if (!cps.equals(other.cps))
-                               return false;
-                       if (parent == null) {
-                               if (other.parent != null)
-                                       return false;
-                       } else if (!parent.equals(other.parent))
-                               return false;
-                       return true;
-               }
-
-    }
-    
-       public StandardProceduralChildVariable(ReadGraph graph, Variable parent, VariableNode node, String name, Resource type, List<Property> properties, Collection<Connection> conns) throws DatabaseException {
+    public StandardProceduralChildVariable(ReadGraph graph, Variable parent, VariableNode node, String name, Resource type, List<Property> properties, Collection<Connection> conns) throws DatabaseException {
                super(node);
                assert name != null;
         assert type != null;
@@ -242,7 +145,7 @@ public class StandardProceduralChildVariable extends AbstractChildVariable {
                                fc = new FixedConnection(parent);
                                map.put(p, fc);
                        }
-                       fc.cps.addAll(cps);             
+                       fc.addAll(cps);         
                    }
                }
                for(Map.Entry<Resource, FixedConnection> entry : map.entrySet()) {