KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > editors > text > JavaFileEditorInput


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.editors.text;
12
13 import org.eclipse.core.filesystem.EFS;
14 import org.eclipse.core.filesystem.IFileStore;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IPath;
18 import org.eclipse.core.runtime.Path;
19 import org.eclipse.core.runtime.Platform;
20
21 import org.eclipse.core.resources.IStorage;
22
23 import org.eclipse.jface.resource.ImageDescriptor;
24
25 import org.eclipse.jface.text.Assert;
26
27 import org.eclipse.ui.editors.text.ILocationProvider;
28
29 import org.eclipse.ui.IPathEditorInput;
30 import org.eclipse.ui.IPersistableElement;
31 import org.eclipse.ui.IStorageEditorInput;
32 import org.eclipse.ui.model.IWorkbenchAdapter;
33
34 /**
35  * @since 3.0
36  */

37 public class JavaFileEditorInput implements IPathEditorInput, IStorageEditorInput, ILocationProvider {
38
39     /**
40      * The workbench adapter which simply provides the label.
41      *
42      * @since 3.1
43      */

44     private class WorkbenchAdapter implements IWorkbenchAdapter {
45         /*
46          * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object)
47          */

48         public Object JavaDoc[] getChildren(Object JavaDoc o) {
49             return null;
50         }
51
52         /*
53          * @see org.eclipse.ui.model.IWorkbenchAdapter#getImageDescriptor(java.lang.Object)
54          */

55         public ImageDescriptor getImageDescriptor(Object JavaDoc object) {
56             return null;
57         }
58
59         /*
60          * @see org.eclipse.ui.model.IWorkbenchAdapter#getLabel(java.lang.Object)
61          */

62         public String JavaDoc getLabel(Object JavaDoc o) {
63             return ((JavaFileEditorInput)o).getName();
64         }
65
66         /*
67          * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object)
68          */

69         public Object JavaDoc getParent(Object JavaDoc o) {
70             return null;
71         }
72     }
73
74     private IFileStore fFileStore;
75     private WorkbenchAdapter fWorkbenchAdapter= new WorkbenchAdapter();
76     private IStorage fStorage;
77     private IPath fPath;
78     
79     public JavaFileEditorInput(IFileStore fileStore) {
80         Assert.isNotNull(fileStore);
81         Assert.isTrue(EFS.SCHEME_FILE.equals(fileStore.getFileSystem().getScheme()));
82         fFileStore= fileStore;
83         fWorkbenchAdapter= new WorkbenchAdapter();
84     }
85     /*
86      * @see org.eclipse.ui.IEditorInput#exists()
87      */

88     public boolean exists() {
89         return fFileStore.fetchInfo().exists();
90     }
91
92     /*
93      * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
94      */

95     public ImageDescriptor getImageDescriptor() {
96         return null;
97     }
98
99     /*
100      * @see org.eclipse.ui.IEditorInput#getName()
101      */

102     public String JavaDoc getName() {
103         return fFileStore.getName();
104     }
105
106     /*
107      * @see org.eclipse.ui.IEditorInput#getPersistable()
108      */

109     public IPersistableElement getPersistable() {
110         return null;
111     }
112
113     /*
114      * @see org.eclipse.ui.IEditorInput#getToolTipText()
115      */

116     public String JavaDoc getToolTipText() {
117         return fFileStore.toString();
118     }
119
120     /*
121      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
122      */

123     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
124         if (ILocationProvider.class.equals(adapter))
125             return this;
126         if (IWorkbenchAdapter.class.equals(adapter))
127             return fWorkbenchAdapter;
128         return Platform.getAdapterManager().getAdapter(this, adapter);
129     }
130
131     /*
132      * @see org.eclipse.ui.editors.text.ILocationProvider#getPath(java.lang.Object)
133      */

134     public IPath getPath(Object JavaDoc element) {
135         if (element instanceof JavaFileEditorInput)
136             return ((JavaFileEditorInput)element).getPath();
137         
138         return null;
139     }
140
141     /*
142      * @see org.eclipse.ui.IPathEditorInput#getPath()
143      * @since 3.1
144      */

145     public IPath getPath() {
146         if (fPath == null)
147             fPath= new Path(fFileStore.toURI().getPath());
148         return fPath;
149     }
150
151     /*
152      * @see java.lang.Object#equals(java.lang.Object)
153      */

154     public boolean equals(Object JavaDoc o) {
155         if (o == this)
156             return true;
157
158         if (o instanceof JavaFileEditorInput) {
159             JavaFileEditorInput input= (JavaFileEditorInput) o;
160             return fFileStore.equals(input.fFileStore);
161         }
162
163         if (o instanceof IPathEditorInput) {
164             IPathEditorInput input= (IPathEditorInput)o;
165             return getPath().equals(input.getPath());
166         }
167
168         return false;
169     }
170
171     /*
172      * @see java.lang.Object#hashCode()
173      */

174     public int hashCode() {
175         return fFileStore.hashCode();
176     }
177
178     /*
179      * @see org.eclipse.ui.IStorageEditorInput#getStorage()
180      * @since 3.2
181      */

182     public IStorage getStorage() throws CoreException {
183         if (fStorage == null)
184             fStorage= new JavaFileStorage(fFileStore);
185         return fStorage;
186     }
187
188 }
189
Popular Tags