]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.editors/src/org/simantics/editors/internal/SystemFile.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.editors / src / org / simantics / editors / internal / SystemFile.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.editors.internal;\r
13 \r
14 import java.io.FileInputStream;\r
15 import java.io.FileNotFoundException;\r
16 import java.io.InputStream;\r
17 import java.io.Reader;\r
18 import java.net.URI;\r
19 import java.util.Map;\r
20 \r
21 import org.eclipse.core.resources.IContainer;\r
22 import org.eclipse.core.resources.IFile;\r
23 import org.eclipse.core.resources.IFileState;\r
24 import org.eclipse.core.resources.IMarker;\r
25 import org.eclipse.core.resources.IPathVariableManager;\r
26 import org.eclipse.core.resources.IProject;\r
27 import org.eclipse.core.resources.IProjectDescription;\r
28 import org.eclipse.core.resources.IResourceProxy;\r
29 import org.eclipse.core.resources.IResourceProxyVisitor;\r
30 import org.eclipse.core.resources.IResourceVisitor;\r
31 import org.eclipse.core.resources.IWorkspace;\r
32 import org.eclipse.core.resources.ResourceAttributes;\r
33 import org.eclipse.core.runtime.CoreException;\r
34 import org.eclipse.core.runtime.IPath;\r
35 import org.eclipse.core.runtime.IProgressMonitor;\r
36 import org.eclipse.core.runtime.Path;\r
37 import org.eclipse.core.runtime.QualifiedName;\r
38 import org.eclipse.core.runtime.Status;\r
39 import org.eclipse.core.runtime.content.IContentDescription;\r
40 import org.eclipse.core.runtime.jobs.ISchedulingRule;\r
41 import org.simantics.editors.Activator;\r
42 \r
43 /**\r
44  * This is an implementation of IFile that can be used to open external editor for any file.\r
45  * (Original implementation (org.eclipse.core.filesystem.File) doesn't work without project/file structure) \r
46  * \r
47  * @author Marko Luukkainen <Marko.Luukkainen@vtt.fi>\r
48  *\r
49  */\r
50 public class SystemFile implements IFile {\r
51         private java.io.File file;\r
52         private IWorkspace workspace;\r
53         \r
54         \r
55         public SystemFile(java.io.File file, IWorkspace ws) {\r
56                 this.file = file;\r
57                 this.workspace = ws;\r
58         }\r
59 \r
60         @Override\r
61         public void accept(IResourceProxyVisitor visitor, int memberFlags) throws CoreException {\r
62                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
63         }\r
64         \r
65         @Override\r
66         public void accept(IResourceVisitor visitor) throws CoreException {\r
67                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
68         }\r
69         \r
70         @Override\r
71         public void accept(IResourceVisitor visitor, int depth, boolean includePhantoms) throws CoreException {\r
72                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
73         }\r
74         \r
75         @Override\r
76         public void accept(IResourceVisitor visitor, int depth, int memberFlags) throws CoreException {\r
77                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
78         }\r
79 \r
80         /* (non-Javadoc)\r
81          * @see org.eclipse.core.resources.IResource#accept(org.eclipse.core.resources.IResourceProxyVisitor, int, int)\r
82          * @since 3.8\r
83          */\r
84         public void accept(IResourceProxyVisitor visitor, int depth, int memberFlags) throws CoreException {\r
85         }\r
86 \r
87         @Override\r
88         public void clearHistory(IProgressMonitor monitor) throws CoreException {\r
89                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
90         }\r
91 \r
92         @Override\r
93         public void copy(IPath destination, boolean force, IProgressMonitor monitor) throws CoreException {\r
94                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
95                 \r
96         }\r
97 \r
98         @Override\r
99         public void copy(IPath destination, int updateFlags, IProgressMonitor monitor) throws CoreException {\r
100                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
101                 \r
102         }\r
103 \r
104         @Override\r
105         public void copy(IProjectDescription description, boolean force, IProgressMonitor monitor) throws CoreException {\r
106                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
107                 \r
108         }\r
109 \r
110         @Override\r
111         public void copy(IProjectDescription description, int updateFlags, IProgressMonitor monitor) throws CoreException {\r
112                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
113                 \r
114         }\r
115 \r
116         @Override\r
117         public IMarker createMarker(String type) throws CoreException {\r
118                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
119         }\r
120 \r
121         @Override\r
122         public IResourceProxy createProxy() {\r
123                 return null;\r
124         }\r
125 \r
126         @Override\r
127         public void delete(boolean force, IProgressMonitor monitor) throws CoreException {\r
128                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
129         }\r
130 \r
131         @Override\r
132         public void delete(int updateFlags, IProgressMonitor monitor) throws CoreException {\r
133                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
134                 \r
135         }\r
136 \r
137         @Override\r
138         public void deleteMarkers(String type, boolean includeSubtypes, int depth) throws CoreException {\r
139                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
140         }\r
141 \r
142         @Override\r
143         public boolean exists() {\r
144                 return false;\r
145         }\r
146 \r
147         @Override\r
148         public IMarker findMarker(long id) throws CoreException {\r
149                 return null;\r
150         }\r
151 \r
152         @Override\r
153         public IMarker[] findMarkers(String type, boolean includeSubtypes, int depth) throws CoreException {\r
154                 return null;\r
155         }\r
156 \r
157         @Override\r
158         public int findMaxProblemSeverity(String type, boolean includeSubtypes, int depth) throws CoreException {\r
159                 return 0;\r
160         }\r
161 \r
162         @Override\r
163         public String getFileExtension() {\r
164                 String name = file.getName();\r
165                 // FIXME : names that do not contain "." won't work\r
166                 return name.substring(name.lastIndexOf("."));\r
167         }\r
168 \r
169         @Override\r
170         public long getLocalTimeStamp() {\r
171                 return 0;\r
172         }\r
173 \r
174         @Override\r
175         public IPath getLocation() {\r
176                 return null;\r
177         }\r
178 \r
179         @Override\r
180         public URI getLocationURI() {\r
181                 return file.toURI();\r
182         }\r
183 \r
184         @Override\r
185         public IMarker getMarker(long id) {\r
186                 return null;\r
187         }\r
188 \r
189         @Override\r
190         public long getModificationStamp() {\r
191                 return 0;\r
192         }\r
193 \r
194         @Override\r
195         public IContainer getParent() {\r
196                 return null;\r
197         }\r
198 \r
199         @Override\r
200         public String getPersistentProperty(QualifiedName key)throws CoreException {\r
201                 return null;\r
202         }\r
203 \r
204         @Override\r
205         public IProject getProject() {\r
206                 return null;\r
207         }\r
208 \r
209         @Override\r
210         public IPath getProjectRelativePath() {\r
211                 return null;\r
212         }\r
213 \r
214         @Override\r
215         public IPath getRawLocation() {\r
216                 return null;\r
217         }\r
218 \r
219         @Override\r
220         public URI getRawLocationURI() {\r
221                 return file.toURI();\r
222         }\r
223 \r
224         @Override\r
225         public ResourceAttributes getResourceAttributes() {\r
226                 return null;\r
227         }\r
228 \r
229         @Override\r
230         public Object getSessionProperty(QualifiedName key) throws CoreException {\r
231                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
232         }\r
233 \r
234         @Override\r
235         public int getType() {\r
236                 return IFile.FILE;\r
237         }\r
238 \r
239         @Override\r
240         public IWorkspace getWorkspace() {\r
241                 return workspace;\r
242         }\r
243 \r
244         @Override\r
245         public boolean isAccessible() {\r
246                 return false;\r
247         }\r
248 \r
249         @Override\r
250         public boolean isDerived() {\r
251                 return false;\r
252         }\r
253 \r
254         @Override\r
255         public boolean isLinked() {\r
256                 return false;\r
257         }\r
258 \r
259         @Override\r
260         public boolean isLinked(int options) {\r
261                 return false;\r
262         }\r
263 \r
264         @Override\r
265         public boolean isLocal(int depth) {\r
266                 return false;\r
267         }\r
268 \r
269         @Override\r
270         public boolean isPhantom() {\r
271                 return false;\r
272         }\r
273 \r
274         @Override\r
275         public boolean isSynchronized(int depth) {\r
276                 return false;\r
277         }\r
278 \r
279         @Override\r
280         public boolean isTeamPrivateMember() {\r
281                 return false;\r
282         }\r
283 \r
284         @Override\r
285         public void move(IPath destination, boolean force, IProgressMonitor monitor) throws CoreException {\r
286                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
287         }\r
288 \r
289         @Override\r
290         public void move(IPath destination, int updateFlags, IProgressMonitor monitor) throws CoreException {\r
291                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
292         }\r
293 \r
294         @Override\r
295         public void move(IProjectDescription description, boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException {\r
296                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
297         }\r
298 \r
299         @Override\r
300         public void move(IProjectDescription description, int updateFlags, IProgressMonitor monitor) throws CoreException {\r
301                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
302         }\r
303 \r
304         @Override\r
305         public void refreshLocal(int depth, IProgressMonitor monitor) throws CoreException {\r
306                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
307         }\r
308 \r
309         @Override\r
310         public void revertModificationStamp(long value) throws CoreException {\r
311                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
312         }\r
313 \r
314         @Override\r
315         public void setDerived(boolean isDerived) throws CoreException {\r
316                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
317         }\r
318 \r
319         @Override\r
320         public void setLocal(boolean flag, int depth, IProgressMonitor monitor) throws CoreException {\r
321                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
322         }\r
323 \r
324         @Override\r
325         public long setLocalTimeStamp(long value) throws CoreException {\r
326                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
327         }\r
328 \r
329         @Override\r
330         public void setPersistentProperty(QualifiedName key, String value) throws CoreException {\r
331                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
332         }\r
333 \r
334         @Override\r
335         public void setReadOnly(boolean readOnly) {\r
336 \r
337         }\r
338 \r
339         @Override\r
340         public void setResourceAttributes(ResourceAttributes attributes) throws CoreException {\r
341                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
342                 \r
343         }\r
344 \r
345         @Override\r
346         public void setSessionProperty(QualifiedName key, Object value) throws CoreException {\r
347                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));  \r
348         }\r
349 \r
350         @Override\r
351         public void setTeamPrivateMember(boolean isTeamPrivate) throws CoreException {\r
352                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
353         }\r
354 \r
355         @Override\r
356         public void touch(IProgressMonitor monitor) throws CoreException {\r
357                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));  \r
358         }\r
359 \r
360         @SuppressWarnings({ "rawtypes" })\r
361         @Override\r
362         public Object getAdapter(Class adapter) {\r
363                 return null;\r
364         }\r
365 \r
366         @Override\r
367         public boolean contains(ISchedulingRule rule) {\r
368                 return false;\r
369         }\r
370 \r
371         @Override\r
372         public boolean isConflicting(ISchedulingRule rule) {\r
373                 return false;\r
374         }\r
375 \r
376         @Override\r
377         public void appendContents(InputStream source, boolean force,boolean keepHistory, IProgressMonitor monitor) throws CoreException {\r
378                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
379         }\r
380 \r
381         @Override\r
382         public void appendContents(InputStream source, int updateFlags, IProgressMonitor monitor) throws CoreException {\r
383                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));  \r
384         }\r
385 \r
386         @Override\r
387         public void create(InputStream source, boolean force, IProgressMonitor monitor) throws CoreException {\r
388                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
389         }\r
390 \r
391         @Override\r
392         public void create(InputStream source, int updateFlags, IProgressMonitor monitor) throws CoreException {\r
393                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
394                 \r
395         }\r
396 \r
397         @Override\r
398         public void createLink(IPath localLocation, int updateFlags, IProgressMonitor monitor) throws CoreException {\r
399                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
400                 \r
401         }\r
402 \r
403         @Override\r
404         public void createLink(URI location, int updateFlags, IProgressMonitor monitor) throws CoreException {\r
405                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
406         }\r
407 \r
408         @Override\r
409         public void delete(boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException {\r
410                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
411                 \r
412         }\r
413 \r
414         @Override\r
415         public String getCharset() throws CoreException {\r
416                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
417         }\r
418 \r
419         @Override\r
420         public String getCharset(boolean checkImplicit) throws CoreException {\r
421                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
422         }\r
423 \r
424         @Override\r
425         public String getCharsetFor(Reader reader) throws CoreException {\r
426                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
427         }\r
428 \r
429         @Override\r
430         public IContentDescription getContentDescription() throws CoreException {\r
431                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
432         }\r
433 \r
434         @Override\r
435         public InputStream getContents() throws CoreException {\r
436                 return getContents(false);\r
437         }\r
438 \r
439         @Override\r
440         public InputStream getContents(boolean force) throws CoreException {\r
441                 try {\r
442                         return new FileInputStream(file);\r
443                 } catch (FileNotFoundException e) {\r
444                         throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"File " + getName() + " not found"));\r
445                 }\r
446         }\r
447 \r
448         @Override\r
449         public int getEncoding() throws CoreException {\r
450                 return 0;\r
451         }\r
452 \r
453         @Override\r
454         public IPath getFullPath() {\r
455                 return new Path(file.getAbsolutePath());\r
456         }\r
457 \r
458         @Override\r
459         public IFileState[] getHistory(IProgressMonitor monitor) throws CoreException {\r
460                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
461         }\r
462 \r
463         @Override\r
464         public String getName() {\r
465                 return file.getName();\r
466         }\r
467 \r
468         @Override\r
469         public boolean isReadOnly() {\r
470                 return true;\r
471         }\r
472 \r
473         @Override\r
474         public void move(IPath destination, boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException {\r
475                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
476         }\r
477 \r
478         @Override\r
479         public void setCharset(String newCharset, IProgressMonitor monitor) throws CoreException {\r
480                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
481         }\r
482 \r
483         @Override\r
484         public void setCharset(String newCharset) throws CoreException {\r
485                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
486         }\r
487 \r
488         @Override\r
489         public void setContents(IFileState source, boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException {\r
490                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
491                 \r
492         }\r
493 \r
494         @Override\r
495         public void setContents(IFileState source, int updateFlags,\r
496                         IProgressMonitor monitor) throws CoreException {\r
497                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
498         }\r
499 \r
500         @Override\r
501         public void setContents(InputStream source, boolean force,\r
502                         boolean keepHistory, IProgressMonitor monitor)\r
503                         throws CoreException {\r
504                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
505                 \r
506         }\r
507 \r
508         @Override\r
509         public void setContents(InputStream source, int updateFlags, IProgressMonitor monitor) throws CoreException {\r
510                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));\r
511         }\r
512 \r
513         @SuppressWarnings({ "rawtypes", "unchecked" })\r
514         @Override\r
515         public Map getPersistentProperties() throws CoreException {\r
516                 return null;\r
517         }\r
518 \r
519         @SuppressWarnings({ "rawtypes", "unchecked" })\r
520         @Override\r
521         public Map getSessionProperties() throws CoreException {\r
522                 return null;\r
523         }\r
524 \r
525         //@Override\r
526         public boolean isDerived(int options) {\r
527                 return false;\r
528         }\r
529 \r
530         //@Override\r
531         public boolean isHidden() {\r
532                 return false;\r
533         }\r
534 \r
535         //@Override\r
536         public void setHidden(boolean isHidden) throws CoreException {\r
537 \r
538         }\r
539 \r
540         //@Override\r
541         public boolean isHidden(int options) {\r
542                 return false;\r
543         }\r
544 \r
545         //@Override\r
546         public boolean isTeamPrivateMember(int options) {\r
547                 return false;\r
548         }\r
549         \r
550         //@Override\r
551         public IPathVariableManager getPathVariableManager() {\r
552                 return null;\r
553         }\r
554         \r
555         //@Override\r
556         public boolean isVirtual() {\r
557                 return false;\r
558         }\r
559         \r
560         //@Override\r
561         public void setDerived(boolean isDerived, IProgressMonitor monitor)\r
562                         throws CoreException {\r
563                 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));          \r
564         }\r
565 \r
566 }\r