]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.graphfile/src/org/simantics/graphfile/hack/GraphPath.java
Merge commit '0b471805f017da83d715a0d8409f53bdd009d31e'
[simantics/platform.git] / bundles / org.simantics.graphfile / src / org / simantics / graphfile / hack / GraphPath.java
1 /*******************************************************************************\r
2  * Copyright (c) 2013 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.graphfile.hack;\r
13 \r
14 import java.io.File;\r
15 import java.util.ArrayList;\r
16 import java.util.List;\r
17 \r
18 import org.eclipse.core.runtime.IPath;\r
19 import org.simantics.Simantics;\r
20 import org.simantics.db.ReadGraph;\r
21 import org.simantics.db.Resource;\r
22 import org.simantics.db.common.request.ReadRequest;\r
23 import org.simantics.db.exception.DatabaseException;\r
24 import org.simantics.graphfile.ontology.GraphFileResource;\r
25 import org.simantics.layer0.Layer0;\r
26 \r
27 public class GraphPath implements IPath {\r
28         \r
29         private GraphFile file;\r
30         List<String> path = new ArrayList<String>();\r
31         \r
32         public GraphPath(GraphFile f) {\r
33                 this.file = f;\r
34                 try {\r
35                         Simantics.getSession().syncRequest(new ReadRequest() {\r
36                                 \r
37                                 @Override\r
38                                 public void run(ReadGraph graph) throws DatabaseException {\r
39                                         Layer0 l0 = Layer0.getInstance(graph);\r
40                                         GraphFileResource gf = GraphFileResource.getInstance(graph);\r
41                                         Resource fileResource = file.getFileResource();\r
42                                         Resource t = fileResource;\r
43                                         while (true) {\r
44                                                 t = graph.getPossibleObject(t, gf.PartOfSystemResource);\r
45                                                 if (t != null) {\r
46                                                         path.add(0, (String)graph.getRelatedValue(t, l0.HasName));\r
47                                                 } else {\r
48                                                         break;\r
49                                                 }\r
50                                         }\r
51                                         \r
52                                 }\r
53                         });\r
54                 } catch (DatabaseException e) {\r
55                         throw new RuntimeException("Could not evaluate graph path",e);\r
56                 }\r
57         }\r
58 \r
59         @Override\r
60         public IPath addFileExtension(String extension) {\r
61                 // TODO Auto-generated method stub\r
62                 return null;\r
63         }\r
64 \r
65         @Override\r
66         public IPath addTrailingSeparator() {\r
67                 // TODO Auto-generated method stub\r
68                 return null;\r
69         }\r
70 \r
71         @Override\r
72         public IPath append(String path) {\r
73                 // TODO Auto-generated method stub\r
74                 return null;\r
75         }\r
76 \r
77         @Override\r
78         public IPath append(IPath path) {\r
79                 // TODO Auto-generated method stub\r
80                 return null;\r
81         }\r
82 \r
83         @Override\r
84         public String getDevice() {\r
85                 return "SimanticsGraph";\r
86         }\r
87 \r
88         @Override\r
89         public String getFileExtension() {\r
90                 // TODO Auto-generated method stub\r
91                 return null;\r
92         }\r
93 \r
94         @Override\r
95         public boolean hasTrailingSeparator() {\r
96                 // TODO Auto-generated method stub\r
97                 return false;\r
98         }\r
99 \r
100         @Override\r
101         public boolean isAbsolute() {\r
102                 // TODO Auto-generated method stub\r
103                 return false;\r
104         }\r
105 \r
106         @Override\r
107         public boolean isEmpty() {\r
108                 // TODO Auto-generated method stub\r
109                 return false;\r
110         }\r
111 \r
112         @Override\r
113         public boolean isPrefixOf(IPath anotherPath) {\r
114                 // TODO Auto-generated method stub\r
115                 return false;\r
116         }\r
117 \r
118         @Override\r
119         public boolean isRoot() {\r
120                 // TODO Auto-generated method stub\r
121                 return false;\r
122         }\r
123 \r
124         @Override\r
125         public boolean isUNC() {\r
126                 // TODO Auto-generated method stub\r
127                 return false;\r
128         }\r
129 \r
130         @Override\r
131         public boolean isValidPath(String path) {\r
132                 // TODO Auto-generated method stub\r
133                 return false;\r
134         }\r
135 \r
136         @Override\r
137         public boolean isValidSegment(String segment) {\r
138                 // TODO Auto-generated method stub\r
139                 return false;\r
140         }\r
141 \r
142         @Override\r
143         public String lastSegment() {\r
144                 // TODO Auto-generated method stub\r
145                 return null;\r
146         }\r
147 \r
148         @Override\r
149         public IPath makeAbsolute() {\r
150                 return this;\r
151         }\r
152 \r
153         @Override\r
154         public IPath makeRelative() {\r
155                 return this;\r
156         }\r
157 \r
158         @Override\r
159         public IPath makeRelativeTo(IPath base) {\r
160                 // TODO Auto-generated method stub\r
161                 return null;\r
162         }\r
163 \r
164         @Override\r
165         public IPath makeUNC(boolean toUNC) {\r
166                 // TODO Auto-generated method stub\r
167                 return null;\r
168         }\r
169 \r
170         @Override\r
171         public int matchingFirstSegments(IPath anotherPath) {\r
172                 // TODO Auto-generated method stub\r
173                 return 0;\r
174         }\r
175 \r
176         @Override\r
177         public IPath removeFileExtension() {\r
178                 // TODO Auto-generated method stub\r
179                 return null;\r
180         }\r
181 \r
182         @Override\r
183         public IPath removeFirstSegments(int count) {\r
184                 // TODO Auto-generated method stub\r
185                 return null;\r
186         }\r
187 \r
188         @Override\r
189         public IPath removeLastSegments(int count) {\r
190                 // TODO Auto-generated method stub\r
191                 return null;\r
192         }\r
193 \r
194         @Override\r
195         public IPath removeTrailingSeparator() {\r
196                 // TODO Auto-generated method stub\r
197                 return null;\r
198         }\r
199 \r
200         @Override\r
201         public String segment(int index) {\r
202                 // TODO Auto-generated method stub\r
203                 return null;\r
204         }\r
205 \r
206         @Override\r
207         public int segmentCount() {\r
208                 // TODO Auto-generated method stub\r
209                 return 0;\r
210         }\r
211 \r
212         @Override\r
213         public String[] segments() {\r
214                 // TODO Auto-generated method stub\r
215                 return null;\r
216         }\r
217 \r
218         @Override\r
219         public IPath setDevice(String device) {\r
220                 // TODO Auto-generated method stub\r
221                 return null;\r
222         }\r
223 \r
224         @Override\r
225         public File toFile() {\r
226                 // TODO Auto-generated method stub\r
227                 return new GraphJavaFile(file.getFileResource());\r
228         }\r
229 \r
230         @Override\r
231         public String toOSString() {\r
232                 // TODO Auto-generated method stub\r
233                 return null;\r
234         }\r
235 \r
236         @Override\r
237         public String toPortableString() {\r
238                 // TODO Auto-generated method stub\r
239                 return null;\r
240         }\r
241 \r
242         @Override\r
243         public IPath uptoSegment(int count) {\r
244                 // TODO Auto-generated method stub\r
245                 return null;\r
246         }\r
247 \r
248         @Override\r
249         public Object clone()  {\r
250                 return null;\r
251         }\r
252         \r
253         @Override\r
254         public String toString() {\r
255                 String name = "";\r
256                 for (String s : path) {\r
257                         name+= s + SEPARATOR; \r
258                 }\r
259                 name += file.getName();\r
260                 return name;\r
261         }\r
262 \r
263 }\r