1 20 21 package org.apache.directory.ldapstudio.schemas.controller; 22 23 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 import org.apache.directory.ldapstudio.schemas.Activator; 28 import org.apache.directory.ldapstudio.schemas.PluginConstants; 29 import org.apache.directory.ldapstudio.schemas.controller.actions.HideAttributeTypesAction; 30 import org.apache.directory.ldapstudio.schemas.controller.actions.HideObjectClassesAction; 31 import org.apache.directory.ldapstudio.schemas.controller.actions.LinkWithEditorSchemaElementsView; 32 import org.apache.directory.ldapstudio.schemas.controller.actions.OpenSchemaElementsViewSortDialogAction; 33 import org.apache.directory.ldapstudio.schemas.controller.actions.OpenTypeHierarchyAction; 34 import org.apache.directory.ldapstudio.schemas.controller.actions.OpenSchemaElementsViewPreferencesAction; 35 import org.apache.directory.ldapstudio.schemas.view.editors.attributeType.AttributeTypeEditor; 36 import org.apache.directory.ldapstudio.schemas.view.editors.attributeType.AttributeTypeEditorInput; 37 import org.apache.directory.ldapstudio.schemas.view.editors.objectClass.ObjectClassEditor; 38 import org.apache.directory.ldapstudio.schemas.view.editors.objectClass.ObjectClassEditorInput; 39 import org.apache.directory.ldapstudio.schemas.view.views.SchemaElementsView; 40 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.AttributeTypeWrapper; 41 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.IntermediateNode; 42 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.ObjectClassWrapper; 43 import org.apache.log4j.Logger; 44 import org.eclipse.jface.action.Action; 45 import org.eclipse.jface.action.IMenuListener; 46 import org.eclipse.jface.action.IMenuManager; 47 import org.eclipse.jface.action.IToolBarManager; 48 import org.eclipse.jface.action.MenuManager; 49 import org.eclipse.jface.action.Separator; 50 import org.eclipse.jface.util.IPropertyChangeListener; 51 import org.eclipse.jface.util.PropertyChangeEvent; 52 import org.eclipse.jface.viewers.DoubleClickEvent; 53 import org.eclipse.jface.viewers.IDoubleClickListener; 54 import org.eclipse.jface.viewers.StructuredSelection; 55 import org.eclipse.jface.viewers.TreeSelection; 56 import org.eclipse.jface.viewers.TreeViewer; 57 import org.eclipse.ui.IEditorInput; 58 import org.eclipse.ui.IWorkbenchActionConstants; 59 import org.eclipse.ui.IWorkbenchPage; 60 import org.eclipse.ui.PartInitException; 61 import org.eclipse.ui.PlatformUI; 62 63 64 70 public class SchemaElementsController 71 { 72 73 private static Logger logger = Logger.getLogger( SchemaElementsController.class ); 74 75 76 List <String > authorizedPrefs; 77 78 79 private SchemaElementsView view; 80 81 82 private MenuManager contextMenu; 83 84 private Action hideObjectClasses; 86 private Action hideAttributeTypes; 87 private Action linkWithEditor; 88 private Action openSortDialog; 89 private Action openPreferencePage; 90 private Action openTypeHierarchy; 91 92 93 96 public SchemaElementsController( SchemaElementsView view ) 97 { 98 this.view = view; 99 100 initAuthorizedPrefs(); 101 initActions(); 102 initToolbar(); 103 initMenu(); 104 initContextMenu(); 105 initDoubleClickListener(); 106 initPreferencesListener(); 107 } 108 109 110 private void initAuthorizedPrefs() 111 { 112 authorizedPrefs = new ArrayList <String >(); 113 authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_LABEL ); 114 authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_ABBREVIATE ); 115 authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_ABBREVIATE_MAX_LENGTH ); 116 authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SECONDARY_LABEL_DISPLAY ); 117 authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SECONDARY_LABEL ); 118 authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SECONDARY_LABEL_ABBREVIATE ); 119 authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH ); 120 authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_GROUPING ); 121 authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SORTING_BY ); 122 authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SORTING_ORDER ); 123 } 124 125 126 129 private void initActions() 130 { 131 hideObjectClasses = new HideObjectClassesAction( view.getViewer() ); 132 hideAttributeTypes = new HideAttributeTypesAction( view.getViewer() ); 133 linkWithEditor = new LinkWithEditorSchemaElementsView( view ); 134 openSortDialog = new OpenSchemaElementsViewSortDialogAction(); 135 openPreferencePage = new OpenSchemaElementsViewPreferencesAction(); 136 openTypeHierarchy = new OpenTypeHierarchyAction(); 137 } 138 139 140 143 private void initToolbar() 144 { 145 IToolBarManager toolbar = view.getViewSite().getActionBars().getToolBarManager(); 146 toolbar.add( hideObjectClasses ); 147 toolbar.add( hideAttributeTypes ); 148 toolbar.add( new Separator() ); 149 toolbar.add( linkWithEditor ); 150 } 151 152 153 156 private void initMenu() 157 { 158 IMenuManager menu = view.getViewSite().getActionBars().getMenuManager(); 159 menu.add( openSortDialog ); 160 menu.add( new Separator() ); 161 menu.add( linkWithEditor ); 162 menu.add( new Separator() ); 163 menu.add( openPreferencePage ); 164 } 165 166 167 170 private void initDoubleClickListener() 171 { 172 view.getViewer().addDoubleClickListener( new IDoubleClickListener() 173 { 174 public void doubleClick( DoubleClickEvent event ) 175 { 176 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); 177 178 SchemaElementsView view = ( SchemaElementsView ) PlatformUI.getWorkbench().getActiveWorkbenchWindow() 179 .getActivePage().findView( SchemaElementsView.ID ); 180 TreeViewer viewer = view.getViewer(); 181 182 StructuredSelection selection = ( StructuredSelection ) event.getSelection(); 184 185 Object objectSelection = selection.getFirstElement(); 187 IEditorInput input = null; 188 String editorId = null; 189 190 if ( objectSelection instanceof AttributeTypeWrapper ) 192 { 193 input = new AttributeTypeEditorInput( ( ( AttributeTypeWrapper ) objectSelection ) 194 .getMyAttributeType() ); 195 editorId = AttributeTypeEditor.ID; 196 } 197 else if ( objectSelection instanceof ObjectClassWrapper ) 198 { 199 input = new ObjectClassEditorInput( ( ( ObjectClassWrapper ) objectSelection ).getMyObjectClass() ); 200 editorId = ObjectClassEditor.ID; 201 } 202 else if ( objectSelection instanceof IntermediateNode ) 203 { 204 viewer.setExpandedState( objectSelection, !viewer.getExpandedState( objectSelection ) ); 206 } 207 208 if ( input != null ) 210 { 211 try 212 { 213 page.openEditor( input, editorId ); 214 } 215 catch ( PartInitException e ) 216 { 217 logger.debug( "error when opening the editor" ); } 219 } 220 } 221 } ); 222 } 223 224 225 228 private void initPreferencesListener() 229 { 230 Activator.getDefault().getPreferenceStore().addPropertyChangeListener( new IPropertyChangeListener() 231 { 232 235 public void propertyChange( PropertyChangeEvent event ) 236 { 237 if ( authorizedPrefs.contains( event.getProperty() ) ) 238 { 239 if ( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_GROUPING == event.getProperty() ) 240 { 241 view.refresh(); 242 } 243 else 244 { 245 view.update(); 246 } 247 } 248 } 249 } ); 250 } 251 252 253 256 private void initContextMenu() 257 { 258 TreeViewer viewer = view.getViewer(); 259 contextMenu = new MenuManager( "" ); contextMenu.setRemoveAllWhenShown( true ); 261 contextMenu.addMenuListener( new IMenuListener() 262 { 263 public void menuAboutToShow( IMenuManager manager ) 264 { 265 Object selection = ( ( TreeSelection ) view.getViewer().getSelection() ).getFirstElement(); 266 267 if ( ( selection instanceof AttributeTypeWrapper ) ) 268 { 269 manager.add( openTypeHierarchy ); 270 } 271 else if ( ( selection instanceof ObjectClassWrapper ) ) 272 { 273 manager.add( openTypeHierarchy ); 274 } 275 276 manager.add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) ); 277 } 278 } ); 279 280 viewer.getControl().setMenu( contextMenu.createContextMenu( viewer.getControl() ) ); 282 283 view.getSite().registerContextMenu( contextMenu, viewer ); 285 } 286 } 287 | Popular Tags |