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