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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.graphfile.hack;
\r
14 import java.io.FileInputStream;
\r
15 import java.io.FileNotFoundException;
\r
16 import java.io.FileOutputStream;
\r
17 import java.io.IOException;
\r
18 import java.io.InputStream;
\r
19 import java.io.Reader;
\r
20 import java.net.URI;
\r
21 import java.util.Map;
\r
23 import org.eclipse.core.resources.IContainer;
\r
24 import org.eclipse.core.resources.IFile;
\r
25 import org.eclipse.core.resources.IFileState;
\r
26 import org.eclipse.core.resources.IMarker;
\r
27 import org.eclipse.core.resources.IPathVariableManager;
\r
28 import org.eclipse.core.resources.IProject;
\r
29 import org.eclipse.core.resources.IProjectDescription;
\r
30 import org.eclipse.core.resources.IResourceProxy;
\r
31 import org.eclipse.core.resources.IResourceProxyVisitor;
\r
32 import org.eclipse.core.resources.IResourceVisitor;
\r
33 import org.eclipse.core.resources.IWorkspace;
\r
34 import org.eclipse.core.resources.ResourceAttributes;
\r
35 import org.eclipse.core.runtime.CoreException;
\r
36 import org.eclipse.core.runtime.IPath;
\r
37 import org.eclipse.core.runtime.IProgressMonitor;
\r
38 import org.eclipse.core.runtime.Path;
\r
39 import org.eclipse.core.runtime.QualifiedName;
\r
40 import org.eclipse.core.runtime.Status;
\r
41 import org.eclipse.core.runtime.content.IContentDescription;
\r
42 import org.eclipse.core.runtime.jobs.ISchedulingRule;
\r
43 import org.simantics.graphfile.Activator;
\r
46 * This is an implementation of IFile that can be used to open external editor for any file.
\r
47 * (Original implementation (org.eclipse.core.filesystem.File) doesn't work without project/file structure)
\r
49 * @author Marko Luukkainen <Marko.Luukkainen@vtt.fi>
\r
52 public class SystemFile implements IFile {
\r
53 private java.io.File file;
\r
54 private IWorkspace workspace;
\r
57 public SystemFile(java.io.File file, IWorkspace ws) {
\r
59 this.workspace = ws;
\r
63 public void accept(IResourceProxyVisitor visitor, int memberFlags) throws CoreException {
\r
64 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
68 public void accept(IResourceVisitor visitor) throws CoreException {
\r
69 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
73 public void accept(IResourceVisitor visitor, int depth, boolean includePhantoms) throws CoreException {
\r
74 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
78 public void accept(IResourceVisitor visitor, int depth, int memberFlags) throws CoreException {
\r
79 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
83 public void accept(IResourceProxyVisitor visitor, int depth, int memberFlags) throws CoreException {
\r
84 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
88 public void clearHistory(IProgressMonitor monitor) throws CoreException {
\r
89 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\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
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
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
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
117 public IMarker createMarker(String type) throws CoreException {
\r
118 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
122 public IResourceProxy createProxy() {
\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
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
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
143 public boolean exists() {
\r
148 public IMarker findMarker(long id) throws CoreException {
\r
153 public IMarker[] findMarkers(String type, boolean includeSubtypes, int depth) throws CoreException {
\r
158 public int findMaxProblemSeverity(String type, boolean includeSubtypes, int depth) throws CoreException {
\r
163 public String getFileExtension() {
\r
164 String name = file.getName();
\r
165 // FIXME : names that do not contain "." won't work
\r
166 int i = name.lastIndexOf(".");
\r
168 return name.substring(i);
\r
175 public long getLocalTimeStamp() {
\r
176 return file.lastModified();
\r
180 public IPath getLocation() {
\r
181 return new Path(file.getAbsolutePath());
\r
185 public URI getLocationURI() {
\r
186 return file.toURI();
\r
190 public IMarker getMarker(long id) {
\r
195 public long getModificationStamp() {
\r
196 return file.lastModified();
\r
200 public IContainer getParent() {
\r
201 return SystemProject.getDefault();
\r
205 public String getPersistentProperty(QualifiedName key)throws CoreException {
\r
210 public IProject getProject() {
\r
211 return SystemProject.getDefault();
\r
215 public IPath getProjectRelativePath() {
\r
220 public IPath getRawLocation() {
\r
221 return new Path(file.getAbsolutePath());
\r
225 public URI getRawLocationURI() {
\r
226 return file.toURI();
\r
230 public ResourceAttributes getResourceAttributes() {
\r
235 public Object getSessionProperty(QualifiedName key) throws CoreException {
\r
236 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
240 public int getType() {
\r
245 public IWorkspace getWorkspace() {
\r
250 public boolean isAccessible() {
\r
255 public boolean isDerived() {
\r
260 public boolean isLinked() {
\r
265 public boolean isLinked(int options) {
\r
270 public boolean isLocal(int depth) {
\r
275 public boolean isPhantom() {
\r
280 public boolean isSynchronized(int depth) {
\r
281 return true; // FIXME
\r
285 public boolean isTeamPrivateMember() {
\r
290 public void move(IPath destination, boolean force, IProgressMonitor monitor) throws CoreException {
\r
291 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
295 public void move(IPath destination, int updateFlags, IProgressMonitor monitor) throws CoreException {
\r
296 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
300 public void move(IProjectDescription description, boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException {
\r
301 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
305 public void move(IProjectDescription description, int updateFlags, IProgressMonitor monitor) throws CoreException {
\r
306 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
310 public void refreshLocal(int depth, IProgressMonitor monitor) throws CoreException {
\r
312 //throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
316 public void revertModificationStamp(long value) throws CoreException {
\r
317 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
321 public void setDerived(boolean isDerived) throws CoreException {
\r
322 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
326 public void setLocal(boolean flag, int depth, IProgressMonitor monitor) throws CoreException {
\r
327 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
331 public long setLocalTimeStamp(long value) throws CoreException {
\r
332 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
336 public void setPersistentProperty(QualifiedName key, String value) throws CoreException {
\r
337 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
341 public void setReadOnly(boolean readOnly) {
\r
346 public void setResourceAttributes(ResourceAttributes attributes) throws CoreException {
\r
347 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
352 public void setSessionProperty(QualifiedName key, Object value) throws CoreException {
\r
353 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
357 public void setTeamPrivateMember(boolean isTeamPrivate) throws CoreException {
\r
358 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
362 public void touch(IProgressMonitor monitor) throws CoreException {
\r
363 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
366 @SuppressWarnings({ "rawtypes" })
\r
368 public Object getAdapter(Class adapter) {
\r
373 public boolean contains(ISchedulingRule rule) {
\r
374 if (this.equals(rule))
\r
380 public boolean isConflicting(ISchedulingRule rule) {
\r
381 if (this.equals(rule)) // TODO : check cached timestamp
\r
387 public void appendContents(InputStream source, boolean force,boolean keepHistory, IProgressMonitor monitor) throws CoreException {
\r
388 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
392 public void appendContents(InputStream source, int updateFlags, IProgressMonitor monitor) throws CoreException {
\r
393 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
397 public void create(InputStream source, boolean force, IProgressMonitor monitor) throws CoreException {
\r
398 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
402 public void create(InputStream source, int updateFlags, IProgressMonitor monitor) throws CoreException {
\r
403 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
408 public void createLink(IPath localLocation, int updateFlags, IProgressMonitor monitor) throws CoreException {
\r
409 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
414 public void createLink(URI location, int updateFlags, IProgressMonitor monitor) throws CoreException {
\r
415 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
419 public void delete(boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException {
\r
420 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
425 public String getCharset() throws CoreException {
\r
426 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
430 public String getCharset(boolean checkImplicit) throws CoreException {
\r
432 //throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
436 public String getCharsetFor(Reader reader) throws CoreException {
\r
437 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
441 public IContentDescription getContentDescription() throws CoreException {
\r
442 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
446 public InputStream getContents() throws CoreException {
\r
447 return getContents(false);
\r
451 public InputStream getContents(boolean force) throws CoreException {
\r
453 return new FileInputStream(file);
\r
454 } catch (FileNotFoundException e) {
\r
455 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"File " + getName() + " not found"));
\r
460 public int getEncoding() throws CoreException {
\r
465 public IPath getFullPath() {
\r
466 return new Path(file.getAbsolutePath());
\r
470 public IFileState[] getHistory(IProgressMonitor monitor) throws CoreException {
\r
471 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
475 public String getName() {
\r
476 return file.getName();
\r
480 public boolean isReadOnly() {
\r
481 return !file.canWrite();
\r
485 public void move(IPath destination, boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException {
\r
486 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
490 public void setCharset(String newCharset, IProgressMonitor monitor) throws CoreException {
\r
491 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
495 public void setCharset(String newCharset) throws CoreException {
\r
496 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
500 public void setContents(IFileState source, boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException {
\r
501 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
506 public void setContents(IFileState source, int updateFlags,
\r
507 IProgressMonitor monitor) throws CoreException {
\r
508 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
512 public void setContents(InputStream source, boolean force,
\r
513 boolean keepHistory, IProgressMonitor monitor)
\r
514 throws CoreException {
\r
515 FileOutputStream fos;
\r
517 fos = new FileOutputStream(file);
\r
518 byte buf[] = new byte[1024];
\r
520 while ((count = source.read(buf)) > 0) {
\r
521 fos.write(buf,0,count);
\r
524 } catch (FileNotFoundException e) {
\r
525 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"File \"" + file.getAbsolutePath() + "\" not found",e));
\r
526 } catch (IOException e) {
\r
527 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"File \"" + file.getAbsolutePath() + "\" IO error",e));
\r
535 public void setContents(InputStream source, int updateFlags, IProgressMonitor monitor) throws CoreException {
\r
536 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r
539 @SuppressWarnings({ "rawtypes" })
\r
541 public Map getPersistentProperties() throws CoreException {
\r
545 @SuppressWarnings({ "rawtypes" })
\r
547 public Map getSessionProperties() throws CoreException {
\r
552 public boolean isDerived(int options) {
\r
557 public boolean isHidden() {
\r
562 public void setHidden(boolean isHidden) throws CoreException {
\r
567 public boolean isHidden(int options) {
\r
572 public boolean isTeamPrivateMember(int options) {
\r
577 public IPathVariableManager getPathVariableManager() {
\r
582 public boolean isVirtual() {
\r
587 public void setDerived(boolean isDerived, IProgressMonitor monitor)
\r
588 throws CoreException {
\r
589 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
\r