KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Iterator JavaDoc;
25
26 import org.apache.directory.ldapstudio.browser.core.model.IEntry;
27 import org.apache.directory.ldapstudio.browser.ui.actions.CopyAttributeDescriptionAction;
28 import org.apache.directory.ldapstudio.browser.ui.actions.CopyDnAction;
29 import org.apache.directory.ldapstudio.browser.ui.actions.CopySearchFilterAction;
30 import org.apache.directory.ldapstudio.browser.ui.actions.CopyUrlAction;
31 import org.apache.directory.ldapstudio.browser.ui.actions.CopyValueAction;
32 import org.apache.directory.ldapstudio.browser.ui.actions.ExpandAllAction;
33 import org.apache.directory.ldapstudio.browser.ui.actions.LocateDnInDitAction;
34 import org.apache.directory.ldapstudio.browser.ui.actions.NewBatchOperationAction;
35 import org.apache.directory.ldapstudio.browser.ui.actions.NewSearchAction;
36 import org.apache.directory.ldapstudio.browser.ui.actions.OpenSchemaBrowserAction;
37 import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
38 import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
39 import org.apache.directory.ldapstudio.browser.common.actions.CollapseAllAction;
40 import org.apache.directory.ldapstudio.browser.common.actions.DeleteAllValuesAction;
41 import org.apache.directory.ldapstudio.browser.common.actions.NewAttributeAction;
42 import org.apache.directory.ldapstudio.browser.common.actions.RefreshAction;
43 import org.apache.directory.ldapstudio.browser.common.actions.proxy.EntryEditorActionProxy;
44 import org.apache.directory.ldapstudio.browser.common.widgets.entryeditor.EditAttributeDescriptionAction;
45 import org.apache.directory.ldapstudio.browser.common.widgets.entryeditor.EntryEditorWidgetActionGroup;
46 import org.apache.directory.ldapstudio.browser.common.widgets.entryeditor.OpenDefaultEditorAction;
47 import org.eclipse.jface.action.IAction;
48 import org.eclipse.jface.action.IMenuListener;
49 import org.eclipse.jface.action.IMenuManager;
50 import org.eclipse.jface.action.IToolBarManager;
51 import org.eclipse.jface.action.MenuManager;
52 import org.eclipse.jface.action.Separator;
53 import org.eclipse.jface.commands.ActionHandler;
54 import org.eclipse.jface.viewers.TreeViewer;
55 import org.eclipse.ui.IWorkbenchActionConstants;
56 import org.eclipse.ui.PlatformUI;
57 import org.eclipse.ui.actions.ActionFactory;
58 import org.eclipse.ui.actions.ContributionItemFactory;
59 import org.eclipse.ui.commands.ICommandService;
60
61
62 /**
63  * The EntryEditorWidgetActionGroup manages all actions of the entry editor.
64  *
65  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
66  * @version $Rev$, $Date$
67  */

