From: Antti Villberg Date: Wed, 31 Oct 2018 05:02:45 +0000 (+0200) Subject: foobaz X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=3d1f8e3dbccff974e2f4e0ea5f8bc61ad136e194;p=simantics%2Fplatform.git foobaz Change-Id: I20803c442f025337535530211d638c75df5ccdb2 --- 3d1f8e3dbccff974e2f4e0ea5f8bc61ad136e194 diff --cc bundles/org.simantics.db.common/src/org/simantics/db/common/request/AdaptValue.java index 02877596b,02877596b..7daf9a5c3 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/request/AdaptValue.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/request/AdaptValue.java @@@ -1,13 -1,13 +1,13 @@@ package org.simantics.db.common.request; ++import org.simantics.db.ComputationalValue; ++import org.simantics.db.ConverterComputationalValue; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.utils.Functions; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.RuntimeDatabaseException; import org.simantics.layer0.Layer0; --import org.simantics.scl.reflection.ReflectionUtils; --import org.simantics.scl.reflection.ValueNotFoundException; import org.simantics.scl.runtime.function.FunctionImpl3; /** @@@ -20,7 -20,7 +20,7 @@@ public class AdaptValue extends Resourc super(resource); } -- private static final FunctionImpl3 functionApplication = new FunctionImpl3() { ++ public static final FunctionImpl3 functionApplication = new FunctionImpl3() { @Override public Object apply(ReadGraph graph, Resource resource, Object context) { @@@ -36,12 -36,12 +36,10 @@@ @Override public Object perform(ReadGraph graph) throws DatabaseException { String uri = graph.getURI(resource); -- try { -- if(Layer0.URIs.Functions_functionApplication.equals(uri)) return functionApplication; -- return ReflectionUtils.getValue(uri).getValue(); -- } catch (ValueNotFoundException e) { -- throw new DatabaseException("Couldn't adapt the value " + uri, e); -- } ++ if(Layer0.URIs.Functions_functionApplication.equals(uri)) return functionApplication; ++ ComputationalValue ev = graph.adapt(resource, ComputationalValue.class); ++ return ev.getValue(graph, resource); ++ } } diff --cc bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java index 3feb22e00,3feb22e00..61a312e9e --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java @@@ -45,6 -45,6 +45,7 @@@ import org.simantics.databoard.type.Dat import org.simantics.databoard.util.binary.BinaryFile; import org.simantics.databoard.util.binary.RandomAccessBinary; import org.simantics.db.AsyncReadGraph; ++import org.simantics.db.ComputationalValue; import org.simantics.db.DevelopmentKeys; import org.simantics.db.ExternalValueSupport; import org.simantics.db.ReadGraph; @@@ -181,7 -181,7 +182,6 @@@ import org.simantics.layer0.Layer0 import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.exceptions.SCLTypeParseException; import org.simantics.scl.reflection.ReflectionUtils; --import org.simantics.scl.reflection.ValueNotFoundException; import org.simantics.scl.runtime.function.Function3; import org.simantics.utils.DataContainer; import org.simantics.utils.Development; @@@ -6102,13 -6102,13 +6102,22 @@@ public class ReadGraphImpl implements A return getValue(r, binding); } } else if(types.contains(L0.ExternalValue)) { -- try { -- return (T)ReflectionUtils.getValue(getURI(r)).getValue(); -- } catch(ValueNotFoundException e) { -- throw new DatabaseException(e); -- } catch(ClassCastException e) { -- throw new DatabaseException(e); -- } ++ try { ++ ComputationalValue cv = adapt(r, ComputationalValue.class); ++ return cv.getValue(this, r); ++ //return (T)ReflectionUtils.getValue(getURI(r)).getValue(); ++// } catch(ValueNotFoundException e) { ++// throw new DatabaseException(e); ++ } catch(ClassCastException e) { ++ throw new DatabaseException(e); ++ } ++// try { ++// return (T)ReflectionUtils.getValue(getURI(r)).getValue(); ++// } catch(ValueNotFoundException e) { ++// throw new DatabaseException(e); ++// } catch(ClassCastException e) { ++// throw new DatabaseException(e); ++// } } else { Function3 function = requestValueFunction(r); diff --cc bundles/org.simantics.db.layer0/adapters.xml index 9e85e9a1b,9e85e9a1b..c2071e5c5 --- a/bundles/org.simantics.db.layer0/adapters.xml +++ b/bundles/org.simantics.db.layer0/adapters.xml @@@ -284,4 -284,4 +284,14 @@@ ++ ++ ++ ++ ++ ++ ++ ++ diff --cc bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/function/All.java index f93023b77,f93023b77..6f6f9b3b8 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/function/All.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/function/All.java @@@ -1186,16 -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 { diff --cc bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/AbstractExpressionCompilationRequest.java index d40f82d4d,d40f82d4d..21758a2e5 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/AbstractExpressionCompilationRequest.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/AbstractExpressionCompilationRequest.java @@@ -5,6 -5,6 +5,7 @@@ import java.util.List import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; ++import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.RuntimeDatabaseException; import org.simantics.db.request.Read; @@@ -226,9 -226,9 +227,9 @@@ implements Read compile(ReadGraph graph, Resource literal) throws DatabaseException { ++ return graph.syncRequest(new CompileResourceValueRequest(literal), ++ TransientCacheListener.>instance()); ++ } ++ @Override protected String getExpressionText(ReadGraph graph) throws DatabaseException { diff --cc bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/CompileValueRequest.java index e1804d790,e1804d790..1c82e32a4 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/CompileValueRequest.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/CompileValueRequest.java @@@ -66,6 -66,6 +66,23 @@@ public class CompileValueRequest extend } } ++ public static Function1 compile(ReadGraph graph, Resource component, Resource literal, Resource predicate) throws DatabaseException { ++ SCLContext sclContext = SCLContext.getCurrent(); ++ Object oldGraph = sclContext.get("graph"); ++ try { ++ Function1 exp = graph.syncRequest(new CompileValueRequest(component, literal, predicate), ++ TransientCacheListener.>instance()); ++ sclContext.put("graph", graph); ++ return exp; ++ } catch (DatabaseException e) { ++ throw (DatabaseException)e; ++ } catch (Throwable t) { ++ throw new DatabaseException(t); ++ } finally { ++ sclContext.put("graph", oldGraph); ++ } ++ } ++ @Override protected String getExpressionText(ReadGraph graph) throws DatabaseException { diff --cc bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyChildVariable.java index 6ee8a5384,6ee8a5384..89664698a --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyChildVariable.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyChildVariable.java @@@ -48,6 -48,6 +48,7 @@@ public class ProxyChildVariable extend } public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException { ++ System.err.println("other: " + other.getURI(graph) + " " + name ); Variable otherChild = other.getPossibleChild(graph, name); if(otherChild == null) return null; return create(base, this, otherChild, name); diff --cc bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyVariable.java index fb5ea925a,fb5ea925a..db28afed5 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyVariable.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyVariable.java @@@ -1,6 -1,6 +1,8 @@@ package org.simantics.db.layer0.variable; ++import java.util.ArrayList; import java.util.Collection; ++import java.util.Collections; import java.util.Set; import org.simantics.databoard.binding.Binding; @@@ -10,21 -10,21 +12,16 @@@ import org.simantics.db.ReadGraph import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.exception.DatabaseException; ++import org.simantics.db.layer0.request.PropertyInfo; import org.simantics.db.layer0.variable.RVI.RVIPart; ++import org.simantics.db.layer0.variable.Variables.Role; --/** -- * @deprecated this implementation is pretty much useless, it is too -- * straightforward and requires extenders to override pretty much -- * everything in it to work correctly. Do not use. -- * @see ValueProxyVariable -- */ --@Deprecated --public abstract class ProxyVariable implements Variable { ++public class ProxyVariable implements Variable { protected final Variable proxy; protected final Variable parent; -- public ProxyVariable(Variable proxy, Variable parent) { ++ public ProxyVariable(Variable parent, Variable proxy) { if (proxy == null) throw new NullPointerException("null proxy"); if (parent == null) @@@ -125,86 -125,86 +122,134 @@@ @Override public Variable getChild(ReadGraph graph, String name) throws DatabaseException { -- return proxy.getChild(graph, name); ++ Variable child = proxy.getChild(graph, name); ++ return ProxyVariables.tryToOwn(graph, this, child); } @Override public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException { -- return proxy.getPossibleChild(graph, name); ++ Variable child = proxy.getPossibleChild(graph, name); ++ return ProxyVariables.tryToOwn(graph, this, child); } @Override public Variable getProperty(ReadGraph graph, String name) throws DatabaseException { -- return proxy.getProperty(graph, name); ++ Variable property = proxy.getProperty(graph, name); ++ return ProxyVariables.tryToOwn(graph, this, property); } @Override -- public Variable getProperty(ReadGraph graph, Resource property) throws DatabaseException { -- return proxy.getProperty(graph, property); ++ public Variable getProperty(ReadGraph graph, Resource property_) throws DatabaseException { ++ Variable property = proxy.getProperty(graph, property_); ++ return ProxyVariables.tryToOwn(graph, this, property); } @Override public Variable getPossibleProperty(ReadGraph graph, String name) throws DatabaseException { -- return proxy.getPossibleProperty(graph, name); ++ Variable property = proxy.getPossibleProperty(graph, name); ++ return ProxyVariables.tryToOwn(graph, this, property); } @Override -- public Variable getPossibleProperty(ReadGraph graph, Resource property) throws DatabaseException { -- return proxy.getPossibleProperty(graph, property); ++ public Variable getPossibleProperty(ReadGraph graph, Resource property_) throws DatabaseException { ++ Variable property = proxy.getPossibleProperty(graph, property_); ++ return ProxyVariables.tryToOwn(graph, this, property); } @Override public Collection browseChildren(ReadGraph graph) throws DatabaseException { -- return proxy.browseChildren(graph); ++ Collection children = proxy.browseChildren(graph); ++ if(children.isEmpty()) return Collections.emptyList(); ++ Collection result = new ArrayList<>(); ++ for(Variable child : children) { ++ Variable owned = ProxyVariables.tryToOwn(graph, this, child); ++ if(owned != null) result.add(owned); ++ } ++ return result; } @Override public Collection getChildren(ReadGraph graph) throws DatabaseException { -- return proxy.getChildren(graph); ++ Collection children = proxy.getChildren(graph); ++ if(children.isEmpty()) return Collections.emptyList(); ++ Collection result = new ArrayList<>(); ++ for(Variable child : children) { ++ Variable owned = ProxyVariables.tryToOwn(graph, this, child); ++ if(owned != null) result.add(owned); ++ } ++ return result; } @Override public Collection browseProperties(ReadGraph graph) throws DatabaseException { -- return proxy.browseProperties(graph); ++ Collection children = proxy.browseProperties(graph); ++ if(children.isEmpty()) return Collections.emptyList(); ++ Collection result = new ArrayList<>(); ++ for(Variable child : children) { ++ Variable owned = ProxyVariables.tryToOwn(graph, this, child); ++ if(owned != null) result.add(owned); ++ } ++ return result; } @Override public Collection getProperties(ReadGraph graph) throws DatabaseException { -- return proxy.getProperties(graph); ++ Collection children = proxy.getProperties(graph); ++ if(children.isEmpty()) return Collections.emptyList(); ++ Collection result = new ArrayList<>(); ++ for(Variable child : children) { ++ Variable owned = ProxyVariables.tryToOwn(graph, this, child); ++ if(owned != null) result.add(owned); ++ } ++ return result; } @Override public Collection getProperties(ReadGraph graph, String classification) throws DatabaseException { -- return proxy.getProperties(graph, classification); ++ Collection children = proxy.getProperties(graph, classification); ++ if(children.isEmpty()) return Collections.emptyList(); ++ Collection result = new ArrayList<>(); ++ for(Variable child : children) { ++ Variable owned = ProxyVariables.tryToOwn(graph, this, child); ++ if(owned != null) result.add(owned); ++ } ++ return result; } @Override public Collection getProperties(ReadGraph graph, Resource classification) throws DatabaseException { -- return proxy.getProperties(graph, classification); ++ Collection children = proxy.getProperties(graph, classification); ++ if(children.isEmpty()) return Collections.emptyList(); ++ Collection result = new ArrayList<>(); ++ for(Variable child : children) { ++ Variable owned = ProxyVariables.tryToOwn(graph, this, child); ++ if(owned != null) result.add(owned); ++ } ++ return result; } @Override public Variable browse(ReadGraph graph, String suffix) throws DatabaseException { -- if (suffix.isEmpty()) -- return this; -- return proxy.browse(graph, suffix); ++ Variable variable = proxy.browse(graph, suffix); ++ return ProxyVariables.tryToOwn(graph, this, variable); } @Override public Variable browsePossible(ReadGraph graph, String suffix) throws DatabaseException { -- if (suffix.isEmpty()) -- return this; -- return proxy.browsePossible(graph, suffix); ++ Variable variable = proxy.browsePossible(graph, suffix); ++ return ProxyVariables.tryToOwn(graph, this, variable); } @Override public Variable browse(ReadGraph graph, Resource config) throws DatabaseException { -- return proxy.browse(graph, config); ++ Variable variable = proxy.browse(graph, config); ++ return ProxyVariables.tryToOwn(graph, this, variable); } @Override public Variable browsePossible(ReadGraph graph, Resource config) throws DatabaseException { -- return proxy.browsePossible(graph, config); ++ Variable variable = proxy.browsePossible(graph, config); ++ return ProxyVariables.tryToOwn(graph, this, variable); } @Override @@@ -227,20 -227,20 +272,16 @@@ return proxy.getURI(graph); } -- @Override -- public abstract int hashCode(); -- -- @Override -- public abstract boolean equals(Object obj); -- @Override public Variable resolve(ReadGraph graph, RVIPart part) throws DatabaseException { -- return proxy.resolve(graph, part); ++ Variable variable = proxy.resolve(graph, part); ++ return ProxyVariables.tryToOwn(graph, this, variable); } @Override public Variable resolvePossible(ReadGraph graph, RVIPart part) throws DatabaseException { -- return proxy.resolvePossible(graph, part); ++ Variable variable = proxy.resolvePossible(graph, part); ++ return ProxyVariables.tryToOwn(graph, this, variable); } @Override @@@ -336,4 -336,4 +377,56 @@@ public Resource getPossibleType(ReadGraph graph, Resource baseType) throws DatabaseException { return proxy.getPossibleType(graph, baseType); } ++ ++ @Override ++ public PropertyInfo getPropertyInfo(ReadGraph graph) throws DatabaseException { ++ return proxy.getPropertyInfo(graph); ++ } ++ ++ @Override ++ public Resource getIndexRoot(ReadGraph graph) throws DatabaseException { ++ return proxy.getIndexRoot(graph); ++ } ++ ++ @Override ++ public Role getRole(ReadGraph graph) throws DatabaseException { ++ return proxy.getRole(graph); ++ } ++ ++ @Override ++ public Role getPossibleRole(ReadGraph graph) throws DatabaseException { ++ return proxy.getPossibleRole(graph); ++ } ++ ++ @Override ++ public int hashCode() { ++ final int prime = 31; ++ int result = 1; ++ result = prime * result + ((parent == null) ? 0 : parent.hashCode()); ++ result = prime * result + ((proxy == null) ? 0 : proxy.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; ++ ProxyVariable other = (ProxyVariable) obj; ++ if (parent == null) { ++ if (other.parent != null) ++ return false; ++ } else if (!parent.equals(other.parent)) ++ return false; ++ if (proxy == null) { ++ if (other.proxy != null) ++ return false; ++ } else if (!proxy.equals(other.proxy)) ++ return false; ++ return true; ++ } ++ } diff --cc bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyVariables.java index db552650b,db552650b..8fa9bf426 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyVariables.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyVariables.java @@@ -4,8 -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"); diff --cc bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/VariableDebugger.java index 9c02bbe2a,9c02bbe2a..08342593f --- a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/VariableDebugger.java +++ b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/VariableDebugger.java @@@ -694,7 -694,7 +694,7 @@@ public class VariableDebugger extends C content.append("\n"); content.append("\n"); content.append("\n"); -- content.append("\n"); ++ content.append("\n"); content.append("\n"); content.append("
URI").append(uri).append("
RVI").append(rviString).append("
Class").append(var.getClass().getCanonicalName()).append("
Class").append(var.getClass()).append("
Solver node").append(node).append("
\n"); content.append("\n"); diff --cc bundles/org.simantics.document.base.ontology/graph/Components.pgraph index 5384db0b2,5384db0b2..d3372b12c --- a/bundles/org.simantics.document.base.ontology/graph/Components.pgraph +++ b/bundles/org.simantics.document.base.ontology/graph/Components.pgraph @@@ -31,9 -31,9 +31,9 @@@ sclAttribute = COMPONENTS.sclAttribute L0.SCLValue.expression %command L0.default false --DOC.SCL : L0.SCLModule -- L0.SCLModule.definition _ : L0.String -- @L0.loadString "scl/Code.scl" ++//DOC.SCL : L0.SCLModule ++// L0.SCLModule.definition _ : L0.String ++// @L0.loadString "scl/Code.scl" DOC.scl : L0.Template @template %subject %property %expression %valueType @@@ -49,10 -49,10 +49,13 @@@ DOC.sclValue : L0.Templat L0.HasValueType %valueType DOC.SCLValue compileDocumentSCLValueExpression self""" "Variable -> String" @L0.assert L0.ConvertsToValueWith DOC.Functions.sclValue : L0.ExternalValue ++DOC.HandlerSCLValue -- COMPONENTS.Component.manualOrdinal --> L0.Integer -- Documentation.Properties.state -- L0.Asserts _ : L0.Assertion ++ @L0.sclAssertion Documentation.Properties.state "stateVariable self" "Variable" ++/* L0.Asserts _ : L0.Assertion L0.HasPredicate Documentation.Properties.state -- L0.HasObject FUNCTIONS.state ++ L0.HasObject FUNCTIONS.state*/ >-- Documentation.Properties.session L0.Asserts _ : L0.Assertion L0.HasPredicate Documentation.Properties.session diff --cc bundles/org.simantics.document.base.ontology/graph/Properties.pgraph index d502e3d2f,d502e3d2f..e1c71fe97 --- a/bundles/org.simantics.document.base.ontology/graph/Properties.pgraph +++ b/bundles/org.simantics.document.base.ontology/graph/Properties.pgraph @@@ -52,7 -52,7 +52,7 @@@ PROPERTIES.model "Variable" PROPERTIES.primitiveProperties "String" ++ ==> "DocumentProperties" PROPERTIES.exists @defAttribute L0.Value diff --cc bundles/org.simantics.document.server/adapters.xml index 7a1476025,7a1476025..76622e38b --- a/bundles/org.simantics.document.server/adapters.xml +++ b/bundles/org.simantics.document.server/adapters.xml @@@ -15,4 -15,4 +15,14 @@@ ++ ++ ++ ++ ++ ++ ++ ++ diff --cc bundles/org.simantics.document.server/scl/Document/All.scl index 4db639f5b,4db639f5b..c6967b559 --- a/bundles/org.simantics.document.server/scl/Document/All.scl +++ b/bundles/org.simantics.document.server/scl/Document/All.scl @@@ -2,6 -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 -> () @@@ -110,6 -110,6 +113,9 @@@ importJava "org.simantics.document.serv dataDefinitions :: Variable -> [DataDefinition] ++ @JavaName "dataDefinitions" ++ computeDataDefinitions :: Variable -> [DataDefinition] ++ emptyOnClick :: () -> AbstractEventHandler writeEventHandler :: Variable -> (Variable -> (String -> Maybe String) -> String) -> AbstractEventHandler @@@ -139,6 -139,6 +145,8 @@@ compileDocumentSCLValueExpression :: Variable -> String ++ primitiveProperties :: DocumentProperties ++ propertyValueCached :: Serializable a => Typeable a => Variable -> String -> a propertyValueCached var prop = propertyValueCached_ var prop binding diff --cc bundles/org.simantics.document.server/src/org/simantics/document/server/DocumentServerUtils.java index 5e1f5cc30,5e1f5cc30..95fa78da8 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/DocumentServerUtils.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/DocumentServerUtils.java @@@ -19,12 -19,12 +19,10 @@@ import org.simantics.db.layer0.variable 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 -127,7 +125,7 @@@ public static Variable getPossibleOtherConnectionPoint(ReadGraph graph, Variable connectionPoint, Connection conn) throws DatabaseException { -- Collection descs = conn.getConnectionPointDescriptors(graph, null); ++ Collection descs = conn.getConnectionPointDescriptors(graph, connectionPoint.getParent(graph), null); if(descs.size() != 2) return null; for(VariableConnectionPointDescriptor desc : descs) { @@@ -141,7 -141,7 +139,7 @@@ public static Variable getPossibleChildConnectionPoint(ReadGraph graph, Variable connectionPoint, Connection conn) throws DatabaseException { -- Collection descs = conn.getConnectionPointDescriptors(graph, null); ++ Collection descs = conn.getConnectionPointDescriptors(graph, connectionPoint.getParent(graph), null); if(descs.size() != 2) return null; DocumentationResource DOC = DocumentationResource.getInstance(graph); @@@ -174,7 -174,7 +172,7 @@@ public static Variable getPossibleCommandTriggerConnectionPoint(ReadGraph graph, Variable connectionPoint, Connection conn) throws DatabaseException { -- Collection cpts = conn.getConnectionPoints(graph, null); ++ Collection cpts = conn.getConnectionPoints(graph, connectionPoint.getParent(graph), null); Variable result = null; @@@ -208,9 -208,9 +206,14 @@@ 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 -294,81 +297,72 @@@ return variable.getProperties(graph, DOC.Document_AttributeRelation); } -- public static class AttributesRequest extends VariableRead>> { -- -- public AttributesRequest(Variable variable) { -- super(variable); -- } -- -- @Override -- public Pair> perform(ReadGraph graph) throws DatabaseException { -- ArrayList statics = new ArrayList(); -- 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>(staticContent, Collections.emptyList()); -- -- } -- -- JSONObject computeStatic(ReadGraph graph, Variable variable, ArrayList 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 exceptions = (Map)DocumentServerUtils.getValue(graph, attrib); -- -- List errorList = object.getJSONField(NodeRequest.ERRORS); -- if(errorList == null) -- errorList = new ArrayList(); -- -- for (Map.Entry 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 errorList = object.getJSONField(NodeRequest.ERRORS); -- if(errorList == null) -- errorList = new ArrayList(); -- -- String errorMessage = NodeRequestUtils.formatErrorMessage(name, t); -- -- errorList.add(errorMessage); -- object.addJSONField(NodeRequest.ERRORS, errorList); -- } -- -- } -- -- return object; -- -- } -- -- } ++ public static class AttributesRequest extends VariableRead { ++ ++ 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 exceptions = (Map)statics.getValue(graph, variable, name);//(Map)DocumentServerUtils.getValue(graph, attrib); ++ ++ List errorList = object.getJSONField(NodeRequest.ERRORS); ++ if(errorList == null) ++ errorList = new ArrayList(); ++ ++ for (Map.Entry 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 errorList = object.getJSONField(NodeRequest.ERRORS); ++ if(errorList == null) ++ errorList = new ArrayList(); ++ ++ String errorMessage = NodeRequestUtils.formatErrorMessage(name, t); ++ ++ errorList.add(errorMessage); ++ object.addJSONField(NodeRequest.ERRORS, errorList); ++ } ++ ++ } ++ ++ return object; ++ ++ } ++ ++ } public static Collection getDynamicAttributes(ReadGraph graph, final DocumentationResource DOC, Variable variable) throws DatabaseException { -- Pair> 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); diff --cc bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java index aabe7b29f,aabe7b29f..f0a7b4f47 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java @@@ -15,7 -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 -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 -42,15 +41,14 @@@ import org.simantics.db.layer0.scl.SCLD 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 -107,21 +105,6 @@@ public class Functions private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(Functions.class); -- private static class PrimitivePropertyStatementsProcedure implements AsyncProcedure { -- -- 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 map) { @@@ -229,11 -229,11 +212,42 @@@ }; ++ static class StandardDocumentProperties implements DocumentProperties { ++ ++ @Override ++ public Collection getKeys(ReadGraph graph, Variable context) throws DatabaseException { ++ ++ DocumentationResource DOC = DocumentationResource.getInstance(graph); ++ StandardGraphPropertyVariable asd = new StandardGraphPropertyVariable(graph, context, DOC.Properties_primitiveProperties); ++ Map 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 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 -257,7 +271,7 @@@ }; -- 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 -269,13 +283,17 @@@ } 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 -283,36 +301,45 @@@ } -- public Collection getChildren(ReadGraph graph) throws DatabaseException { -- -- Collection 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 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 -1200,6 +1227,8 @@@ 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(property, binding)); } @@@ -1252,11 -1252,11 +1281,11 @@@ return true; } } else { -- Variable parentCp = graph.sync(new UnaryRead(conn) { ++ Variable parentCp = graph.sync(new BinaryRead(widget, conn) { @Override public Variable perform(ReadGraph graph) throws DatabaseException { DocumentationResource DOC = DocumentationResource.getInstance(graph); -- Collection descs = parameter.getConnectionPointDescriptors(graph, null); ++ Collection descs = parameter2.getConnectionPointDescriptors(graph, parameter, null); for(VariableConnectionPointDescriptor desc : descs) { if (DOC.Relations_partN.equals(desc.getConnectionPointResource(graph))) { diff --cc bundles/org.simantics.document.server/src/org/simantics/document/server/request/NodeRequest.java index d9418db99,d9418db99..2622c2994 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/NodeRequest.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/NodeRequest.java @@@ -17,51 -17,51 +17,18 @@@ public class NodeRequest extends Variab 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> 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 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 errorList = new ArrayList<>(); ++ @SuppressWarnings("unchecked") ++ @Override ++ public JSONObject perform(ReadGraph graph) throws DatabaseException { -- if(dynamicContent.containsKey(ERRORS)) -- errorList.addAll((List)dynamicContent.get(ERRORS)); ++ long s = System.nanoTime(); -- if(staticContent.getJSONField(ERRORS) != null) -- errorList.addAll((List)staticContent.getJSONField(ERRORS)); -- -- result.addJSONField(ERRORS, errorList); -- } ++ JSONObject staticContent = graph.syncRequest(new AttributesRequest(variable)); if(DocumentRequest.PROFILE) { long dura = System.nanoTime()-s; @@@ -69,8 -69,8 +36,9 @@@ System.err.println("NodeRequest " + System.identityHashCode(this) + " in " + 1e-6*dura + "ms. " + variable.getURI(graph)); } } -- -- return result; ++ ++ ++ return staticContent; } diff --cc bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLHandlerValueRequest.java index 4a4164303,4a4164303..01017efff --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLHandlerValueRequest.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLHandlerValueRequest.java @@@ -8,12 -8,12 +8,14 @@@ import org.simantics.db.ReadGraph import org.simantics.db.Resource; import org.simantics.db.common.procedure.adapter.TransientCacheListener; import org.simantics.db.common.request.IndexRoot; ++import org.simantics.db.common.request.PossibleTypedParent; ++import org.simantics.db.common.request.UnaryRead; import org.simantics.db.exception.DatabaseException; --import org.simantics.db.layer0.request.VariableRead; import org.simantics.db.layer0.scl.AbstractExpressionCompilationContext; import org.simantics.db.layer0.scl.AbstractExpressionCompilationRequest; import org.simantics.db.layer0.util.RuntimeEnvironmentRequest2; import org.simantics.db.layer0.variable.Variable; ++import org.simantics.document.base.ontology.DocumentationResource; import org.simantics.document.server.request.ServerSCLHandlerValueRequest.CompilationContext; import org.simantics.layer0.Layer0; import org.simantics.scl.compiler.elaboration.expressions.EApply; @@@ -37,7 -37,7 +39,6 @@@ import org.simantics.utils.datastructur public class ServerSCLHandlerValueRequest extends AbstractExpressionCompilationRequest { -- private final Variable context; private final Pair componentTypeAndRoot; private final Resource literal; protected String possibleExpectedValueType; @@@ -52,18 -52,18 +53,21 @@@ } } -- private ServerSCLHandlerValueRequest(Variable context, Pair componentTypeAndRoot, Resource literal, String possibleExpectedValueType) { -- assert(literal != null); -- this.context = context; -- this.literal = literal; -- this.componentTypeAndRoot = componentTypeAndRoot; -- this.possibleExpectedValueType = possibleExpectedValueType; ++ private ServerSCLHandlerValueRequest(Pair componentTypeAndRoot, Resource literal, String possibleExpectedValueType) { ++ assert(literal != null); ++ this.literal = literal; ++ this.componentTypeAndRoot = componentTypeAndRoot; ++ this.possibleExpectedValueType = possibleExpectedValueType; } -- public ServerSCLHandlerValueRequest(ReadGraph graph, Variable context) throws DatabaseException { -- this(context, getComponentTypeAndRoot(graph, context), context.getRepresents(graph), resolveExpectedValueType(graph, context)); -- } ++ public ServerSCLHandlerValueRequest(ReadGraph graph, Variable context) throws DatabaseException { ++ this(getComponentTypeAndRoot(graph, context), context.getRepresents(graph), resolveExpectedValueType(graph, context.getPredicateResource(graph))); ++ } ++ public ServerSCLHandlerValueRequest(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException { ++ this(getComponentTypeAndRoot(graph, s), o, resolveExpectedValueType(graph, p)); ++ } ++ private static Pair getComponentTypeAndRoot(ReadGraph graph, Variable property) throws DatabaseException { Variable parent = property.getParent(graph); Resource represents = parent.getRepresents(graph); @@@ -79,6 -79,6 +83,21 @@@ return Pair.make(parent.getType(graph), root); } ++ private static Pair getComponentTypeAndRoot(ReadGraph graph, Resource component) throws DatabaseException { ++ if(component != null) { ++ Resource type = graph.syncRequest(new FindPossibleComponentTypeRequest(component)); ++ if(type != null) { ++ Resource root = graph.syncRequest(new IndexRoot(type)); ++ return Pair.make(type, root); ++ } else { ++ Resource doc = graph.syncRequest(new PossibleTypedParent(component, DocumentationResource.getInstance(graph).Document)); ++ Resource componentType = graph.getSingleType(doc); ++ Resource root = graph.syncRequest(new IndexRoot(doc)); ++ return Pair.make(componentType, root); ++ } ++ } ++ throw new IllegalStateException(); ++ } public static List getEffects(ReadGraph graph, Variable context) throws DatabaseException { try { @@@ -108,6 -108,6 +127,14 @@@ } } ++ public static Function1 compile(ReadGraph graph, Variable context) throws DatabaseException { ++ return graph.syncRequest(new ServerSCLHandlerValueRequest(graph, context), TransientCacheListener.>instance()); ++ } ++ ++ public static Function1 compile(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException { ++ return graph.syncRequest(new ServerSCLHandlerValueRequest(graph, s, o, p), TransientCacheListener.>instance()); ++ } ++ @Override protected String getExpressionText(ReadGraph graph) throws DatabaseException { @@@ -127,30 -127,30 +154,23 @@@ @Override protected CompilationContext getCompilationContext(ReadGraph graph) throws DatabaseException { -- -- return graph.syncRequest(new VariableRead(context) { -- -- @Override -- public CompilationContext perform(ReadGraph graph) throws DatabaseException { -- -- Pair parameter = getComponentTypeAndRoot(graph, variable); -- RuntimeEnvironment runtimeEnvironment = graph.syncRequest(getRuntimeEnvironmentRequest(parameter.first, parameter.second)); -- -- Map propertyMap = -- graph.syncRequest(new ReadComponentTypeInterfaceRequest(parameter.first, runtimeEnvironment.getEnvironment()), -- TransientCacheListener.>instance()); ++ ++ return graph.syncRequest(new UnaryRead,CompilationContext>(componentTypeAndRoot) { ++ ++ @Override ++ public CompilationContext perform(ReadGraph graph) throws DatabaseException { ++ ++ RuntimeEnvironment runtimeEnvironment = graph.syncRequest(getRuntimeEnvironmentRequest(parameter.first, parameter.second)); ++ Map propertyMap = ++ graph.syncRequest(new ReadComponentTypeInterfaceRequest(parameter.first, runtimeEnvironment.getEnvironment()), ++ TransientCacheListener.>instance()); ++ return new CompilationContext(runtimeEnvironment, propertyMap); ++ ++ ++ } ++ ++ }); --// Map result = new HashMap(propertyMap); --// for(DataDefinition dd : Functions.dataDefinitions(graph, variable)) { --// result.put(dd.target, null); --// } -- -- return new CompilationContext(runtimeEnvironment, propertyMap); -- -- } -- -- }); -- } @Override @@@ -227,44 -227,44 +247,22 @@@ return super.getExpectedType(graph, context); } -- @Override -- public int hashCode() { -- final int prime = 31; -- int result = 1; -- result = prime * result + ((context == null) ? 0 : context.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; -- ServerSCLHandlerValueRequest other = (ServerSCLHandlerValueRequest) obj; -- if (context == null) { -- if (other.context != null) -- return false; -- } else if (!context.equals(other.context)) -- return false; -- return true; -- } ++ @Override ++ public int hashCode() { ++ return 31*(31*getClass().hashCode() + literal.hashCode()) + componentTypeAndRoot.hashCode(); ++ } --// @Override --// public int hashCode() { --// return 31*(31*getClass().hashCode() + literal.hashCode()) + componentTypeAndRoot.hashCode(); --// } --// --// @Override --// public boolean equals(Object obj) { --// if(this == obj) --// return true; --// if(obj == null || obj.getClass() != getClass()) --// return false; --// ServerSCLHandlerValueRequest other = (ServerSCLHandlerValueRequest)obj; --// return literal.equals(other.literal) && componentTypeAndRoot.equals(other.componentTypeAndRoot); --// } ++ @Override ++ public boolean equals(Object obj) { ++ if (this == obj) ++ return true; ++ if (obj == null) ++ return false; ++ if (getClass() != obj.getClass()) ++ return false; ++ ServerSCLHandlerValueRequest other = (ServerSCLHandlerValueRequest) obj; ++ return literal.equals(other.literal) && componentTypeAndRoot.equals(other.componentTypeAndRoot); ++ } ++ } diff --cc bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java index f9181d271,f9181d271..2f363a151 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java @@@ -7,12 -7,12 +7,14 @@@ import org.simantics.db.ReadGraph import org.simantics.db.Resource; import org.simantics.db.common.procedure.adapter.TransientCacheListener; import org.simantics.db.common.request.IndexRoot; ++import org.simantics.db.common.request.PossibleTypedParent; import org.simantics.db.common.request.UnaryRead; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.scl.AbstractExpressionCompilationContext; import org.simantics.db.layer0.scl.AbstractExpressionCompilationRequest; import org.simantics.db.layer0.util.RuntimeEnvironmentRequest2; import org.simantics.db.layer0.variable.Variable; ++import org.simantics.document.base.ontology.DocumentationResource; import org.simantics.document.server.request.ServerSCLValueRequest.CompilationContext; import org.simantics.layer0.Layer0; import org.simantics.scl.compiler.common.names.Name; @@@ -64,7 -64,7 +66,11 @@@ public class ServerSCLValueRequest exte } public ServerSCLValueRequest(ReadGraph graph, Variable context) throws DatabaseException { -- this(getComponentTypeAndRoot(graph, context), context.getRepresents(graph), resolveExpectedValueType(graph, context)); ++ this(getComponentTypeAndRoot(graph, context), context.getRepresents(graph), resolveExpectedValueType(graph, context.getPredicateResource(graph))); ++ } ++ ++ public ServerSCLValueRequest(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException { ++ this(getComponentTypeAndRoot(graph, s), o, resolveExpectedValueType(graph, p)); } private static Pair getComponentTypeAndRoot(ReadGraph graph, Variable property) throws DatabaseException { @@@ -82,6 -82,6 +88,30 @@@ return Pair.make(parent.getType(graph), root); } ++ private static Pair getComponentTypeAndRoot(ReadGraph graph, Resource component) throws DatabaseException { ++ if(component != null) { ++ Resource type = graph.syncRequest(new FindPossibleComponentTypeRequest(component)); ++ if(type != null) { ++ Resource root = graph.syncRequest(new IndexRoot(type)); ++ // System.err.println("getComponentTypeAndRoot3 " + graph.getPossibleURI(component) + " => " + graph.getPossibleURI(type) + " " + graph.getPossibleURI(root)); ++ return Pair.make(type, root); ++ } else { ++ Resource doc = graph.syncRequest(new PossibleTypedParent(component, DocumentationResource.getInstance(graph).Document)); ++ if(doc != null) { ++ Resource componentType = graph.getSingleType(doc); ++ Resource root = graph.syncRequest(new IndexRoot(doc)); ++ return Pair.make(componentType, root); ++ } else { ++ System.err.println("component = " + component); ++ Resource root = graph.syncRequest(new IndexRoot(component)); ++// Resource componentType = graph.getSingleType(doc); ++ return Pair.make(null, root); ++ } ++ } ++ } ++ throw new IllegalStateException(); ++ } ++ public static Object compileAndEvaluate(ReadGraph graph, Variable context) throws DatabaseException { SCLContext sclContext = SCLContext.getCurrent(); Object oldGraph = sclContext.get("graph"); @@@ -102,6 -102,6 +132,10 @@@ return graph.syncRequest(new ServerSCLValueRequest(graph, context), TransientCacheListener.>instance()); } ++ public static Function1 compile(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException { ++ return graph.syncRequest(new ServerSCLValueRequest(graph, s, o, p), TransientCacheListener.>instance()); ++ } ++ @Override protected String getExpressionText(ReadGraph graph) throws DatabaseException { diff --cc bundles/org.simantics.layer0/graph/Layer0SCL.pgraph index 783f4f401,783f4f401..ec31d0350 --- a/bundles/org.simantics.layer0/graph/Layer0SCL.pgraph +++ b/bundles/org.simantics.layer0/graph/Layer0SCL.pgraph @@@ -10,7 -10,7 +10,12 @@@ L0.Functions.entityLabel : L0.ExternalV L0.Functions.listResources : L0.ExternalValue L0.Functions.resourceAsValue : L0.ExternalValue L0.Functions.functionApplication : L0.ExternalValue ++ ++// This was replaced by L0.Functions.sclValue to make things more uniform L0.Functions.computeExpression : L0.ExternalValue ++ @L0.tag L0.Deprecated ++ ++L0.Functions.sclValue : L0.ExternalValue L0.Functions.composedPropertyValue : L0.ExternalValue L0.Functions.standardValueAccessor : L0.ExternalValue diff --cc bundles/org.simantics.layer0/graph/Layer0Values.pgraph index c36cf60e5,16f01a7be..358aaa7e9 --- a/bundles/org.simantics.layer0/graph/Layer0Values.pgraph +++ b/bundles/org.simantics.layer0/graph/Layer0Values.pgraph @@@ -28,7 -28,7 +28,7 @@@ L0.SCLValue -- L0.SCLValue.expression --> L0.String -- L0.SCLValue.environment --> L0.SCLValue.Environment -- L0.SCLValueType.validator ==> "Variable -> String" ++ ++ ++ ++ ++ diff --cc bundles/org.simantics.structural2/src/org/simantics/structural2/ConnectionImpl2.java index e4b898a6b,e4b898a6b..c6384ed64 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/ConnectionImpl2.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/ConnectionImpl2.java @@@ -26,11 -26,11 +26,9 @@@ import gnu.trove.set.hash.THashSet public class ConnectionImpl2 implements Connection { -- private final Variable component; private final Resource predicate; -- public ConnectionImpl2(Variable component, Resource predicate) { -- this.component = component; ++ public ConnectionImpl2(Resource predicate) { this.predicate = predicate; } @@@ -61,15 -61,15 +59,22 @@@ @Override public Collection getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException { -- Set result = new THashSet(); -- for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, predicate, relationType)) { -- result.add(desc.getVariable(graph)); -- } -- return result; ++ throw new UnsupportedOperationException(); } @Override public Collection getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException { ++ throw new UnsupportedOperationException(); ++ } ++ ++ @Override ++ public Collection getConnectionPointDescriptors(ReadGraph graph, Resource relationType) throws DatabaseException { ++ throw new UnsupportedOperationException(); ++ } ++ ++ @Override ++ public Collection getConnectionPointURIs(ReadGraph graph, Variable component, Resource relationType) ++ throws DatabaseException { Set result = new THashSet(); for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, predicate, relationType)) { result.add(desc.getURI(graph)); @@@ -78,7 -78,7 +83,18 @@@ } @Override -- public Collection getConnectionPointDescriptors(ReadGraph graph, Resource relationType) throws DatabaseException { ++ public Collection getConnectionPoints(ReadGraph graph, Variable component, Resource relationType) ++ throws DatabaseException { ++ Set result = new THashSet(); ++ for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, predicate, relationType)) { ++ result.add(desc.getVariable(graph)); ++ } ++ return result; ++ } ++ ++ @Override ++ public Collection getConnectionPointDescriptors(ReadGraph graph, ++ Variable component, Resource relationType) throws DatabaseException { return ConnectionBrowser.flatten(graph, component, predicate, relationType); } diff --cc bundles/org.simantics.structural2/src/org/simantics/structural2/Functions.java index f429fdc91,f429fdc91..96b1c8820 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/Functions.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/Functions.java @@@ -180,7 -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,6 +308,82 @@@ } ++ public static class StructuralChildMapOfResource extends ResourceRead> { ++ ++ public StructuralChildMapOfResource(Resource resource) { ++ super(resource); ++ } ++ ++ @Override ++ public Map 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 map = graph.syncRequest(new UnescapedChildMapOfResource(definition)); ++ if (!map.isEmpty()) ++ return map; ++ } ++ } ++ Map directChildren = graph.syncRequest(new UnescapedChildMapOfResource(resource)); ++ return directChildren; ++ } ++ ++ } ++ ++ public static class StructuralChildMapOfResourceT extends ResourceRead> { ++ ++ public StructuralChildMapOfResourceT(Resource resource) { ++ super(resource); ++ } ++ ++ @Override ++ public Map perform(ReadGraph graph) throws DatabaseException { ++ StructuralResource2 STR = StructuralResource2.getInstance(graph); ++ Resource definition = graph.getPossibleObject(resource, STR.IsDefinedBy); ++ if(definition != null) { ++ Map map = graph.syncRequest(new UnescapedChildMapOfResource(definition)); ++ if (!map.isEmpty()) ++ return map; ++ } ++ return Collections.emptyMap(); ++ } ++ ++ } ++ ++ static class StructuralRunChildMapOfResource extends ResourceRead> { ++ ++ public StructuralRunChildMapOfResource(Resource resource) { ++ super(resource); ++ } ++ ++ public Map fromContext(ReadGraph graph, Resource context) throws DatabaseException { ++ return graph.sync(new StructuralChildMapOfResource(context)); ++ } ++ ++ @Override ++ public Map 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> { public SubstructureRequest(Variable context) { super(context); diff --cc bundles/org.simantics.structural2/src/org/simantics/structural2/procedural/Terminal.java index 5f07295a7,5f07295a7..96c26fa05 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/procedural/Terminal.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/procedural/Terminal.java @@@ -7,6 -7,6 +7,8 @@@ public class Terminal implements Connec public final Resource relation; public Terminal(String component, Resource relation) { ++ assert(component != null); ++ assert(relation != null); this.component = component; this.relation = relation; } diff --cc bundles/org.simantics.structural2/src/org/simantics/structural2/scl/CompileStructuralValueRequest.java index 3b54c0f62,3b54c0f62..b947e995d --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/CompileStructuralValueRequest.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/CompileStructuralValueRequest.java @@@ -48,6 -48,6 +48,10 @@@ public class CompileStructuralValueRequ sclContext.put("graph", oldGraph); } } ++ ++ public static Function1 compile(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException { ++ return graph.syncRequest(new CompileStructuralValueRequest(s, o, p), TransientCacheListener.>instance()); ++ } @Override protected String getExpressionText(ReadGraph graph) diff --cc bundles/org.simantics.structural2/src/org/simantics/structural2/variables/Connection.java index b404932e7,b404932e7..f62606996 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/Connection.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/Connection.java @@@ -7,7 -7,7 +7,7 @@@ import org.simantics.db.Resource import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.variable.Variable; --public interface Connection { ++public interface Connection extends Connection2 { /** * Return absolute URIs of the connection points. An optional (may be null) relationType may be used @@@ -21,5 -21,5 +21,5 @@@ Collection getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException; Collection getConnectionPointDescriptors(ReadGraph graph, Resource relationType) throws DatabaseException; -- ++ } diff --cc bundles/org.simantics.structural2/src/org/simantics/structural2/variables/ConnectionBrowser.java index b2b92039f,b2b92039f..4339049ec --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/ConnectionBrowser.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/ConnectionBrowser.java @@@ -36,7 -36,7 +36,6 @@@ import org.simantics.structural2.Functi 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 -338,14 +337,9 @@@ public class ConnectionBrowser Variable conn = child.getPossibleProperty(graph, cp); FixedConnection fc = (FixedConnection)conn.getValue(graph); -- Set result = new THashSet(1+fc.cps.size()); ++ Set result = new THashSet(1+fc.size()); result.add(new ComponentConnectionDescriptor(child, cp));// (graph, STR, curConfiguration, "/" + c.name + "#" + conn.getName(graph))); -- for(Pair 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 --cc bundles/org.simantics.structural2/src/org/simantics/structural2/variables/StandardProceduralChildVariable.java index f133adee0,f133adee0..13ef05145 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/StandardProceduralChildVariable.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/StandardProceduralChildVariable.java @@@ -1,8 -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 -39,9 +36,11 @@@ import org.simantics.structural2.proced 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 -64,103 +63,7 @@@ final private Map properties; final private List propertyIdentity; -- public static class FixedConnection implements org.simantics.structural2.variables.Connection { -- -- final public Collection> cps = new ArrayList>(); -- -- final private Variable parent; -- -- public FixedConnection(Variable parent) { -- this.parent = parent; -- } -- -- @Override -- public Collection getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException { -- -- Set result = new THashSet(); -- for(Pair 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 getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException { -- -- Set result = new THashSet(); -- for(Pair 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 getConnectionPointDescriptors(ReadGraph graph, Resource relationType) throws DatabaseException { -- -- Set result = new THashSet(); -- for(Pair 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 properties, Collection conns) throws DatabaseException { ++ public StandardProceduralChildVariable(ReadGraph graph, Variable parent, VariableNode node, String name, Resource type, List properties, Collection conns) throws DatabaseException { super(node); assert name != null; assert type != null; @@@ -242,7 -242,7 +145,7 @@@ fc = new FixedConnection(parent); map.put(p, fc); } -- fc.cps.addAll(cps); ++ fc.addAll(cps); } } for(Map.Entry entry : map.entrySet()) {