]> gerrit.simantics Code Review - simantics/interop.git/blob - org.simantics.interop/src/org/simantics/interop/browsing/ImportNode2.java
54a8adaef71298bef19509f12e241ad7570b87c6
[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.WriteGraph;\r
14 import org.simantics.db.exception.DatabaseException;\r
15 import org.simantics.interop.Activator;\r
16 import org.simantics.interop.stubs.InteropResource;\r
17 import org.simantics.modeling.ui.modelBrowser.model.INode;\r
18 \r
19 @SuppressWarnings("deprecation")\r
20 public class ImportNode2 implements INode {\r
21         \r
22         private Resource project;\r
23         \r
24         public ImportNode2(Resource project) {\r
25                 this.project = project;\r
26         }\r
27         \r
28         @SuppressWarnings("rawtypes")\r
29         @Override\r
30         public Object getAdapter(Class adapter) {\r
31                 return null;\r
32         }\r
33         \r
34         @Override\r
35         public int getCategory(ReadGraph graph) throws DatabaseException {\r
36                 return 0;\r
37         }\r
38         \r
39         \r
40         @Override\r
41         public ImageDescriptor getImage(ReadGraph graph) throws DatabaseException {\r
42                 return Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/silk/database_connect.png");\r
43         }\r
44         \r
45         @Override\r
46         public String getLabel(ReadGraph graph) throws DatabaseException {\r
47                 return "Imports";\r
48         }\r
49         \r
50         @Override\r
51         public Modifier getModifier(Session session, String columnId) {\r
52                 // TODO Auto-generated method stub\r
53                 return null;\r
54         }\r
55         \r
56         @Override\r
57         public void handleDelete(WriteGraph graph) throws DatabaseException {\r
58                 // TODO Auto-generated method stub\r
59                 \r
60         }\r
61         \r
62         @Override\r
63         public void handleDrop(Session session, ISelection selection) {\r
64                 // TODO Auto-generated method stub\r
65                 \r
66         }\r
67         \r
68         @Override\r
69         public boolean hasChildren(ReadGraph graph) throws DatabaseException {\r
70                 return getChildren(graph).size() > 0;\r
71         }\r
72         \r
73         @Override\r
74         public Collection<?> getChildren(ReadGraph graph) throws DatabaseException {\r
75                 List<INode> nodes = new ArrayList<INode>();\r
76                 InteropResource i = InteropResource.getInstance(graph);\r
77 \r
78                 Collection<Resource> objs = graph.getObjects(project, i.HasImportData);\r
79                 for (Resource o : objs) {\r
80                         if (graph.isInstanceOf(o, i.ImportLibrary)) {\r
81                                 INode node = graph.adapt(o, INode.class);\r
82                                 nodes.add(node);\r
83                         }\r
84                 }\r
85                 return nodes;\r
86 \r
87         }\r
88         \r
89 \r
90 }\r