KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > ui > editors > searchresult > SearchResultEditorInput


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

50 public class SearchResultEditorInput implements IEditorInput
51 {
52
53     /** The search input */
54     private ISearch search;
55
56     /** One instance hack flag */
57     private static boolean oneInstanceHackEnabled = true;
58
59
60     /**
61      * Creates a new instance of SearchResultEditorInput.
62      *
63      * @param search the search input
64      */

65     public SearchResultEditorInput( ISearch search )
66     {
67         this.search = search;
68     }
69
70
71     /**
72      * This implementation always return false because
73      * a search should not be visible in the
74      * "File Most Recently Used" menu.
75      *
76      * {@inheritDoc}
77      */

78     public boolean exists()
79     {
80         return false;
81     }
82
83
84     /**
85      * {@inheritDoc}
86      */

87     public ImageDescriptor getImageDescriptor()
88     {
89         return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_BROWSER_SEARCHRESULTEDITOR );
90     }
91
92
93     /**
94      * {@inheritDoc}
95      */

96     public String JavaDoc getName()
97     {
98         return "Search Result Editor";
99     }
100
101
102     /**
103      * {@inheritDoc}
104      */

105     public String JavaDoc getToolTipText()
106     {
107         return "";
108     }
109
110
111     /**
112      * This implementation always return null.
113      *
114      * {@inheritDoc}
115      */

116     public IPersistableElement getPersistable()
117     {
118         return null;
119     }
120
121
122     /**
123      * {@inheritDoc}
124      */

125     public Object JavaDoc getAdapter( Class JavaDoc adapter )
126     {
127         return null;
128     }
129
130
131     /**
132      * Gets the search input, may be null.
133      *
134      * @return the search input or null
135      */

136     public ISearch getSearch()
137     {
138         return search;
139     }
140
141
142     /**
143      * {@inheritDoc}
144      */

145     public int hashCode()
146     {
147         return getToolTipText().hashCode();
148     }
149
150
151     /**
152      * {@inheritDoc}
153      */

154     public boolean equals( Object JavaDoc obj )
155     {
156
157         boolean equal;
158
159         if ( oneInstanceHackEnabled )
160         {
161             equal = ( obj instanceof SearchResultEditorInput );
162         }
163         else
164         {
165             if ( obj instanceof SearchResultEditorInput )
166             {
167                 SearchResultEditorInput other = ( SearchResultEditorInput ) obj;
168                 if ( this.search == null && other.search == null )
169                 {
170                     return true;
171                 }
172                 else if ( this.search == null || other.search == null )
173                 {
174                     return false;
175                 }
176                 else
177                 {
178                     equal = other.search.equals( this.search );
179                 }
180             }
181             else
182             {
183                 equal = false;
184             }
185         }
186
187         return equal;
188     }
189
190
191     /**
192      * Enables or disabled the one instance hack.
193      *
194      * @param b
195      * true to enable the one instance hack,
196      * false to disable the one instance hack
197      */

198     public static void enableOneInstanceHack( boolean b )
199     {
200         oneInstanceHackEnabled = b;
201     }
202
203 }
204
Popular Tags