]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Removed jsonValues since there already is Data/Json 50/450/8
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 20 Apr 2017 10:54:20 +0000 (13:54 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Sun, 23 Apr 2017 13:22:04 +0000 (16:22 +0300)
A more generic possibleFromDynamic.

Alternative method modelling.

Combined multiple Antti's commits

Get rid of uses of gnu.trove2

refs #7156

instantiateUnder function property for types

refs #7157

SCLDropAction

refs #7158

Empty RVI literal in L0

refs #7159

possibleFromDynamic coersion function in Simantics/DB

refs #7160

jsonValues parsing function into Simantics/DB

refs #7161

Generic instantiation action based on instantiateUnder

refs #7162

ModelBrowser.handleDrop action should be run in SWT thread

refs #7163

RVI support in Simantics/Variables

refs #7164

Variables change

Change-Id: If21b623c27b660a9b6bc150c905f0360b15d08a0

20 files changed:
bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/ModelBrowser.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/function/All.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/UnescapedMethodMapOfResource.java [new file with mode: 0644]
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/Variables.java
bundles/org.simantics.layer0/graph.tg
bundles/org.simantics.layer0/graph/Layer0.pgraph
bundles/org.simantics.layer0/graph/Layer0Literals.pgraph
bundles/org.simantics.layer0/graph/Layer0SCL.pgraph
bundles/org.simantics.layer0/src/org/simantics/layer0/Layer0.java
bundles/org.simantics.modeling.ontology/graph.tg
bundles/org.simantics.modeling.ontology/graph/ModelingViewpoint.pgraph
bundles/org.simantics.modeling.ontology/src/org/simantics/modeling/ModelingResources.java
bundles/org.simantics.modeling/adapters.xml
bundles/org.simantics.modeling/scl/Simantics/Action.scl [new file with mode: 0644]
bundles/org.simantics.modeling/scl/Simantics/All.scl
bundles/org.simantics.modeling/src/org/simantics/modeling/SCLDropAction.java [new file with mode: 0644]
bundles/org.simantics.scl.db/META-INF/MANIFEST.MF
bundles/org.simantics.scl.db/scl/Simantics/DB.scl
bundles/org.simantics.scl.db/scl/Simantics/Variables.scl
bundles/org.simantics.scl.db/src/org/simantics/scl/db/SCLFunctions.java

index eb48bdd3c76807e15d811f5379957f065d7a9d6a..c8744f2634e3fb3bc1ce911672c2b2de6fe93616 100644 (file)
@@ -19,7 +19,9 @@ import java.util.Map;
 import java.util.Set;
 
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.IWorkbenchSite;
+import org.simantics.Simantics;
 import org.simantics.browsing.ui.NodeContext;
 import org.simantics.browsing.ui.common.ErrorLogger;
 import org.simantics.browsing.ui.model.InvalidContribution;
@@ -33,7 +35,6 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.ResourceNotFoundException;
 import org.simantics.db.procedure.Procedure;
 import org.simantics.db.request.Read;
-import org.simantics.ui.SimanticsUI;
 import org.simantics.utils.ui.ExceptionUtils;
 
 public class ModelBrowser extends GraphExplorerComposite {
@@ -62,10 +63,10 @@ public class ModelBrowser extends GraphExplorerComposite {
 
     protected static Set<String> loadBrowseContexts(final Set<String> browseContexts) {
         try {
-            return SimanticsUI.getSession().syncRequest(new Read<Set<String>>() {
+            return Simantics.getSession().syncRequest(new Read<Set<String>>() {
                 @Override
                 public Set<String> perform(ReadGraph graph) throws DatabaseException {
-                    Collection<Resource> browseContextResources = new ArrayList<Resource>(browseContexts.size());
+                    Collection<Resource> browseContextResources = new ArrayList<>(browseContexts.size());
                     for (String browseContext : browseContexts) {
                         try {
                             browseContextResources.add(graph.getResource(browseContext));
@@ -77,7 +78,7 @@ public class ModelBrowser extends GraphExplorerComposite {
                         }
                     }
                     Collection<Resource> allBrowseContextResources = BrowseContext.findSubcontexts(graph, browseContextResources);
-                    Set<String> result = new HashSet<String>();
+                    Set<String> result = new HashSet<>();
                     for (Resource r : allBrowseContextResources)
                         result.add(graph.getURI(r));
                     return result;
@@ -99,10 +100,10 @@ public class ModelBrowser extends GraphExplorerComposite {
         this.hideComparatorSelector = true;
         this.hideViewpointSelector = true;
 
-        SimanticsUI.getSession().asyncRequest(new ReadRequest() {
+        Simantics.getSession().asyncRequest(new ReadRequest() {
             @Override
             public void run(ReadGraph graph) throws DatabaseException { 
-                ArrayList<Resource> browseContexts = new ArrayList<Resource>();
+                ArrayList<Resource> browseContexts = new ArrayList<>();
                 for (String uri : _browseContexts) {
                     Resource browseContext = graph.getPossibleResource(uri);
                     if (browseContext != null)
@@ -122,7 +123,7 @@ public class ModelBrowser extends GraphExplorerComposite {
         if (target == null)
             return;
 
-        SimanticsUI.getSession().asyncRequest(new Read<Runnable>() {
+        Simantics.getSession().asyncRequest(new Read<Runnable>() {
             @Override
             public Runnable perform(ReadGraph graph) throws DatabaseException {
                 if (dndBrowseContext == null)
@@ -132,8 +133,10 @@ public class ModelBrowser extends GraphExplorerComposite {
         }, new Procedure<Runnable>() {
             @Override
             public void execute(Runnable result) {
-                if (result != null)
-                    result.run();
+                Display.getDefault().asyncExec(() -> {
+                    if (!Display.getCurrent().isDisposed() && result != null)
+                        result.run();
+                });
             }
 
             @Override
index 6a144165247732a36e1d47aa08240c5fbf9c0f86..08ed3edf2650873f316c8ceb1228bcf89e1afee1 100644 (file)
@@ -3,6 +3,7 @@ package org.simantics.db.layer0.function;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -41,6 +42,7 @@ import org.simantics.db.common.validation.L0Validations;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.DoesNotContainValueException;
 import org.simantics.db.exception.NoSingleResultException;
+import org.simantics.db.exception.RuntimeDatabaseException;
 import org.simantics.db.layer0.exception.MissingVariableValueException;
 import org.simantics.db.layer0.exception.PendingVariableException;
 import org.simantics.db.layer0.exception.VariableException;
@@ -48,6 +50,7 @@ import org.simantics.db.layer0.request.PossibleURI;
 import org.simantics.db.layer0.request.PropertyInfo;
 import org.simantics.db.layer0.request.PropertyInfoRequest;
 import org.simantics.db.layer0.request.UnescapedAssertedPropertyMapOfResource;
+import org.simantics.db.layer0.request.UnescapedMethodMapOfResource;
 import org.simantics.db.layer0.request.UnescapedPropertyMapOfResource;
 import org.simantics.db.layer0.scl.CompileResourceValueRequest;
 import org.simantics.db.layer0.scl.CompileValueRequest;
@@ -78,8 +81,10 @@ import org.simantics.db.service.UndoRedoSupport;
 import org.simantics.issues.ontology.IssueResource;
 import org.simantics.layer0.Layer0;
 import org.simantics.scl.reflection.annotations.SCLValue;
+import org.simantics.scl.runtime.SCLContext;
 import org.simantics.scl.runtime.function.Function4;
 import org.simantics.scl.runtime.function.FunctionImpl1;
+import org.simantics.scl.runtime.function.FunctionImpl2;
 import org.simantics.simulator.variable.exceptions.NodeManagerException;
 import org.simantics.utils.Development;
 import org.simantics.utils.datastructures.Pair;
@@ -596,6 +601,43 @@ public class All {
                
        };
        
+    @SCLValue(type = "VariableMap")
+       public static VariableMap methodsPropertyDomainProperties = new VariableMapImpl() {
+       
+               @Override
+               public Variable getVariable(ReadGraph graph, Variable context, String name) throws DatabaseException {
+                       Variable parent = context.getParent(graph);
+                       Resource container = parent.getPossibleRepresents(graph);
+                       Map<String,Resource> methods = graph.syncRequest(new UnescapedMethodMapOfResource(container));
+                       Resource predicate = methods.get(name);
+                       if(predicate != null) {
+                               Layer0 L0 = Layer0.getInstance(graph);
+                               PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(L0.Entity_method));
+                               Resource value = graph.getSingleObject(container, predicate);
+                               return new StandardGraphPropertyVariable(context, null, container, info, value);
+                       }
+                       return null;
+               }
+
+               @Override
+               public Map<String, Variable> getVariables(ReadGraph graph, Variable context, Map<String, Variable> map) throws DatabaseException {
+                       Variable parent = context.getParent(graph);
+                       Resource container = parent.getPossibleRepresents(graph);
+                       Map<String,Resource> methods = graph.syncRequest(new UnescapedMethodMapOfResource(container));
+                       for(Map.Entry<String, Resource> entry : methods.entrySet()) {
+                               String name = entry.getKey();
+                               Resource predicate = entry.getValue();
+                               Layer0 L0 = Layer0.getInstance(graph);
+                               PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(L0.Entity_method));
+                               Resource value = graph.getSingleObject(container, predicate);
+                               if(map == null) map = new HashMap<>();
+                               map.put(name, new StandardGraphPropertyVariable(context, null, container, info, value));
+                       }
+                       return map;
+               }
+               
+       };
+
        public static Variable getStandardPropertyDomainPropertyVariableFromValue(ReadGraph graph, Variable context, String name) throws DatabaseException {
 
                if(context instanceof StandardGraphPropertyVariable) {
@@ -1581,4 +1623,28 @@ public class All {
                return parent.node.support.manager.getPropertyURI(parent.node.node, node);
        }
     
+
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> a")
+    public static Object defaultInstantiateUnder(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {
+        return new FunctionImpl2<Resource, Resource, Resource>() {
+            public Resource apply(Resource container, Resource type) {
+                try {
+                    WriteGraph graph = (WriteGraph)SCLContext.getCurrent().get("graph");
+
+                    Layer0 L0 = Layer0.getInstance(graph);
+                    CommonDBUtils.selectClusterSet(graph, container);
+                    Resource result = graph.newResource();
+                    String name = NameUtils.findFreshInstanceName(graph, type, container);
+                    graph.claim(result, L0.InstanceOf, type);
+                    graph.addLiteral(result, L0.HasName, L0.NameOf, name, Bindings.STRING);
+                    graph.claim(container, L0.ConsistsOf, L0.PartOf, result);
+
+                    return result;
+                } catch (DatabaseException e) {
+                    throw new RuntimeDatabaseException(e);
+                }
+            }
+        };
+    }
+
 }
\ No newline at end of file
diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/UnescapedMethodMapOfResource.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/UnescapedMethodMapOfResource.java
new file mode 100644 (file)
index 0000000..31cacdc
--- /dev/null
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.layer0.request;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.ResourceRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.layer0.Layer0;
+
+import gnu.trove.map.hash.THashMap;
+
+public class UnescapedMethodMapOfResource extends ResourceRead<Map<String, Resource>> {
+
+       public UnescapedMethodMapOfResource(Resource resource) {
+           super(resource);
+       }
+
+       @Override
+       public Map<String,Resource> perform(ReadGraph graph) throws DatabaseException {
+
+               Layer0 L0 = Layer0.getInstance(graph);
+               Collection<Resource> predicates = graph.getPredicates(resource); 
+        THashMap<String, Resource> result = new THashMap<String, Resource>(predicates.size());
+               for(Resource predicate : predicates) {
+                       if(graph.isSubrelationOf(predicate, L0.HasMethod)) {
+                               String name = graph.getPossibleRelatedValue(predicate, L0.HasName, Bindings.STRING);
+                               if(name != null) {
+                               if (result.put(name, predicate) != null)
+                                       System.err.println(this + ": The database resource $" + resource.getResourceId() + " contains siblings with the same name " + name + " (resource=$" + predicate.getResourceId() +").");
+                               }
+                       }
+               }
+               return result;
+               
+       }
+       
+}
index 06050adf7417f275f2329ca90f1543ec8b161f38..5fb0636a08dec5e41a616b863c58bbb7fbbaa4df 100644 (file)
@@ -18,6 +18,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
+import org.simantics.databoard.Databoard;
 import org.simantics.databoard.binding.Binding;
 import org.simantics.databoard.binding.mutable.Variant;
 import org.simantics.databoard.type.Datatype;
@@ -26,6 +27,7 @@ import org.simantics.databoard.util.URIStringUtils;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.RequestProcessor;
 import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
 import org.simantics.db.common.request.PossibleIndexRoot;
 import org.simantics.db.common.request.TernaryRead;
 import org.simantics.db.common.utils.Logger;
@@ -803,5 +805,13 @@ final public class Variables {
                return new SCLValueAccessor(getValue1, getValue2, setValue2, setValue3, getDatatype);
        }
 
-    
+    public static void setRVIProperty(WriteGraph graph, Variable variable, RVI rvi) throws DatabaseException {
+        Layer0 L0 = Layer0.getInstance(graph);
+        Binding rviBinding = graph.getService(Databoard.class).getBindingUnchecked( RVI.class );
+        Resource predicate = variable.getPredicateResource(graph);
+        Resource subject = variable.getParent(graph).getRepresents(graph);
+        graph.deny(subject, predicate);
+        graph.claimLiteral(subject, predicate, L0.RVI, rvi, rviBinding);
+    }
+
 }
index c072a1509ea33d52a41a360843a67308acb38783..053b27ddf0ce810a043ef0ef3a2a70e024891bc6 100644 (file)
Binary files a/bundles/org.simantics.layer0/graph.tg and b/bundles/org.simantics.layer0/graph.tg differ
index 482f606fcb77d838e8a5ae4067e209bfc6d1d691..ec2048acbd40d158762430d95b9b0a0e8a78167f 100644 (file)
@@ -35,6 +35,15 @@ L0.Entity : L0.Type
     @L0.property L0.HasNext
     >-- L0.Entity.published --> L0.Boolean <R L0.HasProperty : L0.FunctionalRelation
       L0.readOnly true
+    >-- L0.Entity.methods
+    @L0.assert L0.Entity.methods
+      _ : L0.Value
+    
+L0.Entity.methods --> L0.Value <R L0.HasProperty : L0.FunctionalRelation
+  L0.domainProperties L0.Functions.methodsPropertyDomainProperties
+  
+L0.Entity.method <R L0.HasProperty : L0.FunctionalRelation
+    
 L0.Type <T L0.Entity
     L0.HasDescription "All types are instances of this type."
     >-- L0.Asserts --> L0.Assertion <R L0.IsComposedOf
@@ -46,6 +55,8 @@ L0.Type <T L0.Entity
     @L0.property L0.HasPropertyDefinition        
     @L0.property L0.Asserts
     @L0.property L0.Inherits
+    >-- L0.Type.instantiateUnder ==> "Resource -> Resource -> <WriteGraph> Resource" <R L0.HasMethod : L0.FunctionalRelation
+    @L0.assert L0.Type.instantiateUnder L0.Functions.defaultInstantiateUnder
 L0.Assertion <T L0.Entity
     L0.HasDescription "The statement modelled by an assertion is implied for all instances of the asserting type."
     >-- L0.HasPredicate --> L0.Relation <R L0.IsRelatedTo : L0.TotalFunction
@@ -95,6 +106,9 @@ L0.HasProperty <R L0.IsComposedOf : L0.PropertyRelation
     L0.InverseOf L0.PropertyOf
     L0.HasRange L0.Value
     
+L0.HasMethod <R L0.DependsOn
+    L0.InverseOf L0.MethodOf
+    L0.HasRange L0.Value
     
 // Libraries
 L0.IndexRootType <T L0.Type
index 09f4781feb77eca4ad75a86eeeafe463a8f1b789..329cfa12dc7576c302420de57bd1586b1517466f 100644 (file)
@@ -79,6 +79,8 @@ L0.RevisionId <T L0.Literal
 
 L0.RVI <T L0.Literal
     @L0.assert L0.HasDataType ${ parts : ( | ResourceRVIPart { role : |CHILD|PROPERTY, resource : Long(unit="resource") } | StringRVIPart { role : |CHILD|PROPERTY, string : String } | GuidRVIPart { role : |CHILD|PROPERTY, guid : { mostSignificantPart : Long , leastSignificantPart : Long }  } ) [] }
+
+L0.EmptyRVI = { parts = [] } : L0.RVI
    
 // Constant literals   
 L0.True = true
index 30e3885f439f2e971bcf5fc2dcbe53738e844b01..88e081701957e78fef70711179b413fdd67f1d1c 100644 (file)
@@ -23,6 +23,8 @@ L0.Functions.standardChildDomainChildren : L0.ExternalValue
   L0.HasValueType "VariableMap"
 L0.Functions.standardPropertyDomainChildren : L0.ExternalValue
   L0.HasValueType "VariableMap"
+L0.Functions.methodsPropertyDomainProperties : L0.ExternalValue
+  L0.HasValueType "VariableMap"
 L0.Functions.standardClassifications : L0.Function
   L0.HasValueType "[String]"
 
@@ -60,3 +62,6 @@ L0.SCLModule <T L0.Entity
 L0.entityReplacer ==> "Resource -> Resource -> <WriteGraph> ()" <R L0.HasProperty : L0.FunctionalRelation
     L0.HasDescription """Used for defining an SCL function that knows how to copy the contents from one entity instance to another when both instances are known to be of the same type.
 The first resource parameter is the source entity that will be used to replace the target entity which is defined by the second resource parameter."""
+
+L0.Functions.defaultInstantiateUnder : L0.Function
+    L0.HasValueType "Resource -> Resource -> <WriteGraph> Resource"
index 2ea58b89cf78b46fab593e6a15df777c029d694a..5467995bb7f600390cf61bb07ae603f7d22e296c 100644 (file)
@@ -55,12 +55,17 @@ public class Layer0 {
     public final Resource DomainOf;
     public final Resource Double;
     public final Resource DoubleArray;
+    public final Resource EmptyRVI;
     public final Resource Entity;
     public final Resource Entity_ClusterConstraint;
     public final Resource Entity_PropertyConstraint;
     public final Resource Entity_RelationConstraint;
     public final Resource Entity_URIConstraint;
     public final Resource Entity_ValueConstraint;
+    public final Resource Entity_method;
+    public final Resource Entity_method_Inverse;
+    public final Resource Entity_methods;
+    public final Resource Entity_methods_Inverse;
     public final Resource Entity_published;
     public final Resource Entity_published_Inverse;
     public final Resource Enumeration;
@@ -77,10 +82,12 @@ public class Layer0 {
     public final Resource Functions_clusterValidator;
     public final Resource Functions_composedPropertyValue;
     public final Resource Functions_computeExpression;
+    public final Resource Functions_defaultInstantiateUnder;
     public final Resource Functions_entityLabel;
     public final Resource Functions_functionApplication;
     public final Resource Functions_hasStandardResource;
     public final Resource Functions_listResources;
+    public final Resource Functions_methodsPropertyDomainProperties;
     public final Resource Functions_numberInputValidator;
     public final Resource Functions_propertyValidator;
     public final Resource Functions_relationValidator;
@@ -116,6 +123,7 @@ public class Layer0 {
     @Deprecated public final Resource HasElement;
     public final Resource HasLabel;
     public final Resource HasLabel_Inverse;
+    public final Resource HasMethod;
     public final Resource HasName;
     public final Resource HasNext;
     public final Resource HasObject;
@@ -170,6 +178,7 @@ public class Layer0 {
     public final Resource Literal_LongValidator;
     public final Resource Long;
     public final Resource LongArray;
+    public final Resource MethodOf;
     public final Resource Migration;
     public final Resource MigrationSequence;
     public final Resource MigrationStep;
@@ -256,6 +265,8 @@ public class Layer0 {
     public final Resource True;
     public final Resource Type;
     public final Resource TypeWithIdentifier;
+    public final Resource Type_instantiateUnder;
+    public final Resource Type_instantiateUnder_Inverse;
     public final Resource URI;
     public final Resource Value;
     public final Resource Variant;
@@ -348,12 +359,17 @@ public class Layer0 {
         public static final String DomainOf = "http://www.simantics.org/Layer0-1.1/DomainOf";
         public static final String Double = "http://www.simantics.org/Layer0-1.1/Double";
         public static final String DoubleArray = "http://www.simantics.org/Layer0-1.1/DoubleArray";
+        public static final String EmptyRVI = "http://www.simantics.org/Layer0-1.1/EmptyRVI";
         public static final String Entity = "http://www.simantics.org/Layer0-1.1/Entity";
         public static final String Entity_ClusterConstraint = "http://www.simantics.org/Layer0-1.1/Entity/ClusterConstraint";
         public static final String Entity_PropertyConstraint = "http://www.simantics.org/Layer0-1.1/Entity/PropertyConstraint";
         public static final String Entity_RelationConstraint = "http://www.simantics.org/Layer0-1.1/Entity/RelationConstraint";
         public static final String Entity_URIConstraint = "http://www.simantics.org/Layer0-1.1/Entity/URIConstraint";
         public static final String Entity_ValueConstraint = "http://www.simantics.org/Layer0-1.1/Entity/ValueConstraint";
+        public static final String Entity_method = "http://www.simantics.org/Layer0-1.1/Entity/method";
+        public static final String Entity_method_Inverse = "http://www.simantics.org/Layer0-1.1/Entity/method/Inverse";
+        public static final String Entity_methods = "http://www.simantics.org/Layer0-1.1/Entity/methods";
+        public static final String Entity_methods_Inverse = "http://www.simantics.org/Layer0-1.1/Entity/methods/Inverse";
         public static final String Entity_published = "http://www.simantics.org/Layer0-1.1/Entity/published";
         public static final String Entity_published_Inverse = "http://www.simantics.org/Layer0-1.1/Entity/published/Inverse";
         public static final String Enumeration = "http://www.simantics.org/Layer0-1.1/Enumeration";
@@ -370,10 +386,12 @@ public class Layer0 {
         public static final String Functions_clusterValidator = "http://www.simantics.org/Layer0-1.1/Functions/clusterValidator";
         public static final String Functions_composedPropertyValue = "http://www.simantics.org/Layer0-1.1/Functions/composedPropertyValue";
         public static final String Functions_computeExpression = "http://www.simantics.org/Layer0-1.1/Functions/computeExpression";
+        public static final String Functions_defaultInstantiateUnder = "http://www.simantics.org/Layer0-1.1/Functions/defaultInstantiateUnder";
         public static final String Functions_entityLabel = "http://www.simantics.org/Layer0-1.1/Functions/entityLabel";
         public static final String Functions_functionApplication = "http://www.simantics.org/Layer0-1.1/Functions/functionApplication";
         public static final String Functions_hasStandardResource = "http://www.simantics.org/Layer0-1.1/Functions/hasStandardResource";
         public static final String Functions_listResources = "http://www.simantics.org/Layer0-1.1/Functions/listResources";
+        public static final String Functions_methodsPropertyDomainProperties = "http://www.simantics.org/Layer0-1.1/Functions/methodsPropertyDomainProperties";
         public static final String Functions_numberInputValidator = "http://www.simantics.org/Layer0-1.1/Functions/numberInputValidator";
         public static final String Functions_propertyValidator = "http://www.simantics.org/Layer0-1.1/Functions/propertyValidator";
         public static final String Functions_relationValidator = "http://www.simantics.org/Layer0-1.1/Functions/relationValidator";
@@ -409,6 +427,7 @@ public class Layer0 {
         @Deprecated public static final String HasElement = "http://www.simantics.org/Layer0-1.1/HasElement";
         public static final String HasLabel = "http://www.simantics.org/Layer0-1.1/HasLabel";
         public static final String HasLabel_Inverse = "http://www.simantics.org/Layer0-1.1/HasLabel/Inverse";
+        public static final String HasMethod = "http://www.simantics.org/Layer0-1.1/HasMethod";
         public static final String HasName = "http://www.simantics.org/Layer0-1.1/HasName";
         public static final String HasNext = "http://www.simantics.org/Layer0-1.1/HasNext";
         public static final String HasObject = "http://www.simantics.org/Layer0-1.1/HasObject";
@@ -463,6 +482,7 @@ public class Layer0 {
         public static final String Literal_LongValidator = "http://www.simantics.org/Layer0-1.1/Literal/LongValidator";
         public static final String Long = "http://www.simantics.org/Layer0-1.1/Long";
         public static final String LongArray = "http://www.simantics.org/Layer0-1.1/LongArray";
+        public static final String MethodOf = "http://www.simantics.org/Layer0-1.1/MethodOf";
         public static final String Migration = "http://www.simantics.org/Layer0-1.1/Migration";
         public static final String MigrationSequence = "http://www.simantics.org/Layer0-1.1/MigrationSequence";
         public static final String MigrationStep = "http://www.simantics.org/Layer0-1.1/MigrationStep";
@@ -549,6 +569,8 @@ public class Layer0 {
         public static final String True = "http://www.simantics.org/Layer0-1.1/True";
         public static final String Type = "http://www.simantics.org/Layer0-1.1/Type";
         public static final String TypeWithIdentifier = "http://www.simantics.org/Layer0-1.1/TypeWithIdentifier";
+        public static final String Type_instantiateUnder = "http://www.simantics.org/Layer0-1.1/Type/instantiateUnder";
+        public static final String Type_instantiateUnder_Inverse = "http://www.simantics.org/Layer0-1.1/Type/instantiateUnder/Inverse";
         public static final String URI = "http://www.simantics.org/Layer0-1.1/URI";
         public static final String Value = "http://www.simantics.org/Layer0-1.1/Value";
         public static final String Variant = "http://www.simantics.org/Layer0-1.1/Variant";
@@ -651,12 +673,17 @@ public class Layer0 {
         DomainOf = getResourceOrNull(graph, URIs.DomainOf);
         Double = getResourceOrNull(graph, URIs.Double);
         DoubleArray = getResourceOrNull(graph, URIs.DoubleArray);
+        EmptyRVI = getResourceOrNull(graph, URIs.EmptyRVI);
         Entity = getResourceOrNull(graph, URIs.Entity);
         Entity_ClusterConstraint = getResourceOrNull(graph, URIs.Entity_ClusterConstraint);
         Entity_PropertyConstraint = getResourceOrNull(graph, URIs.Entity_PropertyConstraint);
         Entity_RelationConstraint = getResourceOrNull(graph, URIs.Entity_RelationConstraint);
         Entity_URIConstraint = getResourceOrNull(graph, URIs.Entity_URIConstraint);
         Entity_ValueConstraint = getResourceOrNull(graph, URIs.Entity_ValueConstraint);
+        Entity_method = getResourceOrNull(graph, URIs.Entity_method);
+        Entity_method_Inverse = getResourceOrNull(graph, URIs.Entity_method_Inverse);
+        Entity_methods = getResourceOrNull(graph, URIs.Entity_methods);
+        Entity_methods_Inverse = getResourceOrNull(graph, URIs.Entity_methods_Inverse);
         Entity_published = getResourceOrNull(graph, URIs.Entity_published);
         Entity_published_Inverse = getResourceOrNull(graph, URIs.Entity_published_Inverse);
         Enumeration = getResourceOrNull(graph, URIs.Enumeration);
@@ -673,10 +700,12 @@ public class Layer0 {
         Functions_clusterValidator = getResourceOrNull(graph, URIs.Functions_clusterValidator);
         Functions_composedPropertyValue = getResourceOrNull(graph, URIs.Functions_composedPropertyValue);
         Functions_computeExpression = getResourceOrNull(graph, URIs.Functions_computeExpression);
+        Functions_defaultInstantiateUnder = getResourceOrNull(graph, URIs.Functions_defaultInstantiateUnder);
         Functions_entityLabel = getResourceOrNull(graph, URIs.Functions_entityLabel);
         Functions_functionApplication = getResourceOrNull(graph, URIs.Functions_functionApplication);
         Functions_hasStandardResource = getResourceOrNull(graph, URIs.Functions_hasStandardResource);
         Functions_listResources = getResourceOrNull(graph, URIs.Functions_listResources);
+        Functions_methodsPropertyDomainProperties = getResourceOrNull(graph, URIs.Functions_methodsPropertyDomainProperties);
         Functions_numberInputValidator = getResourceOrNull(graph, URIs.Functions_numberInputValidator);
         Functions_propertyValidator = getResourceOrNull(graph, URIs.Functions_propertyValidator);
         Functions_relationValidator = getResourceOrNull(graph, URIs.Functions_relationValidator);
@@ -712,6 +741,7 @@ public class Layer0 {
         HasElement = getResourceOrNull(graph, URIs.HasElement);
         HasLabel = getResourceOrNull(graph, URIs.HasLabel);
         HasLabel_Inverse = getResourceOrNull(graph, URIs.HasLabel_Inverse);
+        HasMethod = getResourceOrNull(graph, URIs.HasMethod);
         HasName = getResourceOrNull(graph, URIs.HasName);
         HasNext = getResourceOrNull(graph, URIs.HasNext);
         HasObject = getResourceOrNull(graph, URIs.HasObject);
@@ -766,6 +796,7 @@ public class Layer0 {
         Literal_LongValidator = getResourceOrNull(graph, URIs.Literal_LongValidator);
         Long = getResourceOrNull(graph, URIs.Long);
         LongArray = getResourceOrNull(graph, URIs.LongArray);
+        MethodOf = getResourceOrNull(graph, URIs.MethodOf);
         Migration = getResourceOrNull(graph, URIs.Migration);
         MigrationSequence = getResourceOrNull(graph, URIs.MigrationSequence);
         MigrationStep = getResourceOrNull(graph, URIs.MigrationStep);
@@ -852,6 +883,8 @@ public class Layer0 {
         True = getResourceOrNull(graph, URIs.True);
         Type = getResourceOrNull(graph, URIs.Type);
         TypeWithIdentifier = getResourceOrNull(graph, URIs.TypeWithIdentifier);
+        Type_instantiateUnder = getResourceOrNull(graph, URIs.Type_instantiateUnder);
+        Type_instantiateUnder_Inverse = getResourceOrNull(graph, URIs.Type_instantiateUnder_Inverse);
         URI = getResourceOrNull(graph, URIs.URI);
         Value = getResourceOrNull(graph, URIs.Value);
         Variant = getResourceOrNull(graph, URIs.Variant);
index bf2b0b29ca527232fdbd540daab731ae6eb01772..8c1541725d9898c5eeb01861363de26c926f81a6 100644 (file)
Binary files a/bundles/org.simantics.modeling.ontology/graph.tg and b/bundles/org.simantics.modeling.ontology/graph.tg differ
index c838c0a3648850a5fbb0793844e664577cd4fc07..7e572df9f69e3aeb385fe98b5f4034bfaa0bd08d 100644 (file)
@@ -26,6 +26,9 @@ MOD.SCLLabelRule <T VP.ChildRule
 MOD.SCLAction <T ACT.Action
   --> MOD.SCLAction.action ==> "Resource -> <Proc> ()" <R L0.HasProperty : L0.FunctionalRelation 
 
+MOD.SCLDropAction <T ACT.Action
+  --> MOD.SCLDropAction.action ==> "Resource -> Dynamic -> Integer -> <Proc> ()" <R L0.HasProperty : L0.FunctionalRelation 
+
 MOD.SCLTest <T ACT.Action
   --> MOD.SCLTest.test ==> "Resource -> <ReadGraph> Boolean" <R L0.HasProperty : L0.FunctionalRelation 
 
@@ -369,6 +372,13 @@ MOD.sclAction : L0.Template
             L0.SCLValue.expression %expression
             L0.HasValueType "Resource -> <Proc> ()"
 
+MOD.sclDropAction : L0.Template
+    @template %action %expression
+        %action : MOD.SCLDropAction
+          MOD.SCLDropAction.action _ : MOD.SCLValue
+            L0.SCLValue.expression %expression
+            L0.HasValueType "Resource -> Dynamic -> Integer -> <Proc> ()"
+
 MOD.sclTest : L0.Template
     @template %subject %expression
         %subject : MOD.SCLTest
@@ -642,6 +652,13 @@ ACTIONS.NavigateToSubstructure
 ACTIONS.NewProceduralComponentType : ACT.Action
 ACTIONS.NewComponentType : ACT.Action
 
+MOD.InstantiateUnder <T MOD.SCLAction
+  >-- MOD.InstantiateUnder.HasType --> L0.Type <R L0.IsRelatedTo : L0.TotalFunction
+  @MOD.sclAssertion MOD.SCLAction.action "instantiateUnderAction self" "Resource -> <Proc> ()"
+
+ACTIONS.InstantiateUnder
+  @MOD.sclAction "instantiateUnderAction self"
+
 TESTS = MAC.Tests : L0.Library
 TESTS.IsNotPublished
   @MOD.sclTest "isNotPublished"
index 13cef22bcff11870c4fea3f9a5a81dcbedc65f49..b111ffb0cfcd2a5f5075aa4d22de2c2119178abf 100644 (file)
@@ -222,6 +222,8 @@ public class ModelingResources {
     public final Resource InitialCondition_sclState;
     public final Resource InitialCondition_sclState_Inverse;
     public final Resource Instantiable;
+    public final Resource InstantiateUnder;
+    public final Resource InstantiateUnder_HasType;
     public final Resource IsLocalLibraryOf;
     public final Resource IsTemplatized;
     public final Resource LifeCycleProcess;
@@ -256,6 +258,7 @@ public class ModelingResources {
     public final Resource ModelingActionContext_Actions_FinishSharedOntologyForPublishing;
     public final Resource ModelingActionContext_Actions_Help;
     public final Resource ModelingActionContext_Actions_ImportImages;
+    public final Resource ModelingActionContext_Actions_InstantiateUnder;
     public final Resource ModelingActionContext_Actions_Lock;
     public final Resource ModelingActionContext_Actions_MergeFlags;
     public final Resource ModelingActionContext_Actions_MigrateComponentType;
@@ -349,6 +352,9 @@ public class ModelingResources {
     public final Resource SCLCommandSession;
     public final Resource SCLCommandSession_hasValue;
     public final Resource SCLCommandSession_hasValue_Inverse;
+    public final Resource SCLDropAction;
+    public final Resource SCLDropAction_action;
+    public final Resource SCLDropAction_action_Inverse;
     public final Resource SCLLabelRule;
     public final Resource SCLLabelRule_getLabels;
     public final Resource SCLLabelRule_getLabels_Inverse;
@@ -431,6 +437,7 @@ public class ModelingResources {
     public final Resource scl;
     public final Resource sclAction;
     public final Resource sclAssertion;
+    public final Resource sclDropAction;
     public final Resource sclTest;
     public final Resource self;
     public final Resource self_Inverse;
@@ -650,6 +657,8 @@ public class ModelingResources {
         public static final String InitialCondition_sclState = "http://www.simantics.org/Modeling-1.2/InitialCondition/sclState";
         public static final String InitialCondition_sclState_Inverse = "http://www.simantics.org/Modeling-1.2/InitialCondition/sclState/Inverse";
         public static final String Instantiable = "http://www.simantics.org/Modeling-1.2/Instantiable";
+        public static final String InstantiateUnder = "http://www.simantics.org/Modeling-1.2/InstantiateUnder";
+        public static final String InstantiateUnder_HasType = "http://www.simantics.org/Modeling-1.2/InstantiateUnder/HasType";
         public static final String IsLocalLibraryOf = "http://www.simantics.org/Modeling-1.2/IsLocalLibraryOf";
         public static final String IsTemplatized = "http://www.simantics.org/Modeling-1.2/IsTemplatized";
         public static final String LifeCycleProcess = "http://www.simantics.org/Modeling-1.2/LifeCycleProcess";
@@ -684,6 +693,7 @@ public class ModelingResources {
         public static final String ModelingActionContext_Actions_FinishSharedOntologyForPublishing = "http://www.simantics.org/Modeling-1.2/ModelingActionContext/Actions/FinishSharedOntologyForPublishing";
         public static final String ModelingActionContext_Actions_Help = "http://www.simantics.org/Modeling-1.2/ModelingActionContext/Actions/Help";
         public static final String ModelingActionContext_Actions_ImportImages = "http://www.simantics.org/Modeling-1.2/ModelingActionContext/Actions/ImportImages";
+        public static final String ModelingActionContext_Actions_InstantiateUnder = "http://www.simantics.org/Modeling-1.2/ModelingActionContext/Actions/InstantiateUnder";
         public static final String ModelingActionContext_Actions_Lock = "http://www.simantics.org/Modeling-1.2/ModelingActionContext/Actions/Lock";
         public static final String ModelingActionContext_Actions_MergeFlags = "http://www.simantics.org/Modeling-1.2/ModelingActionContext/Actions/MergeFlags";
         public static final String ModelingActionContext_Actions_MigrateComponentType = "http://www.simantics.org/Modeling-1.2/ModelingActionContext/Actions/MigrateComponentType";
@@ -777,6 +787,9 @@ public class ModelingResources {
         public static final String SCLCommandSession = "http://www.simantics.org/Modeling-1.2/SCLCommandSession";
         public static final String SCLCommandSession_hasValue = "http://www.simantics.org/Modeling-1.2/SCLCommandSession/hasValue";
         public static final String SCLCommandSession_hasValue_Inverse = "http://www.simantics.org/Modeling-1.2/SCLCommandSession/hasValue/Inverse";
+        public static final String SCLDropAction = "http://www.simantics.org/Modeling-1.2/SCLDropAction";
+        public static final String SCLDropAction_action = "http://www.simantics.org/Modeling-1.2/SCLDropAction/action";
+        public static final String SCLDropAction_action_Inverse = "http://www.simantics.org/Modeling-1.2/SCLDropAction/action/Inverse";
         public static final String SCLLabelRule = "http://www.simantics.org/Modeling-1.2/SCLLabelRule";
         public static final String SCLLabelRule_getLabels = "http://www.simantics.org/Modeling-1.2/SCLLabelRule/getLabels";
         public static final String SCLLabelRule_getLabels_Inverse = "http://www.simantics.org/Modeling-1.2/SCLLabelRule/getLabels/Inverse";
@@ -859,6 +872,7 @@ public class ModelingResources {
         public static final String scl = "http://www.simantics.org/Modeling-1.2/scl";
         public static final String sclAction = "http://www.simantics.org/Modeling-1.2/sclAction";
         public static final String sclAssertion = "http://www.simantics.org/Modeling-1.2/sclAssertion";
+        public static final String sclDropAction = "http://www.simantics.org/Modeling-1.2/sclDropAction";
         public static final String sclTest = "http://www.simantics.org/Modeling-1.2/sclTest";
         public static final String self = "http://www.simantics.org/Modeling-1.2/self";
         public static final String self_Inverse = "http://www.simantics.org/Modeling-1.2/self/Inverse";
@@ -1088,6 +1102,8 @@ public class ModelingResources {
         InitialCondition_sclState = getResourceOrNull(graph, URIs.InitialCondition_sclState);
         InitialCondition_sclState_Inverse = getResourceOrNull(graph, URIs.InitialCondition_sclState_Inverse);
         Instantiable = getResourceOrNull(graph, URIs.Instantiable);
+        InstantiateUnder = getResourceOrNull(graph, URIs.InstantiateUnder);
+        InstantiateUnder_HasType = getResourceOrNull(graph, URIs.InstantiateUnder_HasType);
         IsLocalLibraryOf = getResourceOrNull(graph, URIs.IsLocalLibraryOf);
         IsTemplatized = getResourceOrNull(graph, URIs.IsTemplatized);
         LifeCycleProcess = getResourceOrNull(graph, URIs.LifeCycleProcess);
@@ -1122,6 +1138,7 @@ public class ModelingResources {
         ModelingActionContext_Actions_FinishSharedOntologyForPublishing = getResourceOrNull(graph, URIs.ModelingActionContext_Actions_FinishSharedOntologyForPublishing);
         ModelingActionContext_Actions_Help = getResourceOrNull(graph, URIs.ModelingActionContext_Actions_Help);
         ModelingActionContext_Actions_ImportImages = getResourceOrNull(graph, URIs.ModelingActionContext_Actions_ImportImages);
+        ModelingActionContext_Actions_InstantiateUnder = getResourceOrNull(graph, URIs.ModelingActionContext_Actions_InstantiateUnder);
         ModelingActionContext_Actions_Lock = getResourceOrNull(graph, URIs.ModelingActionContext_Actions_Lock);
         ModelingActionContext_Actions_MergeFlags = getResourceOrNull(graph, URIs.ModelingActionContext_Actions_MergeFlags);
         ModelingActionContext_Actions_MigrateComponentType = getResourceOrNull(graph, URIs.ModelingActionContext_Actions_MigrateComponentType);
@@ -1215,6 +1232,9 @@ public class ModelingResources {
         SCLCommandSession = getResourceOrNull(graph, URIs.SCLCommandSession);
         SCLCommandSession_hasValue = getResourceOrNull(graph, URIs.SCLCommandSession_hasValue);
         SCLCommandSession_hasValue_Inverse = getResourceOrNull(graph, URIs.SCLCommandSession_hasValue_Inverse);
+        SCLDropAction = getResourceOrNull(graph, URIs.SCLDropAction);
+        SCLDropAction_action = getResourceOrNull(graph, URIs.SCLDropAction_action);
+        SCLDropAction_action_Inverse = getResourceOrNull(graph, URIs.SCLDropAction_action_Inverse);
         SCLLabelRule = getResourceOrNull(graph, URIs.SCLLabelRule);
         SCLLabelRule_getLabels = getResourceOrNull(graph, URIs.SCLLabelRule_getLabels);
         SCLLabelRule_getLabels_Inverse = getResourceOrNull(graph, URIs.SCLLabelRule_getLabels_Inverse);
@@ -1297,6 +1317,7 @@ public class ModelingResources {
         scl = getResourceOrNull(graph, URIs.scl);
         sclAction = getResourceOrNull(graph, URIs.sclAction);
         sclAssertion = getResourceOrNull(graph, URIs.sclAssertion);
+        sclDropAction = getResourceOrNull(graph, URIs.sclDropAction);
         sclTest = getResourceOrNull(graph, URIs.sclTest);
         self = getResourceOrNull(graph, URIs.self);
         self_Inverse = getResourceOrNull(graph, URIs.self_Inverse);
index b1a0bf3e15cde228e022bfcff9b73d9d166a2e25..0e3870c356673adc721d392164649b8588d89b73 100644 (file)
                <resource uri="http://www.simantics.org/Modeling-0.0/ModelingActionContext/Actions/Help"
                        class="org.simantics.modeling.actions.Help" />
     </target>
-    
+
+       <target interface="org.simantics.db.layer0.adapter.DropActionFactory">
+               <type uri="http://www.simantics.org/Modeling-0.0/SCLDropAction"
+                       class="org.simantics.modeling.SCLDropAction">
+                       <graph/>
+                       <this/>
+               </type>
+       </target>
+
     <target interface="org.simantics.browsing.ui.model.children.ChildRule">
         <type uri="http://www.simantics.org/Modeling-0.0/SCLChildRule"
             class="org.simantics.modeling.adapters.SCLChildRule">
diff --git a/bundles/org.simantics.modeling/scl/Simantics/Action.scl b/bundles/org.simantics.modeling/scl/Simantics/Action.scl
new file mode 100644 (file)
index 0000000..102012e
--- /dev/null
@@ -0,0 +1,10 @@
+import "Simantics/Variables"
+   
+instantiateUnderAction :: Variable -> Resource -> <Proc> ()
+instantiateUnderAction ruleVariable context = do
+   syncWrite (\x -> do
+     typeToInstantiate = singleObject (represents $ parent ruleVariable) MOD.InstantiateUnder.HasType
+     typeVariable = resourceVariable typeToInstantiate
+     fn = typeVariable#methods#instantiateUnder :: Resource -> Resource -> <WriteGraph> Resource
+     fn context typeToInstantiate)
+   ()
\ No newline at end of file
index 02457e67f0811baac1465e760e143d32bdaac768..07f8a04641ebbb14a4e49679ea75ebaa99e928bf 100644 (file)
@@ -31,3 +31,4 @@ include "SWT/All"
 include "Simantics/UI"
 include "Simantics/SelectionView"
 include "Simantics/Formatting"
+include "Simantics/Action"
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLDropAction.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLDropAction.java
new file mode 100644 (file)
index 0000000..74b19a2
--- /dev/null
@@ -0,0 +1,69 @@
+package org.simantics.modeling;
+
+import org.simantics.Simantics;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.ResourceRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.DropActionFactory;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.db.layer0.variable.Variables;
+import org.simantics.diagram.Logger;
+import org.simantics.scl.runtime.function.Function3;
+
+public class SCLDropAction implements DropActionFactory {
+
+       final private Resource rule;
+
+       public SCLDropAction(ReadGraph graph, Resource rule) throws DatabaseException {
+               this.rule = rule;
+       }
+
+       static class RuleFunctionRequest extends ResourceRead<Function3<Resource,Object,Integer,Object>> {
+
+               protected RuleFunctionRequest(Resource rule) {
+                       super(rule);
+               }
+
+               @Override
+               public Function3<Resource, Object, Integer, Object> perform(ReadGraph graph) throws DatabaseException {
+                       Variable ruleVariable = Variables.getVariable(graph, resource);
+                       ModelingResources MOD = ModelingResources.getInstance(graph);
+                       return ruleVariable.getPossiblePropertyValue(graph, MOD.SCLDropAction_action);
+               }
+
+       }
+
+       public static class SCLDropActionRunnable implements Runnable {
+
+               public Resource rule;
+               public Resource target;
+               public Object source;
+               public int operation;
+
+               public SCLDropActionRunnable(Resource rule, Resource target, Object source, int operation) {
+                       this.rule = rule;
+                       this.target = target;
+                       this.source = source;
+                       this.operation = operation;
+               }
+
+               @Override
+               public void run() {
+                       Simantics.getSession().markUndoPoint();
+                       try {
+                               Function3<Resource, Object, Integer, Object> function = Simantics.getSession().syncRequest(new RuleFunctionRequest(rule));
+                               function.apply(target, source, operation);
+                       } catch (DatabaseException e) {
+                               Logger.defaultLogError(e);
+                       }
+               }
+
+       }
+
+       @Override
+       public Runnable create(ReadGraph g, Object target, Object source, int operation) throws DatabaseException {
+               return new SCLDropActionRunnable(rule, (Resource)target, source, operation);
+       }
+
+}
index 91f6e66febe9a292d2edd621001b356a77bc561d..e867e9bded98daa36a6ea9637798e872bd23febc 100644 (file)
@@ -12,7 +12,8 @@ Require-Bundle: org.eclipse.core.runtime,
  org.simantics.scl.osgi;bundle-version="1.0.4",
  org.simantics.application,
  org.simantics.db.management,
- org.simantics.layer0.utils
+ org.simantics.layer0.utils,
+ org.slf4j.api;bundle-version="1.7.0"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Bundle-Vendor: VTT Technical Research Centre of Finland
 Export-Package: org.simantics.scl.db
index 3d71ae5143a577bf7ec7aeafa3f863b4b978260b..54696a83d12a0936d5fa7300c98c5d963f6231f4 100644 (file)
@@ -1,5 +1,6 @@
 import "JavaBuiltin" as Java
 include "http://www.simantics.org/Layer0-1.1" as L0
+import "Map" as Map
 
 infixl 5 (#)
  
@@ -322,6 +323,8 @@ importJava "org.simantics.scl.db.SCLFunctions" where
     subquery :: (<ReadGraph,Proc> a) -> <ReadGraph,Proc> a
     "Makes a new read request with given procedure for calculating the result. The request is always cached."
     subqueryC :: (<ReadGraph,Proc> a) -> <ReadGraph,Proc> a
+    "Tries to convert the given Dynamic value to a value with the inferred type"
+    possibleFromDynamic :: Typeable a => String -> Dynamic -> Maybe a
 
 importJava "org.simantics.db.layer0.util.Layer0Utils" where
     undo :: () -> <Proc> String
index 721d52b15696fe5748947daeec249671006c586c..1def7102cd72382f27baa20bc058b219048f80f8 100644 (file)
@@ -73,6 +73,11 @@ Example:
     instanceIndexRoot :: Variable -> <ReadGraph> Resource
     
     createValueAccessor :: (Variable -> <ReadGraph> a) -> (Variable -> Binding b -> <ReadGraph> b) -> (Variable -> c -> <WriteGraph> ()) -> (Variable -> d -> Binding d -> <WriteGraph> ()) -> (Variable -> <ReadGraph> Datatype) -> ValueAccessor
+
+    @JavaName getConfigurationContext
+    possibleConfigurationContext :: Resource -> <ReadGraph> Variable
+
+    setRVIProperty :: Variable -> RVI -> <WriteGraph> ()
     
 importJava "org.simantics.db.layer0.function.All" where
 
@@ -90,6 +95,9 @@ importJava "org.simantics.db.layer0.variable.ValueAccessor" where
 
 importJava "org.simantics.db.layer0.variable.Variable" where
     data Variable
+
+    @JavaName getRVI
+    rviOf :: Variable -> <ReadGraph> RVI
     
     @JavaName getProperties
     properties_ :: Variable -> <ReadGraph> Collection Variable
@@ -402,4 +410,14 @@ instance Browsable Variable where
 
 propertiesClassified :: Variable -> Resource -> <ReadGraph> [Variable]
 propertiesClassified parent classified = do
-    collectionToList $ propertiesClassified_ parent classified
\ No newline at end of file
+    collectionToList $ propertiesClassified_ parent classified
+
+importJava "org.simantics.db.layer0.variable.RVI" where
+    data RVI
+    
+    resolvePossible :: RVI -> Variable -> <ReadGraph> Maybe Variable
+
+instantiateUnder :: Resource -> Resource -> <WriteGraph> Resource
+instantiateUnder container typeToInstantiate = do
+    fn = (resourceVariable typeToInstantiate)#methods#instantiateUnder :: Resource -> Resource -> <WriteGraph> Resource  
+    fn container typeToInstantiate
\ No newline at end of file
index 9b4d6b8ac92ec90d5c3970285efbe15d7550c008..00df313ad4e34eaed68253b4ccc93640f52d1c79 100644 (file)
@@ -2,6 +2,7 @@ package org.simantics.scl.db;
 
 import java.io.IOException;
 
+import org.cojen.classfile.TypeDesc;
 import org.simantics.Simantics;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
@@ -21,6 +22,14 @@ import org.simantics.db.service.ClusterControl;
 import org.simantics.db.service.SerialisationSupport;
 import org.simantics.db.service.VirtualGraphSupport;
 import org.simantics.layer0.utils.triggers.IActivationManager;
+import org.simantics.scl.compiler.environment.specification.EnvironmentSpecification;
+import org.simantics.scl.compiler.errors.Failable;
+import org.simantics.scl.compiler.internal.codegen.types.JavaTypeTranslator;
+import org.simantics.scl.compiler.module.Module;
+import org.simantics.scl.compiler.module.repository.ImportFailureException;
+import org.simantics.scl.compiler.runtime.RuntimeEnvironment;
+import org.simantics.scl.compiler.types.Type;
+import org.simantics.scl.osgi.SCLOsgi;
 import org.simantics.scl.runtime.SCLContext;
 import org.simantics.scl.runtime.function.Function;
 import org.simantics.scl.runtime.function.Function1;
@@ -310,4 +319,28 @@ public class SCLFunctions {
     public static Object subqueryC(ReadGraph graph, Function q) throws DatabaseException {
         return graph.syncRequest(new Subquery(q), TransientCacheAsyncListener.<Object>instance());
     }
+
+    public static Object possibleFromDynamic(Type expectedType, String moduleName, Object value) {
+       
+        try {
+
+               
+            Failable<Module> failable = SCLOsgi.MODULE_REPOSITORY.getModule(moduleName);
+            Module module = failable.getResult();
+            
+               RuntimeEnvironment env = SCLOsgi.MODULE_REPOSITORY.createRuntimeEnvironment(
+                               EnvironmentSpecification.of(moduleName, ""), module.getParentClassLoader());
+
+            JavaTypeTranslator tr = new JavaTypeTranslator(env.getEnvironment());
+            TypeDesc desc = tr.toTypeDesc(expectedType);
+            String className = desc.getFullName();
+            Class<?> clazz = env.getMutableClassLoader().loadClass(className);
+            if (!clazz.isAssignableFrom(value.getClass()))
+                return null;
+            
+        } catch (ImportFailureException | ClassNotFoundException e) {
+        }
+        return value;
+    }
+
 }