]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge "VariableOrResource SCL type"
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 22 Aug 2019 06:13:57 +0000 (06:13 +0000)
committerGerrit Code Review <gerrit2@simantics>
Thu, 22 Aug 2019 06:13:57 +0000 (06:13 +0000)
38 files changed:
bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/EnumerationVariableModifier3.java
bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/GetEnumerationValue.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewer.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewerData.java
bundles/org.simantics.modeling/scl/Simantics/Diagram.scl
bundles/org.simantics.modeling/src/org/simantics/modeling/userComponent/ComponentTypeCommands.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/UpdateMethodFactory.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/impl/Mapping.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/MappedElementRule.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/MappedElementsRule.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/ValueRule.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/CompoundValueAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/LinkedListAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/MappingUtils.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedObjectAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedObjectsAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedOrderedSetElementsAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedValueAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/range/FieldAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/DynamicSimpleLinkType.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/OrderedSetSimpleLinkType.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/SimpleLinkType.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/annotations/factories/UpdateMethodFactory.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/RelatedObjectAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/RelatedObjectsAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/RelatedOrderedSetElementsAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/RelatedValueAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/StructuralRelatedObjectAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/StructuralRelatedObjectsAccessor.java
bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/schema/SimpleLinkType.java
bundles/org.simantics.scl.compiler/scl/SCL/ModuleRepository.scl
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/repository/ModuleRepository.java
bundles/org.simantics.selectionview/src/org/simantics/selectionview/function/All.java
bundles/org.simantics.structural.ontology/graph/Structural.pgraph
bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/base/ModuleUpdateContext.java
bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/base/SynchronizationEventHandlerBase.java
bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/utils/MappingBase.java
bundles/org.simantics.structural2/src/org/simantics/structural2/Functions.java

index 32bd28c17f789f1658a271a5e064807c4932f833..3bd3e7b91217ef5233388158c88f86e8bb24abdc 100644 (file)
@@ -13,10 +13,12 @@ package org.simantics.browsing.ui.graph.impl;
 
 import java.util.List;
 
+import org.simantics.browsing.ui.common.modifiers.EnumerationValue;
 import org.simantics.browsing.ui.content.Labeler.EnumerationModifier;
 import org.simantics.databoard.Bindings;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.RequestProcessor;
+import org.simantics.db.Resource;
 import org.simantics.db.Session;
 import org.simantics.db.VirtualGraph;
 import org.simantics.db.WriteGraph;
