From: Tuukka Lehtonen Date: Thu, 20 Apr 2017 10:54:20 +0000 (+0300) Subject: Removed jsonValues since there already is Data/Json X-Git-Tag: v1.29.0~90^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=277ddb17bc33a7c0b5c352f80bbc2605acaee50d;p=simantics%2Fplatform.git Removed jsonValues since there already is Data/Json 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 --- diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/ModelBrowser.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/ModelBrowser.java index eb48bdd3c..c8744f263 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/ModelBrowser.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/ModelBrowser.java @@ -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 loadBrowseContexts(final Set browseContexts) { try { - return SimanticsUI.getSession().syncRequest(new Read>() { + return Simantics.getSession().syncRequest(new Read>() { @Override public Set perform(ReadGraph graph) throws DatabaseException { - Collection browseContextResources = new ArrayList(browseContexts.size()); + Collection 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 allBrowseContextResources = BrowseContext.findSubcontexts(graph, browseContextResources); - Set result = new HashSet(); + Set 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 browseContexts = new ArrayList(); + ArrayList 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() { + Simantics.getSession().asyncRequest(new Read() { @Override public Runnable perform(ReadGraph graph) throws DatabaseException { if (dndBrowseContext == null) @@ -132,8 +133,10 @@ public class ModelBrowser extends GraphExplorerComposite { }, new Procedure() { @Override public void execute(Runnable result) { - if (result != null) - result.run(); + Display.getDefault().asyncExec(() -> { + if (!Display.getCurrent().isDisposed() && result != null) + result.run(); + }); } @Override diff --git 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 index 6a1441652..08ed3edf2 100644 --- 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 @@ -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 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 getVariables(ReadGraph graph, Variable context, Map map) throws DatabaseException { + Variable parent = context.getParent(graph); + Resource container = parent.getPossibleRepresents(graph); + Map methods = graph.syncRequest(new UnescapedMethodMapOfResource(container)); + for(Map.Entry 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() { + 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 index 000000000..31cacdc6f --- /dev/null +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/UnescapedMethodMapOfResource.java @@ -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> { + + public UnescapedMethodMapOfResource(Resource resource) { + super(resource); + } + + @Override + public Map perform(ReadGraph graph) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(graph); + Collection predicates = graph.getPredicates(resource); + THashMap result = new THashMap(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; + + } + +} diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/Variables.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/Variables.java index 06050adf7..5fb0636a0 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/Variables.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/Variables.java @@ -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); + } + } diff --git a/bundles/org.simantics.layer0/graph.tg b/bundles/org.simantics.layer0/graph.tg index c072a1509..053b27ddf 100644 Binary files a/bundles/org.simantics.layer0/graph.tg and b/bundles/org.simantics.layer0/graph.tg differ diff --git a/bundles/org.simantics.layer0/graph/Layer0.pgraph b/bundles/org.simantics.layer0/graph/Layer0.pgraph index 482f606fc..ec2048acb 100644 --- a/bundles/org.simantics.layer0/graph/Layer0.pgraph +++ b/bundles/org.simantics.layer0/graph/Layer0.pgraph @@ -35,6 +35,15 @@ L0.Entity : L0.Type @L0.property L0.HasNext >-- L0.Entity.published --> L0.Boolean -- L0.Entity.methods + @L0.assert L0.Entity.methods + _ : L0.Value + +L0.Entity.methods --> L0.Value -- L0.Asserts --> L0.Assertion -- L0.Type.instantiateUnder ==> "Resource -> Resource -> Resource" -- L0.HasPredicate --> L0.Relation "Resource -> Resource -> ()" Resource -> Resource" diff --git a/bundles/org.simantics.layer0/src/org/simantics/layer0/Layer0.java b/bundles/org.simantics.layer0/src/org/simantics/layer0/Layer0.java index 2ea58b89c..5467995bb 100644 --- a/bundles/org.simantics.layer0/src/org/simantics/layer0/Layer0.java +++ b/bundles/org.simantics.layer0/src/org/simantics/layer0/Layer0.java @@ -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); diff --git a/bundles/org.simantics.modeling.ontology/graph.tg b/bundles/org.simantics.modeling.ontology/graph.tg index bf2b0b29c..8c1541725 100644 Binary files a/bundles/org.simantics.modeling.ontology/graph.tg and b/bundles/org.simantics.modeling.ontology/graph.tg differ diff --git a/bundles/org.simantics.modeling.ontology/graph/ModelingViewpoint.pgraph b/bundles/org.simantics.modeling.ontology/graph/ModelingViewpoint.pgraph index c838c0a36..7e572df9f 100644 --- a/bundles/org.simantics.modeling.ontology/graph/ModelingViewpoint.pgraph +++ b/bundles/org.simantics.modeling.ontology/graph/ModelingViewpoint.pgraph @@ -26,6 +26,9 @@ MOD.SCLLabelRule MOD.SCLAction.action ==> "Resource -> ()" MOD.SCLDropAction.action ==> "Resource -> Dynamic -> Integer -> ()" MOD.SCLTest.test ==> "Resource -> Boolean" ()" +MOD.sclDropAction : L0.Template + @template %action %expression + %action : MOD.SCLDropAction + MOD.SCLDropAction.action _ : MOD.SCLValue + L0.SCLValue.expression %expression + L0.HasValueType "Resource -> Dynamic -> Integer -> ()" + 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 -- MOD.InstantiateUnder.HasType --> L0.Type ()" + +ACTIONS.InstantiateUnder + @MOD.sclAction "instantiateUnderAction self" + TESTS = MAC.Tests : L0.Library TESTS.IsNotPublished @MOD.sclTest "isNotPublished" diff --git a/bundles/org.simantics.modeling.ontology/src/org/simantics/modeling/ModelingResources.java b/bundles/org.simantics.modeling.ontology/src/org/simantics/modeling/ModelingResources.java index 13cef22bc..b111ffb0c 100644 --- a/bundles/org.simantics.modeling.ontology/src/org/simantics/modeling/ModelingResources.java +++ b/bundles/org.simantics.modeling.ontology/src/org/simantics/modeling/ModelingResources.java @@ -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); diff --git a/bundles/org.simantics.modeling/adapters.xml b/bundles/org.simantics.modeling/adapters.xml index b1a0bf3e1..0e3870c35 100644 --- a/bundles/org.simantics.modeling/adapters.xml +++ b/bundles/org.simantics.modeling/adapters.xml @@ -162,7 +162,15 @@ - + + + + + + + + diff --git a/bundles/org.simantics.modeling/scl/Simantics/Action.scl b/bundles/org.simantics.modeling/scl/Simantics/Action.scl new file mode 100644 index 000000000..102012ecf --- /dev/null +++ b/bundles/org.simantics.modeling/scl/Simantics/Action.scl @@ -0,0 +1,10 @@ +import "Simantics/Variables" + +instantiateUnderAction :: Variable -> Resource -> () +instantiateUnderAction ruleVariable context = do + syncWrite (\x -> do + typeToInstantiate = singleObject (represents $ parent ruleVariable) MOD.InstantiateUnder.HasType + typeVariable = resourceVariable typeToInstantiate + fn = typeVariable#methods#instantiateUnder :: Resource -> Resource -> Resource + fn context typeToInstantiate) + () \ No newline at end of file diff --git a/bundles/org.simantics.modeling/scl/Simantics/All.scl b/bundles/org.simantics.modeling/scl/Simantics/All.scl index 02457e67f..07f8a0464 100644 --- a/bundles/org.simantics.modeling/scl/Simantics/All.scl +++ b/bundles/org.simantics.modeling/scl/Simantics/All.scl @@ -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 index 000000000..74b19a214 --- /dev/null +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLDropAction.java @@ -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> { + + protected RuleFunctionRequest(Resource rule) { + super(rule); + } + + @Override + public Function3 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 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); + } + +} diff --git a/bundles/org.simantics.scl.db/META-INF/MANIFEST.MF b/bundles/org.simantics.scl.db/META-INF/MANIFEST.MF index 91f6e66fe..e867e9bde 100644 --- a/bundles/org.simantics.scl.db/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.scl.db/META-INF/MANIFEST.MF @@ -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 diff --git a/bundles/org.simantics.scl.db/scl/Simantics/DB.scl b/bundles/org.simantics.scl.db/scl/Simantics/DB.scl index 3d71ae514..54696a83d 100644 --- a/bundles/org.simantics.scl.db/scl/Simantics/DB.scl +++ b/bundles/org.simantics.scl.db/scl/Simantics/DB.scl @@ -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 :: ( a) -> a "Makes a new read request with given procedure for calculating the result. The request is always cached." subqueryC :: ( a) -> 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 :: () -> String diff --git a/bundles/org.simantics.scl.db/scl/Simantics/Variables.scl b/bundles/org.simantics.scl.db/scl/Simantics/Variables.scl index 721d52b15..1def7102c 100644 --- a/bundles/org.simantics.scl.db/scl/Simantics/Variables.scl +++ b/bundles/org.simantics.scl.db/scl/Simantics/Variables.scl @@ -73,6 +73,11 @@ Example: instanceIndexRoot :: Variable -> Resource createValueAccessor :: (Variable -> a) -> (Variable -> Binding b -> b) -> (Variable -> c -> ()) -> (Variable -> d -> Binding d -> ()) -> (Variable -> Datatype) -> ValueAccessor + + @JavaName getConfigurationContext + possibleConfigurationContext :: Resource -> Variable + + setRVIProperty :: Variable -> RVI -> () 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 -> RVI @JavaName getProperties properties_ :: Variable -> Collection Variable @@ -402,4 +410,14 @@ instance Browsable Variable where propertiesClassified :: Variable -> Resource -> [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 -> Maybe Variable + +instantiateUnder :: Resource -> Resource -> Resource +instantiateUnder container typeToInstantiate = do + fn = (resourceVariable typeToInstantiate)#methods#instantiateUnder :: Resource -> Resource -> Resource + fn container typeToInstantiate \ No newline at end of file diff --git a/bundles/org.simantics.scl.db/src/org/simantics/scl/db/SCLFunctions.java b/bundles/org.simantics.scl.db/src/org/simantics/scl/db/SCLFunctions.java index 9b4d6b8ac..00df313ad 100644 --- a/bundles/org.simantics.scl.db/src/org/simantics/scl/db/SCLFunctions.java +++ b/bundles/org.simantics.scl.db/src/org/simantics/scl/db/SCLFunctions.java @@ -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.instance()); } + + public static Object possibleFromDynamic(Type expectedType, String moduleName, Object value) { + + try { + + + Failable 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; + } + }