import java.util.List;
import java.util.Map;
+import org.simantics.databoard.Bindings;
import org.simantics.databoard.Databoard;
import org.simantics.databoard.binding.Binding;
import org.simantics.databoard.binding.mutable.Variant;
import org.simantics.db.WriteGraph;
import org.simantics.db.common.request.PossibleIndexRoot;
import org.simantics.db.common.request.TernaryRead;
+import org.simantics.db.common.utils.CommonDBUtils;
import org.simantics.db.common.utils.Logger;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.layer0.exception.InvalidVariableException;
public static Variable getPossibleVariable(ReadGraph graph, Resource resource) throws DatabaseException {
String uri = graph.getPossibleURI(resource);
- return uri != null ? getPossibleVariable(graph, uri) : null;
+ if (uri != null)
+ return getPossibleVariable(graph, uri);
+ Resource parent = CommonDBUtils.getPossibleOwner(graph, resource);
+ if (parent == null)
+ return null;
+ Variable possibleVariable = getPossibleVariable(graph, parent);
+ if (possibleVariable == null)
+ return null;
+ String possibleName = graph.getPossibleRelatedValue(resource, Layer0.getInstance(graph).HasName, Bindings.STRING);
+ if (possibleName == null)
+ possibleName = VariableUtils.unnamedResourceName(resource);
+ Variable possibleChild = possibleVariable.getPossibleChild(graph, possibleName);
+ if (possibleChild != null)
+ return possibleChild;
+ for (Variable v : possibleVariable.getChildren(graph)) {
+ Resource vr = v.getPossibleRepresents(graph);
+ if (vr != null && vr.equals(resource)) {
+ return v;
+ }
+ }
+ return null;
}
public static Variable getPossibleVariable(ReadGraph graph, String uri) throws DatabaseException {