1 package org.simantics.document.linking.ge;
3 import java.util.ArrayList;
4 import java.util.Collection;
6 import org.simantics.db.ReadGraph;
7 import org.simantics.db.Resource;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.db.layer0.variable.StandardGraphChildVariable;
10 import org.simantics.db.layer0.variable.Variable;
11 import org.simantics.document.linking.ontology.DocumentLink;
12 import org.simantics.document.linking.utils.SourceLinkUtil;
15 * A rule for browsing document links of an object. Properties are not included.
17 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
20 public class ObjectChildRule implements org.simantics.browsing.ui.model.children.ChildRule{
22 private boolean showOnlyCheckable = false;
25 public boolean isCompatible(Class<?> contentType) {
26 return contentType.equals(Resource.class) || contentType.equals(Variable.class);
29 public void setShowOnlyCheckable(boolean showOnlyCheckable) {
30 this.showOnlyCheckable = showOnlyCheckable;
34 public Collection<?> getChildren(ReadGraph graph, Object obj)
35 throws DatabaseException {
37 ArrayList<Variable> children = new ArrayList<Variable>();
40 Resource resource = null;
41 Variable variable = null;
42 if (obj instanceof Resource) {
43 resource = (Resource)obj;
45 variable = graph.adapt(resource, Variable.class);
46 } catch (Throwable t) {
49 children.add(new StandardGraphChildVariable(variable, null, resource));
52 variable = (Variable)obj;
53 resource = variable.getPossibleRepresents(graph);
57 DocumentLink sl = DocumentLink.getInstance(graph);
58 if (graph.isInstanceOf(resource, sl.Source))
62 //find sources declared on parentResource using consernsRelation
63 Variable parentVariable = variable.getParent(graph);
64 Resource parentRes = null;
65 Resource relation = null;
66 if (parentVariable != null) {
67 parentRes = parentVariable.getPossibleRepresents(graph);
68 relation = variable.getPossiblePredicateResource(graph);
71 if (parentRes != null && relation != null) {
72 Collection<Resource> sources = graph.getObjects(parentRes, sl.hasSource);
73 for (Resource source : sources) {
74 Resource rel = graph.getPossibleObject(source, sl.consernsRelation);
75 if (rel != null && rel.equals(relation)) {
76 if (showOnlyCheckable &&
77 (SourceLinkUtil.isValidSource(graph, source) &&
78 SourceLinkUtil.isUpToDateSource(graph, source)))
80 children.add(new StandardGraphChildVariable(variable, null, source));
84 //find sources declared on this resource, ie. sources that do not have consernsRelation.
85 Collection<Resource> sources = graph.getObjects(resource, sl.hasSource);
86 for (Resource source : sources) {
87 Resource rel = graph.getPossibleObject(source, sl.consernsRelation);
89 if (showOnlyCheckable &&
90 (SourceLinkUtil.isValidSource(graph, source) &&
91 SourceLinkUtil.isUpToDateSource(graph, source)))
93 children.add(new StandardGraphChildVariable(variable, null, source));
96 while (children.remove(variable)) {
105 public Collection<?> getParents(ReadGraph graph, Object child)
106 throws DatabaseException {
107 return new ArrayList<Resource>();