KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > ldifeditor > editor > PathEditorInput


1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.apache.directory.ldapstudio.ldifeditor.editor;
12
13
14 import org.eclipse.core.runtime.IPath;
15 import org.eclipse.core.runtime.Platform;
16 import org.eclipse.jface.resource.ImageDescriptor;
17 import org.eclipse.ui.IPathEditorInput;
18 import org.eclipse.ui.IPersistableElement;
19 import org.eclipse.ui.PlatformUI;
20 import org.eclipse.ui.editors.text.ILocationProvider;
21
22
23 /**
24  * EditorInput that stores a path.
25  */

26
27 /**
28  * This EditorInput is used to open LDIF files that are located in the local file system.
29  *
30  * Inspired from org.eclipse.ui.internal.editors.text.NonExistingFileEditorInput.java
31  *
32  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
33  * @version $Rev$, $Date$
34  */

35 public class PathEditorInput implements IPathEditorInput, ILocationProvider
36 {
37
38     /** The absolute path in local file system */
39     private IPath path;
40
41
42     /**
43      *
44      * Creates a new instance of PathEditorInput.
45      *
46      * @param path the absolute path
47      */

48     public PathEditorInput( IPath path )
49     {
50         if ( path == null )
51         {
52             throw new IllegalArgumentException JavaDoc();
53         }
54
55         this.path = path;
56     }
57
58
59     /**
60      * Returns hash code of the path.
61      */

62     public int hashCode()
63     {
64         return path.hashCode();
65     }
66
67
68     /**
69      * This implemention just compares the names
70      */

71     public boolean equals( Object JavaDoc o )
72     {
73         if ( this == o )
74         {
75             return true;
76         }
77
78         if ( o instanceof PathEditorInput )
79         {
80             PathEditorInput input = ( PathEditorInput ) o;
81             return path.equals( input.path );
82         }
83
84         return false;
85     }
86
87
88     /*
89      * @see org.eclipse.ui.IEditorInput#exists()
90      */

91     public boolean exists()
92     {
93         return path.toFile().exists();
94     }
95
96
97     /**
98      * Returns the LDIF file image.
99      */

100     public ImageDescriptor getImageDescriptor()
101     {
102         return PlatformUI.getWorkbench().getEditorRegistry().getImageDescriptor( path.toString() );
103     }
104
105
106     /**
107      * Returns the file name only.
108      */

109     public String JavaDoc getName()
110     {
111         return path.toFile().getName();
112         //return path.toString();
113
}
114
115
116     /**
117      * Returns the complete path.
118      */

119     public String JavaDoc getToolTipText()
120     {
121         return path.makeRelative().toOSString();
122     }
123
124
125     /**
126      * Returns the path.
127      */

128     public IPath getPath()
129     {
130         return path;
131     }
132
133
134     /**
135      * An EditorInput must return a good ILocationProvider, otherwise
136      * the editor is not editable.
137      */

138     public Object JavaDoc getAdapter( Class JavaDoc adapter )
139     {
140         if ( ILocationProvider.class.equals( adapter ) )
141         {
142             return this;
143         }
144
145         return Platform.getAdapterManager().getAdapter( this, adapter );
146     }
147
148
149     /*
150      * @see org.eclipse.ui.IEditorInput#getPersistable()
151      */

152     public IPersistableElement getPersistable()
153     {
154         return null;
155     }
156
157
158     /**
159      * Returns the path.
160      */

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