+
+ 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<Resource> graphTypes1 = QueryIndexUtils.searchByTypeAndName(graph, L0Res, L0.ValueType, newValue);
+ Collection<Resource> graphTypes2 = QueryIndexUtils.searchByTypeAndName(graph, root, L0.ValueType, newValue);
+
+ Collection<Resource> graphTypes = new HashSet<>(graphTypes1);
+ graphTypes.addAll(graphTypes2);
+
+ Set<Pair<Resource, String>> candidates = new HashSet<>();
+ for (Resource graphType : graphTypes) {
+ Collection<Statement> 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<Resource, String> 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);