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=820d45f2e1ecf9365a65aa3895771b68519ee8ee;hp=ea10d6d8d4e44d700cf6cc789b97ca49ed9e6e6c;hb=a175b74181c4841b403170f03e1ad9caac946f53;hpb=99fde2d98f5eda43f77c3fad4c07a2f4f234380c 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..820d45f2e 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.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> { + public TypeDefinitionMapRequest(Resource resource) { + super(resource); + } + + @Override + public Map perform(ReadGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + Map result = new HashMap<>(); + for(Resource valueType : QueryIndexUtils.searchByType(graph, resource, L0.ValueType)) { + Collection 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 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); } });