X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2FcomponentTypeEditor%2FComponentTypeViewerData.java;fp=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2FcomponentTypeEditor%2FComponentTypeViewerData.java;h=01c799d45832b824835b1a477c20c3ecd3dfce16;hp=ea10d6d8d4e44d700cf6cc789b97ca49ed9e6e6c;hb=3a25ce941361ea625bc07a427b0574fe5cb17180;hpb=46cdf23c4ea4733a3acbfd5c9895ec9e65965c7d diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewerData.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewerData.java index ea10d6d8d..01c799d45 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewerData.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewerData.java @@ -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.HashSet; import java.util.List; +import java.util.Set; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; @@ -33,6 +36,7 @@ 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; @@ -40,15 +44,20 @@ import org.simantics.databoard.util.Range; import org.simantics.databoard.util.RangeException; 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.WriteRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.function.DbConsumer; +import org.simantics.db.layer0.QueryIndexUtils; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.layer0.Layer0; import org.simantics.modeling.userComponent.ComponentTypeCommands; import org.simantics.scl.runtime.function.Function2; import org.simantics.scl.runtime.function.Function4; +import org.simantics.utils.datastructures.Pair; import org.simantics.utils.threads.ThreadUtils; import org.simantics.utils.ui.ErrorLogger; @@ -246,12 +255,47 @@ 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); + + String newValue2 = newValue; + + Resource possibleGraphType = null; + Resource root = graph.syncRequest(new IndexRoot(componentType)); + + Resource L0Res = graph.getResource("http://www.simantics.org/Layer0-1.1"); + Layer0 L0 = Layer0.getInstance(graph); + + Collection graphTypes1 = QueryIndexUtils.searchByTypeAndName(graph, L0Res, L0.ValueType, newValue); + Collection graphTypes2 = QueryIndexUtils.searchByTypeAndName(graph, root, L0.ValueType, newValue); + + Collection graphTypes = new HashSet<>(graphTypes1); + graphTypes.addAll(graphTypes2); + + Set> candidates = new HashSet<>(); + for (Resource graphType : graphTypes) { + Collection stms = graph.getAssertedStatements(graphType, L0.HasValueType); + if(stms.size() == 1) { + // Only accept valueType if it asserts HasValueType with the same name + String hasValueType = graph.getValue(stms.iterator().next().getObject(), Bindings.STRING); + if (hasValueType.equals(newValue)) { + candidates.add(new Pair<>(graphType, hasValueType)); + } + } + } + + // We support only graph types with unique name at this point. Later we could implement UI to let the user to select from multiple graph types. + if (candidates.size() == 1) { + Pair result = candidates.iterator().next(); + possibleGraphType = result.first; + newValue2 = result.second; + } + + ComponentTypeCommands.editType(graph, componentType, propertyInfo.resource, convertDefaultValue, newValue2, possibleGraphType); if (range != null) ComponentTypeCommands.setRange(graph, componentType, propertyInfo.resource, range); } });