1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 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.editors.internal;
14 import java.io.FileInputStream;
15 import java.io.FileNotFoundException;
16 import java.io.InputStream;
17 import java.io.Reader;
21 import org.eclipse.core.resources.IContainer;
22 import org.eclipse.core.resources.IFile;
23 import org.eclipse.core.resources.IFileState;
24 import org.eclipse.core.resources.IMarker;
25 import org.eclipse.core.resources.IPathVariableManager;
26 import org.eclipse.core.resources.IProject;
27 import org.eclipse.core.resources.IProjectDescription;
28 import org.eclipse.core.resources.IResourceProxy;
29 import org.eclipse.core.resources.IResourceProxyVisitor;
30 import org.eclipse.core.resources.IResourceVisitor;
31 import org.eclipse.core.resources.IWorkspace;
32 import org.eclipse.core.resources.ResourceAttributes;
33 import org.eclipse.core.runtime.CoreException;
34 import org.eclipse.core.runtime.IPath;
35 import org.eclipse.core.runtime.IProgressMonitor;
36 import org.eclipse.core.runtime.Path;
37 import org.eclipse.core.runtime.QualifiedName;
38 import org.eclipse.core.runtime.Status;
39 import org.eclipse.core.runtime.content.IContentDescription;
40 import org.eclipse.core.runtime.jobs.ISchedulingRule;
41 import org.simantics.editors.Activator;
44 * This is an implementation of IFile that can be used to open external editor for any file.
45 * (Original implementation (org.eclipse.core.filesystem.File) doesn't work without project/file structure)
47 * @author Marko Luukkainen <Marko.Luukkainen@vtt.fi>
50 public class SystemFile implements IFile {
51 private java.io.File file;
52 private IWorkspace workspace;
55 public SystemFile(java.io.File file, IWorkspace ws) {
61 public void accept(IResourceProxyVisitor visitor, int memberFlags) throws CoreException {
62 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
66 public void accept(IResourceVisitor visitor) throws CoreException {
67 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
71 public void accept(IResourceVisitor visitor, int depth, boolean includePhantoms) throws CoreException {
72 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
76 public void accept(IResourceVisitor visitor, int depth, int memberFlags) throws CoreException {
77 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
81 * @see org.eclipse.core.resources.IResource#accept(org.eclipse.core.resources.IResourceProxyVisitor, int, int)
84 public void accept(IResourceProxyVisitor visitor, int depth, int memberFlags) throws CoreException {
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 return name.substring(name.lastIndexOf("."));
170 public long getLocalTimeStamp() {
175 public IPath getLocation() {
180 public URI getLocationURI() {
185 public IMarker getMarker(long id) {
190 public long getModificationStamp() {
195 public IContainer getParent() {
200 public String getPersistentProperty(QualifiedName key)throws CoreException {
205 public IProject getProject() {
210 public IPath getProjectRelativePath() {
215 public IPath getRawLocation() {
220 public URI getRawLocationURI() {
225 public ResourceAttributes getResourceAttributes() {
230 public Object getSessionProperty(QualifiedName key) throws CoreException {
231 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
235 public int getType() {
240 public IWorkspace getWorkspace() {
245 public boolean isAccessible() {
250 public boolean isDerived() {
255 public boolean isLinked() {
260 public boolean isLinked(int options) {
265 public boolean isLocal(int depth) {
270 public boolean isPhantom() {
275 public boolean isSynchronized(int depth) {
280 public boolean isTeamPrivateMember() {
285 public void move(IPath destination, boolean force, IProgressMonitor monitor) throws CoreException {
286 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
290 public void move(IPath destination, int updateFlags, IProgressMonitor monitor) throws CoreException {
291 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
295 public void move(IProjectDescription description, boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException {
296 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
300 public void move(IProjectDescription description, int updateFlags, IProgressMonitor monitor) throws CoreException {
301 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
305 public void refreshLocal(int depth, IProgressMonitor monitor) throws CoreException {
306 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
310 public void revertModificationStamp(long value) throws CoreException {
311 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
315 public void setDerived(boolean isDerived) throws CoreException {
316 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
320 public void setLocal(boolean flag, int depth, IProgressMonitor monitor) throws CoreException {
321 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
325 public long setLocalTimeStamp(long value) throws CoreException {
326 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
330 public void setPersistentProperty(QualifiedName key, String value) throws CoreException {
331 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
335 public void setReadOnly(boolean readOnly) {
340 public void setResourceAttributes(ResourceAttributes attributes) throws CoreException {
341 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
346 public void setSessionProperty(QualifiedName key, Object value) throws CoreException {
347 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
351 public void setTeamPrivateMember(boolean isTeamPrivate) throws CoreException {
352 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
356 public void touch(IProgressMonitor monitor) throws CoreException {
357 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
360 @SuppressWarnings({ "rawtypes" })
362 public Object getAdapter(Class adapter) {
367 public boolean contains(ISchedulingRule rule) {
372 public boolean isConflicting(ISchedulingRule rule) {
377 public void appendContents(InputStream source, boolean force,boolean keepHistory, IProgressMonitor monitor) throws CoreException {
378 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
382 public void appendContents(InputStream source, int updateFlags, IProgressMonitor monitor) throws CoreException {
383 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
387 public void create(InputStream source, boolean force, IProgressMonitor monitor) throws CoreException {
388 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
392 public void create(InputStream source, int updateFlags, IProgressMonitor monitor) throws CoreException {
393 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
398 public void createLink(IPath localLocation, int updateFlags, IProgressMonitor monitor) throws CoreException {
399 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
404 public void createLink(URI location, int updateFlags, IProgressMonitor monitor) throws CoreException {
405 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
409 public void delete(boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException {
410 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
415 public String getCharset() throws CoreException {
416 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
420 public String getCharset(boolean checkImplicit) throws CoreException {
421 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
425 public String getCharsetFor(Reader reader) throws CoreException {
426 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
430 public IContentDescription getContentDescription() throws CoreException {
431 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
435 public InputStream getContents() throws CoreException {
436 return getContents(false);
440 public InputStream getContents(boolean force) throws CoreException {
442 return new FileInputStream(file);
443 } catch (FileNotFoundException e) {
444 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"File " + getName() + " not found"));
449 public int getEncoding() throws CoreException {
454 public IPath getFullPath() {
455 return new Path(file.getAbsolutePath());
459 public IFileState[] getHistory(IProgressMonitor monitor) throws CoreException {
460 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
464 public String getName() {
465 return file.getName();
469 public boolean isReadOnly() {
474 public void move(IPath destination, boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException {
475 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
479 public void setCharset(String newCharset, IProgressMonitor monitor) throws CoreException {
480 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
484 public void setCharset(String newCharset) throws CoreException {
485 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
489 public void setContents(IFileState source, boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException {
490 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
495 public void setContents(IFileState source, int updateFlags,
496 IProgressMonitor monitor) throws CoreException {
497 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
501 public void setContents(InputStream source, boolean force,
502 boolean keepHistory, IProgressMonitor monitor)
503 throws CoreException {
504 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
509 public void setContents(InputStream source, int updateFlags, IProgressMonitor monitor) throws CoreException {
510 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));
513 @SuppressWarnings({ "rawtypes", "unchecked" })
515 public Map getPersistentProperties() throws CoreException {
519 @SuppressWarnings({ "rawtypes", "unchecked" })
521 public Map getSessionProperties() throws CoreException {
526 public boolean isDerived(int options) {
531 public boolean isHidden() {
536 public void setHidden(boolean isHidden) throws CoreException {
541 public boolean isHidden(int options) {
546 public boolean isTeamPrivateMember(int options) {
551 public IPathVariableManager getPathVariableManager() {
556 public boolean isVirtual() {
561 public void setDerived(boolean isDerived, IProgressMonitor monitor)
562 throws CoreException {
563 throw new CoreException(new Status(Status.ERROR,Activator.PLUGIN_ID,"not supported"));