]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/adapters/ScenegraphChildrenRule.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling.template2d.ui / src / org / simantics / modeling / template2d / ui / adapters / ScenegraphChildrenRule.java
1 /*******************************************************************************
2  * Copyright (c) 2013 Association for Decentralized Information Management in
3  * Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.modeling.template2d.ui.adapters;
13
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.Collections;
17
18 import org.simantics.browsing.ui.model.children.ChildRule;
19 import org.simantics.db.ReadGraph;
20 import org.simantics.db.Resource;
21 import org.simantics.db.common.utils.ListUtils;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.layer0.Layer0;
24 import org.simantics.scenegraph.ontology.ScenegraphResources;
25
26 public class ScenegraphChildrenRule implements ChildRule {
27
28         @Override
29         public boolean isCompatible(Class<?> contentType) {
30                 return contentType.equals(Resource.class);
31         }
32
33         @Override
34         public Collection<?> getChildren(ReadGraph graph, Object parent)
35                         throws DatabaseException {
36
37                 Resource entry = (Resource)parent;
38                 Layer0 L0 = Layer0.getInstance(graph);
39                 ScenegraphResources SG = ScenegraphResources.getInstance(graph);
40                 Resource list = graph.getPossibleObject(entry, SG.Node_children);
41                 if(list != null) {
42                         if(graph.isInstanceOf(list, L0.List)) return ListUtils.toList(graph, list);
43                 }
44                 return Collections.emptyList();
45     }
46
47         @Override
48         public Collection<?> getParents(ReadGraph graph, Object child)
49                         throws DatabaseException {
50                 return new ArrayList<Resource>();
51         }
52
53 }