1 /*******************************************************************************
2 * Copyright (c) 2013 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.graphfile.hack;
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;
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;
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)
49 * @author Marko Luukkainen <Marko.Luukkainen@vtt.fi>
52 public class SystemFile implements IFile {
53 private java.io.File file;
54 private IWorkspace workspace;
57 public SystemFile(java.io.File file, IWorkspace ws) {
63 public void accept(IResourceProxyVisitor visitor, int memberFlags) throws CoreException {
64 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
68 public void accept(IResourceVisitor visitor) throws CoreException {
69 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
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"));
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"));
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"));
88 public void clearHistory(IProgressMonitor monitor) throws CoreException {
89 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
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"));
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"));
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"));
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"));
117 public IMarker createMarker(String type) throws CoreException {
118 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
122 public IResourceProxy createProxy() {
127 public void delete(boolean force, IProgressMonitor monitor) throws CoreException {
128 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
132 public void delete(int updateFlags, IProgressMonitor monitor) throws CoreException {
133 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
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"));
143 public boolean exists() {
148 public IMarker findMarker(long id) throws CoreException {
153 public IMarker[] findMarkers(String type, boolean includeSubtypes, int depth) throws CoreException {
158 public int findMaxProblemSeverity(String type, boolean includeSubtypes, int depth) throws CoreException {
163 public String getFileExtension() {
164 String name = file.getName();
165 // FIXME : names that do not contain "." won't work
166 int i = name.lastIndexOf(".");
168 return name.substring(i);
175 public long getLocalTimeStamp() {
176 return file.lastModified();
180 public IPath getLocation() {
181 return new Path(file.getAbsolutePath());
185 public URI getLocationURI() {
190 public IMarker getMarker(long id) {
195 public long getModificationStamp() {
196 return file.lastModified();
200 public IContainer getParent() {
201 return SystemProject.getDefault();
205 public String getPersistentProperty(QualifiedName key)throws CoreException {
210 public IProject getProject() {
211 return SystemProject.getDefault();
215 public IPath getProjectRelativePath() {
220 public IPath getRawLocation() {
221 return new Path(file.getAbsolutePath());
225 public URI getRawLocationURI() {
230 public ResourceAttributes getResourceAttributes() {
235 public Object getSessionProperty(QualifiedName key) throws CoreException {
236 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
240 public int getType() {
245 public IWorkspace getWorkspace() {
250 public boolean isAccessible() {
255 public boolean isDerived() {
260 public boolean isLinked() {
265 public boolean isLinked(int options) {
270 public boolean isLocal(int depth) {
275 public boolean isPhantom() {
280 public boolean isSynchronized(int depth) {
281 return true; // FIXME
285 public boolean isTeamPrivateMember() {
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"));
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"));
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"));
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"));
310 public void refreshLocal(int depth, IProgressMonitor monitor) throws CoreException {
312 //throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
316 public void revertModificationStamp(long value) throws CoreException {
317 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
321 public void setDerived(boolean isDerived) throws CoreException {
322 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
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"));
331 public long setLocalTimeStamp(long value) throws CoreException {
332 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
336 public void setPersistentProperty(QualifiedName key, String value) throws CoreException {
337 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
341 public void setReadOnly(boolean readOnly) {
346 public void setResourceAttributes(ResourceAttributes attributes) throws CoreException {
347 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
352 public void setSessionProperty(QualifiedName key, Object value) throws CoreException {
353 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
357 public void setTeamPrivateMember(boolean isTeamPrivate) throws CoreException {
358 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
362 public void touch(IProgressMonitor monitor) throws CoreException {
363 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
366 @SuppressWarnings({ "rawtypes" })
368 public Object getAdapter(Class adapter) {
373 public boolean contains(ISchedulingRule rule) {
374 if (this.equals(rule))
380 public boolean isConflicting(ISchedulingRule rule) {
381 if (this.equals(rule)) // TODO : check cached timestamp
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"));
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"));
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"));
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"));
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"));
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"));
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"));
425 public String getCharset() throws CoreException {
426 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
430 public String getCharset(boolean checkImplicit) throws CoreException {
432 //throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
436 public String getCharsetFor(Reader reader) throws CoreException {
437 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
441 public IContentDescription getContentDescription() throws CoreException {
442 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
446 public InputStream getContents() throws CoreException {
447 return getContents(false);
451 public InputStream getContents(boolean force) throws CoreException {
453 return new FileInputStream(file);
454 } catch (FileNotFoundException e) {
455 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"File " + getName() + " not found"));
460 public int getEncoding() throws CoreException {
465 public IPath getFullPath() {
466 return new Path(file.getAbsolutePath());
470 public IFileState[] getHistory(IProgressMonitor monitor) throws CoreException {
471 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
475 public String getName() {
476 return file.getName();
480 public boolean isReadOnly() {
481 return !file.canWrite();
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"));
490 public void setCharset(String newCharset, IProgressMonitor monitor) throws CoreException {
491 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
495 public void setCharset(String newCharset) throws CoreException {
496 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
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"));
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"));
512 public void setContents(InputStream source, boolean force,
513 boolean keepHistory, IProgressMonitor monitor)
514 throws CoreException {
515 FileOutputStream fos;
517 fos = new FileOutputStream(file);
518 byte buf[] = new byte[1024];
520 while ((count = source.read(buf)) > 0) {
521 fos.write(buf,0,count);
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));
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"));
539 @SuppressWarnings({ "rawtypes" })
541 public Map getPersistentProperties() throws CoreException {
545 @SuppressWarnings({ "rawtypes" })
547 public Map getSessionProperties() throws CoreException {
552 public boolean isDerived(int options) {
557 public boolean isHidden() {
562 public void setHidden(boolean isHidden) throws CoreException {
567 public boolean isHidden(int options) {
572 public boolean isTeamPrivateMember(int options) {
577 public IPathVariableManager getPathVariableManager() {
582 public boolean isVirtual() {
587 public void setDerived(boolean isDerived, IProgressMonitor monitor)
588 throws CoreException {
589 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));