68 public class EntryEditorActionGroup extends EntryEditorWidgetActionGroup
69 {
70
71     /** The show operational attributes action. */
72     private ShowOperationalAttributesAction showOperationalAttributesAction;
73
74     /** The open entry editor preference page. */
75     private OpenEntryEditorPreferencePageAction openEntryEditorPreferencePage;
76
77     /** The collapse all action. */
78     private CollapseAllAction collapseAllAction;
79
80     /** The expand all action. */
81     private ExpandAllAction expandAllAction;
82
83     /** The Constant editAttributeDescriptionAction. */
84     private static final String JavaDoc editAttributeDescriptionAction = "editAttributeDescriptionAction";
85
86     /** The Constant refreshAttributesAction. */
87     private static final String JavaDoc refreshAttributesAction = "refreshAttributesAction";
88
89     /** The Constant newAttributeAction. */
90     private static final String JavaDoc newAttributeAction = "newAttributeAction";
91
92     /** The Constant newSearchAction. */
93     private static final String JavaDoc newSearchAction = "newSearchDialogAction";
94
95     /** The Constant newBatchOperationAction. */
96     private static final String JavaDoc newBatchOperationAction = "newBatchOperationAction";
97
98     /** The Constant copyDnAction. */
99     private static final String JavaDoc copyDnAction = "copyDnAction";
100
101     /** The Constant copyUrlAction. */
102     private static final String JavaDoc copyUrlAction = "copyUrlAction";
103
104     /** The Constant copyAttriuteDescriptionAction. */
105     private static final String JavaDoc copyAttriuteDescriptionAction = "copyAttriuteDescriptionAction";
106
107     /** The Constant copyValueUtf8Action. */
108     private static final String JavaDoc copyValueUtf8Action = "copyValueUtf8Action";
109
110     /** The Constant copyValueBase64Action. */
111     private static final String JavaDoc copyValueBase64Action = "copyValueBase64Action";
112
113     /** The Constant copyValueHexAction. */
114     private static final String JavaDoc copyValueHexAction = "copyValueHexAction";
115
116     /** The Constant copyValueAsLdifAction. */
117     private static final String JavaDoc copyValueAsLdifAction = "copyValueAsLdifAction";
118
119     /** The Constant copySearchFilterAction. */
120     private static final String JavaDoc copySearchFilterAction = "copySearchFilterAction";
121
122     /** The Constant copyNotSearchFilterAction. */
123     private static final String JavaDoc copyNotSearchFilterAction = "copyNotSearchFilterAction";
124
125     /** The Constant copyAndSearchFilterAction. */
126     private static final String JavaDoc copyAndSearchFilterAction = "copyAndSearchFilterAction";
127
128     /** The Constant copyOrSearchFilterAction. */
129     private static final String JavaDoc copyOrSearchFilterAction = "copyOrSearchFilterAction";
130
131     /** The Constant deleteAllValuesAction. */
132     private static final String JavaDoc deleteAllValuesAction = "deleteAllValuesAction";
133
134     /** The Constant locateDnInDitAction. */
135     private static final String JavaDoc locateDnInDitAction = "locateDnInDitAction";
136
137     /** The Constant showOcdAction. */
138     private static final String JavaDoc showOcdAction = "showOcdAction";
139
140     /** The Constant showAtdAction. */
141     private static final String JavaDoc showAtdAction = "showAtdAction";
142
143     /** The Constant showEqualityMrdAction. */
144     private static final String JavaDoc showEqualityMrdAction = "showEqualityMrdAction";
145
146     /** The Constant showSubstringMrdAction. */
147     private static final String JavaDoc showSubstringMrdAction = "showSubstringMrdAction";
148
149     /** The Constant showOrderingMrdAction. */
150     private static final String JavaDoc showOrderingMrdAction = "showOrderingMrdAction";
151
152     /** The Constant showLsdAction. */
153     private static final String JavaDoc showLsdAction = "showLsdAction";
154
155
156     /**
157      * Creates a new instance of EntryEditorActionGroup.
158      *
159      * @param entryEditor the entry editor
160      */

161     public EntryEditorActionGroup( EntryEditor entryEditor )
162     {
163         super( entryEditor.getMainWidget(), entryEditor.getConfiguration() );
164         TreeViewer viewer = entryEditor.getMainWidget().getViewer();
165
166         // create OpenDefaultEditorAction with enabled rename action flag
167
openDefaultValueEditorActionProxy.dispose();
168         openDefaultValueEditorActionProxy = new EntryEditorActionProxy( viewer, new OpenDefaultEditorAction( viewer,
169             openBestValueEditorActionProxy, true ) );
170
171         showOperationalAttributesAction = new ShowOperationalAttributesAction();
172         openEntryEditorPreferencePage = new OpenEntryEditorPreferencePageAction();
173         collapseAllAction = new CollapseAllAction( viewer );
174         expandAllAction = new ExpandAllAction( viewer );
175
176         entryEditorActionMap.put( editAttributeDescriptionAction, new EntryEditorActionProxy( viewer,
177             new EditAttributeDescriptionAction( viewer ) ) );
178
179         entryEditorActionMap.put( refreshAttributesAction, new EntryEditorActionProxy( viewer, new RefreshAction() ) );
180
181         entryEditorActionMap.put( newAttributeAction, new EntryEditorActionProxy( viewer, new NewAttributeAction() ) );
182         entryEditorActionMap.put( newSearchAction, new EntryEditorActionProxy( viewer, new NewSearchAction() ) );
183         entryEditorActionMap.put( newBatchOperationAction, new EntryEditorActionProxy( viewer,
184             new NewBatchOperationAction() ) );
185
186         entryEditorActionMap.put( locateDnInDitAction, new EntryEditorActionProxy( viewer, new LocateDnInDitAction() ) );
187         entryEditorActionMap.put( showOcdAction, new EntryEditorActionProxy( viewer, new OpenSchemaBrowserAction(
188             OpenSchemaBrowserAction.MODE_OBJECTCLASS ) ) );
189         entryEditorActionMap.put( showAtdAction, new EntryEditorActionProxy( viewer, new OpenSchemaBrowserAction(
190             OpenSchemaBrowserAction.MODE_ATTRIBUTETYPE ) ) );
191         entryEditorActionMap.put( showEqualityMrdAction, new EntryEditorActionProxy( viewer,
192             new OpenSchemaBrowserAction( OpenSchemaBrowserAction.MODE_EQUALITYMATCHINGRULE ) ) );
193         entryEditorActionMap.put( showSubstringMrdAction, new EntryEditorActionProxy( viewer,
194             new OpenSchemaBrowserAction( OpenSchemaBrowserAction.MODE_SUBSTRINGMATCHINGRULE ) ) );
195         entryEditorActionMap.put( showOrderingMrdAction, new EntryEditorActionProxy( viewer,
196             new OpenSchemaBrowserAction( OpenSchemaBrowserAction.MODE_ORDERINGMATCHINGRULE ) ) );
197         entryEditorActionMap.put( showLsdAction, new EntryEditorActionProxy( viewer, new OpenSchemaBrowserAction(
198             OpenSchemaBrowserAction.MODE_SYNTAX ) ) );
199
200         entryEditorActionMap.put( copyDnAction, new EntryEditorActionProxy( viewer, new CopyDnAction() ) );
201         entryEditorActionMap.put( copyUrlAction, new EntryEditorActionProxy( viewer, new CopyUrlAction() ) );
202         entryEditorActionMap.put( copyAttriuteDescriptionAction, new EntryEditorActionProxy( viewer,
203             new CopyAttributeDescriptionAction() ) );
204         entryEditorActionMap.put( copyValueUtf8Action, new EntryEditorActionProxy( viewer, new CopyValueAction(
205             CopyValueAction.MODE_UTF8 ) ) );
206         entryEditorActionMap.put( copyValueBase64Action, new EntryEditorActionProxy( viewer, new CopyValueAction(
207             CopyValueAction.MODE_BASE64 ) ) );
208         entryEditorActionMap.put( copyValueHexAction, new EntryEditorActionProxy( viewer, new CopyValueAction(
209             CopyValueAction.MODE_HEX ) ) );
210         entryEditorActionMap.put( copyValueAsLdifAction, new EntryEditorActionProxy( viewer, new CopyValueAction(
211             CopyValueAction.MODE_LDIF ) ) );
212
213         entryEditorActionMap.put( copySearchFilterAction, new EntryEditorActionProxy( viewer,
214             new CopySearchFilterAction( CopySearchFilterAction.MODE_EQUALS ) ) );
215         entryEditorActionMap.put( copyNotSearchFilterAction, new EntryEditorActionProxy( viewer,
216             new CopySearchFilterAction( CopySearchFilterAction.MODE_NOT ) ) );
217         entryEditorActionMap.put( copyAndSearchFilterAction, new EntryEditorActionProxy( viewer,
218             new CopySearchFilterAction( CopySearchFilterAction.MODE_AND ) ) );
219         entryEditorActionMap.put( copyOrSearchFilterAction, new EntryEditorActionProxy( viewer,
220             new CopySearchFilterAction( CopySearchFilterAction.MODE_OR ) ) );
221
222         entryEditorActionMap.put( deleteAllValuesAction, new EntryEditorActionProxy( viewer,
223             new DeleteAllValuesAction() ) );
224
225     }
226
227
228     /**
229      * {@inheritDoc}
230      */

231     public void dispose()
232     {
233         if ( showOperationalAttributesAction != null )
234         {
235             deactivateGlobalActionHandlers();
236
237             openEntryEditorPreferencePage = null;
238             showOperationalAttributesAction = null;
239             expandAllAction.dispose();
240             expandAllAction = null;
241             collapseAllAction.dispose();
242             collapseAllAction = null;
243         }
244
245         super.dispose();
246     }
247
248
249     /**
250      * {@inheritDoc}
251      */

252     public void fillToolBar( IToolBarManager toolBarManager )
253     {
254         toolBarManager.add( new Separator() );
255         toolBarManager.add( ( IAction ) entryEditorActionMap.get( newValueAction ) );
256         toolBarManager.add( ( IAction ) entryEditorActionMap.get( newAttributeAction ) );
257         toolBarManager.add( new Separator() );
258         toolBarManager.add( ( IAction ) entryEditorActionMap.get( deleteAction ) );
259         toolBarManager.add( ( IAction ) entryEditorActionMap.get( deleteAllValuesAction ) );
260         toolBarManager.add( new Separator() );
261         toolBarManager.add( ( IAction ) entryEditorActionMap.get( refreshAttributesAction ) );
262         toolBarManager.add( new Separator() );
263         toolBarManager.add( expandAllAction );
264         toolBarManager.add( collapseAllAction );
265         toolBarManager.add( new Separator() );
266         toolBarManager.add( showQuickFilterAction );
267         toolBarManager.update( true );
268     }
269
270
271     /**
272      * {@inheritDoc}
273      */

274     public void fillMenu( IMenuManager menuManager )
275     {
276         menuManager.add( openSortDialogAction );
277         menuManager.add( new Separator() );
278         menuManager.add( showOperationalAttributesAction );
279         menuManager.add( showRawValuesAction );
280         menuManager.add( new Separator() );
281         menuManager.add( openEntryEditorPreferencePage );
282         menuManager.addMenuListener( new IMenuListener()
283         {
284             public void menuAboutToShow( IMenuManager manager )
285             {
286                 showRawValuesAction.setChecked( BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
287                     BrowserCommonConstants.PREFERENCE_SHOW_RAW_VALUES ) );
288                 showOperationalAttributesAction.setChecked( BrowserCommonActivator.getDefault().getPreferenceStore()
289                     .getBoolean( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_OPERATIONAL_ATTRIBUTES ) );
290             }
291         } );
292         menuManager.update( true );
293     }
294
295
296     /**
297      * {@inheritDoc}
298      */

