package org.simantics.district.network.techtype.variable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Map;
+
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.common.procedure.adapter.TransientCacheListener;
+import org.simantics.db.common.request.PossibleIndexRoot;
import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.AbstractChildVariable;
import org.simantics.db.layer0.variable.ValueAccessor;
import org.simantics.db.layer0.variable.Variable;
import org.simantics.district.network.techtype.TechTypeUtils;
+import org.simantics.district.network.techtype.requests.PossibleTechTypeTable;
+import org.simantics.district.network.techtype.requests.TechTypeTableData;
import org.simantics.scl.reflection.annotations.SCLValue;
import org.simantics.structural.stubs.StructuralResource2;
TechTypeUtils.updateComponent(graph, component.getRepresents(graph));
}
+
+ @SCLValue(type = "ReadGraph -> Resource -> a -> b")
+ public static Object techTypeKeys(ReadGraph graph, Resource resource, Object context) throws DatabaseException {
+ if (!(context instanceof Variable))
+ return Collections.<String>emptyList();
+
+ Variable var = (Variable)context;
+ // Typically 'var' is <component>#<property>#HasDisplayValue#HasEnumerationValues
+ // We want the component part
+ while (!(var instanceof AbstractChildVariable))
+ var = var.getParent(graph);
+
+ Resource type = var.getType(graph, StructuralResource2.getInstance(graph).Component);
+ Resource model = var.getIndexRoot(graph);
+ if (model == null)
+ return Collections.<String>emptyList();
+ Resource table = graph.syncRequest(new PossibleTechTypeTable(model , type), TransientCacheListener.instance());
+ if (table == null)
+ return Collections.<String>emptyList();
+
+ Map<String, Map<String, String>> data = graph.syncRequest(new TechTypeTableData(table, true), TransientCacheListener.instance());
+ ArrayList<String> result = new ArrayList<String>(data.keySet());
+
+ // Sort so that all numbers are in growing order
+ result.sort(TechTypeUtils::compareNatural);
+
+ return result;
+ }
}