]> gerrit.simantics Code Review - simantics/platform.git/blob
d16a776c7c1e24826fb59ff26e4d3c334ab65f14
[simantics/platform.git] /
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.common.utils.ListUtils;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.diagram.stubs.DiagramResource;
24 import org.simantics.scenegraph.profile.ProfileUtils;
25
26 public class ProfileEntryChildren implements ChildRule {
27
28         @Override
29         public boolean isCompatible(Class<?> contentType) {
30                 return contentType.equals(ResourcePair.class);
31         }
32
33         @Override
34         public Collection<?> getChildren(ReadGraph graph, Object parent)
35                         throws DatabaseException {
36
37                 ResourcePair entry = (ResourcePair)parent;
38         ArrayList<ResourcePair> entries = new ArrayList<ResourcePair>();
39         DiagramResource DIA = DiagramResource.getInstance(graph);
40         Resource children = graph.getPossibleObject(entry.getSecond(), DIA.HasEntries);
41         if(children == null) return Collections.emptyList();
42         else {
43                 for(Resource entry2 : ProfileUtils.getProfileChildrenFromEntries(graph, children)) entries.add(new ResourcePair(entry.getFirst(), entry2));
44                 return entries;
45         }
46     }
47
48         @Override
49         public Collection<?> getParents(ReadGraph graph, Object child)
50                         throws DatabaseException {
51                 return new ArrayList<Resource>();
52         }
53
54 }