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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package org.eclipse.jdt.internal.ui.javaeditor;
15 import org.eclipse.core.runtime.Assert;
16 import org.eclipse.core.runtime.IPath;
18 import org.eclipse.core.resources.IStorage;
20 import org.eclipse.jface.resource.ImageDescriptor;
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;
28 import org.eclipse.jdt.core.IJarEntryResource;
29 import org.eclipse.jdt.core.IPackageFragmentRoot;
31 import org.eclipse.jdt.internal.ui.JarEntryEditorInputFactory;
32 import org.eclipse.jdt.internal.ui.viewsupport.BasicElementLabels;
35 * An EditorInput for a JarEntryFile.
37 public class JarEntryEditorInput implements IStorageEditorInput {
39 private final IStorage fJarEntryFile;
41 public JarEntryEditorInput(IStorage jarEntryFile) {
42 Assert.isNotNull(jarEntryFile);
43 fJarEntryFile= jarEntryFile;
47 public boolean equals(Object obj) {
50 if (!(obj instanceof JarEntryEditorInput))
52 JarEntryEditorInput other= (JarEntryEditorInput) obj;
53 return other.generated_6375753644952833218(this);
57 public int hashCode() {
58 return fJarEntryFile.hashCode();
62 * @see IEditorInput#getPersistable()
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);
71 public String getFactoryId() {
72 return JarEntryEditorInputFactory.FACTORY_ID;
81 * @see IEditorInput#getName()
83 public String getName() {
84 return fJarEntryFile.getName();
88 * @see IEditorInput#getContentType()
90 public String getContentType() {
91 return fJarEntryFile.getFullPath().getFileExtension();
95 * @see IEditorInput#getToolTipText()
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());
105 IPath fullPath= fJarEntryFile.getFullPath();
106 if (fullPath == null)
108 return BasicElementLabels.getPathLabel(fullPath, false);
112 * @see IEditorInput#getImageDescriptor()
114 public ImageDescriptor getImageDescriptor() {
115 IEditorRegistry registry= PlatformUI.getWorkbench().getEditorRegistry();
116 return registry.getImageDescriptor(getContentType());
120 * @see IEditorInput#exists()
122 public boolean exists() {
123 // JAR entries can't be deleted
128 * @see IAdaptable#getAdapter(Class)
130 public Object getAdapter(Class adapter) {
135 * see IStorageEditorInput#getStorage()
137 public IStorage getStorage() {
138 return fJarEntryFile;
141 public boolean generated_6375753644952833218(JarEntryEditorInput jarentryeditorinput) {
142 return jarentryeditorinput.fJarEntryFile.equals(fJarEntryFile);