1
2
3
4
5
6
7
8
9
10
11
12 package sk.uniba.euromath.editor;
13 import java.io.File;
14
15 import org.eclipse.core.runtime.IPath;
16 import org.eclipse.jface.resource.ImageDescriptor;
17 import org.eclipse.ui.IEditorInput;
18 import org.eclipse.ui.IPersistableElement;
19 /***
20 * Implements editor input that can read file from local filesystem.
21 * @author Martin Vysny
22 */
23 public final class LocalFilesystemEditorInput implements IEditorInput {
24 /***
25 * XML file represented by this object.
26 */
27 private final IPath path;
28 /***
29 * If not <code>null</code> then this class simply delegates method calls
30 * to this instance (except the <code>getFile()</code> function).
31 */
32 private final IEditorInput underlyingInput;
33 /***
34 * Constructs new instance of the object.
35 * @param path must point to a xml file that can be loaded.
36 * @param underlyingInput if not <code>null</code> then this class simply
37 * delegates method calls to this instance (except the
38 * <code>getFile()</code> function).
39 */
40 public LocalFilesystemEditorInput(IPath path, IEditorInput underlyingInput) {
41 super();
42 File f = path.toFile();
43 if (!f.exists() || !f.canRead() || !f.isFile())
44 throw new IllegalArgumentException(
45 "path does not denote existing file");
46 this.path = path;
47 this.underlyingInput = underlyingInput;
48 }
49
50
51
52
53 public boolean exists() {
54 if (this.underlyingInput == null)
55 return true;
56 return this.underlyingInput.exists();
57 }
58
59
60
61
62 public ImageDescriptor getImageDescriptor() {
63 if (underlyingInput == null) {
64 return XML_FILE_ICON;
65 }
66 return this.underlyingInput.getImageDescriptor();
67 }
68 /***
69 * Icon of the XML file.
70 */
71 static final ImageDescriptor XML_FILE_ICON = ImageDescriptor.createFromFile(
72 LocalFilesystemEditorInput.class, "/icons/newdocument.gif");
73
74
75
76
77
78 public String getName() {
79 if (this.underlyingInput == null) {
80 return this.path.lastSegment();
81 }
82 return this.underlyingInput.getName();
83 }
84
85
86
87
88 public IPersistableElement getPersistable() {
89 return null;
90 }
91
92
93
94
95 public String getToolTipText() {
96 if (this.underlyingInput == null) {
97 return this.path.toPortableString();
98 }
99 return this.underlyingInput.getToolTipText();
100 }
101
102
103
104
105 public Object getAdapter(Class adapter) {
106 if (adapter == LocalFilesystemEditorInput.class)
107 return this;
108 if (adapter == IPath.class)
109 return this.path;
110 if (this.underlyingInput != null)
111 return this.underlyingInput.getAdapter(adapter);
112 return null;
113 }
114 /***
115 * Returns file denoted by this object.
116 * @return XML file.
117 */
118 public IPath getFile() {
119 return this.path;
120 }
121 }