1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package pl.edu.agh.cast.backward.resources;
19
20 import org.eclipse.core.resources.IFile;
21 import org.eclipse.core.runtime.IPath;
22 import org.eclipse.jface.resource.ImageDescriptor;
23 import org.eclipse.ui.IEditorInput;
24 import org.eclipse.ui.IPathEditorInput;
25 import org.eclipse.ui.IPersistableElement;
26
27
28
29
30
31
32 public class FileEditorInput implements IEditorInput, IPathEditorInput {
33
34 private IFile file;
35
36 public IPath getPath() {
37 return file.getLocation();
38 }
39
40
41
42
43
44
45
46 public FileEditorInput(IFile file) {
47 this.file = file;
48 }
49
50 public IFile getFile() {
51 return file;
52 }
53
54
55
56
57
58
59 public boolean exists() {
60 return file.exists();
61 }
62
63 public ImageDescriptor getImageDescriptor() {
64 return null;
65 }
66
67 public String getName() {
68 return file.getName();
69 }
70
71 public IPersistableElement getPersistable() {
72 return null;
73 }
74
75
76
77
78
79
80 public String getToolTipText() {
81 return file.getLocation() == null ? "" :
82 file.getLocation().toOSString();
83 }
84
85
86
87
88
89
90 @SuppressWarnings("unchecked")
91 public Object getAdapter(Class adapter) {
92 return null;
93 }
94
95
96
97
98
99
100 @Override
101 public String toString() {
102 return file.getName();
103 }
104
105
106
107
108
109
110 @Override
111 public boolean equals(Object obj) {
112 if (this == obj) {
113 return true;
114 }
115 if (!(obj instanceof FileEditorInput)) {
116 return false;
117 }
118
119 FileEditorInput that = (FileEditorInput)obj;
120 if (file == null) {
121 if (that.file != null) {
122 return false;
123 }
124 } else if (!file.equals(that.file)) {
125 return false;
126 }
127 return true;
128 }
129
130
131
132
133
134
135 @Override
136 public int hashCode() {
137 return file == null ? 1234 : file.hashCode();
138 }
139 }