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.LinkWithEditorHierarchyView; 30 import org.apache.directory.ldapstudio.schemas.controller.actions.OpenHierarchyViewPreferencesAction; 31 import org.apache.directory.ldapstudio.schemas.controller.actions.ShowSubtypeHierarchyAction; 32 import org.apache.directory.ldapstudio.schemas.controller.actions.ShowSupertypeHierarchyAction; 33 import org.apache.directory.ldapstudio.schemas.model.LDAPModelEvent; 34 import org.apache.directory.ldapstudio.schemas.model.PoolListener; 35 import org.apache.directory.ldapstudio.schemas.model.SchemaPool; 36 import org.apache.directory.ldapstudio.schemas.view.editors.attributeType.AttributeTypeEditor; 37 import org.apache.directory.ldapstudio.schemas.view.editors.attributeType.AttributeTypeEditorInput; 38 import org.apache.directory.ldapstudio.schemas.view.editors.objectClass.ObjectClassEditor; 39 import org.apache.directory.ldapstudio.schemas.view.editors.objectClass.ObjectClassEditorInput; 40 import org.apache.directory.ldapstudio.schemas.view.views.HierarchyView; 41 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.AttributeTypeWrapper; 42 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.ObjectClassWrapper; 43 import org.eclipse.jface.action.Action; 44 import org.eclipse.jface.action.IMenuManager; 45 import org.eclipse.jface.action.IToolBarManager; 46 import org.eclipse.jface.action.Separator; 47 import org.eclipse.jface.util.IPropertyChangeListener; 48 import org.eclipse.jface.util.PropertyChangeEvent; 49 import org.eclipse.jface.viewers.DoubleClickEvent; 50 import org.eclipse.jface.viewers.IDoubleClickListener; 51 import org.eclipse.jface.viewers.StructuredSelection; 52 import org.eclipse.ui.IEditorInput; 53 import org.eclipse.ui.IWorkbenchPage; 54 import org.eclipse.ui.PartInitException; 55 import org.eclipse.ui.PlatformUI; 56 57 58 64 public class HierarchyViewController implements PoolListener 65 { 66 67 private HierarchyView view; 68 69 70 List <String > authorizedPrefs; 71 72 private Action showSupertypeHierarchy; 74 private Action showSubtypeHierarchy; 75 private Action linkWithEditor; 76 private Action openPreferencePage; 77 78 79 85 public HierarchyViewController( HierarchyView view ) 86 { 87 this.view = view; 88 89 SchemaPool.getInstance().addListener( this ); 90 91 initAuthorizedPrefs(); 92 initActions(); 93 initToolbar(); 94 initMenu(); 95 initDoubleClickListener(); 96 initPreferencesListener(); 97 } 98 99 100 103 private void initAuthorizedPrefs() 104 { 105 authorizedPrefs = new ArrayList <String >(); 106 authorizedPrefs.add( PluginConstants.PREFS_HIERARCHY_VIEW_LABEL ); 107 authorizedPrefs.add( PluginConstants.PREFS_HIERARCHY_VIEW_ABBREVIATE ); 108 authorizedPrefs.add( PluginConstants.PREFS_HIERARCHY_VIEW_ABBREVIATE_MAX_LENGTH ); 109 authorizedPrefs.add( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_DISPLAY ); 110 authorizedPrefs.add( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL ); 111 authorizedPrefs.add( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_ABBREVIATE ); 112 authorizedPrefs.add( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH ); 113 } 114 115 116 119 private void initActions() 120 { 121 if ( Activator.getDefault().getDialogSettings().get( PluginConstants.PREFS_HIERARCHY_VIEW_MODE ) == null ) 123 { 124 Activator.getDefault().getDialogSettings().put( PluginConstants.PREFS_HIERARCHY_VIEW_MODE, 125 PluginConstants.PREFS_HIERARCHY_VIEW_MODE_SUPERTYPE ); 126 } 127 showSupertypeHierarchy = new ShowSupertypeHierarchyAction( view ); 128 showSubtypeHierarchy = new ShowSubtypeHierarchyAction( view ); 129 linkWithEditor = new LinkWithEditorHierarchyView( view ); 130 openPreferencePage = new OpenHierarchyViewPreferencesAction(); 131 } 132 133 134 137 private void initToolbar() 138 { 139 IToolBarManager toolbar = view.getViewSite().getActionBars().getToolBarManager(); 140 toolbar.add( showSupertypeHierarchy ); 141 toolbar.add( showSubtypeHierarchy ); 142 } 143 144 145 148 private void initMenu() 149 { 150 IMenuManager menu = view.getViewSite().getActionBars().getMenuManager(); 151 menu.add( showSupertypeHierarchy ); 152 menu.add( showSubtypeHierarchy ); 153 menu.add( new Separator() ); 154 menu.add( linkWithEditor ); 155 menu.add( new Separator() ); 156 menu.add( openPreferencePage ); 157 } 158 159 160 163 private void initDoubleClickListener() 164 { 165 view.getViewer().addDoubleClickListener( new IDoubleClickListener() 166 { 167 public void doubleClick( DoubleClickEvent event ) 168 { 169 StructuredSelection selection = ( StructuredSelection ) event.getSelection(); 171 172 Object objectSelection = selection.getFirstElement(); 174 IEditorInput input = null; 175 String editorId = null; 176 177 if ( objectSelection instanceof AttributeTypeWrapper ) 179 { 180 input = new AttributeTypeEditorInput( ( ( AttributeTypeWrapper ) objectSelection ) 181 .getMyAttributeType() ); 182 editorId = AttributeTypeEditor.ID; 183 } 184 else if ( objectSelection instanceof ObjectClassWrapper ) 185 { 186 input = new ObjectClassEditorInput( ( ( ObjectClassWrapper ) objectSelection ).getMyObjectClass() ); 187 editorId = ObjectClassEditor.ID; 188 } 189 190 if ( input != null ) 192 { 193 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); 194 try 195 { 196 page.openEditor( input, editorId ); 197 } 198 catch ( PartInitException e ) 199 { 200 } 202 } 203 } 204 } ); 205 } 206 207 208 211 private void initPreferencesListener() 212 { 213 Activator.getDefault().getPreferenceStore().addPropertyChangeListener( new IPropertyChangeListener() 214 { 215 218 public void propertyChange( PropertyChangeEvent event ) 219 { 220 if ( authorizedPrefs.contains( event.getProperty() ) ) 221 { 222 view.refresh(); 223 } 224 } 225 } ); 226 } 227 228 229 232 public void poolChanged( SchemaPool p, LDAPModelEvent e ) 233 { 234 view.refresh(); 235 } 236 } 237 | Popular Tags |