KickJava   Java API By Example, From Geeks To Geeks.

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


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.core.runtime.IPath;
16
17 import org.eclipse.core.resources.IStorage;
18
19 import org.eclipse.jface.resource.ImageDescriptor;
20
21 import org.eclipse.ui.IEditorRegistry;
22 import org.eclipse.ui.IPersistableElement;
23 import org.eclipse.ui.IStorageEditorInput;
24 import org.eclipse.ui.PlatformUI;
25
26 import org.eclipse.jdt.core.IJarEntryResource;
27 import org.eclipse.jdt.core.IPackageFragmentRoot;
28
29
30 /**
31  * An EditorInput for a JarEntryFile.
32  */

33 public class JarEntryEditorInput implements IStorageEditorInput {
34
35     private IStorage fJarEntryFile;
36
37     public JarEntryEditorInput(IStorage jarEntryFile) {
38         fJarEntryFile= jarEntryFile;
39     }
40
41     /*
42      */

43     public boolean equals(Object JavaDoc obj) {
44         if (this == obj)
45             return true;
46         if (!(obj instanceof JarEntryEditorInput))
47             return false;
48         JarEntryEditorInput other= (JarEntryEditorInput) obj;
49         return fJarEntryFile.equals(other.fJarEntryFile);
50     }
51
52     /*
53      * @see IEditorInput#getPersistable()
54      */

55     public IPersistableElement getPersistable() {
56         return null;
57     }
58
59     /*
60      * @see IEditorInput#getName()
61      */

62     public String JavaDoc getName() {
63         return fJarEntryFile.getName();
64     }
65
66     /*
67      * @see IEditorInput#getContentType()
68      */

69     public String JavaDoc getContentType() {
70         return fJarEntryFile.getFullPath().getFileExtension();
71     }
72
73     /*
74      * @see IEditorInput#getToolTipText()
75      */

76     public String JavaDoc getToolTipText() {
77         if (fJarEntryFile instanceof IJarEntryResource) {
78             IJarEntryResource jarEntry= (IJarEntryResource)fJarEntryFile;
79             IPackageFragmentRoot root= jarEntry.getPackageFragmentRoot();
80             IPath fullPath= root.getPath().append(fJarEntryFile.getFullPath());
81             if (root.isExternal())
82                 return fullPath.toOSString();
83             return fullPath.toString();
84             
85         }
86         
87         IPath fullPath= fJarEntryFile.getFullPath();
88         if (fullPath == null)
89             return null;
90         return fullPath.toString();
91     }
92
93     /*
94      * @see IEditorInput#getImageDescriptor()
95      */

96     public ImageDescriptor getImageDescriptor() {
97         IEditorRegistry registry= PlatformUI.getWorkbench().getEditorRegistry();
98         return registry.getImageDescriptor(getContentType());
99     }
100
101     /*
102      * @see IEditorInput#exists()
103      */

104     public boolean exists() {
105         // JAR entries can't be deleted
106
return true;
107     }
108
109     /*
110      * @see IAdaptable#getAdapter(Class)
111      */

112     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
113         return null;
114     }
115
116     /*
117      * see IStorageEditorInput#getStorage()
118      */

119      public IStorage getStorage() {
120         return fJarEntryFile;
121      }
122 }
123
124
125
Popular Tags