Skip to main content
summaryrefslogtreecommitdiffstats
blob: 17ee5a4642537a584e20686025851b123d087556 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*******************************************************************************
 * Copyright (c) 2006 Sybase, Inc. and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http:// www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Sybase, Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.pagedesigner.jsf.ui.elementedit.jsfcore;

import org.eclipse.core.resources.IStorage;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IEditorRegistry;
import org.eclipse.ui.IPersistableElement;
import org.eclipse.ui.IStorageEditorInput;
import org.eclipse.ui.PlatformUI;

/**
 * @author mengbo
 * @version 1.5
 */
public class JarEntryEditorInput implements IStorageEditorInput
{

    private IStorage fJarEntryFile;

    /**
     * @param jarEntryFile
     */
    public JarEntryEditorInput(IStorage jarEntryFile)
    {
        fJarEntryFile = jarEntryFile;
    }

    /*
     */
    public boolean equals(Object obj)
    {
        if (this == obj)
        {
            return true;
        }
        if (!(obj instanceof JarEntryEditorInput))
        {
            return false;
        }
        JarEntryEditorInput other = (JarEntryEditorInput) obj;
        return fJarEntryFile.equals(other.fJarEntryFile);
    }

    
    @Override
    public int hashCode() 
    {
        // two editor inputs are equal if their fJarEntryFile's are
        // equal.  Therefore use the same criteria for hashcodes
        return fJarEntryFile.hashCode();
    }

    /*
     * @see IEditorInput#getPersistable()
     */
    public IPersistableElement getPersistable()
    {
        return null;
    }

    /*
     * @see IEditorInput#getName()
     */
    public String getName()
    {
        return fJarEntryFile.getName();
    }


    /**
     * @return the full path of the entry as a string
     */
    public String getFullPath()
    {
        return fJarEntryFile.getFullPath().toString();
    }


    /**
     * @return the file extension of this input
     */
    public String getContentType()
    {
        return fJarEntryFile.getFullPath().getFileExtension();
    }

    /*
     * @see IEditorInput#getToolTipText()
     */
    public String getToolTipText()
    {
        return fJarEntryFile.getFullPath().toString();
    }

    /*
     * @see IEditorInput#getImageDescriptor()
     */
    public ImageDescriptor getImageDescriptor()
    {
        IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
        return registry.getImageDescriptor(fJarEntryFile.getFullPath().getFileExtension());
    }

    /*
     * @see IEditorInput#exists()
     */
    public boolean exists()
    {
        // JAR entries can't be deleted
        return true;
    }

    /*
     * @see IAdaptable#getAdapter(Class)
     */
    public Object getAdapter(Class adapter)
    {
        return null;
    }

    /*
     * see IStorageEditorInput#getStorage()
     */
    public IStorage getStorage()
    {
        return fJarEntryFile;
    }
}

Back to the top