]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.structural.ui/src/org/simantics/structural/ui/modelBrowser/contributions/ProjectComponentTypes.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.structural.ui / src / org / simantics / structural / ui / modelBrowser / contributions / ProjectComponentTypes.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.structural.ui.modelBrowser.contributions;\r
13 \r
14 import java.util.ArrayList;\r
15 import java.util.Collection;\r
16 \r
17 import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
18 import org.simantics.db.ReadGraph;\r
19 import org.simantics.db.Resource;\r
20 import org.simantics.db.common.request.ObjectsWithType;\r
21 import org.simantics.db.exception.DatabaseException;\r
22 import org.simantics.layer0.Layer0;\r
23 import org.simantics.structural.stubs.StructuralResource2;\r
24 import org.simantics.structural.ui.modelBrowser.nodes.AbstractNode;\r
25 \r
26 /**\r
27  * This contributor tries to find all the models related to a project and will\r
28  * only be invoked when the input is a database resource.\r
29  */\r
30 public class ProjectComponentTypes extends ViewpointContributor<Resource> {\r
31 \r
32     @Override\r
33     public Collection<?> getContribution(ReadGraph graph, Resource project)\r
34     throws DatabaseException {\r
35 \r
36         ArrayList<AbstractNode> result = new ArrayList<AbstractNode>();\r
37         Layer0 b = Layer0.getInstance(graph);\r
38         for(Resource r : graph.syncRequest(new ObjectsWithType(project, b.ConsistsOf, \r
39                         StructuralResource2.getInstance(graph).ComponentType))) {\r
40             try {\r
41                 result.add(graph.adapt(r, AbstractNode.class));\r
42             } catch(DatabaseException e) {\r
43                 e.printStackTrace();\r
44             }\r
45         }\r
46         return result;\r
47 \r
48     }\r
49 \r
50     @Override\r
51     public String getViewpointId() {\r
52         return "Standard";\r
53     }\r
54 \r
55 }\r