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