KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > widgets > entryeditor > EntryEditorWidgetActionGroupWithAttribute


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.common.widgets.entryeditor;
22
23
24 import org.apache.directory.ldapstudio.browser.common.actions.DeleteAllValuesAction;
25 import org.apache.directory.ldapstudio.browser.common.actions.NewAttributeAction;
26 import org.apache.directory.ldapstudio.browser.common.actions.proxy.EntryEditorActionProxy;
27 import org.eclipse.jface.action.IAction;
28 import org.eclipse.jface.action.IMenuManager;
29 import org.eclipse.jface.action.IToolBarManager;
30 import org.eclipse.jface.action.MenuManager;
31 import org.eclipse.jface.action.Separator;
32 import org.eclipse.jface.commands.ActionHandler;
33 import org.eclipse.jface.viewers.TreeViewer;
34 import org.eclipse.ui.PlatformUI;
35 import org.eclipse.ui.commands.ICommandService;
36
37
38 /**
39  * This class manages all the actions of the attribute page of the new entry wizard.
40  *
41  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
42  * @version $Rev$, $Date$
43  */

44 public class EntryEditorWidgetActionGroupWithAttribute extends EntryEditorWidgetActionGroup
45 {
46
47     /** The Constant editAttributeDescriptionAction. */
48     private static final String JavaDoc editAttributeDescriptionAction = "editAttributeDescriptionAction";
49
50     /** The Constant newAttributeAction. */
51     private static final String JavaDoc newAttributeAction = "newAttributeAction";
52
53     /** The Constant deleteAllValuesAction. */
54     private static final String JavaDoc deleteAllValuesAction = "deleteAllValuesAction";
55
56
57     /**
58      *
59      * Creates a new instance of NewEntryAttributesWizardPageActionGroup.
60      *
61      * @param mainWidget
62      * @param configuration
63      */

64     public EntryEditorWidgetActionGroupWithAttribute( EntryEditorWidget mainWidget,
65         EntryEditorWidgetConfiguration configuration )
66     {
67         super( mainWidget, configuration );
68         TreeViewer viewer = mainWidget.getViewer();
69
70         entryEditorActionMap.put( editAttributeDescriptionAction, new EntryEditorActionProxy( viewer,
71             new EditAttributeDescriptionAction( viewer ) ) );
72         entryEditorActionMap.put( newAttributeAction, new EntryEditorActionProxy( viewer, new NewAttributeAction() ) );
73         entryEditorActionMap.put( deleteAllValuesAction, new EntryEditorActionProxy( viewer,
74             new DeleteAllValuesAction() ) );
75
76     }
77
78
79     /**
80      * {@inheritDoc}
81      */

82     public void fillToolBar( IToolBarManager toolBarManager )
83     {
84         toolBarManager.add( ( IAction ) entryEditorActionMap.get( newValueAction ) );
85         toolBarManager.add( ( IAction ) entryEditorActionMap.get( newAttributeAction ) );
86         toolBarManager.add( new Separator() );
87         toolBarManager.add( ( IAction ) this.entryEditorActionMap.get( deleteAction ) );
88         toolBarManager.add( ( IAction ) this.entryEditorActionMap.get( deleteAllValuesAction ) );
89         toolBarManager.add( new Separator() );
90         toolBarManager.add( this.showQuickFilterAction );
91         toolBarManager.update( true );
92     }
93
94
95     /**
96      * {@inheritDoc}
97      */

98     protected void contextMenuAboutToShow( IMenuManager menuManager )
99     {
100         // new
101
menuManager.add( ( IAction ) entryEditorActionMap.get( newAttributeAction ) );
102         menuManager.add( ( IAction ) entryEditorActionMap.get( newValueAction ) );
103         menuManager.add( new Separator() );
104
105         // copy, paste, delete
106
menuManager.add( ( IAction ) entryEditorActionMap.get( copyAction ) );
107         menuManager.add( ( IAction ) entryEditorActionMap.get( pasteAction ) );
108         menuManager.add( ( IAction ) entryEditorActionMap.get( deleteAction ) );
109         menuManager.add( ( IAction ) entryEditorActionMap.get( selectAllAction ) );
110         MenuManager copyMenuManager = new MenuManager( "Advanced" );
111         copyMenuManager.add( ( IAction ) entryEditorActionMap.get( deleteAllValuesAction ) );
112         menuManager.add( copyMenuManager );
113         menuManager.add( new Separator() );
114
115         // edit
116
menuManager.add( ( IAction ) entryEditorActionMap.get( editAttributeDescriptionAction ) );
117         super.addEditMenu( menuManager );
118         menuManager.add( new Separator() );
119
120         // properties
121
menuManager.add( ( IAction ) entryEditorActionMap.get( propertyDialogAction ) );
122     }
123
124
125     /**
126      * {@inheritDoc}
127      */

128     public void activateGlobalActionHandlers()
129     {
130         super.activateGlobalActionHandlers();
131
132         ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter(
133             ICommandService.class );
134         if ( commandService != null )
135         {
136             IAction naa = ( IAction ) entryEditorActionMap.get( newAttributeAction );
137             commandService.getCommand( naa.getActionDefinitionId() ).setHandler( new ActionHandler( naa ) );
138             IAction eada = ( IAction ) entryEditorActionMap.get( editAttributeDescriptionAction );
139             commandService.getCommand( eada.getActionDefinitionId() ).setHandler( new ActionHandler( eada ) );
140         }
141     }
142
143
144     /**
145      * {@inheritDoc}
146      */

147     public void deactivateGlobalActionHandlers()
148     {
149         super.deactivateGlobalActionHandlers();
150
151         ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter(
152             ICommandService.class );
153         if ( commandService != null )
154         {
155             IAction naa = ( IAction ) entryEditorActionMap.get( newAttributeAction );
156             commandService.getCommand( naa.getActionDefinitionId() ).setHandler( null );
157             IAction eada = ( IAction ) entryEditorActionMap.get( editAttributeDescriptionAction );
158             commandService.getCommand( eada.getActionDefinitionId() ).setHandler( null );
159         }
160     }
161
162 }
163
Popular Tags