]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileEntryChildren.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.diagram.profile / src / org / simantics / diagram / profile / view / ProfileEntryChildren.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.diagram.profile.view;\r
13 \r
14 import java.util.ArrayList;\r
15 import java.util.Collection;\r
16 import java.util.Collections;\r
17 \r
18 import org.simantics.browsing.ui.model.children.ChildRule;\r
19 import org.simantics.db.ReadGraph;\r
20 import org.simantics.db.Resource;\r
21 import org.simantics.db.common.utils.ListUtils;\r
22 import org.simantics.db.exception.DatabaseException;\r
23 import org.simantics.diagram.stubs.DiagramResource;\r
24 import org.simantics.scenegraph.profile.ProfileUtils;\r
25 \r
26 public class ProfileEntryChildren implements ChildRule {\r
27 \r
28         @Override\r
29         public boolean isCompatible(Class<?> contentType) {\r
30                 return contentType.equals(ResourcePair.class);\r
31         }\r
32 \r
33         @Override\r
34         public Collection<?> getChildren(ReadGraph graph, Object parent)\r
35                         throws DatabaseException {\r
36 \r
37                 ResourcePair entry = (ResourcePair)parent;\r
38         ArrayList<ResourcePair> entries = new ArrayList<ResourcePair>();\r
39         DiagramResource DIA = DiagramResource.getInstance(graph);\r
40         Resource children = graph.getPossibleObject(entry.getSecond(), DIA.HasEntries);\r
41         if(children == null) return Collections.emptyList();\r
42         else {\r
43                 for(Resource entry2 : ProfileUtils.getProfileChildrenFromEntries(graph, children)) entries.add(new ResourcePair(entry.getFirst(), entry2));\r
44                 return entries;\r
45         }\r
46     }\r
47 \r
48         @Override\r
49         public Collection<?> getParents(ReadGraph graph, Object child)\r
50                         throws DatabaseException {\r
51                 return new ArrayList<Resource>();\r
52         }\r
53 \r
54 }\r