KickJava   Java API By Example, From Geeks To Geeks.

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


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.BrowserCorePlugin;
25 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
26 import org.apache.directory.ldapstudio.browser.core.model.ISearch;
27 import org.eclipse.ui.IEditorPart;
28 import org.eclipse.ui.IMemento;
29 import org.eclipse.ui.INavigationLocation;
30 import org.eclipse.ui.NavigationLocation;
31
32
33 /**
34  * This class is used to mark the search result editor input to the navigation history.
35  *
36  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
37  * @version $Rev$, $Date$
38  */

39 public class SearchResultEditorNavigationLocation extends NavigationLocation
40 {
41
42     /**
43      * Creates a new instance of SearchResultEditorNavigationLocation.
44      *
45      * @param editor the search result editor
46      */

47     SearchResultEditorNavigationLocation( SearchResultEditor editor )
48     {
49         super( editor );
50     }
51
52
53     /**
54      * {@inheritDoc}
55      */

56     public String JavaDoc getText()
57     {
58         ISearch search = getSearch();
59         if ( search != null )
60         {
61             return "Search " + search.getName();
62         }
63         else
64         {
65             return super.getText();
66         }
67     }
68
69
70     /**
71      * {@inheritDoc}
72      */

73     public void saveState( IMemento memento )
74     {
75         ISearch search = getSearch();
76         memento.putString( "SEARCH", search.getName() );
77         memento.putString( "CONNECTION", search.getConnection().getName() );
78     }
79
80
81     /**
82      * {@inheritDoc}
83      */

84     public void restoreState( IMemento memento )
85     {
86         IConnection connection = BrowserCorePlugin.getDefault().getConnectionManager().getConnection(
87             memento.getString( "CONNECTION" ) );
88         ISearch search = connection.getSearchManager().getSearch( memento.getString( "SEARCH" ) );
89         super.setInput( new SearchResultEditorInput( search ) );
90     }
91
92
93     /**
94      * {@inheritDoc}
95      */

96     public void restoreLocation()
97     {
98         IEditorPart editorPart = getEditorPart();
99         if ( editorPart != null && editorPart instanceof SearchResultEditor )
100         {
101             SearchResultEditor searchResultEditor = ( SearchResultEditor ) editorPart;
102             searchResultEditor.setInput( ( SearchResultEditorInput ) getInput() );
103         }
104     }
105
106
107     /**
108      * {@inheritDoc}
109      */

110     public boolean mergeInto( INavigationLocation currentLocation )
111     {
112         if ( currentLocation == null )
113         {
114             return false;
115         }
116
117         if ( getClass() != currentLocation.getClass() )
118         {
119             return false;
120         }
121
122         SearchResultEditorNavigationLocation location = ( SearchResultEditorNavigationLocation ) currentLocation;
123         ISearch other = location.getSearch();
124         ISearch search = getSearch();
125
126         if ( other == null && search == null )
127         {
128             return true;
129         }
130         else if ( other == null || search == null )
131         {
132             return false;
133         }
134         else
135         {
136             return search.equals( other );
137         }
138     }
139
140
141     /**
142      * {@inheritDoc}
143      */

144     public void update()
145     {
146     }
147
148
149     /**
150      * Gets the search.
151      *
152      * @return the search
153      */

154     private ISearch getSearch()
155     {
156
157         Object JavaDoc editorInput = getInput();
158         if ( editorInput != null && editorInput instanceof SearchResultEditorInput )
159         {
160             SearchResultEditorInput searchResultEditorInput = ( SearchResultEditorInput ) editorInput;
161             ISearch search = searchResultEditorInput.getSearch();
162             if ( search != null )
163             {
164                 return search;
165             }
166         }
167
168         return null;
169     }
170
171
172     /**
173      * {@inheritDoc}
174      */

175     public String JavaDoc toString()
176     {
177         return "" + getSearch();
178     }
179
180 }
181
Popular Tags