KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > ui > editors > entry > EntryEditor


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.entry;
22
23
24 import org.apache.directory.ldapstudio.browser.common.widgets.entryeditor.EntryEditorWidget;
25 import org.apache.directory.ldapstudio.browser.core.model.IEntry;
26 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
27 import org.apache.directory.ldapstudio.browser.ui.views.browser.BrowserView;
28 import org.eclipse.core.runtime.IProgressMonitor;
29 import org.eclipse.swt.SWT;
30 import org.eclipse.swt.layout.GridData;
31 import org.eclipse.swt.layout.GridLayout;
32 import org.eclipse.swt.widgets.Composite;
33 import org.eclipse.ui.IEditorInput;
34 import org.eclipse.ui.IEditorPart;
35 import org.eclipse.ui.IEditorSite;
36 import org.eclipse.ui.INavigationLocation;
37 import org.eclipse.ui.INavigationLocationProvider;
38 import org.eclipse.ui.IReusableEditor;
39 import org.eclipse.ui.PartInitException;
40 import org.eclipse.ui.PlatformUI;
41 import org.eclipse.ui.part.EditorPart;
42 import org.eclipse.ui.part.IShowInSource;
43 import org.eclipse.ui.part.IShowInTargetList;
44 import org.eclipse.ui.part.ShowInContext;
45 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
46
47
48 /**
49  * The EntryEditor is an {@link IEditorPart} is used to display and edit the attributes of an entry.
50  *
51  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
52  * @version $Rev$, $Date$
53  */

