Fix - Unless clicking an element except the first one, it is impossible to enable...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / builder / ExternalEditorInput.java
1 package net.sourceforge.phpeclipse.builder;
2
3 import org.eclipse.core.resources.IStorage;
4 import org.eclipse.jface.resource.ImageDescriptor;
5 import org.eclipse.ui.IEditorRegistry;
6 import org.eclipse.ui.IPersistableElement;
7 import org.eclipse.ui.IStorageEditorInput;
8 import org.eclipse.ui.PlatformUI;
9
10 /**
11  * An EditorInput for an external file.
12  */
13 public class ExternalEditorInput implements IStorageEditorInput {
14
15         IStorage externalFile;
16
17         /**
18          * Two ExternalEditorInputs are equal if their IStorage's are equal.
19          * 
20          * @see java.lang.Object#equals(java.lang.Object)
21          */
22         public boolean equals(Object obj) {
23                 if (this == obj)
24                         return true;
25                 if (!(obj instanceof ExternalEditorInput))
26                         return false;
27                 ExternalEditorInput other = (ExternalEditorInput) obj;
28                 return externalFile.equals(other.externalFile);
29         }
30
31         /*
32          * @see IEditorInput#exists()
33          */
34         public boolean exists() {
35                 // External file can not be deleted
36                 return true;
37         }
38
39         /*
40          * @see IAdaptable#getAdapter(Class)
41          */
42         public Object getAdapter(Class adapter) {
43                 return null;
44         }
45
46         /*
47          * @see IEditorInput#getContentType()
48          */
49         public String getContentType() {
50                 return externalFile.getFullPath().getFileExtension();
51         }
52
53         /*
54          * @see IEditorInput#getFullPath()
55          */
56         public String getFullPath() {
57                 return externalFile.getFullPath().toString();
58         }
59
60         /*
61          * @see IEditorInput#getImageDescriptor()
62          */
63         public ImageDescriptor getImageDescriptor() {
64                 IEditorRegistry registry = PlatformUI.getWorkbench()
65                                 .getEditorRegistry();
66                 return registry.getImageDescriptor(externalFile.getFullPath()
67                                 .getFileExtension());
68         }
69
70         /*
71          * @see IEditorInput#getName()
72          */
73         public String getName() {
74                 return externalFile.getName();
75         }
76
77         /*
78          * @see IEditorInput#getPersistable()
79          */
80         public IPersistableElement getPersistable() {
81                 return null;
82         }
83
84         /*
85          * see IStorageEditorInput#getStorage()
86          */
87         public IStorage getStorage() {
88                 return externalFile;
89         }
90
91         /*
92          * @see IEditorInput#getToolTipText()
93          */
94         public String getToolTipText() {
95                 return externalFile.getFullPath().toString();
96         }
97
98         public ExternalEditorInput(IStorage exFile) {
99                 externalFile = exFile;
100         }
101 }