1 20 21 package org.apache.directory.ldapstudio.browser.ui.editors.entry; 22 23 24 import java.util.Iterator ; 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 68 public class EntryEditorActionGroup extends EntryEditorWidgetActionGroup 69 { 70 71 72 private ShowOperationalAttributesAction showOperationalAttributesAction; 73 74 75 private OpenEntryEditorPreferencePageAction openEntryEditorPreferencePage; 76 77 78 private CollapseAllAction collapseAllAction; 79 80 81 private ExpandAllAction expandAllAction; 82 83 84 private static final String editAttributeDescriptionAction = "editAttributeDescriptionAction"; 85 86 87 private static final String refreshAttributesAction = "refreshAttributesAction"; 88 89 90 private static final String newAttributeAction = "newAttributeAction"; 91 92 93 private static final String newSearchAction = "newSearchDialogAction"; 94 95 96 private static final String newBatchOperationAction = "newBatchOperationAction"; 97 98 99 private static final String copyDnAction = "copyDnAction"; 100 101 102 private static final String copyUrlAction = "copyUrlAction"; 103 104 105 private static final String copyAttriuteDescriptionAction = "copyAttriuteDescriptionAction"; 106 107 108 private static final String copyValueUtf8Action = "copyValueUtf8Action"; 109 110 111 private static final String copyValueBase64Action = "copyValueBase64Action"; 112 113 114 private static final String copyValueHexAction = "copyValueHexAction"; 115 116 117 private static final String copyValueAsLdifAction = "copyValueAsLdifAction"; 118 119 120 private static final String copySearchFilterAction = "copySearchFilterAction"; 121 122 123 private static final String copyNotSearchFilterAction = "copyNotSearchFilterAction"; 124 125 126 private static final String copyAndSearchFilterAction = "copyAndSearchFilterAction"; 127 128 129 private static final String copyOrSearchFilterAction = "copyOrSearchFilterAction"; 130 131 132 private static final String deleteAllValuesAction = "deleteAllValuesAction"; 133 134 135 private static final String locateDnInDitAction = "locateDnInDitAction"; 136 137 138 private static final String showOcdAction = "showOcdAction"; 139 140 141 private static final String showAtdAction = "showAtdAction"; 142 143 144 private static final String showEqualityMrdAction = "showEqualityMrdAction"; 145 146 147 private static final String showSubstringMrdAction = "showSubstringMrdAction"; 148 149 150 private static final String showOrderingMrdAction = "showOrderingMrdAction"; 151 152 153 private static final String showLsdAction = "showLsdAction"; 154 155 156 161 public EntryEditorActionGroup( EntryEditor entryEditor ) 162 { 163 super( entryEditor.getMainWidget(), entryEditor.getConfiguration() ); 164 TreeViewer viewer = entryEditor.getMainWidget().getViewer(); 165 166 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 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 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 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 299 protected void contextMenuAboutToShow( IMenuManager menuManager ) 300 { 301 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 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 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 menuManager.add( ( IAction ) entryEditorActionMap.get( editAttributeDescriptionAction ) ); 353 super.addEditMenu( menuManager ); 354 menuManager.add( new Separator() ); 355 356 menuManager.add( ( IAction ) entryEditorActionMap.get( refreshAttributesAction ) ); 358 menuManager.add( new Separator() ); 359 360 menuManager.add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) ); 362 363 menuManager.add( ( IAction ) entryEditorActionMap.get( propertyDialogAction ) ); 365 } 366 367 368 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 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 426 public void setInput( IEntry entry ) 427 { 428 for ( Iterator it = entryEditorActionMap.values().iterator(); it.hasNext(); ) 429 { 430 EntryEditorActionProxy action = ( EntryEditorActionProxy ) it.next(); 431 action.inputChanged( entry ); 432 } 433 } 434 435 } 436 | Popular Tags |