KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > ui > editors > schemabrowser > SchemaBrowserInput


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.browser.ui.editors.schemabrowser;
22
23
24 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
25 import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaPart;
26 import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
27 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
28 import org.eclipse.jface.resource.ImageDescriptor;
29 import org.eclipse.ui.IEditorInput;
30 import org.eclipse.ui.IPersistableElement;
31
32
33 /**
34  * The input for the schema browser.
35  *
36  * There is a trick to provide a single instance of the schema browser:
37  * <ul>
38  * <li>If oneInstanceHackEnabled is true the equals method returns always
39  * true as long as the compared object is also of type SchemaBrowserInput.
40  * With this trick only one instance of the schema browser is opened
41  * by the eclipse editor framework.
42  * <li>If oneInstanceHackEnabled is false the equals method returns
43  * true only if the wrapped objects (IConnection and SchemaPart) are equal.
44  * This is necessary for the history navigation because it must be able
45  * to distinguish the different input objects.
46  * </ul>
47  *
48  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
49  * @version $Rev$, $Date$
50  */

51 public class SchemaBrowserInput implements IEditorInput
52 {
53
54     /** The connection */
55     private IConnection connection;
56     
57     /** The schema element */
58     private SchemaPart schemaElement;
59     
60     /** One instance hack flag */
61     private static boolean oneInstanceHackEnabled = true;
62
63
64     /**
65      * Creates a new instance of SchemaBrowserInput.
66      *
67      *@param connection the connection
68      * @param schemaElement the schema element input
69      */

70     public SchemaBrowserInput( IConnection connection, SchemaPart schemaElement )
71     {
72         this.connection = connection;
73         this.schemaElement = schemaElement;
74     }
75     
76
77     /**
78      * This implementation always return false because
79      * a schema element should not be visible in the
80      * "File Most Recently Used" menu.
81      *
82      * {@inheritDoc}
83      */

84     public boolean exists()
85     {
86         return false;
87     }
88
89
90     /**
91      * {@inheritDoc}
92      */

93     public ImageDescriptor getImageDescriptor()
94     {
95         return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_BROWSER_SCHEMABROWSEREDITOR );
96     }
97
98
99     /**
100      * {@inheritDoc}
101      */

102     public String JavaDoc getName()
103     {
104         return "Schema Browser";
105     }
106
107
108     /**
109      * This implementation always return null.
110      *
111      * {@inheritDoc}
112      */

113     public IPersistableElement getPersistable()
114     {
115         return null;
116     }
117
118
119     /**
120      * {@inheritDoc}
121      */

122     public String JavaDoc getToolTipText()
123     {
124         return "";
125     }
126
127
128     /**
129      * {@inheritDoc}
130      */

131     public Object JavaDoc getAdapter( Class JavaDoc adapter )
132     {
133         return null;
134     }
135     
136
137     /**
138      * Gets the connection.
139      *
140      * @return the connection
141      */

142     public IConnection getConnection()
143     {
144         return connection;
145     }
146     
147     
148     /**
149     /**
150      * Gets the schema element, may be null.
151      *
152      * @return the schema element or null
153      */

154     public SchemaPart getSchemaElement()
155     {
156         return schemaElement;
157     }
158     
159     
160     /**
161      * {@inheritDoc}
162      */

163     public int hashCode()
164     {
165         return getToolTipText().hashCode();
166     }
167
168
169     /**
170      * {@inheritDoc}
171      */

172     public boolean equals( Object JavaDoc obj )
173     {
174
175         boolean equal;
176
177         if ( oneInstanceHackEnabled )
178         {
179             equal = ( obj instanceof SchemaBrowserInput );
180         }
181         else
182         {
183             if ( obj instanceof SchemaBrowserInput )
184             {
185                 SchemaBrowserInput other = ( SchemaBrowserInput ) obj;
186                 if ( this.connection == null && other.connection == null)
187                 {
188                     return true;
189                 }
190                 else if ( this.connection == null || other.connection == null)
191                 {
192                     return false;
193                 }
194                 else if ( !this.connection.equals( other.connection ))
195                 {
196                     return false;
197                 }
198                 else if ( this.schemaElement == null && other.schemaElement == null )
199                 {
200                     return true;
201                 }
202                 else if ( this.schemaElement == null || other.schemaElement == null )
203                 {
204                     return false;
205                 }
206                 else
207                 {
208                     equal = other.schemaElement.equals( this.schemaElement );
209                 }
210             }
211             else
212             {
213                 equal = false;
214             }
215         }
216
217         return equal;
218     }
219
220
221     /**
222      * Enables or disabled the one instance hack.
223      *
224      * @param b
225      * true to enable the one instance hack,
226      * false to disable the one instance hack
227      */

228     public static void enableOneInstanceHack( boolean b )
229     {
230         oneInstanceHackEnabled = b;
231     }
232
233 }
234
Popular Tags