X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.document.linking.ui%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Flinking%2Fge%2FObjectChildRule.java;fp=bundles%2Forg.simantics.document.linking.ui%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Flinking%2Fge%2FObjectChildRule.java;h=0f21c78d102dd0a12ae843960742b9d8f124ab6f;hp=76e3fe1cf2c0e4ba44b6420bb463919527866612;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.document.linking.ui/src/org/simantics/document/linking/ge/ObjectChildRule.java b/bundles/org.simantics.document.linking.ui/src/org/simantics/document/linking/ge/ObjectChildRule.java index 76e3fe1cf..0f21c78d1 100644 --- a/bundles/org.simantics.document.linking.ui/src/org/simantics/document/linking/ge/ObjectChildRule.java +++ b/bundles/org.simantics.document.linking.ui/src/org/simantics/document/linking/ge/ObjectChildRule.java @@ -1,110 +1,110 @@ -package org.simantics.document.linking.ge; - -import java.util.ArrayList; -import java.util.Collection; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.variable.StandardGraphChildVariable; -import org.simantics.db.layer0.variable.Variable; -import org.simantics.document.linking.ontology.DocumentLink; -import org.simantics.document.linking.utils.SourceLinkUtil; - -/** - * A rule for browsing document links of an object. Properties are not included. - * - * @author Marko Luukkainen - * - */ -public class ObjectChildRule implements org.simantics.browsing.ui.model.children.ChildRule{ - - private boolean showOnlyCheckable = false; - - @Override - public boolean isCompatible(Class contentType) { - return contentType.equals(Resource.class) || contentType.equals(Variable.class); - } - - public void setShowOnlyCheckable(boolean showOnlyCheckable) { - this.showOnlyCheckable = showOnlyCheckable; - } - - @Override - public Collection getChildren(ReadGraph graph, Object obj) - throws DatabaseException { - - ArrayList children = new ArrayList(); - - - Resource resource = null; - Variable variable = null; - if (obj instanceof Resource) { - resource = (Resource)obj; - try { - variable = graph.adapt(resource, Variable.class); - } catch (Throwable t) { - return children; - } - children.add(new StandardGraphChildVariable(variable, null, resource)); - return children; - } else { - variable = (Variable)obj; - resource = variable.getPossibleRepresents(graph); - } - - - DocumentLink sl = DocumentLink.getInstance(graph); - if (graph.isInstanceOf(resource, sl.Source)) - return children; - - - //find sources declared on parentResource using consernsRelation - Variable parentVariable = variable.getParent(graph); - Resource parentRes = null; - Resource relation = null; - if (parentVariable != null) { - parentRes = parentVariable.getPossibleRepresents(graph); - relation = variable.getPossiblePredicateResource(graph); - } - - if (parentRes != null && relation != null) { - Collection sources = graph.getObjects(parentRes, sl.hasSource); - for (Resource source : sources) { - Resource rel = graph.getPossibleObject(source, sl.consernsRelation); - if (rel != null && rel.equals(relation)) { - if (showOnlyCheckable && - (SourceLinkUtil.isValidSource(graph, source) && - SourceLinkUtil.isUpToDateSource(graph, source))) - continue; - children.add(new StandardGraphChildVariable(variable, null, source)); - } - } - } - //find sources declared on this resource, ie. sources that do not have consernsRelation. - Collection sources = graph.getObjects(resource, sl.hasSource); - for (Resource source : sources) { - Resource rel = graph.getPossibleObject(source, sl.consernsRelation); - if (rel == null) { - if (showOnlyCheckable && - (SourceLinkUtil.isValidSource(graph, source) && - SourceLinkUtil.isUpToDateSource(graph, source))) - continue; - children.add(new StandardGraphChildVariable(variable, null, source)); - } - } - while (children.remove(variable)) { - - } - - - return children; - } - - @Override - public Collection getParents(ReadGraph graph, Object child) - throws DatabaseException { - return new ArrayList(); - } - -} +package org.simantics.document.linking.ge; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.StandardGraphChildVariable; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.document.linking.ontology.DocumentLink; +import org.simantics.document.linking.utils.SourceLinkUtil; + +/** + * A rule for browsing document links of an object. Properties are not included. + * + * @author Marko Luukkainen + * + */ +public class ObjectChildRule implements org.simantics.browsing.ui.model.children.ChildRule{ + + private boolean showOnlyCheckable = false; + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class) || contentType.equals(Variable.class); + } + + public void setShowOnlyCheckable(boolean showOnlyCheckable) { + this.showOnlyCheckable = showOnlyCheckable; + } + + @Override + public Collection getChildren(ReadGraph graph, Object obj) + throws DatabaseException { + + ArrayList children = new ArrayList(); + + + Resource resource = null; + Variable variable = null; + if (obj instanceof Resource) { + resource = (Resource)obj; + try { + variable = graph.adapt(resource, Variable.class); + } catch (Throwable t) { + return children; + } + children.add(new StandardGraphChildVariable(variable, null, resource)); + return children; + } else { + variable = (Variable)obj; + resource = variable.getPossibleRepresents(graph); + } + + + DocumentLink sl = DocumentLink.getInstance(graph); + if (graph.isInstanceOf(resource, sl.Source)) + return children; + + + //find sources declared on parentResource using consernsRelation + Variable parentVariable = variable.getParent(graph); + Resource parentRes = null; + Resource relation = null; + if (parentVariable != null) { + parentRes = parentVariable.getPossibleRepresents(graph); + relation = variable.getPossiblePredicateResource(graph); + } + + if (parentRes != null && relation != null) { + Collection sources = graph.getObjects(parentRes, sl.hasSource); + for (Resource source : sources) { + Resource rel = graph.getPossibleObject(source, sl.consernsRelation); + if (rel != null && rel.equals(relation)) { + if (showOnlyCheckable && + (SourceLinkUtil.isValidSource(graph, source) && + SourceLinkUtil.isUpToDateSource(graph, source))) + continue; + children.add(new StandardGraphChildVariable(variable, null, source)); + } + } + } + //find sources declared on this resource, ie. sources that do not have consernsRelation. + Collection sources = graph.getObjects(resource, sl.hasSource); + for (Resource source : sources) { + Resource rel = graph.getPossibleObject(source, sl.consernsRelation); + if (rel == null) { + if (showOnlyCheckable && + (SourceLinkUtil.isValidSource(graph, source) && + SourceLinkUtil.isUpToDateSource(graph, source))) + continue; + children.add(new StandardGraphChildVariable(variable, null, source)); + } + } + while (children.remove(variable)) { + + } + + + return children; + } + + @Override + public Collection getParents(ReadGraph graph, Object child) + throws DatabaseException { + return new ArrayList(); + } + +}