54 public class EntryEditor extends EditorPart implements INavigationLocationProvider, IReusableEditor
55 {
56
57     /** The editor configuration. */
58     private EntryEditorConfiguration configuration;
59
60     /** The action group. */
61     private EntryEditorActionGroup actionGroup;
62
63     /** The main widget. */
64     private EntryEditorWidget mainWidget;
65
66     /** The universal listener. */
67     private EntryEditorUniversalListener universalListener;
68
69     /** The outline page. */
70     private EntryEditorOutlinePage outlinePage;
71
72
73     /**
74      * Gets the ID of the EntryEditor.
75      *
76      * @return the id of the EntryEditor
77      */

78     public static String JavaDoc getId()
79     {
80         return EntryEditor.class.getName();
81     }
82
83
84     /**
85      * {@inheritDoc}
86      */

87     public void setInput( IEditorInput input )
88     {
89         super.setInput( input );
90
91         if ( input instanceof EntryEditorInput && universalListener != null )
92         {
93             EntryEditorInput eei = ( EntryEditorInput ) input;
94             IEntry entry = eei.getResolvedEntry();
95
96             // inform listener
97
universalListener.setInput( entry );
98
99             // mark location for back/forward history navigation
100
if ( entry != null )
101             {
102                 // enable one instance hack before fireing the input change event
103
// otherwise the navigation history is cleared.
104
EntryEditorInput.enableOneInstanceHack( true );
105                 firePropertyChange( IEditorPart.PROP_INPUT );
106
107                 // disable one instance hack for marking the location
108
EntryEditorInput.enableOneInstanceHack( false );
109                 getSite().getPage().getNavigationHistory().markLocation( this );
110             }
111
112             // refresh outline
113
if ( outlinePage != null )
114             {
115                 outlinePage.refresh();
116             }
117
118             // finally enable the one instance hack
119
EntryEditorInput.enableOneInstanceHack( true );
120         }
121     }
122
123
124     /**
125      * {@inheritDoc}
126      */

127     public void init( IEditorSite site, IEditorInput input ) throws PartInitException
128     {
129         super.setSite( site );
130
131         // mark dummy location, necessary because the first marked
132
// location doesn't appear in history
133
setInput( new EntryEditorInput( ( IEntry ) null ) );
134         getSite().getPage().getNavigationHistory().markLocation( this );
135
136         setInput( input );
137     }
138
139
140     /**
141      * {@inheritDoc}
142      */

143     public void createPartControl( Composite parent )
144     {
145         Composite composite = new Composite( parent, SWT.NONE );
146         composite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
147         GridLayout layout = new GridLayout();
148         layout.marginWidth = 0;
149         layout.marginHeight = 0;
150         layout.verticalSpacing = 0;
151         composite.setLayout( layout );
152
153         PlatformUI.getWorkbench().getHelpSystem().setHelp( composite,
154             BrowserUIPlugin.PLUGIN_ID + "." + "tools_entry_editor" );
155
156         // create configuration
157
configuration = new EntryEditorConfiguration();
158
159         // create main widget
160
mainWidget = new EntryEditorWidget( this.configuration );
161         mainWidget.createWidget( composite );
162
163         // create actions and context menu and register global actions
164
actionGroup = new EntryEditorActionGroup( this );
165         actionGroup.fillToolBar( mainWidget.getToolBarManager() );
166         actionGroup.fillMenu( mainWidget.getMenuManager() );
167         actionGroup.enableGlobalActionHandlers( getEditorSite().getActionBars() );
168         actionGroup.fillContextMenu( mainWidget.getContextMenuManager() );
169
170         // create the listener
171
getSite().setSelectionProvider( mainWidget.getViewer() );
172         universalListener = new EntryEditorUniversalListener( this );
173         setInput( getEditorInput() );
174     }
175
176
177     /**
178      * {@inheritDoc}
179      */

180     public void setFocus()
181     {
182         mainWidget.setFocus();
183     }
184
185
186     /**
187      * {@inheritDoc}
188      */

189     public Object JavaDoc getAdapter( Class JavaDoc required )
190     {
191         if ( IContentOutlinePage.class.equals( required ) )
192         {
193             if ( outlinePage == null || outlinePage.getControl() == null || outlinePage.getControl().isDisposed() )
194             {
195                 outlinePage = new EntryEditorOutlinePage( this );
196             }
197             return outlinePage;
198         }
199
200         if ( IShowInTargetList.class.equals( required ) )
201         {
202             return new IShowInTargetList()
203             {
204                 public String JavaDoc[] getShowInTargetIds()
205                 {
206                     return new String JavaDoc[]
207                         { BrowserView.getId() };
208                 }
209             };
210         }
211
212         if ( IShowInSource.class.equals( required ) )
213         {
214             return new IShowInSource()
215             {
216                 public ShowInContext getShowInContext()
217                 {
218                     return new ShowInContext( getMainWidget().getViewer().getInput(), getMainWidget().getViewer()
219                         .getSelection() );
220                 }
221             };
222         }
223
224         return super.getAdapter( required );
225     }
226
227
228     /**
229      * {@inheritDoc}
230      */

231     public void dispose()
232     {
233         if ( configuration != null )
234         {
235             universalListener.dispose();
236             universalListener = null;
237             mainWidget.dispose();
238             mainWidget = null;
239             actionGroup.dispose();
240             actionGroup = null;
241             configuration.dispose();
242             configuration = null;
243             getSite().setSelectionProvider( null );
244         }
245
246         super.dispose();
247     }
248
249
250     /**
251      * {@inheritDoc}
252      */

253     public void doSave( IProgressMonitor monitor )
254     {
255     }
256
257
258     /**
259      * {@inheritDoc}
260      */

261     public void doSaveAs()
262     {
263     }
264
265
266     /**
267      * {@inheritDoc}
268      */

269     public boolean isDirty()
270     {
271         return false;
272     }
273
274
275     /**
276      * {@inheritDoc}
277      */

278     public boolean isSaveAsAllowed()
279     {
280         return false;
281     }
282
283
284     /**
285      * Gets the action group.
286      *
287      * @return the action group
288      */

289     public EntryEditorActionGroup getActionGroup()
290     {
291         return actionGroup;
292     }
293
294
295     /**
296      * Gets the configuration.
297      *
298      * @return the configuration
299      */

300     public EntryEditorConfiguration getConfiguration()
301     {
302         return configuration;
303     }
304
305
306     /**
307      * Gets the main widget.
308      *
309      * @return the main widget
310      */

311     public EntryEditorWidget getMainWidget()
312     {
313         return mainWidget;
314     }
315
316
317     /**
318      * Gets the outline page.
319      *
320      * @return the outline page
321      */

322     public EntryEditorOutlinePage getOutlinePage()
323     {
324         return outlinePage;
325     }
326
327
328     /**
329      * Gets the universal listener.
330      *
331      * @return the universal listener
332      */

333     public EntryEditorUniversalListener getUniversalListener()
334     {
335         return universalListener;
336     }
337
338
339     /**
340      * {@inheritDoc}
341      */

342     public INavigationLocation createEmptyNavigationLocation()
343     {
344         return null;
345     }
346
347
348     /**
349      * {@inheritDoc}
350      */

351     public INavigationLocation createNavigationLocation()
352     {
353         return new EntryEditorNavigationLocation( this );
354     }
355
356 }
357
Popular Tags