1 /*******************************************************************************
2 * Copyright (c) 2010, 2011 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.browsing.ui.model.children;
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.Collections;
18 import org.simantics.browsing.ui.model.tests.Test;
19 import org.simantics.db.ReadGraph;
20 import org.simantics.db.Resource;
21 import org.simantics.db.Statement;
22 import org.simantics.db.exception.DatabaseException;
25 * A child rule that says that there is exactly one child node whose content
26 * is equal to the content of the parent.
27 * @author Hannu Niemistö
29 public class RelationStatementRule implements ChildRule {
33 public RelationStatementRule(Resource relation, Test test) {
34 this.relation = relation;
38 public Collection<?> getChildren(ReadGraph graph, Object parent) throws DatabaseException {
39 ArrayList<Statement> result = new ArrayList<Statement>();
40 for(Resource property : graph.getPredicates((Resource)parent)) {
41 if(graph.isSubrelationOf(property, relation)) {
42 result.addAll(graph.getStatements((Resource)parent, property));
49 public Collection<?> getParents(ReadGraph graph, Object child)
50 throws DatabaseException {
51 return Collections.emptyList();
55 public boolean isCompatible(Class<?> contentType) {
56 return contentType.equals(Resource.class);