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
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;
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 {
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));
}
}
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;
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)
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)
}, 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
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;
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;
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;
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;
};
+ @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) {
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
--- /dev/null
+/*******************************************************************************
+ * 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;
+
+ }
+
+}
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;
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;
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);
+ }
+
}
@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
@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
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
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
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]"
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"
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;
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;
@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;
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;
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;
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";
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";
@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";
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";
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";
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);
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);
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);
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);
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);
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
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
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"
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;
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;
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;
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;
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";
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";
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";
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";
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);
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);
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);
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);
<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">
--- /dev/null
+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
include "Simantics/UI"
include "Simantics/SelectionView"
include "Simantics/Formatting"
+include "Simantics/Action"
\ No newline at end of file
--- /dev/null
+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);
+ }
+
+}
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
import "JavaBuiltin" as Java
include "http://www.simantics.org/Layer0-1.1" as L0
+import "Map" as Map
infixl 5 (#)
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
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
importJava "org.simantics.db.layer0.variable.Variable" where
data Variable
+
+ @JavaName getRVI
+ rviOf :: Variable -> <ReadGraph> RVI
@JavaName getProperties
properties_ :: Variable -> <ReadGraph> Collection Variable
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
import java.io.IOException;
+import org.cojen.classfile.TypeDesc;
import org.simantics.Simantics;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
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;
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;
+ }
+
}