001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.editor;
011:
012: import java.io.File;
013:
014: import org.eclipse.core.resources.IStorage;
015: import org.eclipse.jface.resource.ImageDescriptor;
016: import org.eclipse.ui.IEditorRegistry;
017: import org.eclipse.ui.IPersistableElement;
018: import org.eclipse.ui.IStorageEditorInput;
019: import org.eclipse.ui.PlatformUI;
020:
021: /**
022: * An EditorInput for a JarEntryFile.
023: */
024: public class JarEntryEditorInput implements IStorageEditorInput {
025:
026: private IStorage fJarEntryFile;
027:
028: public JarEntryEditorInput(IStorage jarEntryFile) {
029: fJarEntryFile = jarEntryFile;
030: }
031:
032: /*
033: */
034: public boolean equals(Object obj) {
035: if (this == obj)
036: return true;
037: if (!(obj instanceof JarEntryEditorInput))
038: return false;
039: JarEntryEditorInput other = (JarEntryEditorInput) obj;
040: return fJarEntryFile.equals(other.fJarEntryFile);
041: }
042:
043: /*
044: * @see IEditorInput#getPersistable()
045: */
046: public IPersistableElement getPersistable() {
047: return null;
048: }
049:
050: /*
051: * @see IEditorInput#getName()
052: */
053: public String getName() {
054: return fJarEntryFile.getName();
055: }
056:
057: /*
058: * @see IEditorInput#getFullPath()
059: */
060: public String getFullPath() {
061: return fJarEntryFile.getFullPath().toString();
062: }
063:
064: /*
065: * @see IEditorInput#getContentType()
066: */
067: public String getContentType() {
068: return fJarEntryFile.getFullPath().getFileExtension();
069: }
070:
071: /*
072: * @see IEditorInput#getToolTipText()
073: */
074: public String getToolTipText() {
075: File file = (File) fJarEntryFile.getAdapter(File.class);
076: if (file != null)
077: return file.getAbsolutePath();
078: return fJarEntryFile.getFullPath().toString();
079: }
080:
081: /*
082: * @see IEditorInput#getImageDescriptor()
083: */
084: public ImageDescriptor getImageDescriptor() {
085: IEditorRegistry registry = PlatformUI.getWorkbench()
086: .getEditorRegistry();
087: return registry.getImageDescriptor(fJarEntryFile.getFullPath()
088: .getFileExtension());
089: }
090:
091: /*
092: * @see IEditorInput#exists()
093: */
094: public boolean exists() {
095: // JAR entries can't be deleted
096: return true;
097: }
098:
099: /*
100: * @see IAdaptable#getAdapter(Class)
101: */
102: public Object getAdapter(Class adapter) {
103: if (adapter.equals(File.class))
104: return fJarEntryFile.getAdapter(File.class);
105: return null;
106: }
107:
108: /*
109: * see IStorageEditorInput#getStorage()
110: */
111: public IStorage getStorage() {
112: return fJarEntryFile;
113: }
114: }
|