]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/javaeditor/JarEntryEditorInput.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / internal / ui / javaeditor / JarEntryEditorInput.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2011 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.Assert;
16 import org.eclipse.core.runtime.IPath;
17
18 import org.eclipse.core.resources.IStorage;
19
20 import org.eclipse.jface.resource.ImageDescriptor;
21
22 import org.eclipse.ui.IEditorRegistry;
23 import org.eclipse.ui.IMemento;
24 import org.eclipse.ui.IPersistableElement;
25 import org.eclipse.ui.IStorageEditorInput;
26 import org.eclipse.ui.PlatformUI;
27
28 import org.eclipse.jdt.core.IJarEntryResource;
29 import org.eclipse.jdt.core.IPackageFragmentRoot;
30
31 import org.eclipse.jdt.internal.ui.JarEntryEditorInputFactory;
32 import org.eclipse.jdt.internal.ui.viewsupport.BasicElementLabels;
33
34 /**
35  * An EditorInput for a JarEntryFile.
36  */
37 public class JarEntryEditorInput implements IStorageEditorInput {
38
39         private final IStorage fJarEntryFile;
40
41         public JarEntryEditorInput(IStorage jarEntryFile) {
42                 Assert.isNotNull(jarEntryFile);
43                 fJarEntryFile= jarEntryFile;
44         }
45
46         @Override
47         public boolean equals(Object obj) {
48                 if (this == obj)
49                         return true;
50                 if (!(obj instanceof JarEntryEditorInput))
51                         return false;
52                 JarEntryEditorInput other= (JarEntryEditorInput) obj;
53                 return other.generated_6375753644952833218(this);
54         }
55
56         @Override
57         public int hashCode() {
58                 return fJarEntryFile.hashCode();
59         }
60         
61         /*
62          * @see IEditorInput#getPersistable()
63          */
64         public IPersistableElement getPersistable() {
65                 if (fJarEntryFile instanceof IJarEntryResource) {
66                         return new IPersistableElement() {
67                                 public void saveState(IMemento memento) {
68                                         JarEntryEditorInputFactory.saveState(memento, (IJarEntryResource) fJarEntryFile);
69                                 }
70
71                                 public String getFactoryId() {
72                                         return JarEntryEditorInputFactory.FACTORY_ID;
73                                 }
74                         };
75                 } else {
76                         return null;
77                 }
78         }
79
80         /*
81          * @see IEditorInput#getName()
82          */
83         public String getName() {
84                 return fJarEntryFile.getName();
85         }
86
87         /*
88          * @see IEditorInput#getContentType()
89          */
90         public String getContentType() {
91                 return fJarEntryFile.getFullPath().getFileExtension();
92         }
93
94         /*
95          * @see IEditorInput#getToolTipText()
96          */
97         public String getToolTipText() {
98                 if (fJarEntryFile instanceof IJarEntryResource) {
99                         IJarEntryResource jarEntry= (IJarEntryResource)fJarEntryFile;
100                         IPackageFragmentRoot root= jarEntry.getPackageFragmentRoot();
101                         IPath fullPath= root.getPath().append(fJarEntryFile.getFullPath());
102                         return BasicElementLabels.getPathLabel(fullPath, root.isExternal());
103                 }
104
105                 IPath fullPath= fJarEntryFile.getFullPath();
106                 if (fullPath == null)
107                         return null;
108                 return BasicElementLabels.getPathLabel(fullPath, false);
109         }
110
111         /*
112          * @see IEditorInput#getImageDescriptor()
113          */
114         public ImageDescriptor getImageDescriptor() {
115                 IEditorRegistry registry= PlatformUI.getWorkbench().getEditorRegistry();
116                 return registry.getImageDescriptor(getContentType());
117         }
118
119         /*
120          * @see IEditorInput#exists()
121          */
122         public boolean exists() {
123                 // JAR entries can't be deleted
124                 return true;
125         }
126
127         /*
128          * @see IAdaptable#getAdapter(Class)
129          */
130         public Object getAdapter(Class adapter) {
131                 return null;
132         }
133
134         /*
135          * see IStorageEditorInput#getStorage()
136          */
137          public IStorage getStorage() {
138                 return fJarEntryFile;
139          }
140
141         public boolean generated_6375753644952833218(JarEntryEditorInput jarentryeditorinput) {
142                 return jarentryeditorinput.fJarEntryFile.equals(fJarEntryFile);
143         }
144 }
145
146