]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/request/ProfileEntryResources.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scenegraph.profile / src / org / simantics / scenegraph / profile / request / ProfileEntryResources.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.scenegraph.profile.request;\r
13 \r
14 import java.util.ArrayList;\r
15 import java.util.Collection;\r
16 import java.util.HashSet;\r
17 import java.util.List;\r
18 \r
19 import org.simantics.db.ReadGraph;\r
20 import org.simantics.db.Resource;\r
21 import org.simantics.db.common.request.ResourceRead2;\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 /**\r
27  * @author Tuukka Lehtonen\r
28  */\r
29 public class ProfileEntryResources extends ResourceRead2<Collection<Resource>> {\r
30 \r
31     protected DiagramResource DIA;\r
32 \r
33     public ProfileEntryResources(Resource profile, Resource entry) {\r
34         super(profile, entry);\r
35     }\r
36 \r
37     protected boolean test(ReadGraph graph, Resource activeProfile, Resource entry) throws DatabaseException {\r
38         return true;\r
39     }\r
40 \r
41     public List<Resource> process(ReadGraph graph, Resource activeProfile, Resource item, List<Resource> result, HashSet<Resource> visited) throws DatabaseException {\r
42         List<Resource> entries = ProfileUtils.getProfileChildrenFromEntries(graph, item);\r
43         for (Resource entry : entries) {\r
44                 Resource children = graph.getPossibleObject(entry, DIA.HasEntries);\r
45             if (children != null) {\r
46                 process(graph, activeProfile, children, result, visited);\r
47             } else {\r
48                 if (test(graph, activeProfile, entry)) {\r
49                     if (!visited.contains(entry)) {\r
50                         result.add(entry);\r
51                         visited.add(entry);\r
52                     }\r
53                 }\r
54             }\r
55         }\r
56 \r
57         return result;\r
58     }\r
59 \r
60     @Override\r
61     public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {\r
62         this.DIA = DiagramResource.getInstance(graph);\r
63         return process(graph, resource, resource2, new ArrayList<Resource>(), new HashSet<Resource>());\r
64     }\r
65 \r
66 }\r