]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileEntryChildren.java
Better support for ontological profiles
[simantics/platform.git] / bundles / org.simantics.diagram.profile / src / org / simantics / diagram / profile / view / ProfileEntryChildren.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in 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.diagram.profile.view;
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.exception.DatabaseException;
22 import org.simantics.diagram.stubs.DiagramResource;
23 import org.simantics.scenegraph.profile.ProfileUtils;
24
25 public class ProfileEntryChildren implements ChildRule {
26
27         @Override
28         public boolean isCompatible(Class<?> contentType) {
29                 return contentType.equals(ProfileTuple.class);
30         }
31
32         @Override
33         public Collection<?> getChildren(ReadGraph graph, Object parent)
34                         throws DatabaseException {
35                 ProfileTuple entry = (ProfileTuple) parent;
36                 ArrayList<ProfileTuple> entries = new ArrayList<>();
37                 DiagramResource DIA = DiagramResource.getInstance(graph);
38                 Resource children = graph.getPossibleObject(entry.getEntry(), DIA.HasEntries);
39                 if (children != null) {
40                         for (Resource entry2 : ProfileUtils.getProfileChildrenFromEntries(graph, children))
41                                 entries.add(new ProfileTuple(entry.getBaseProfile(), entry2, entry.getRuntimeDiagram()));
42                         return entries;
43                 }
44                 return Collections.emptyList();
45         }
46
47         @Override
48         public Collection<?> getParents(ReadGraph graph, Object child)
49                         throws DatabaseException {
50                 return Collections.emptyList();
51         }
52
53 }