package org.simantics.district.network.techtype.variable; import org.simantics.databoard.binding.Binding; import org.simantics.databoard.type.Datatype; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.variable.ValueAccessor; import org.simantics.db.layer0.variable.Variable; import org.simantics.district.network.techtype.TechTypeUtils; import org.simantics.scl.reflection.annotations.SCLValue; import org.simantics.structural.stubs.StructuralResource2; public class Functions { @SCLValue(type = "ValueAccessor") public static final ValueAccessor techTypeCodeValueAccessor = new ValueAccessor() { @Override public Object getValue(ReadGraph graph, Variable context) throws DatabaseException { return org.simantics.db.layer0.function.All.standardValueAccessor.getValue(graph, context); } @Override public Object getValue(ReadGraph graph, Variable context, Binding binding) throws DatabaseException { return org.simantics.db.layer0.function.All.standardValueAccessor.getValue(graph, context, binding); } @Override public void setValue(WriteGraph graph, Variable context, Object value) throws DatabaseException { org.simantics.db.layer0.function.All.standardValueAccessor.setValue(graph, context, value); updateComponentProperties(graph, context, value); } @Override public void setValue(WriteGraph graph, Variable context, Object value, Binding binding) throws DatabaseException { org.simantics.db.layer0.function.All.standardValueAccessor.setValue(graph, context, value, binding); updateComponentProperties(graph, context, value); } @Override public Datatype getDatatype(ReadGraph graph, Variable context) throws DatabaseException { return org.simantics.db.layer0.function.All.standardValueAccessor.getDatatype(graph, context); } }; protected static void updateComponentProperties(WriteGraph graph, Variable context, Object value) throws DatabaseException { Variable component = context.getParent(graph); Resource type = component.getPossibleType(graph, StructuralResource2.getInstance(graph).Component); if (type == null) return; TechTypeUtils.updateComponent(graph, component.getRepresents(graph)); } }