299     protected void contextMenuAboutToShow( IMenuManager menuManager )
300     {
301         // new
302
menuManager.add( ( IAction ) entryEditorActionMap.get( newAttributeAction ) );
303         menuManager.add( ( IAction ) entryEditorActionMap.get( newValueAction ) );
304         menuManager.add( ( IAction ) entryEditorActionMap.get( newSearchAction ) );
305         menuManager.add( ( IAction ) entryEditorActionMap.get( newBatchOperationAction ) );
306         menuManager.add( new Separator() );
307
308         // navigation
309
menuManager.add( ( IAction ) entryEditorActionMap.get( locateDnInDitAction ) );
310         MenuManager schemaMenuManager = new MenuManager( "Open Schema Browser" );
311         schemaMenuManager.add( ( IAction ) entryEditorActionMap.get( showOcdAction ) );
312         schemaMenuManager.add( ( IAction ) entryEditorActionMap.get( showAtdAction ) );
313         schemaMenuManager.add( ( IAction ) entryEditorActionMap.get( showEqualityMrdAction ) );
314         schemaMenuManager.add( ( IAction ) entryEditorActionMap.get( showSubstringMrdAction ) );
315         schemaMenuManager.add( ( IAction ) entryEditorActionMap.get( showOrderingMrdAction ) );
316         schemaMenuManager.add( ( IAction ) entryEditorActionMap.get( showLsdAction ) );
317         menuManager.add( schemaMenuManager );
318         MenuManager showInSubMenu = new MenuManager( "Show In" );
319         showInSubMenu.add( ContributionItemFactory.VIEWS_SHOW_IN.create( PlatformUI.getWorkbench()
320             .getActiveWorkbenchWindow() ) );
321         menuManager.add( showInSubMenu );
322
323         menuManager.add( new Separator() );
324
325         // copy, paste, delete
326
menuManager.add( ( IAction ) entryEditorActionMap.get( copyAction ) );
327         menuManager.add( ( IAction ) entryEditorActionMap.get( pasteAction ) );
328         menuManager.add( ( IAction ) entryEditorActionMap.get( deleteAction ) );
329         menuManager.add( ( IAction ) entryEditorActionMap.get( selectAllAction ) );
330         MenuManager advancedMenuManager = new MenuManager( "Advanced" );
331         advancedMenuManager.add( ( IAction ) entryEditorActionMap.get( copyDnAction ) );
332         advancedMenuManager.add( ( IAction ) entryEditorActionMap.get( copyUrlAction ) );
333         advancedMenuManager.add( new Separator() );
334         advancedMenuManager.add( ( IAction ) entryEditorActionMap.get( copyAttriuteDescriptionAction ) );
335         advancedMenuManager.add( new Separator() );
336         advancedMenuManager.add( ( IAction ) entryEditorActionMap.get( copyValueUtf8Action ) );
337         advancedMenuManager.add( ( IAction ) entryEditorActionMap.get( copyValueBase64Action ) );
338         advancedMenuManager.add( ( IAction ) entryEditorActionMap.get( copyValueHexAction ) );
339         advancedMenuManager.add( new Separator() );
340         advancedMenuManager.add( ( IAction ) entryEditorActionMap.get( copyValueAsLdifAction ) );
341         advancedMenuManager.add( new Separator() );
342         advancedMenuManager.add( ( IAction ) entryEditorActionMap.get( copySearchFilterAction ) );
343         advancedMenuManager.add( ( IAction ) entryEditorActionMap.get( copyNotSearchFilterAction ) );
344         advancedMenuManager.add( ( IAction ) entryEditorActionMap.get( copyAndSearchFilterAction ) );
345         advancedMenuManager.add( ( IAction ) entryEditorActionMap.get( copyOrSearchFilterAction ) );
346         advancedMenuManager.add( new Separator() );
347         advancedMenuManager.add( ( IAction ) entryEditorActionMap.get( deleteAllValuesAction ) );
348         menuManager.add( advancedMenuManager );
349         menuManager.add( new Separator() );
350
351         // edit
352
menuManager.add( ( IAction ) entryEditorActionMap.get( editAttributeDescriptionAction ) );
353         super.addEditMenu( menuManager );
354         menuManager.add( new Separator() );
355
356         // refresh
357
menuManager.add( ( IAction ) entryEditorActionMap.get( refreshAttributesAction ) );
358         menuManager.add( new Separator() );
359
360         // additions
361
menuManager.add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) );
362
363         // properties
364
menuManager.add( ( IAction ) entryEditorActionMap.get( propertyDialogAction ) );
365     }
366
367
368     /**
369      * {@inheritDoc}
370      */

