KickJava   Java API By Example, From Geeks To Geeks.

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


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.ldifeditor.editor;
22
23
24 import org.apache.directory.ldapstudio.ldifeditor.LdifEditorConstants;
25 import org.apache.directory.ldapstudio.ldifeditor.LdifEditorActivator;
26 import org.eclipse.core.runtime.IPath;
27 import org.eclipse.core.runtime.Platform;
28 import org.eclipse.jface.resource.ImageDescriptor;
29 import org.eclipse.ui.IPathEditorInput;
30 import org.eclipse.ui.IPersistableElement;
31 import org.eclipse.ui.editors.text.ILocationProvider;
32
33
34 /**
35  * This EditorInput is used to create a LDIF file that isn't saved yet.
36  * It is used from File->New, but also from the embedded LDIF editors
37  * in modification view, in batch operation wizard and the LDIF preference page.
38  *
39  * Inspired from org.eclipse.ui.internal.editors.text.NonExistingFileEditorInput.java
40  *
41  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
42  * @version $Rev$, $Date$
43  */

44 public class NonExistingLdifEditorInput implements IPathEditorInput, ILocationProvider
45 {
46     /** The counter to create unique names */
47     private static int counter = 0;
48
49     /** The name, displayed in Editor tab */
50     private String JavaDoc name;
51
52
53     /**
54      * Creates a new instance of NonExistingLdifEditorInput.
55      */

56     public NonExistingLdifEditorInput()
57     {
58         counter++;
59         name = "LDIF " + counter; //$NON-NLS-1$
60
}
61
62
63     /**
64      * As the name says, this implementations always returns false.
65      */

66     public boolean exists()
67     {
68         return false;
69     }
70
71
72     /**
73      * Returns the LDIF file image.
74      */

75     public ImageDescriptor getImageDescriptor()
76     {
77         return LdifEditorActivator.getDefault().getImageDescriptor( LdifEditorConstants.IMG_BROWSER_LDIFEDITOR );
78     }
79
80
81     /**
82      * Returns the name.
83      */

84     public String JavaDoc getName()
85     {
86         return name;
87     }
88
89
90     /**
91      * As the name says, this implementations always returns false.
92      */

93     public IPersistableElement getPersistable()
94     {
95         return null;
96     }
97
98
99     /**
100      * Returns the name.
101      */

102     public String JavaDoc getToolTipText()
103     {
104         return name;
105     }
106
107
108     /**
109      * An EditorInput must return a good ILocationProvider, otherwise
110      * the editor is not editable.
111      */

112     public Object JavaDoc getAdapter( Class JavaDoc adapter )
113     {
114         if ( ILocationProvider.class.equals( adapter ) )
115         {
116             return this;
117         }
118         
119         return Platform.getAdapterManager().getAdapter( this, adapter );
120     }
121
122
123     /**
124      * This implementation returns a path that point to the plugin's
125      * state location.
126      *
127      * A valid, writeable path must be returned, otherwise the editor
128      * is not editable.
129      */

130     public IPath getPath( Object JavaDoc element )
131     {
132         if ( element instanceof NonExistingLdifEditorInput )
133         {
134             NonExistingLdifEditorInput input = ( NonExistingLdifEditorInput ) element;
135             return input.getPath();
136         }
137         
138         return null;
139     }
140
141
142     /**
143      * This implemention just compares the names
144      */

145     public boolean equals( Object JavaDoc o )
146     {
147         if ( o == this )
148         {
149             return true;
150         }
151
152         if ( o instanceof NonExistingLdifEditorInput )
153         {
154             NonExistingLdifEditorInput input = ( NonExistingLdifEditorInput ) o;
155             return name.equals( input.name );
156         }
157
158         return false;
159     }
160
161
162     /**
163      * Returns hash code of the name string.
164      */

165     public int hashCode()
166     {
167         return name.hashCode();
168     }
169
170
171     /**
172      * This implementation returns a path that point to the plugin's
173      * state location. The state location is a platform indepentend
174      * location that is writeable.
175      *
176      * A valid, writeable path must be returned, otherwise the editor
177      * is not editable.
178      */

179     public IPath getPath()
180     {
181         return LdifEditorActivator.getDefault().getStateLocation().append( name + ".ldif" );
182     }
183
184 }
185
Popular Tags