@@ -53,6 +55,10 @@ public class EnumerationVariableModifier3 implements EnumerationModifier {
            return processor.syncRequest(new Read<String>() {
                 @Override
                 public String perform(ReadGraph graph) throws DatabaseException {
+                    EnumerationValue<Resource> ev = graph.syncRequest(new GetEnumerationValue(variable.getParent(graph).getRepresents(graph)));
+                    if(ev != null) {
+                           return ev.getEnumeratedValue().getName();
+                    }
           //           System.err.println(variable.getURI(graph));
                        return variable.getValue(graph);//variable.getPossiblePropertyValue(graph, Variables.LABEL);
                 }
index c246e7bd9091f5142014ccc37acf53d8250e0372..9e8adfebea1fa65805c66078c0794e14a49ffec1 100644 (file)
@@ -41,6 +41,14 @@ public class GetEnumerationValue extends ResourceRead<EnumerationValue<Resource>
     public EnumerationValue<Resource> perform(ReadGraph graph) throws DatabaseException {
         return enumerate(graph, resource);
     }
+    
+    public static String getEnumerationValueName(ReadGraph graph, Resource resource) throws DatabaseException {
+        Layer0 L0 = Layer0.getInstance(graph);
+        String label = graph.getPossibleRelatedValue(resource, L0.HasLabel, Bindings.STRING);
+        if(label != null)
+            return label;
+        return safeName(graph, resource);
+    }
 
     public static EnumerationValue<Resource> enumerate(ReadGraph graph, Resource resource) throws DatabaseException {
         Layer0 l0 = Layer0.getInstance(graph);
@@ -61,7 +69,7 @@ public class GetEnumerationValue extends ResourceRead<EnumerationValue<Resource>
                     Collection<Resource> values = graph.getObjects(type, l0.ConsistsOf);
                     List<EnumeratedValue<Resource>> result = new ArrayList<EnumeratedValue<Resource>>(values.size());
                     for (Resource value : values) {
-                        result.add(new EnumeratedValue<Resource>(safeName(graph, value), value));
+                        result.add(new EnumeratedValue<Resource>(getEnumerationValueName(graph, value), value));
                     }
                     Enumeration<Resource> enumeration = new Enumeration<Resource>(result);
                     return new EnumerationValue<Resource>(enumeration, enumeration.find(resource));
index 75c60d24cd28d27190c382fba285def14f1f46a6..ef63fabe09dc52db6ce5cad752b352c09247d3c6 100644 (file)
@@ -34,6 +34,7 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.simantics.Simantics;
+import org.simantics.browsing.ui.graph.impl.GetEnumerationValue;
 import org.simantics.databoard.Bindings;
 import org.simantics.databoard.binding.Binding;
 import org.simantics.databoard.binding.error.BindingException;
@@ -42,6 +43,7 @@ import org.simantics.databoard.type.NumberType;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.common.NamedResource;
+import org.simantics.db.common.request.IsEnumeratedValue;
 import org.simantics.db.common.request.UniqueRead;
 import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.exception.DatabaseException;
@@ -198,10 +200,12 @@ public class ComponentTypeViewer {
                         
                         for(Resource assertion : graph.getAssertedObjects(data.componentType, relation)) {
                             try {
-                                expression = graph.getPossibleRelatedValue(assertion, L0.SCLValue_expression, Bindings.STRING);
+                               expression = graph.getPossibleRelatedValue(assertion, L0.SCLValue_expression, Bindings.STRING);
                                 if(expression != null) {
                                        defaultValue = "=" + expression; //$NON-NLS-1$
-                                } else {
+                                } else if (graph.sync(new IsEnumeratedValue(assertion))) {
+                                   defaultValue = GetEnumerationValue.getEnumerationValueName(graph, assertion);
+                               } else {
                                        Datatype dt = getPossibleDatatype(graph, assertion);
                                        if (dt == null)
                                            continue;
index ea10d6d8d4e44d700cf6cc789b97ca49ed9e6e6c..820d45f2e1ecf9365a65aa3895771b68519ee8ee 100644 (file)
@@ -1,8 +1,11 @@
 package org.simantics.modeling.ui.componentTypeEditor;
 
 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.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 import java.util.regex.Matcher;
@@ -33,18 +36,24 @@ import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.forms.widgets.Form;
 import org.eclipse.ui.forms.widgets.FormToolkit;
 import org.simantics.Simantics;
+import org.simantics.databoard.Bindings;
 import org.simantics.databoard.type.NumberType;
 import org.simantics.databoard.units.internal.library.UnitLibrary;
 import org.simantics.databoard.util.Limit;
 import org.simantics.databoard.util.Range;
 import org.simantics.databoard.util.RangeException;
+import org.simantics.db.ReadGraph;
 import org.simantics.db.RequestProcessor;
 import org.simantics.db.Resource;
+import org.simantics.db.Statement;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.common.NamedResource;
+import org.simantics.db.common.request.IndexRoot;
+import org.simantics.db.common.request.ResourceRead;
 import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.function.DbConsumer;
+import org.simantics.db.layer0.QueryIndexUtils;
 import org.simantics.layer0.Layer0;
 import org.simantics.modeling.userComponent.ComponentTypeCommands;
 import org.simantics.scl.runtime.function.Function2;
@@ -216,6 +225,26 @@ public class ComponentTypeViewerData {
         editor.setEditor(text, selectedItem, column);
     }
 
+    private static class TypeDefinitionMapRequest extends ResourceRead<Map<String,Resource>> {
+        public TypeDefinitionMapRequest(Resource resource) {
+            super(resource);
+        }
+
+        @Override
+        public Map<String,Resource> perform(ReadGraph graph) throws DatabaseException {
+            Layer0 L0 = Layer0.getInstance(graph);
+            Map<String,Resource> result = new HashMap<>();
+            for(Resource valueType : QueryIndexUtils.searchByType(graph, resource, L0.ValueType)) {
+                Collection<Statement> stms = graph.getAssertedStatements(valueType, L0.HasValueType);
+                if(stms.size() == 1) {
+                    String sclValueType = graph.getValue(stms.iterator().next().getObject(), Bindings.STRING);
+                    result.put(sclValueType, valueType);
+                }
+            }
+            return result;
+        }
+    }
+
     public void editType(Table table, TableEditor editor, final ComponentTypeViewerPropertyInfo propertyInfo, TableItem selectedItem, int column, String range, final boolean convertDefaultValue) {
         int extraStyle = propertyInfo.immutable ? SWT.READ_ONLY : 0;
         final Combo combo = new Combo(table, SWT.NONE | extraStyle);
@@ -246,12 +275,18 @@ public class ComponentTypeViewerData {
                 if (propertyInfo.immutable)
                     return;
 
+                
                 Simantics.getSession().async(new WriteRequest() {
                     @Override
                     public void perform(WriteGraph graph)
                             throws DatabaseException {
                         graph.markUndoPoint();
-                        ComponentTypeCommands.editType(graph, componentType, propertyInfo.resource, convertDefaultValue, newValue);
+
+                        Resource root = graph.syncRequest(new IndexRoot(componentType));
+                        Map<String,Resource> typeDefinitionMap = graph.syncRequest(new TypeDefinitionMapRequest(root));
+                        Resource possibleGraphType = typeDefinitionMap.get(newValue);
+
+                        ComponentTypeCommands.editType(graph, componentType, propertyInfo.resource, convertDefaultValue, newValue, possibleGraphType);
                         if (range != null) ComponentTypeCommands.setRange(graph, componentType, propertyInfo.resource, range);
                     }
                 });
index 8dd1644e8d0737087eef7f67dc47c3751fd5c9a5..14a558bec05c0b549ddd5600e4c3ebec224e6cab 100644 (file)
@@ -220,7 +220,7 @@ deriving instance (Show res) => Show (DiagramElement res)
 
 @private
 transformOf element = Position (da!0) (da!1) (da!2) (da!3) (da!4) (da!5)
-    where da = fromDoubleArray $ relatedValue element DIA.HasTransform
+    where da = relatedValue element DIA.HasTransform :: Vector Double
 
 """Creates a random GUID L0.identifier property for the specified entity resource.""" 
 @private
@@ -443,7 +443,7 @@ setElements (DiagramInfo diagram configuration componentMap) joinMap elementSpec
             hasType componentType,
             hasTypedProperty 
                 DIA.HasTransform
-                (positionToDoubleArray position)
+                (positionToVector position)
                 G2D.Transform,
             hasStatement 
                 MOD.ElementToComponent
@@ -464,8 +464,8 @@ setElements (DiagramInfo diagram configuration componentMap) joinMap elementSpec
         ]
         a = newOrMappedElement aName
         b = newOrMappedElement bName
-        ca = createConnector connection a ar
-        cb = createConnector connection b br
+        ca = createConnector connection a ar DIA.HasPlainConnector
+        cb = createConnector connection b br DIA.HasArrowConnector
         connectNodes ca cb
         Just connection
     createElement (Flag t name label output external tableBinding tableRow position joins) = do
@@ -476,7 +476,7 @@ setElements (DiagramInfo diagram configuration componentMap) joinMap elementSpec
             hasType t,
             hasTypedProperty 
                 DIA.HasTransform
-                (positionToDoubleArray position)
+                (positionToVector position)
                 G2D.Transform,
             hasPossibleProperty 
                 DIA.Flag.HasIOTableBinding
@@ -512,7 +512,10 @@ setElements (DiagramInfo diagram configuration componentMap) joinMap elementSpec
         Just connection
     createNode connection (Terminal elementName terminal) = do
         element = newOrMappedElement elementName
-        createConnector connection element terminal        
+        if terminal == DIA.Flag.ConnectionPoint then
+            createConnector connection element terminal DIA.HasPlainConnector
+        else        
+            createConnector connection element terminal DIA.HasPlainConnector
     createNode connection (RouteLine isHorizontal position) = do
         newEntity [
             hasName (freshElementName ()),
@@ -524,18 +527,37 @@ setElements (DiagramInfo diagram configuration componentMap) joinMap elementSpec
             hasStatement DIA.HasInteriorRouteNode.Inverse
                         connection
         ]
-    createConnector connection component terminal = do
+    createConnector connection component terminal defaultHasConnector = do
         connector = newResource ()
         claim connector
               L0.InstanceOf
               DIA.Connector
         claim component terminal connector
-        claim connection 
-              DIA.HasPlainConnector 
-              connector
+        
+        (connectionRelation, attachmentRelation) = resolveAttachmentRelation component terminal defaultHasConnector
+        
+        claim connection attachmentRelation connector
+                
+        execJust connectionRelation (\cr -> do 
+            if existsStatement cr MOD.NeedsConnectionMappingSpecification then do
+                connectionType = singleObject cr STR.AllowsConnectionType
+                spec = singleObject connectionType MOD.ConnectionTypeToConnectionMappingSpecification
+                claim connector
+                      MOD.HasConnectionMappingSpecification
+                      spec
+            else ())
+        
         connector
     connectNodes a b = 
         claim a DIA.AreConnected b
+    // Returns (connectionRelation :: Maybe Resource, connector attachment relation :: Resource)  
+    resolveAttachmentRelation element terminal defaultAttachmentRelation =
+        if terminal == DIA.Flag.ConnectionPoint then
+            (Nothing, flagTypeToAttachmentRelation element)
+        else
+            match possibleObject terminal MOD.DiagramConnectionRelationToConnectionRelation with
+                Just connectionRelation -> (Just connectionRelation, orElse (possibleObject connectionRelation STR.HasAttachmentRelation) defaultAttachmentRelation)
+                Nothing                 -> (Nothing, defaultAttachmentRelation)
     createElement (SVG document position) =
         Just $ newEntity [
             hasName (freshElementName ()),
@@ -545,7 +567,7 @@ setElements (DiagramInfo diagram configuration componentMap) joinMap elementSpec
                 document,
             hasTypedProperty 
                 DIA.HasTransform
-                (positionToDoubleArray position)
+                (positionToVector position)
                 G2D.Transform
         ]
     createRealizedFont (Font family size style) = do
@@ -568,7 +590,7 @@ setElements (DiagramInfo diagram configuration componentMap) joinMap elementSpec
                 label,
             hasTypedProperty 
                 DIA.HasTransform
-                (positionToDoubleArray position)
+                (positionToVector position)
                 G2D.Transform,
             hasTypedProperty 
                 G2D.HasStrokeWidth
@@ -599,7 +621,7 @@ setElements (DiagramInfo diagram configuration componentMap) joinMap elementSpec
             hasStatement DIA.HasMonitorComponent component,
             hasTypedProperty 
                 DIA.HasTransform
-                (positionToDoubleArray position)
+                (positionToVector position)
                 G2D.Transform,
             hasTypedProperty 
                 G2D.HasStrokeWidth
@@ -622,7 +644,7 @@ setElements (DiagramInfo diagram configuration componentMap) joinMap elementSpec
                 text,
             hasTypedProperty 
                 DIA.HasTransform
-                (positionToDoubleArray position)
+                (positionToVector position)
                 G2D.Transform,
             hasStatement 
                 G2D.HasHorizontalAlignment
@@ -645,6 +667,9 @@ setElements (DiagramInfo diagram configuration componentMap) joinMap elementSpec
             Just c -> claimRelatedValue c L0.HasName name
             Nothing -> () // This is a typical case
     setConnectionName _ = ()
+    flagTypeToAttachmentRelation flag = match possibleObject flag DIA.HasFlagType with
+        Just DIA.FlagType.OutputFlag -> DIA.HasArrowConnector
+        otherwise                    -> DIA.HasPlainConnector
 
 """Returns a diagram in the given model with the given model relative path.""" 
 diagram :: Model -> [String] -> <ReadGraph> Diagram
@@ -894,7 +919,7 @@ and [transformWithScale](#transformWithScale).
 """
 transformElement :: (Position -> Position) -> Resource -> <WriteGraph> ()
 transformElement transformer element =
-    claimRelatedValue element DIA.HasTransform (positionToDoubleArray (transformer (transformOf element)))
+    claimRelatedValue element DIA.HasTransform (positionToVector (transformer (transformOf element)))
     
 """
     transformElements transformer elements
index 74ae599e3797f6a06d9c07f2c9ed6bc7d4789843..c92d80c848cec727999d467fefa167ee792fd3a5 100644 (file)
@@ -11,6 +11,7 @@
  *******************************************************************************/
 package org.simantics.modeling.userComponent;
 
+import java.util.Collections;
 import java.util.Map;
 
 import org.simantics.databoard.Bindings;
@@ -27,11 +28,13 @@ import org.simantics.db.Resource;
 import org.simantics.db.Statement;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.common.CommentMetadata;
+import org.simantics.db.common.request.EnumerationMap;
+import org.simantics.db.common.request.IsEnumeratedValue;
 import org.simantics.db.common.request.UnaryRead;
 import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.ServiceException;
-import org.simantics.db.layer0.request.ModelInstances;
+import org.simantics.db.layer0.QueryIndexUtils;
 import org.simantics.db.layer0.util.Layer0Utils;
 import org.simantics.layer0.Layer0;
 import org.simantics.modeling.ModelingResources;
@@ -42,6 +45,7 @@ import org.simantics.scl.runtime.tuple.Tuple3;
 import org.simantics.selectionview.SelectionViewResources;
 import org.simantics.structural.stubs.StructuralResource2;
 import org.simantics.structural2.utils.StructuralUtils;
+import org.simantics.utils.strings.AlphanumComparator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -199,6 +203,11 @@ public class ComponentTypeCommands {
 
     public static void setRequiredType(WriteGraph g, Resource componentType, Resource property,
             String requiredType) throws DatabaseException {
+        setRequiredType(g, componentType, property, requiredType, null);
+    }
+
+    public static void setRequiredType(WriteGraph g, Resource componentType, Resource property,
+            String requiredType, Resource possibleType) throws DatabaseException {
         Layer0 L0 = Layer0.getInstance(g);
         g.claimLiteral(property, L0.RequiresValueType, requiredType);
 
@@ -211,17 +220,34 @@ public class ComponentTypeCommands {
             }
         }
 
+        // We assert the range of the property only if we are given a dedicated graph value type
+        if(g.hasStatement(property, L0.HasRange))
+            g.deny(property, L0.HasRange);
+        
+        if(possibleType != null) {
+            // We have a dedicated graph type for this SCL value type
+            if(g.hasStatement(possibleType, L0.Enumeration)) {
+                // This value type is an enumeration - let's constrain the range of this predicate to match the enumeration type only
+                g.claim(property, L0.HasRange, possibleType);
+            }
+        }
+
         CommentMetadata cm = g.getMetadata(CommentMetadata.class);
         g.addMetadata(cm.add("Set required type "+ requiredType + " for component/annotation " + property));
     }
     
     public static void editType(WriteGraph graph, Resource componentType, Resource property, boolean convertDefaultValue, String newValue) throws DatabaseException {
-        ComponentTypeCommands.setRequiredType(graph, componentType, property, newValue);
+        editType(graph, componentType, property, convertDefaultValue, newValue, null);
+    }
+
+    public static void editType(WriteGraph graph, Resource componentType, Resource property, boolean convertDefaultValue, String newValue, Resource possibleType) throws DatabaseException {
+        ComponentTypeCommands.setRequiredType(graph, componentType, property, newValue, possibleType);
         if (convertDefaultValue) {
-            ComponentTypeCommands.convertDefaultValue(graph, componentType, property, newValue);
-            Map<String, Resource> instances = graph.sync(new ModelInstances(componentType, componentType));
-            for(Resource instance : instances.values()) {
-                ComponentTypeCommands.convertInstantiatedValue(graph, instance, property, newValue);
+            ComponentTypeCommands.convertDefaultValue(graph, componentType, property, newValue, possibleType);
+            for (Resource indexRoot : Layer0Utils.listIndexRoots(graph)) {
+                for(Resource instance : QueryIndexUtils.searchByTypeShallow(graph, indexRoot, componentType)) {
+                    ComponentTypeCommands.convertInstantiatedValue(graph, instance, property, newValue, componentType);
+                }
             }
         }
     }
@@ -270,11 +296,29 @@ public class ComponentTypeCommands {
                     " in " + NameUtils.getSafeName(g, type) + ".");
             return;
         }
+
+       Layer0 L0 = Layer0.getInstance(g);
+       Resource range = g.getPossibleObject(relation, L0.HasRange);
+       if (range != null) {
+            if(g.hasStatement(range, L0.Enumeration)) {
+                   Map<String,Resource> values = g.syncRequest(new EnumerationMap(range));
+                   Resource value = values.get(valueText);
+                   if (value != null) {
+                       for(Resource assertion : g.getObjects(type, L0.Asserts)) {
+                           Resource p = g.getSingleObject(assertion, L0.HasPredicate);
+                           if (p.equals(relation)) {
+                               g.deny(assertion, L0.HasObject, object);
+                               g.claim(assertion, L0.HasObject, value);
+                           }
+                       }
+                   }
+                   return;
+            }
+        }
         
         if(valueText.length() > 0 && valueText.charAt(0) == '=') {
                
-               String expression = valueText.substring(1);
-               Layer0 L0 = Layer0.getInstance(g);
+            String expression = valueText.substring(1);
                ModelingResources MOD = ModelingResources.getInstance(g);
                if(!g.isInstanceOf(object, MOD.SCLValue)) {
                        Resource assertion = g.getSingleObject(object, L0.HasObjectInverse);
@@ -288,7 +332,6 @@ public class ComponentTypeCommands {
             
         } else {
                
-               Layer0 L0 = Layer0.getInstance(g);
                ModelingResources MOD = ModelingResources.getInstance(g);
                if(g.isInstanceOf(object, MOD.SCLValue)) {
                        Resource assertion = g.getSingleObject(object, L0.HasObjectInverse);
@@ -421,6 +464,22 @@ public class ComponentTypeCommands {
 
     public static void convertDefaultValue(WriteGraph g,
             Resource type, Resource relation, String newSCLType) throws DatabaseException {
+        convertDefaultValue(g, type, relation, newSCLType, null);
+    }
+
+    private static Resource findAssertionWithPO(ReadGraph graph, Resource possibleType, Resource predicate, Resource object) throws DatabaseException {
+           Layer0 L0 = Layer0.getInstance(graph);
+        for(Resource assertion : graph.getObjects(possibleType, L0.Asserts)) {
+            Resource p = graph.getSingleObject(assertion, L0.HasPredicate);
+            Resource o = graph.getSingleObject(assertion, L0.HasObject);
+            if(predicate.equals(p) && object.equals(o))
+                return assertion;
+        }
+        return null;
+    }
+    
+    public static void convertDefaultValue(WriteGraph g,
+            Resource type, Resource relation, String newSCLType, Resource possibleType) throws DatabaseException {
         Resource object = getAssertedObject(g, type, relation);
         if(object == null) {
             LOGGER.warn("Didn't find assertion for " + NameUtils.getSafeName(g, relation) + 
@@ -428,27 +487,60 @@ public class ComponentTypeCommands {
             return;
         }
 
+        Layer0 L0 = Layer0.getInstance(g);
+        if(possibleType != null) {
+            if(g.hasStatement(possibleType, L0.Enumeration)) {
+                if(!g.isInstanceOf(object, possibleType)) {
+                    Map<String, Resource> enumMap = g.syncRequest(new EnumerationMap(possibleType));
+                    String firstKey = Collections.min(enumMap.keySet(), AlphanumComparator.COMPARATOR);
+                    Resource defaultValue = enumMap.get(firstKey);
+                    
+                    if (defaultValue != null) {
+                        Resource assertion = findAssertionWithPO(g, type, relation, object);
+                        if(assertion != null) {
+                            g.deny(assertion, L0.HasObject);
+                            g.claim(assertion, L0.HasObject, defaultValue);
+                            return;
+                        } else {
+                            Layer0Utils.assert_(g, type, relation, defaultValue);
+                            return;
+                        }
+                    }
+                }
+            }
+        }
+
         Tuple tuple = getDatatypeValueAndBinding(g, object, newSCLType);
         if (tuple == null)
             return;
 
-        Layer0 L0 = Layer0.getInstance(g);
         g.claimLiteral(object, L0.HasDataType, L0.DataType, tuple.get(0), Bindings.getBindingUnchecked(Datatype.class));
         g.claimLiteral(object, L0.HasValueType, g.<String>getRelatedValue(relation, L0.RequiresValueType, Bindings.STRING), Bindings.STRING);
         g.claimValue(object, tuple.get(1), (Binding)tuple.get(2));
 
     }
 
-    public static void convertInstantiatedValue(WriteGraph g, Resource instance, Resource relation, String newSCLType)
+    public static void convertInstantiatedValue(WriteGraph g, Resource instance, Resource relation, String newSCLType) throws DatabaseException {
+       convertInstantiatedValue(g, instance, relation, newSCLType, null);
+    }
+    
+    public static void convertInstantiatedValue(WriteGraph g, Resource instance, Resource relation, String newSCLType, Resource possibleType)
             throws DatabaseException {
 
         Statement stm = g.getPossibleStatement(instance, relation);
         if(stm != null && !stm.isAsserted(instance)) {
 
-            Resource object = stm.getObject();
+            Layer0 L0 = Layer0.getInstance(g);
+               Resource object = stm.getObject();
+
+               if(g.sync(new IsEnumeratedValue(object))) {
+                       if(!g.isInstanceOf(object, possibleType)) {
+                               g.deny(instance, relation);
+                       }
+                       return;
+               }
 
             // We can only convert literals
-            Layer0 L0 = Layer0.getInstance(g);
             if(!g.isInstanceOf(object, L0.Literal)) return;
 
             Tuple tuple = getDatatypeValueAndBinding(g, object, newSCLType);
index b201176261496f98942dbd31edc9e1597db68cf1..e1de9f20c20c0983a4ea4c2fe15d40c0db872e04 100644 (file)
@@ -41,7 +41,7 @@ public class UpdateMethodFactory<Domain, Range> implements IMethodRuleFactory<Do
             public boolean updateRange(ReadGraph g, IForwardMapping<Domain, Range> map,
                     Domain domainElement, Range rangeElement)
                     throws MappingException {
-                LOGGER.info("    UpdateMethodFactory.updateRange");      
+                LOGGER.trace("    UpdateMethodFactory.updateRange");      
                 try {
                     return (Boolean)method.invoke(rangeElement, g, domainElement);
                 } catch (Exception e) {
index 1c44ef9304aee20141386a0271c0bbc36aa85cf1..c2ecdf1b1679fe7f9fd5bd21ed9a0cef090ea63d 100644 (file)
@@ -73,7 +73,7 @@ public class Mapping<Domain, Range> implements IMapping<Domain, Range> {
        }
        
        private void createDomain(WriteGraph g, Link<Domain,Range> link) throws MappingException {
-           LOGGER.info("        createDomain for " + link.rangeElement);
+           LOGGER.trace("        createDomain for " + link.rangeElement);
                ILinkType<Domain,Range> type = schema.linkTypeOfRangeElement(link.rangeElement);
                Domain domainElement = type.createDomainElement(g, link.rangeElement);
                link.type = type;
@@ -264,11 +264,11 @@ public class Mapping<Domain, Range> implements IMapping<Domain, Range> {
        
        @Override
        public synchronized Collection<Domain> updateDomain(WriteGraph g) throws MappingException {
-           LOGGER.info("Mapping.updateDomain");
+           LOGGER.trace("Mapping.updateDomain");
                RangeToDomain map = new RangeToDomain(g);
                ArrayList<Domain> updated = new ArrayList<Domain>();
                while(!modifiedRangeLinks.isEmpty()) {
-                   LOGGER.info("    modifiedRangeLinks.size() = " + modifiedRangeLinks.size());
+                   LOGGER.trace("    modifiedRangeLinks.size() = " + modifiedRangeLinks.size());
                    
                        Link<Domain,Range> link = modifiedRangeLinks.remove(modifiedRangeLinks.size()-1);
                        link.rangeModified = false;
@@ -292,11 +292,11 @@ public class Mapping<Domain, Range> implements IMapping<Domain, Range> {
        
        @Override
        public synchronized Collection<Range> updateRange(ReadGraph g) throws MappingException {
-           LOGGER.info("Mapping.updateRange");
+           LOGGER.trace("Mapping.updateRange");
                DomainToRange map = new DomainToRange(g);
                ArrayList<Range> updated = new ArrayList<Range>();
                while(!modifiedDomainLinks.isEmpty()) {             
-                   LOGGER.info("    modifiedDomainLinks.size() = " + modifiedDomainLinks.size());
+                   LOGGER.trace("    modifiedDomainLinks.size() = " + modifiedDomainLinks.size());
                    
                        Link<Domain,Range> link = modifiedDomainLinks.remove(modifiedDomainLinks.size()-1);
                        link.domainModified = false;
@@ -359,7 +359,7 @@ public class Mapping<Domain, Range> implements IMapping<Domain, Range> {
        void domainModified(Link<Domain,Range> link) {
            if(!link.domainModified) {          
                synchronized(modifiedDomainLinks) {
-                   LOGGER.info("        domainModified for " + link.rangeElement);
+                   LOGGER.trace("        domainModified for " + link.rangeElement);
                 link.domainModified = true;
                 modifiedDomainLinks.add(link);
                 if(modifiedDomainLinks.size() == 1) {
index 5e4eec39feb51cc768c15d31de1bc8633ba706b2..9761f555568fbc6b3827eaa2d6cd7ee77e9ad884 100644 (file)
@@ -45,7 +45,7 @@ public class MappedElementRule<Domain, Range> implements IBidirectionalMappingRu
        public boolean updateDomain(WriteGraph g, IBackwardMapping<Domain, Range> map,
                        Domain domainElement, Range rangeElement)
                        throws MappingException {
-        LOGGER.info("    MappedElementRule.updateDomain");
+        LOGGER.trace("    MappedElementRule.updateDomain");
            Range value = rangeAccessor.get(rangeElement);
            Domain mappedValue = value == null ? null : map.inverseMap(g, value);//map.inverseGet(value);
                return domainAccessor.set(g, domainElement, mappedValue);
@@ -55,7 +55,7 @@ public class MappedElementRule<Domain, Range> implements IBidirectionalMappingRu
        public boolean updateRange(ReadGraph g, IForwardMapping<Domain, Range> map,
                        Domain domainElement, Range rangeElement)
                        throws MappingException {
-        LOGGER.info("    MappedElementRule.updateRange");   
+        LOGGER.trace("    MappedElementRule.updateRange");   
            Domain value = domainAccessor.get(g, domainElement);
         Range mappedValue = value == null ? null : map.map(g, value);////map.get(value);
         return rangeAccessor.set(rangeElement, mappedValue);
index 43a8ff49325fc46436954243092c5a22e391998b..7f3c13a106e956989fc4185353de667adad5f6e1 100644 (file)
@@ -49,7 +49,7 @@ public class MappedElementsRule<Domain, Range> implements IBidirectionalMappingR
     public boolean updateDomain(WriteGraph g, IBackwardMapping<Domain, Range> map,
             Domain domainElement, Range rangeElement)
     throws MappingException {
-        LOGGER.info("    MappedElementsRule.updateDomain");
+        LOGGER.trace("    MappedElementsRule.updateDomain");
         // Snapshot the accessed range value for concurrency safety.
         // NOTE: still assumes that the accessed collection is concurrent or
         // synchronized for toArray to be atomic.
@@ -65,7 +65,7 @@ public class MappedElementsRule<Domain, Range> implements IBidirectionalMappingR
     public boolean updateRange(ReadGraph g, IForwardMapping<Domain, Range> map,
             Domain domainElement, Range rangeElement)
     throws MappingException {
-        LOGGER.info("    MappedElementsRule.updateRange");
+        LOGGER.trace("    MappedElementsRule.updateRange");
         Collection<Domain> value = domainAccessor.get(g, domainElement);
         ArrayList<Range> mappedValue = new ArrayList<Range>(value.size());
         for(Domain r : value)
index d40c44f2b3287975c1d9c12a2e791048a83be1d7..9ba9dba11274291b0dadb6664492542bd853951e 100644 (file)
@@ -45,7 +45,7 @@ public class ValueRule<Domain, Range> implements IBidirectionalMappingRule<Domai
        public boolean updateDomain(WriteGraph g, IBackwardMapping<Domain, Range> map,
                        Domain domainElement, Range rangeElement)
                        throws MappingException {
-        LOGGER.info("    ValueRule.updateDomain");         
+        LOGGER.trace("    ValueRule.updateDomain");        
                Object value = rangeAccessor.get(rangeElement);
                return domainAccessor.set(g, domainElement, value);
        }
@@ -54,7 +54,7 @@ public class ValueRule<Domain, Range> implements IBidirectionalMappingRule<Domai
        public boolean updateRange(ReadGraph g, IForwardMapping<Domain, Range> map,
                        Domain domainElement, Range rangeElement)
                        throws MappingException {
-        LOGGER.info("    ValueRule.updateRange");
+        LOGGER.trace("    ValueRule.updateRange");
                Object value = domainAccessor.get(g, domainElement);
                return rangeAccessor.set(rangeElement, value);
        }       
index 53eb0116829fe8181c61dc1147bf96d7b7cf78d9..39df524b270943022478f51669f2a6627cbbe03e 100644 (file)
@@ -52,7 +52,7 @@ public class CompoundValueAccessor implements IDomainAccessor<Resource,Object> {
        public Object get(ReadGraph g, Resource element) throws MappingException {
                try {
                        Layer0 l0 = Layer0.getInstance(g);
-                   LOGGER.info("        CompoundValueAccessor.get");
+                   LOGGER.trace("        CompoundValueAccessor.get");
                    Collection<Statement> coll = g.getStatements(element, objRelation);
                    Map<String,Object> map = new HashMap<String, Object>();
                    for (Statement c : coll) {
@@ -73,7 +73,7 @@ public class CompoundValueAccessor implements IDomainAccessor<Resource,Object> {
                        throws MappingException {
                try {
                        Layer0 l0 = Layer0.getInstance(g);
-                   LOGGER.info("        CompoundValueAccessor.set");
+                   LOGGER.trace("        CompoundValueAccessor.set");
                    @SuppressWarnings("unchecked")
                    Map<String,Object> values = (Map<String, Object>)v;
                    
index efdaab56cf4665f2ec90a7a51182eb4b1cbf0c04..e9104c3d98b4193f9ded854bd4016ebfb35c7c04 100644 (file)
@@ -45,7 +45,7 @@ public class LinkedListAccessor implements IDomainAccessor<Resource,Collection<R
        @Override
        public Collection<Resource> get(ReadGraph g, Resource element) throws MappingException {
                try {
-                       LOGGER.info("        LinkdedListAccessor.get");
+                       LOGGER.trace("        LinkdedListAccessor.get");
                        return ListUtils.toList(g, g.getPossibleObject(element, relation));
                } catch (DatabaseException e) {
                        throw new MappingException(e);
@@ -56,7 +56,7 @@ public class LinkedListAccessor implements IDomainAccessor<Resource,Collection<R
        public boolean set(WriteGraph g, Resource element, Collection<Resource> value)
                        throws MappingException {
                try {
-                       LOGGER.info("        LinkdedListAccessor.set");
+                       LOGGER.trace("        LinkdedListAccessor.set");
                        return MappingUtils.synchronizeList(g, element, relation, listType, new ArrayList<Resource>(value), deleteExtraObjects);
                } catch (DatabaseException e) {
                        throw new MappingException(e);
index 6f7f9260fde774cd50b59be3b95ae4f5a834425b..0bb50ff5726c270d92e69cb1be1074a71e3030bd 100644 (file)
@@ -55,7 +55,7 @@ public class MappingUtils {
                while(true) {
                        int cmp = currentObjects[i].compareTo(objects[j]);
                        if(cmp < 0) {
-                           LOGGER.info("            remove statement");
+                           LOGGER.trace("            remove statement");
                            if(deleteExtraObjects)
                                g.deny(currentObjects[i]);
                            else
@@ -66,7 +66,7 @@ public class MappingUtils {
                                        break;
                        }
                        else if(cmp > 0) {
-                           LOGGER.info("            add statement");
+                           LOGGER.trace("            add statement");
                                g.claim(subject, predicate, objects[j]);
                                modified = true;
                                ++j;
index 2cfc98185f5b3cd842255363c8a17e71f5bf3b07..28000a99e7412688f7544ac392bbafa8fd868c67 100644 (file)
@@ -36,7 +36,7 @@ public class RelatedObjectAccessor implements IDomainAccessor<Resource,Resource>
        @Override
        public Resource get(ReadGraph g, Resource element) throws MappingException {
                try {
-                   LOGGER.info("        RelatedObjectAccessor.get");
+                   LOGGER.trace("        RelatedObjectAccessor.get");
                        return g.getPossibleObject(element, relation);
                } catch (DatabaseException e) {
                        throw new MappingException(e);
@@ -47,7 +47,7 @@ public class RelatedObjectAccessor implements IDomainAccessor<Resource,Resource>
        public boolean set(WriteGraph g, Resource element, Resource value)
                        throws MappingException {
                try {
-                   LOGGER.info("        RelatedObjectAccessor.set");
+                   LOGGER.trace("        RelatedObjectAccessor.set");
                    Resource resource = g.getPossibleObject(element, relation);
                        if(resource == null) {
                            if(value == null)
index d8002d976022398ff7196fbd43606c26d79ba257..d2d1db99a7d78e6cc06f1d93483e3523ae376e93 100644 (file)
@@ -41,7 +41,7 @@ public class RelatedObjectsAccessor implements IDomainAccessor<Resource,Collecti
     @Override
        public Collection<Resource> get(ReadGraph g, Resource element) throws MappingException {
                try {
-                   LOGGER.info("        RelatedObjectsAccessor.get");
+                   LOGGER.trace("        RelatedObjectsAccessor.get");
                        return g.getObjects(element, relation);
                } catch (DatabaseException e) {
                        throw new MappingException(e);
@@ -52,7 +52,7 @@ public class RelatedObjectsAccessor implements IDomainAccessor<Resource,Collecti
        public boolean set(WriteGraph g, Resource element, Collection<Resource> value)
                        throws MappingException {
                try {
-                   LOGGER.info("        RelatedObjectsAccessor.set");
+                   LOGGER.trace("        RelatedObjectsAccessor.set");
                        return MappingUtils.synchronizeStatements(g, element, relation, 
                                value.toArray(new Resource[value.size()]), deleteExtraObjects);
                } catch (DatabaseException e) {
index a272b4f0bc4dd0786688d6ff25719089ee1545f0..4d78956756a7db91ef392c6cdb1999465f2c4c0b 100644 (file)
@@ -40,7 +40,7 @@ public class RelatedOrderedSetElementsAccessor implements IDomainAccessor<Resour
     @Override
        public Collection<Resource> get(ReadGraph g, Resource element) throws MappingException {
                try {
-                   LOGGER.info("        RelatedOrderedSetElementsAccessor.get");
+                   LOGGER.trace("        RelatedOrderedSetElementsAccessor.get");
                        return OrderedSetUtils.toList(g, element);
                } catch (DatabaseException e) {
                        throw new MappingException(e);
@@ -51,7 +51,7 @@ public class RelatedOrderedSetElementsAccessor implements IDomainAccessor<Resour
        public boolean set(WriteGraph g, Resource element, Collection<Resource> value)
                        throws MappingException {
                try {
-                   LOGGER.info("        RelatedOrderedSetElementsAccessor.set");
+                   LOGGER.trace("        RelatedOrderedSetElementsAccessor.set");
                    return OrderedSetUtils.set(g, element, value);
                    // FIXME Implement deleteExtraObjects
                } catch (DatabaseException e) {
index 585b468e60c049217a4ec2e74db26011b6663648..9aa96d8e89ed64a1379b77d39ec762b2f83ac706 100644 (file)
@@ -49,7 +49,7 @@ public class RelatedValueAccessor implements IDomainAccessor<Resource,Object> {
        @Override
        public Object get(ReadGraph g, Resource element) throws MappingException {
                try {
-                   LOGGER.info("        RelatedValueAccessor.get");
+                   LOGGER.trace("        RelatedValueAccessor.get");
                        Resource valueResource = g.getPossibleObject(element, relation);
                        if(valueResource == null)
                                return null;
@@ -63,7 +63,7 @@ public class RelatedValueAccessor implements IDomainAccessor<Resource,Object> {
        public boolean set(WriteGraph g, Resource element, Object value)
                        throws MappingException {
                try {
-                   LOGGER.info("        RelatedValueAccessor.set");
+                   LOGGER.trace("        RelatedValueAccessor.set");
                    Statement valueStatement = g.getPossibleStatement(element, relation);
                        if(valueStatement == null) {
                                if(value == null)
index 278c35a89503a32798b22b6fd31054836d385f98..c5a35613cd07ade3454c45f76b720096ace63d4f 100644 (file)
@@ -38,8 +38,8 @@ public class FieldAccessor<Range,T> implements IRangeAccessor<Range,T> {
                    @SuppressWarnings("unchecked")
                        T result = (T)field.get(element);
                    
-               if(LOGGER.isInfoEnabled())
-                   LOGGER.info("        FieldAccessor.get " +
+               if(LOGGER.isTraceEnabled())
+                   LOGGER.trace("        FieldAccessor.get " +
                            field.getName() + " -> " + result
                    );
                
@@ -56,8 +56,8 @@ public class FieldAccessor<Range,T> implements IRangeAccessor<Range,T> {
                try {
                        Object currentValue = field.get(element);
                        
-            if(LOGGER.isInfoEnabled())
-                LOGGER.info("        FieldAccessor.set " +
+            if(LOGGER.isTraceEnabled())
+                LOGGER.trace("        FieldAccessor.set " +
                         field.getName() + " " + currentValue +  
                         " -> " + value
                 );
index 792813bb1020b8a524723dea76ba7bf1f7aac46d..4f44844dbbaa034afbc9d84dcf702c3cb2965ece 100644 (file)
@@ -70,8 +70,8 @@ public class DynamicSimpleLinkType<Range> extends SimpleLinkType<Range>{
             throws MappingException {
         try {
                String typeUri = (String)typeGetter.invoke(rangeElement, (Object[]) null);
-            if(LOGGER.isInfoEnabled())
-                LOGGER.info("SimpleLinkType.createDomainElement " +
+            if(LOGGER.isTraceEnabled())
+                LOGGER.trace("SimpleLinkType.createDomainElement " +
                         rangeElement.toString()
                 );
             Resource actualDomainType = g.getResource(typeUri);
@@ -95,9 +95,9 @@ public class DynamicSimpleLinkType<Range> extends SimpleLinkType<Range>{
            public Range createRangeElement(ReadGraph g, Resource domainElement)
                    throws MappingException {
                try {
-                   if(LOGGER.isInfoEnabled())
+                   if(LOGGER.isTraceEnabled())
                        try { 
-                           LOGGER.info("SimpleLinkType.createRangeElement " +
+                           LOGGER.trace("SimpleLinkType.createRangeElement " +
                                        NameUtils.getSafeName(g, domainElement)
                                    );
                        } catch(DatabaseException e) {
index bd87c074f0f4ecbe14ecddcce0b05fc4d13369d2..748422df2a5f51deebe85d421c1c4e78fdbe242d 100644 (file)
@@ -20,8 +20,8 @@ public class OrderedSetSimpleLinkType<Range> extends SimpleLinkType<Range> {
        
        public Resource createDomainElement(org.simantics.db.WriteGraph g, Range rangeElement) throws org.simantics.objmap.exceptions.MappingException {
                 try {
-            if(LOGGER.isInfoEnabled())
-                LOGGER.info("SimpleLinkType.createDomainElement " +
+            if(LOGGER.isTraceEnabled())
+                LOGGER.trace("SimpleLinkType.createDomainElement " +
                         rangeElement.toString()
                 );
             Resource result = OrderedSetUtils.create(g, domainType);
index 096d07cb83d609b0d33ccc49090ba49d649f32fb..9ddc437162e12a32720c5faefa6544ddc7e8a246 100644 (file)
@@ -64,8 +64,8 @@ public class SimpleLinkType<Range> implements ILinkType<Resource,Range> {
     public Resource createDomainElement(WriteGraph g, Range rangeElement)
             throws MappingException {
         try {
-            if(LOGGER.isInfoEnabled())
-                LOGGER.info("SimpleLinkType.createDomainElement " +
+            if(LOGGER.isTraceEnabled())
+                LOGGER.trace("SimpleLinkType.createDomainElement " +
                         rangeElement.toString()
                 );
             Resource result = g.newResource();
@@ -80,9 +80,9 @@ public class SimpleLinkType<Range> implements ILinkType<Resource,Range> {
     public Range createRangeElement(ReadGraph g, Resource domainElement)
             throws MappingException {
         try {
-            if(LOGGER.isInfoEnabled())
+            if(LOGGER.isTraceEnabled())
                 try { 
-                    LOGGER.info("SimpleLinkType.createRangeElement " +
+                    LOGGER.trace("SimpleLinkType.createRangeElement " +
                                NameUtils.getSafeName(g, domainElement)
                             );
                 } catch(DatabaseException e) {
@@ -105,9 +105,9 @@ public class SimpleLinkType<Range> implements ILinkType<Resource,Range> {
     };
     
     public boolean updateDomain(WriteGraph g, IBackwardMapping<Resource,Range> map, Resource domainElement, Range rangeElement) throws MappingException {
-        if(LOGGER.isInfoEnabled())
+        if(LOGGER.isTraceEnabled())
             try { 
-                LOGGER.info("SimpleLinkType.updateDomain " +
+                LOGGER.trace("SimpleLinkType.updateDomain " +
                         NameUtils.getSafeName(g, domainElement) + " " +
                         rangeElement.toString()
                         );
@@ -123,9 +123,9 @@ public class SimpleLinkType<Range> implements ILinkType<Resource,Range> {
     
     public boolean updateRange(ReadGraph g, IForwardMapping<Resource,Range> map, Resource domainElement, Range rangeElement) throws MappingException {
     
-        if(LOGGER.isInfoEnabled())
+        if(LOGGER.isTraceEnabled())
             try { 
-                LOGGER.info("SimpleLinkType.updateRange " +
+                LOGGER.trace("SimpleLinkType.updateRange " +
                                NameUtils.getSafeName(g, domainElement) + " " +
                         (rangeElement.getClass().getName() + "@" + Integer.toHexString(rangeElement.hashCode()))
                         );
index 1ce1ef1c61e9f74dc91e449d961f6185bda98d13..a2be5fa42bf978083642deb38b68807e46dc3329 100644 (file)
@@ -41,7 +41,7 @@ public class UpdateMethodFactory<Domain, Range> implements IMethodRuleFactory<Do
             public boolean updateRange(ReadGraph g, IForwardMapping<Domain, Range> map,
                     Domain domainElement, Range rangeElement)
                     throws MappingException {
-                LOGGER.info("    UpdateMethodFactory.updateRange");      
+                LOGGER.trace("    UpdateMethodFactory.updateRange");      
                 try {
                     return (Boolean)method.invoke(rangeElement, g, domainElement);
                 } catch (Exception e) {
index 736f86b39c2a889b9962d8dd8334e809d8426ea8..de80a9a95fdacd3ff4af5fb72166fe7e3df91ae4 100644 (file)
@@ -51,7 +51,7 @@ public class RelatedObjectAccessor implements IDomainAccessor<StructuralResource
        @Override
        public StructuralResource get(ReadGraph g, StructuralResource element) throws MappingException {
                try {
-                   LOGGER.info("        RelatedObjectAccessor.get");
+                   LOGGER.trace("        RelatedObjectAccessor.get");
                    Resource res = getServiceResource(g, element);
                    if (res == null)
                        return null;
@@ -72,7 +72,7 @@ public class RelatedObjectAccessor implements IDomainAccessor<StructuralResource
        public boolean set(WriteGraph g, StructuralResource selement, StructuralResource value)
                        throws MappingException {
                try {
-                   LOGGER.info("        RelatedObjectAccessor.set");
+                   LOGGER.trace("        RelatedObjectAccessor.set");
                    Resource element = getServiceResource(g, selement);
                    if (element == null)
                        return false;
index 1e1be5b76df10f81935f760dc5cd48cf4b21593e..b09de09b83551a1c9d7427c6e11441d4544b0504 100644 (file)
@@ -58,7 +58,7 @@ public class RelatedObjectsAccessor implements IDomainAccessor<StructuralResourc
     @Override
        public Collection<StructuralResource> get(ReadGraph g, StructuralResource element) throws MappingException {
                try {
-                   LOGGER.info("        RelatedObjectsAccessor.get");
+                   LOGGER.trace("        RelatedObjectsAccessor.get");
                        
                   
                    Resource res = getServiceResource(g, element);
@@ -87,7 +87,7 @@ public class RelatedObjectsAccessor implements IDomainAccessor<StructuralResourc
        public boolean set(WriteGraph g, StructuralResource element, Collection<StructuralResource> value)
                        throws MappingException {
                try {
-                   LOGGER.info("        RelatedObjectsAccessor.set");
+                   LOGGER.trace("        RelatedObjectsAccessor.set");
                    Resource res = getServiceResource(g, element);
                    if (res == null)
                        return false;
index 97fde226f2fa522ac8ca472b94146db55feca996..35f98994d23dd9ccb638fb493939c3b8523bdded 100644 (file)
@@ -43,7 +43,7 @@ public class RelatedOrderedSetElementsAccessor implements IDomainAccessor<Struct
     @Override
        public Collection<StructuralResource> get(ReadGraph g, StructuralResource element) throws MappingException {
                try {
-                   LOGGER.info("        RelatedOrderedSetElementsAccessor.get");
+                   LOGGER.trace("        RelatedOrderedSetElementsAccessor.get");
                    Resource res = getServiceResource(g, element);
                    if (res == null)
                        return Collections.emptyList();
@@ -62,7 +62,7 @@ public class RelatedOrderedSetElementsAccessor implements IDomainAccessor<Struct
        public boolean set(WriteGraph g, StructuralResource element, Collection<StructuralResource> value)
                        throws MappingException {
                try {
-                   LOGGER.info("        RelatedOrderedSetElementsAccessor.set");
+                   LOGGER.trace("        RelatedOrderedSetElementsAccessor.set");
                    Resource res = getServiceResource(g, element);
                    if (res == null)
                        return false;
index 41279d1aba8fede41e5bde9fa42b9eeeb33a9c04..21a6733a4b3e4938def7029fbbafa810ca6b9084 100644 (file)
@@ -58,7 +58,7 @@ public class RelatedValueAccessor implements IDomainAccessor<StructuralResource,
        @Override
        public Object get(ReadGraph g, StructuralResource element) throws MappingException {
                try {
-                   LOGGER.info("        RelatedValueAccessor.get");
+                   LOGGER.trace("        RelatedValueAccessor.get");
                    Resource res = getServiceResource(g, element);
                    if (res == null)
                        return null;
@@ -75,7 +75,7 @@ public class RelatedValueAccessor implements IDomainAccessor<StructuralResource,
        public boolean set(WriteGraph g, StructuralResource relement, Object value)
                        throws MappingException {
                try {
-                   LOGGER.info("        RelatedValueAccessor.set");
+                   LOGGER.trace("        RelatedValueAccessor.set");
                    
                    Resource element = getServiceResource(g, relement);
                    if (element == null)
index 865d4249ea78553645dbed7296bc9e4bc0ac8664..1b088754327511cff225e40ae690ec5c926cdec5 100644 (file)
@@ -55,7 +55,7 @@ public class StructuralRelatedObjectAccessor implements IDomainAccessor<Structur
        public StructuralResource get(ReadGraph g, StructuralResource element) throws MappingException {
                try {
                        
-                       LOGGER.info("        RelatedObjectAccessor.get");
+                       LOGGER.trace("        RelatedObjectAccessor.get");
                        
                        if (!element.isStructural())
                                return null;
@@ -85,7 +85,7 @@ public class StructuralRelatedObjectAccessor implements IDomainAccessor<Structur
        public boolean set(WriteGraph g, StructuralResource element, StructuralResource value)
                        throws MappingException {
                try {
-                   LOGGER.info("        RelatedObjectAccessor.set");
+                   LOGGER.trace("        RelatedObjectAccessor.set");
                    Resource instance = StructuralUtils.getContainingInstance(element);
                    Resource publicRelation = null;
                    if (instance == null)
index 6984bdcd02269a556eaef001f210d7be4268db96..aa3fdcad247a9f8e46ae0f9ef28f2bf4502aefab 100644 (file)
@@ -44,7 +44,7 @@ public class StructuralRelatedObjectsAccessor implements IDomainAccessor<Structu
     @Override
        public Collection<StructuralResource> get(ReadGraph g, StructuralResource element) throws MappingException {
                try {
-                   LOGGER.info("        RelatedObjectsAccessor.get");
+                   LOGGER.trace("        RelatedObjectsAccessor.get");
                        
                    if (!element.isStructural())
                        return Collections.emptyList();
@@ -79,7 +79,7 @@ public class StructuralRelatedObjectsAccessor implements IDomainAccessor<Structu
        public boolean set(WriteGraph g, StructuralResource element, Collection<StructuralResource> value)
                        throws MappingException {
                try {
-                   LOGGER.info("        RelatedObjectsAccessor.set");
+                   LOGGER.trace("        RelatedObjectsAccessor.set");
                    
                    if (!element.isStructural())
                        return false;
index ded0f40db8c15e3e1e4e0daad19e82344ac331f3..77b2ab094a50b6baf05c6853b3b10a7da6d91242 100644 (file)
@@ -64,8 +64,8 @@ public class SimpleLinkType implements ILinkType<StructuralResource,IStructuralO
     public StructuralResource createDomainElement(WriteGraph g, IStructuralObject rangeElement)
             throws MappingException {
         try {
-            if(LOGGER.isInfoEnabled())
-                LOGGER.info("SimpleLinkType.createDomainElement " +
+            if(LOGGER.isTraceEnabled())
+                LOGGER.trace("SimpleLinkType.createDomainElement " +
                         rangeElement.toString()
                 );
             if (rangeElement.getContext().size() == 0) {
@@ -98,9 +98,9 @@ public class SimpleLinkType implements ILinkType<StructuralResource,IStructuralO
     public IStructuralObject createRangeElement(ReadGraph g, StructuralResource domainElement)
             throws MappingException {
         try {
-            if(LOGGER.isInfoEnabled())
+            if(LOGGER.isTraceEnabled())
                 try { 
-                    LOGGER.info("SimpleLinkType.createRangeElement " + NameUtils.getSafeName(g, domainElement.getResource()));
+                    LOGGER.trace("SimpleLinkType.createRangeElement " + NameUtils.getSafeName(g, domainElement.getResource()));
                 } catch(DatabaseException e) {
                     throw new MappingException(e);
                 }
@@ -155,9 +155,9 @@ public class SimpleLinkType implements ILinkType<StructuralResource,IStructuralO
     }
     
     public boolean updateDomain(WriteGraph g, IBackwardMapping<StructuralResource,IStructuralObject> map, StructuralResource domainElement, IStructuralObject rangeElement) throws MappingException {
-        if(LOGGER.isInfoEnabled())
+        if(LOGGER.isTraceEnabled())
             try { 
-                LOGGER.info("SimpleLinkType.updateDomain " +
+                LOGGER.trace("SimpleLinkType.updateDomain " +
                         NameUtils.getSafeName(g, domainElement.getResource()) + " " +
                         rangeElement.toString()
                         );
@@ -173,9 +173,9 @@ public class SimpleLinkType implements ILinkType<StructuralResource,IStructuralO
     
     public boolean updateRange(ReadGraph g, IForwardMapping<StructuralResource, IStructuralObject> map, StructuralResource domainElement, IStructuralObject rangeElement) throws MappingException {
     
-        if(LOGGER.isInfoEnabled())
+        if(LOGGER.isTraceEnabled())
             try { 
-                LOGGER.info("SimpleLinkType.updateRange " +
+                LOGGER.trace("SimpleLinkType.updateRange " +
                                NameUtils.getSafeName(g, domainElement.getResource()) + " " +
                         rangeElement.toString()
                         );
index e8d37789b00be77a32ef8cc6306fd6ab8fa6cb16..3925450bd29c71b82bb0bf5e519d00e4155cf430 100644 (file)
@@ -1,6 +1,7 @@
 module {
     export = [possibleUnsafeSclValueByName, unsafeSclValueByName, sclModuleNames, moduleByName,
-              documentationOfSCLValue, sclValueRef, possibleModuleSourceText]
+              documentationOfSCLValue, sclValueRef, possibleModuleSourceText, flushModuleRepository, 
+              flushDefaultModuleRepository]
 }
 
 include "./CurrentModuleRepository"
@@ -30,6 +31,9 @@ importJava "org.simantics.scl.compiler.module.repository.ModuleRepository" where
     @JavaName getModule
     moduleByName_ :: ModuleRepository -> String -> <Proc> Failable Module 
     
+    @JavaName flush
+    flushModuleRepository :: ModuleRepository -> <Proc> ()
+    
 importJava "org.simantics.scl.compiler.source.repository.ModuleSourceRepository" where
     data ModuleSourceRepository
     
@@ -50,6 +54,9 @@ unsafeSclValueByName = unsafeSclValueByName_ MODULE_REPOSITORY
 
 sclValueRef name = sclValueRef_ MODULE_REPOSITORY name
 
+flushDefaultModuleRepository :: <Proc> ()
+flushDefaultModuleRepository = flushModuleRepository MODULE_REPOSITORY
+
 possibleUnsafeSclValueByName :: String -> <Proc> Maybe a
 possibleUnsafeSclValueByName name = Just (unsafeSclValueByName name) `catch` \(_ :: Exception) -> Nothing
 
index 8a86c5ccce36ecef59326e7abcd32a558d7e27ea..a6650e9a44faa5627b41b0cf260ee6ecf6baaadb 100644 (file)
@@ -505,7 +505,7 @@ public class ModuleRepository {
         if (moduleCache != null)
             for (ModuleEntry entry : moduleCache.values())
                 entry.dispose();
-        moduleCache = null;
+        moduleCache = new ConcurrentHashMap<String, ModuleEntry>();
     }
 
     /**
index 79541b06134deb344a5f6f71c4dda854edcfc145..233a1e5a11608fd20088deeb0a82f9c6d31d422d 100644 (file)
@@ -2,6 +2,7 @@ package org.simantics.selectionview.function;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Map;
 import java.util.function.Consumer;
 
@@ -12,7 +13,9 @@ import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.FontDialog;
 import org.simantics.Simantics;
 import org.simantics.browsing.ui.NodeContext;
+import org.simantics.browsing.ui.common.modifiers.EnumerationValue;
 import org.simantics.browsing.ui.content.Labeler.DialogModifier;
+import org.simantics.browsing.ui.graph.impl.GetEnumerationValue;
 import org.simantics.common.format.Formatter;
 import org.simantics.databoard.Bindings;
 import org.simantics.databoard.Datatypes;
@@ -62,6 +65,7 @@ import org.simantics.ui.fonts.Fonts;
 import org.simantics.ui.selection.WorkbenchSelectionElement;
 import org.simantics.ui.selection.WorkbenchSelectionUtils;
 import org.simantics.utils.datastructures.collections.CollectionUtils;
+import org.simantics.utils.strings.AlphanumComparator;
 import org.simantics.utils.ui.AdaptionUtils;
 import org.simantics.utils.ui.ErrorLogger;
 import org.simantics.utils.ui.ISelectionUtils;
@@ -198,7 +202,9 @@ public class All {
                        Resource parameterResource = parameter.getRepresents(graph);
                        if(graph.sync(new IsEnumeratedValue(parameterResource))) {
                                Map<String, Resource> map = graph.sync(new InstanceEnumerationMap(parameterResource));
-                               return new ArrayList<String>(map.keySet());
+                               ArrayList<String> values = new ArrayList<>(map.keySet());
+                               Collections.sort(values, AlphanumComparator.COMPARATOR);
+                               return values;
                        } else if(graph.isInstanceOf(parameterResource, L0.Boolean)) {
                                return CollectionUtils.toList("true", "false");
                        }
@@ -463,6 +469,14 @@ public class All {
                                        value = formatterFunction.apply(property.getValue(graph));
                                }
                        }
+
+                       Resource possibleValue = context.getParent(graph).getPossibleRepresents(graph);
+                       if(possibleValue != null) {
+                               if(graph.syncRequest(new IsEnumeratedValue(possibleValue))) {
+                       return GetEnumerationValue.getEnumerationValueName(graph, possibleValue);
+                               }
+                       }
+
                        if(value == null) {
 
                                Variant variant = property.getVariantValue(graph);
@@ -518,8 +532,14 @@ public class All {
                                String parsedLabel = (String)_value;
                                Object value = parsedLabel;
 
+                               boolean isEnumeration = false;
+                               Resource possibleValue = context.getParent(graph).getPossibleRepresents(graph);
+                               if(possibleValue != null) {
+                                       isEnumeration = graph.syncRequest(new IsEnumeratedValue(possibleValue));
+                               }
+
                                Datatype type = context.getParent(graph).getPossibleDatatype(graph);
-                               if (type != null) {
+                               if (type != null && !isEnumeration) {
 
                                        Binding binding = Bindings.getBinding(type);
 
index cf6f05ab2a087fcf9b2edac0178d415b97841ae4..5f7068162b6219acb8e9a1d46dde2b2c8eb34c9e 100644 (file)
@@ -309,16 +309,16 @@ STR.Property <T L0.FunctionalRelation <T L0.PropertyRelation
             L0.HasValueType "String"
 
 STR.Component
-  L0.HasConstraint STR.ConnectionConstraint : L0.Constraint
+  L0.HasConstraint STR.ConnectionValidationConstraint : L0.Constraint
     L0.Constraint.Validator
       STR.Functions.connectionValidator : L0.Function
 
-STR.ConnectionConstraint.ErrorIssue
+STR.ConnectionValidationConstraint.ErrorIssue
   @ISSUE.issue ISSUE.Severity.Error
     STR.Functions.connectionIssueDescription : L0.Function
       L0.HasValueType "String" 
   
-STR.ConnectionConstraint.Source <T ISSUE.Sources.DependencyTracker
+STR.ConnectionValidationConstraint.Source <T ISSUE.Sources.DependencyTracker
   L0.HasLabel "Structural connection validity"
   @L0.assert ISSUE.Sources.DependencyTracker.HasType STR.Component
   @L0.assert ISSUE.Sources.DependencyTracker.HasSearchType STR.Connection
index a4dea1ab25ad9ce600e7b4edae7897acde3c50e8..246b6936029d3821d52aa54ebb6081ee0555838d 100644 (file)
@@ -66,11 +66,20 @@ public class ModuleUpdateContext<T extends ComponentBase<T>> {
     public int getModuleId() {
         return component.getModuleId();
     }
-    
+
+    public ModuleUpdaterBase<T> getUpdater() {
+        return updater;
+    }
+
     public SynchronizationEventHandlerBase<T> getHandler() {
         return handler;
     }
 
+    @SuppressWarnings("unchecked")
+    public <E extends SynchronizationEventHandlerBase<?>> E getConcreteHandler() {
+        return (E) handler;
+    }
+
     public void setModuleId(int moduleId) {
         component.setModuleId(moduleId);
     }
index a6efeefb2534bc402c25cfc671705ccbb6ad0cbb..67b120b6462cc10b3e36364c70e884f91f8c9d9c 100644 (file)
@@ -248,7 +248,7 @@ public abstract class SynchronizationEventHandlerBase<T extends ComponentBase<T>
                     if(oldChildMap != null)
                         for(T component : oldChildMap.values()) {
                             component.clearParent();
-                            mapping.addPendingRemoval(component);
+                            addPendingRemoval(component);
                         }
                 }
                 // Alternative implementation when uids are not available.
@@ -275,7 +275,7 @@ public abstract class SynchronizationEventHandlerBase<T extends ComponentBase<T>
                     if(oldChildMap != null)
                         for(T component : oldChildMap.values()) {
                             component.clearParent();
-                            mapping.addPendingRemoval(component);
+                            addPendingRemoval(component);
                         }
                 }
 
@@ -334,6 +334,12 @@ public abstract class SynchronizationEventHandlerBase<T extends ComponentBase<T>
         }
     }
 
+    protected void addPendingRemoval(T component) {
+        if (TRACE_EVENTS)
+            System.out.println("addPendingRemoval(" + component.componentId + " : " + component.solverComponentName + ")");
+        mapping.addPendingRemoval(component);
+    }
+
     private String getSubprocessName(String name,
             Collection<SerializedVariable> properties) {
         for(SerializedVariable property : properties)
index 3c96a3feff3a8405938032973f457e25e34ada7e..423e5a1256b5b54921a4f2537bb84a566173bb2f 100644 (file)
@@ -1,12 +1,13 @@
 package org.simantics.structural.synchronization.utils;
 
-import java.io.PrintWriter;
-
 import gnu.trove.map.hash.THashMap;
 import gnu.trove.procedure.TObjectObjectProcedure;
 import gnu.trove.procedure.TObjectProcedure;
 import gnu.trove.set.hash.THashSet;
 
+import java.io.PrintWriter;
+import java.util.function.Consumer;
+
 /**
  * The entry point to the mapping structure between Simantics database and a
  * designated solver. It is used to synchronize changes from Simantics to the
@@ -219,4 +220,11 @@ abstract public class MappingBase<T extends ComponentBase<T>> {
         return !pendingRemoval.isEmpty();
     }
 
+    public void forEachPendingRemoval(Consumer<T> consumer) {
+        pendingRemoval.forEach(c -> {
+            consumer.accept(c);
+            return true;
+        });
+    }
+
 }
index 970e6f9e813dc710545aeed3d6c0ee1c6cf234cd..e43007637ac5ca616a89f33b3cc3f62247ad8fea 100644 (file)
@@ -749,7 +749,7 @@ public class Functions {
 
                for(Resource req : requiredConnections) {
                        if(!connections.contains(req)) {
-                               result.add(new StandardIssue(sr.ConnectionConstraint_ErrorIssue, component, req));
+                               result.add(new StandardIssue(sr.ConnectionValidationConstraint_ErrorIssue, component, req));
                        }
                }