KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > actions > PathEditorInput


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.actions;
22
23
24 import org.eclipse.core.runtime.IPath;
25 import org.eclipse.core.runtime.Platform;
26 import org.eclipse.jface.resource.ImageDescriptor;
27 import org.eclipse.ui.IPathEditorInput;
28 import org.eclipse.ui.IPersistableElement;
29
30
31 /**
32  * This IEditorInput is used to open files that are located in the local file system.
33  *
34  * Inspired from org.eclipse.ui.internal.editors.text.NonExistingFileEditorInput.java
35  *
36  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
37  * @version $Rev$, $Date$
38  */

39 public class PathEditorInput implements IPathEditorInput
40 {
41
42     /** The absolute path in local file system */
43     private IPath path;
44
45     /** The image for the input file */
46     private ImageDescriptor imageDescriptor;
47
48
49     /**
50      *
51      * Creates a new instance of PathEditorInput.
52      *
53      * @param path the absolute path
54      * @param imageDescriptor the image for the input file
55      */

56     public PathEditorInput( IPath path, ImageDescriptor imageDescriptor )
57     {
58         if ( path == null )
59         {
60             throw new IllegalArgumentException JavaDoc();
61         }
62
63         this.path = path;
64         this.imageDescriptor = imageDescriptor;
65     }
66
67
68     /**
69      * Returns hash code of the path.
70      */

71     public int hashCode()
72     {
73         return path.hashCode();
74     }
75
76
77     /**
78      * This implemention just compares the paths
79      */

80     public boolean equals( Object JavaDoc o )
81     {
82         if ( this == o )
83         {
84             return true;
85         }
86
87         if ( o instanceof PathEditorInput )
88         {
89             PathEditorInput input = ( PathEditorInput ) o;
90             return path.equals( input.path );
91         }
92
93         return false;
94     }
95
96
97     /**
98      * {@inheritDoc}
99      */

100     public boolean exists()
101     {
102         return path.toFile().exists();
103     }
104
105
106     /**
107      * {@inheritDoc}
108      */

109     public ImageDescriptor getImageDescriptor()
110     {
111         return imageDescriptor;
112     }
113
114
115     /**
116      * Returns the file name only.
117      */

118     public String JavaDoc getName()
119     {
120         return path.toFile().getName();
121         //return path.toString();
122
}
123
124
125     /**
126      * Returns the complete path.
127      */

128     public String JavaDoc getToolTipText()
129     {
130         return path.makeRelative().toOSString();
131     }
132
133
134     /**
135      * {@inheritDoc}
136      */

137     public IPath getPath()
138     {
139         return path;
140     }
141
142
143     /**
144      * {@inheritDoc}
145      */

146     public Object JavaDoc getAdapter( Class JavaDoc adapter )
147     {
148         return Platform.getAdapterManager().getAdapter( this, adapter );
149     }
150
151
152     /**
153      * {@inheritDoc}
154      */

155     public IPersistableElement getPersistable()
156     {
157         return null;
158     }
159
160
161     /**
162      * Returns the path.
163      */

164     public IPath getPath( Object JavaDoc element )
165     {
166         if ( element instanceof PathEditorInput )
167         {
168             PathEditorInput input = ( PathEditorInput ) element;
169             return input.getPath();
170         }
171
172         return null;
173     }
174 }
175
Popular Tags