371     public void activateGlobalActionHandlers()
372     {
373         if ( actionBars != null )
374         {
375             actionBars.setGlobalActionHandler( ActionFactory.REFRESH.getId(), ( IAction ) entryEditorActionMap
376                 .get( refreshAttributesAction ) );
377         }
378
379         super.activateGlobalActionHandlers();
380
381         ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter(
382             ICommandService.class );
383         if ( commandService != null )
384         {
385             IAction naa = ( IAction ) entryEditorActionMap.get( newAttributeAction );
386             commandService.getCommand( naa.getActionDefinitionId() ).setHandler( new ActionHandler( naa ) );
387             IAction lid = ( IAction ) entryEditorActionMap.get( locateDnInDitAction );
388             commandService.getCommand( lid.getActionDefinitionId() ).setHandler( new ActionHandler( lid ) );
389             IAction eada = ( IAction ) entryEditorActionMap.get( editAttributeDescriptionAction );
390             commandService.getCommand( eada.getActionDefinitionId() ).setHandler( new ActionHandler( eada ) );
391         }
392     }
393
394
395     /**
396      * {@inheritDoc}
397      */

398     public void deactivateGlobalActionHandlers()
399     {
400         if ( actionBars != null )
401         {
402             actionBars.setGlobalActionHandler( ActionFactory.REFRESH.getId(), null );
403         }
404
405         super.deactivateGlobalActionHandlers();
406
407         ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter(
408             ICommandService.class );
409         if ( commandService != null )
410         {
411             IAction naa = ( IAction ) entryEditorActionMap.get( newAttributeAction );
412             commandService.getCommand( naa.getActionDefinitionId() ).setHandler( null );
413             IAction lid = ( IAction ) entryEditorActionMap.get( locateDnInDitAction );
414             commandService.getCommand( lid.getActionDefinitionId() ).setHandler( null );
415             IAction eada = ( IAction ) entryEditorActionMap.get( editAttributeDescriptionAction );
416             commandService.getCommand( eada.getActionDefinitionId() ).setHandler( null );
417         }
418     }
419
420
421     /**
422      * Sets the input.
423      *
424      * @param entry the input
425      */

426     public void setInput( IEntry entry )
427     {
428         for ( Iterator JavaDoc it = entryEditorActionMap.values().iterator(); it.hasNext(); )
429         {
430             EntryEditorActionProxy action = ( EntryEditorActionProxy ) it.next();
431             action.inputChanged( entry );
432         }
433     }
434
435 }
436
Popular Tags