KickJava   Java API By Example, From Geeks To Geeks.

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


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.BrowserUIPlugin;
26 import org.apache.directory.ldapstudio.browser.ui.views.browser.BrowserView;
27
28 import org.eclipse.core.runtime.IProgressMonitor;
29 import org.eclipse.jface.util.IPropertyChangeListener;
30 import org.eclipse.jface.util.PropertyChangeEvent;
31 import org.eclipse.jface.viewers.ISelection;
32 import org.eclipse.swt.SWT;
33 import org.eclipse.swt.layout.GridData;
34 import org.eclipse.swt.layout.GridLayout;
35 import org.eclipse.swt.widgets.Composite;
36 import org.eclipse.ui.IEditorInput;
37 import org.eclipse.ui.IEditorPart;
38 import org.eclipse.ui.IEditorSite;
39 import org.eclipse.ui.INavigationLocation;
40 import org.eclipse.ui.INavigationLocationProvider;
41 import org.eclipse.ui.IReusableEditor;
42 import org.eclipse.ui.PartInitException;
43 import org.eclipse.ui.PlatformUI;
44 import org.eclipse.ui.part.EditorPart;
45 import org.eclipse.ui.part.IShowInSource;
46 import org.eclipse.ui.part.IShowInTargetList;
47 import org.eclipse.ui.part.ShowInContext;
48
49
50 public class SearchResultEditor extends EditorPart implements INavigationLocationProvider, IReusableEditor,
51     IPropertyChangeListener
52 {
53
54     private SearchResultEditorConfiguration configuration;
55
56     private SearchResultEditorActionGroup actionGroup;
57
58     private SearchResultEditorWidget mainWidget;
59
60     private SearchResultEditorUniversalListener universalListener;
61
62
63     public static String JavaDoc getId()
64     {
65         return SearchResultEditor.class.getName();
66     }
67
68     
69     public void setInput( IEditorInput input )
70     {
71         super.setInput( input );
72         
73         if ( input instanceof SearchResultEditorInput && this.universalListener != null )
74         {
75             SearchResultEditorInput srei = ( SearchResultEditorInput ) input;
76             ISearch search = srei.getSearch();
77             this.universalListener.setInput( search );
78
79             if ( search != null )
80             {
81                 // enable one instance hack before fireing the input change event
82
// otherwise the navigation history is cleared.
83
SearchResultEditorInput.enableOneInstanceHack( true );
84                 firePropertyChange( IEditorPart.PROP_INPUT );
85
86                 // disable one instance hack for marking the location
87
SearchResultEditorInput.enableOneInstanceHack( false );
88                 getSite().getPage().getNavigationHistory().markLocation( this );
89             }
90         }
91
92         // finally enable the one instance hack
93
SearchResultEditorInput.enableOneInstanceHack( true );
94     }
95
96
97     public void refresh()
98     {
99         if ( this.universalListener != null )
100         {
101             this.universalListener.refreshInput();
102         }
103     }
104
105
106     public void init( IEditorSite site, IEditorInput input ) throws PartInitException
107     {
108         super.setSite( site );
109
110         // mark dummy location, necessary because the first marked
111
// location doesn't appear in history
112
this.setInput( new SearchResultEditorInput( null ) );
113         getSite().getPage().getNavigationHistory().markLocation( this );
114
115         this.setInput( input );
116     }
117
118
119     public void createPartControl( Composite parent )
120     {
121
122         Composite composite = new Composite( parent, SWT.NONE );
123         composite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
124         GridLayout layout = new GridLayout();
125         layout.marginWidth = 0;
126         layout.marginHeight = 0;
127         // layout.horizontalSpacing = 0;
128
layout.verticalSpacing = 0;
129         composite.setLayout( layout );
130
131         PlatformUI.getWorkbench().getHelpSystem().setHelp( composite,
132             BrowserUIPlugin.PLUGIN_ID + "." + "tools_search_result_editor" );
133
134         // create configuration
135
this.configuration = new SearchResultEditorConfiguration( this );
136
137         // create main widget
138
this.mainWidget = new SearchResultEditorWidget( this.configuration );
139         this.mainWidget.createWidget( composite );
140
141         // create actions and context menu (and register global actions)
142
this.actionGroup = new SearchResultEditorActionGroup( this );
143         this.actionGroup.fillToolBar( this.mainWidget.getToolBarManager() );
144         this.actionGroup.fillMenu( this.mainWidget.getMenuManager() );
145         this.actionGroup.enableGlobalActionHandlers( getEditorSite().getActionBars() );
146         this.actionGroup.fillContextMenu( this.configuration.getContextMenuManager( this.mainWidget.getViewer() ) );
147
148         // create the listener
149
this.universalListener = new SearchResultEditorUniversalListener( this );
150         getSite().setSelectionProvider( this.configuration.getCursor( this.mainWidget.getViewer() ) );
151         this.setInput( getEditorInput() );
152
153         BrowserUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener( this );
154     }
155
156
157     public void setFocus()
158     {
159         this.mainWidget.setFocus();
160     }
161
162
163     public void dispose()
164     {
165         if ( this.configuration != null )
166         {
167             this.actionGroup.dispose();
168             this.actionGroup = null;
169             this.universalListener.dispose();
170             this.universalListener = null;
171             this.mainWidget.dispose();
172             this.mainWidget = null;
173             this.configuration.dispose();
174             this.configuration = null;
175             getSite().setSelectionProvider( null );
176             BrowserUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener( this );
177         }
178
179         super.dispose();
180     }
181
182
183     public void doSave( IProgressMonitor monitor )
184     {
185     }
186
187
188     public void doSaveAs()
189     {
190     }
191
192
193     public boolean isDirty()
194     {
195         return false;
196     }
197
198
199     public boolean isSaveAsAllowed()
200     {
201         return false;
202     }
203
204
205     public INavigationLocation createEmptyNavigationLocation()
206     {
207         return null;
208     }
209
210
211     public INavigationLocation createNavigationLocation()
212     {
213         return new SearchResultEditorNavigationLocation( this );
214     }
215
216
217     public Object JavaDoc getAdapter( Class JavaDoc required )
218     {
219
220         if ( IShowInTargetList.class.equals( required ) )
221         {
222             return new IShowInTargetList()
223             {
224                 public String JavaDoc[] getShowInTargetIds()
225                 {
226                     return new String JavaDoc[]
227                         { BrowserView.getId() };
228                 }
229             };
230         }
231
232         if ( IShowInSource.class.equals( required ) )
233         {
234             return new IShowInSource()
235             {
236                 public ShowInContext getShowInContext()
237                 {
238                     ISelection selection = getConfiguration().getCursor( getMainWidget().getViewer() ).getSelection();
239                     return new ShowInContext( getMainWidget().getViewer().getInput(), selection );
240                 }
241             };
242         }
243
244         return super.getAdapter( required );
245     }
246
247
248     public SearchResultEditorActionGroup getActionGroup()
249     {
250         return actionGroup;
251     }
252
253
254     public SearchResultEditorConfiguration getConfiguration()
255     {
256         return configuration;
257     }
258
259
260     public SearchResultEditorWidget getMainWidget()
261     {
262         return mainWidget;
263     }
264
265
266     public SearchResultEditorUniversalListener getUniversalListener()
267     {
268         return universalListener;
269     }
270
271
272     public void propertyChange( PropertyChangeEvent event )
273     {
274         // if(this.mainWidget.getViewer() != null) {
275
// this.mainWidget.getViewer().refresh();
276
// }
277
this.refresh();
278     }
279
280 }
281
Popular Tags