Author: seelmann Date: Mon Jul 2 13:21:52 2007 New Revision: 552582 URL: http://svn.apache.org/viewvc?view=rev&rev=552582 Log: DIRSTUDIO-96: Added context and improved key binding handling. Modified: directory/studio/trunk/studio-schemaeditor-plugin/plugin.xml directory/studio/trunk/studio-schemaeditor-plugin/src/main/java/org/apache/directory/studio/schemas/PluginConstants.java directory/studio/trunk/studio-schemaeditor-plugin/src/main/java/org/apache/directory/studio/schemas/controller/SchemaElementsController.java directory/studio/trunk/studio-schemaeditor-plugin/src/main/java/org/apache/directory/studio/schemas/controller/SchemasViewController.java Modified: directory/studio/trunk/studio-schemaeditor-plugin/plugin.xml URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor-plugin/plugin.xml?view=diff&rev=552582&r1=552581&r2=552582 ============================================================================== --- directory/studio/trunk/studio-schemaeditor-plugin/plugin.xml (original) +++ directory/studio/trunk/studio-schemaeditor-plugin/plugin.xml Mon Jul 2 13:21:52 2007 @@ -127,11 +127,13 @@ point="org.eclipse.ui.bindings"> @@ -241,5 +243,14 @@ label="Schemas Search" showScopeSection="false" sizeHint="450,300"/> + + + + Modified: directory/studio/trunk/studio-schemaeditor-plugin/src/main/java/org/apache/directory/studio/schemas/PluginConstants.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor-plugin/src/main/java/org/apache/directory/studio/schemas/PluginConstants.java?view=diff&rev=552582&r1=552581&r2=552582 ============================================================================== --- directory/studio/trunk/studio-schemaeditor-plugin/src/main/java/org/apache/directory/studio/schemas/PluginConstants.java (original) +++ directory/studio/trunk/studio-schemaeditor-plugin/src/main/java/org/apache/directory/studio/schemas/PluginConstants.java Mon Jul 2 13:21:52 2007 @@ -300,4 +300,6 @@ public static final String CMD_OPEN_TYPE_HIERARCHY = Activator.PLUGIN_ID + ".cmd.OpenTypeHierarchy"; //$NON-NLS-1$ public static final String CMD_HIERARCHY_VIEW_PREFERENCES = Activator.PLUGIN_ID + ".cmd.OpenHierarchyViewPreferences"; //$NON-NLS-1$ + + public static final String CONTEXT_WINDOWS = Activator.PLUGIN_ID + ".contexts.window"; //$NON-NLS-1$ } Modified: directory/studio/trunk/studio-schemaeditor-plugin/src/main/java/org/apache/directory/studio/schemas/controller/SchemaElementsController.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor-plugin/src/main/java/org/apache/directory/studio/schemas/controller/SchemaElementsController.java?view=diff&rev=552582&r1=552581&r2=552582 ============================================================================== --- directory/studio/trunk/studio-schemaeditor-plugin/src/main/java/org/apache/directory/studio/schemas/controller/SchemaElementsController.java (original) +++ directory/studio/trunk/studio-schemaeditor-plugin/src/main/java/org/apache/directory/studio/schemas/controller/SchemaElementsController.java Mon Jul 2 13:21:52 2007 @@ -47,6 +47,7 @@ import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; +import org.eclipse.jface.commands.ActionHandler; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.DoubleClickEvent; @@ -55,10 +56,15 @@ import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IPartListener2; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPartReference; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandService; +import org.eclipse.ui.contexts.IContextActivation; +import org.eclipse.ui.contexts.IContextService; /** @@ -73,7 +79,7 @@ private static Logger logger = Logger.getLogger( SchemaElementsController.class ); /** The authorized Preferences keys*/ - List authorizedPrefs; + private List authorizedPrefs; /** The associated view */ private SchemaElementsView view; @@ -81,6 +87,9 @@ /** The Context Menu */ private MenuManager contextMenu; + /** Token used to activate and deactivate shortcuts in the view */ + private IContextActivation contextActivation; + // The Actions private Action hideObjectClasses; private Action hideAttributeTypes; @@ -104,6 +113,94 @@ initContextMenu(); initDoubleClickListener(); initPreferencesListener(); + initPartListener(); + } + + + /** + * Initializes the part listener. It is used to activate and deactivate the + * shortcuts (key bindins) when the view is activated and deactivated. + */ + private void initPartListener() + { + + view.getSite().getPage().addPartListener( new IPartListener2() + { + /** + * This implementation deactivates the shortcuts when the part is deactivated. + */ + public void partDeactivated( IWorkbenchPartReference partRef ) + { + if ( partRef.getPart( false ) == view && contextActivation != null ) + { + ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter( + ICommandService.class ); + if ( commandService != null ) + { + commandService.getCommand( openTypeHierarchy.getActionDefinitionId() ).setHandler( null ); + } + + IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter( + IContextService.class ); + contextService.deactivateContext( contextActivation ); + contextActivation = null; + } + } + + + /** + * This implementation activates the shortcuts when the part is activated. + */ + public void partActivated( IWorkbenchPartReference partRef ) + { + if ( partRef.getPart( false ) == view ) + { + IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter( + IContextService.class ); + contextActivation = contextService.activateContext( PluginConstants.CONTEXT_WINDOWS ); + + ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter( + ICommandService.class ); + if ( commandService != null ) + { + commandService.getCommand( openTypeHierarchy.getActionDefinitionId() ).setHandler( + new ActionHandler( openTypeHierarchy ) ); + } + } + } + + + public void partBroughtToTop( IWorkbenchPartReference partRef ) + { + } + + + public void partClosed( IWorkbenchPartReference partRef ) + { + } + + + public void partHidden( IWorkbenchPartReference partRef ) + { + } + + + public void partInputChanged( IWorkbenchPartReference partRef ) + { + } + + + public void partOpened( IWorkbenchPartReference partRef ) + { + } + + + public void partVisible( IWorkbenchPartReference partRef ) + { + } + + } ); + } Modified: directory/studio/trunk/studio-schemaeditor-plugin/src/main/java/org/apache/directory/studio/schemas/controller/SchemasViewController.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor-plugin/src/main/java/org/apache/directory/studio/schemas/controller/SchemasViewController.java?view=diff&rev=552582&r1=552581&r2=552582 ============================================================================== --- directory/studio/trunk/studio-schemaeditor-plugin/src/main/java/org/apache/directory/studio/schemas/controller/SchemasViewController.java (original) +++ directory/studio/trunk/studio-schemaeditor-plugin/src/main/java/org/apache/directory/studio/schemas/controller/SchemasViewController.java Mon Jul 2 13:21:52 2007 @@ -64,6 +64,7 @@ import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; +import org.eclipse.jface.commands.ActionHandler; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.DoubleClickEvent; @@ -80,12 +81,17 @@ import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.dnd.TransferData; import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IPartListener2; import org.eclipse.ui.ISelectionListener; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchPartReference; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandService; +import org.eclipse.ui.contexts.IContextActivation; +import org.eclipse.ui.contexts.IContextService; /** @@ -103,7 +109,7 @@ private SchemasView view; /** The authorized Preferences keys*/ - List authorizedPrefs; + private List authorizedPrefs; /** The Drag'n'Drop FileTransfer Object */ private final static FileTransfer fileTransfer = FileTransfer.getInstance(); @@ -111,6 +117,9 @@ /** The Context Menu */ private MenuManager contextMenu; + /** Token used to activate and deactivate shortcuts in the view */ + private IContextActivation contextActivation; + // The Actions private Action openLocalFile; private Action createANewSchema; @@ -148,6 +157,94 @@ initDoubleClickListener(); registerUpdateActions(); initPreferencesListener(); + initPartListener(); + } + + + /** + * Initializes the part listener. It is used to activate and deactivate the + * shortcuts (key bindins) when the view is activated and deactivated. + */ + private void initPartListener() + { + + view.getSite().getPage().addPartListener( new IPartListener2() + { + /** + * This implementation deactivates the shortcuts when the part is deactivated. + */ + public void partDeactivated( IWorkbenchPartReference partRef ) + { + if ( partRef.getPart( false ) == view && contextActivation != null ) + { + ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter( + ICommandService.class ); + if ( commandService != null ) + { + commandService.getCommand( openLocalFile.getActionDefinitionId() ).setHandler( null ); + } + + IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter( + IContextService.class ); + contextService.deactivateContext( contextActivation ); + contextActivation = null; + } + } + + + /** + * This implementation activates the shortcuts when the part is activated. + */ + public void partActivated( IWorkbenchPartReference partRef ) + { + if ( partRef.getPart( false ) == view ) + { + IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter( + IContextService.class ); + contextActivation = contextService.activateContext( PluginConstants.CONTEXT_WINDOWS ); + + ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter( + ICommandService.class ); + if ( commandService != null ) + { + commandService.getCommand( openLocalFile.getActionDefinitionId() ).setHandler( + new ActionHandler( openLocalFile ) ); + } + } + } + + + public void partBroughtToTop( IWorkbenchPartReference partRef ) + { + } + + + public void partClosed( IWorkbenchPartReference partRef ) + { + } + + + public void partHidden( IWorkbenchPartReference partRef ) + { + } + + + public void partInputChanged( IWorkbenchPartReference partRef ) + { + } + + + public void partOpened( IWorkbenchPartReference partRef ) + { + } + + + public void partVisible( IWorkbenchPartReference partRef ) + { + } + + } ); + } @@ -249,7 +346,7 @@ { manager.add( saveAs ); manager.add( new Separator() ); - manager.add( exportSchemaForADS); + manager.add( exportSchemaForADS ); manager.add( new Separator() ); manager.add( openSchemaSourceCode ); } @@ -262,7 +359,7 @@ manager.add( saveAs ); manager.add( removeSchema ); manager.add( new Separator() ); - manager.add( exportSchemaForADS); + manager.add( exportSchemaForADS ); manager.add( new Separator() ); manager.add( openSchemaSourceCode ); } @@ -451,11 +548,11 @@ */ public void selectionChanged( IWorkbenchPart part, ISelection selection ) { - if ( ! ( selection instanceof TreeSelection ) ) + if ( !( selection instanceof TreeSelection ) ) { return; } - + TreeSelection treeSelection = ( TreeSelection ) selection; Object selectedObject = ( ( TreeSelection ) selection ).getFirstElement();