KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > javaeditor > InternalClassFileEditorInput


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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
12 package org.eclipse.jdt.internal.ui.javaeditor;
13
14
15 import org.eclipse.jface.resource.ImageDescriptor;
16
17 import org.eclipse.ui.IMemento;
18 import org.eclipse.ui.IPersistableElement;
19
20 import org.eclipse.jdt.core.IClassFile;
21 import org.eclipse.jdt.core.JavaModelException;
22
23 import org.eclipse.jdt.internal.ui.JavaPluginImages;
24
25
26 /**
27  * Class file considered as editor input.
28  */

29 public class InternalClassFileEditorInput implements IClassFileEditorInput, IPersistableElement {
30
31     private IClassFile fClassFile;
32
33     public InternalClassFileEditorInput(IClassFile classFile) {
34         fClassFile= classFile;
35     }
36
37     /*
38      * @see Object#equals(Object)
39      */

40     public boolean equals(Object JavaDoc obj) {
41         if (this == obj)
42             return true;
43         if (!(obj instanceof InternalClassFileEditorInput))
44             return false;
45         InternalClassFileEditorInput other= (InternalClassFileEditorInput) obj;
46         return fClassFile.equals(other.fClassFile);
47     }
48
49     /*
50      * @see Object#hashCode
51      */

52     public int hashCode() {
53         return fClassFile.hashCode();
54     }
55
56     /*
57      * @see IClassFileEditorInput#getClassFile()
58      */

59     public IClassFile getClassFile() {
60         return fClassFile;
61     }
62
63     /*
64      * @see IEditorInput#getPersistable()
65      */

66     public IPersistableElement getPersistable() {
67         return this;
68     }
69
70     /*
71      * @see IEditorInput#getName()
72      */

73     public String JavaDoc getName() {
74         return fClassFile.getElementName();
75     }
76
77     /*
78      * @see IEditorInput#getToolTipText()
79      */

80     public String JavaDoc getToolTipText() {
81         return fClassFile.getType().getFullyQualifiedName();
82     }
83
84     /*
85      * @see IEditorInput#getImageDescriptor()
86      */

87     public ImageDescriptor getImageDescriptor() {
88         try {
89             if (fClassFile.isClass())
90                 return JavaPluginImages.DESC_OBJS_CFILECLASS;
91             return JavaPluginImages.DESC_OBJS_CFILEINT;
92         } catch (JavaModelException e) {
93             // fall through
94
}
95         return JavaPluginImages.DESC_OBJS_CFILE;
96     }
97
98     /*
99      * @see IEditorInput#exists()
100      */

101     public boolean exists() {
102         return fClassFile.exists();
103     }
104
105     /*
106      * @see IAdaptable#getAdapter(Class)
107      */

108     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
109         if (adapter == IClassFile.class)
110             return fClassFile;
111         return fClassFile.getAdapter(adapter);
112     }
113
114     /*
115      * @see IPersistableElement#saveState(IMemento)
116      */

117     public void saveState(IMemento memento) {
118         ClassFileEditorInputFactory.saveState(memento, this);
119     }
120
121     /*
122      * @see IPersistableElement#getFactoryId()
123      */

124     public String JavaDoc getFactoryId() {
125         return ClassFileEditorInputFactory.ID;
126     }
127 }
128
129
130
Popular Tags