]> gerrit.simantics Code Review - simantics/interop.git/blob - org.simantics.interop/src/org/simantics/interop/browsing/ImportNode2.java
git-svn-id: https://www.simantics.org/svn/simantics/interoperability/trunk@22034...
[simantics/interop.git] / org.simantics.interop / src / org / simantics / interop / browsing / ImportNode2.java
1 package org.simantics.interop.browsing;\r
2 \r
3 import java.util.ArrayList;\r
4 import java.util.Collection;\r
5 import java.util.List;\r
6 \r
7 import org.eclipse.jface.resource.ImageDescriptor;\r
8 import org.eclipse.jface.viewers.ISelection;\r
9 import org.simantics.browsing.ui.content.Labeler.Modifier;\r
10 import org.simantics.db.ReadGraph;\r
11 import org.simantics.db.Resource;\r
12 import org.simantics.db.Session;\r
13 import org.simantics.db.exception.DatabaseException;\r
14 import org.simantics.interop.Activator;\r
15 import org.simantics.interop.stubs.InteropResource;\r
16 \r
17 public class ImportNode2 implements INode {\r
18         \r
19         private Resource project;\r
20         \r
21         public ImportNode2(Resource project) {\r
22                 this.project = project;\r
23         }\r
24         \r
25         @SuppressWarnings("rawtypes")\r
26         @Override\r
27         public Object getAdapter(Class adapter) {\r
28                 return null;\r
29         }\r
30         \r
31         @Override\r
32         public int getCategory(ReadGraph graph) throws DatabaseException {\r
33                 return 0;\r
34         }\r
35         \r
36         \r
37         @Override\r
38         public ImageDescriptor getImage(ReadGraph graph) throws DatabaseException {\r
39                 return Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/silk/database_connect.png");\r
40         }\r
41         \r
42         @Override\r
43         public String getLabel(ReadGraph graph) throws DatabaseException {\r
44                 return "Imports";\r
45         }\r
46         \r
47         @Override\r
48         public Modifier getModifier(Session session, String columnId) {\r
49                 return null;\r
50         }\r
51         \r
52 \r
53         \r
54         @Override\r
55         public void handleDrop(Session session, ISelection selection) {\r
56                 \r
57         }\r
58         \r
59         @Override\r
60         public boolean hasChildren(ReadGraph graph) throws DatabaseException {\r
61                 return getChildren(graph).size() > 0;\r
62         }\r
63         \r
64         @Override\r
65         public Collection<?> getChildren(ReadGraph graph) throws DatabaseException {\r
66                 List<INode> nodes = new ArrayList<INode>();\r
67                 InteropResource i = InteropResource.getInstance(graph);\r
68 \r
69                 Collection<Resource> objs = graph.getObjects(project, i.HasImportData);\r
70                 for (Resource o : objs) {\r
71                         if (graph.isInstanceOf(o, i.ImportLibrary)) {\r
72                                 INode node = graph.adapt(o, INode.class);\r
73                                 nodes.add(node);\r
74                         }\r
75                 }\r
76                 return nodes;\r
77 \r
78         }\r
79         \r
80 \r
81 }\r