1 20 package org.apache.directory.ldapstudio.schemas.controller.actions; 21 22 23 import org.apache.directory.ldapstudio.schemas.Activator; 24 import org.apache.directory.ldapstudio.schemas.Messages; 25 import org.apache.directory.ldapstudio.schemas.PluginConstants; 26 import org.apache.directory.ldapstudio.schemas.model.AttributeType; 27 import org.apache.directory.ldapstudio.schemas.model.ObjectClass; 28 import org.apache.directory.ldapstudio.schemas.model.SchemaElement; 29 import org.apache.directory.ldapstudio.schemas.view.editors.attributeType.AttributeTypeEditor; 30 import org.apache.directory.ldapstudio.schemas.view.editors.objectClass.ObjectClassEditor; 31 import org.apache.directory.ldapstudio.schemas.view.views.HierarchyView; 32 import org.eclipse.jface.action.Action; 33 import org.eclipse.ui.IEditorPart; 34 import org.eclipse.ui.IPartListener2; 35 import org.eclipse.ui.IWorkbenchPart; 36 import org.eclipse.ui.IWorkbenchPartReference; 37 import org.eclipse.ui.PlatformUI; 38 import org.eclipse.ui.plugin.AbstractUIPlugin; 39 40 41 47 public class LinkWithEditorHierarchyView extends Action 48 { 49 50 private static final String LINK_WITH_EDITOR_HIERARCHY_VIEW_DS_KEY = LinkWithEditorHierarchyView.class.getName() 51 + ".dialogsettingkey"; 53 54 private HierarchyView view; 55 56 57 private IPartListener2 editorListener = new IPartListener2() 58 { 59 62 public void partVisible( IWorkbenchPartReference partRef ) 63 { 64 IWorkbenchPart part = partRef.getPart( true ); 65 66 if ( part instanceof ObjectClassEditor ) 67 { 68 linkViewWithEditor( ( ( ObjectClassEditor ) part ).getOriginalObjectClass() ); 69 } 70 else if ( part instanceof AttributeTypeEditor ) 71 { 72 linkViewWithEditor( ( ( AttributeTypeEditor ) part ).getOriginalAttributeType() ); 73 } 74 } 75 76 77 80 public void partActivated( IWorkbenchPartReference partRef ) 81 { 82 } 83 84 85 88 public void partClosed( IWorkbenchPartReference partRef ) 89 { 90 } 91 92 93 96 public void partDeactivated( IWorkbenchPartReference partRef ) 97 { 98 } 99 100 101 104 public void partHidden( IWorkbenchPartReference partRef ) 105 { 106 } 107 108 109 112 public void partInputChanged( IWorkbenchPartReference partRef ) 113 { 114 } 115 116 117 120 public void partOpened( IWorkbenchPartReference partRef ) 121 { 122 } 123 124 125 128 public void partBroughtToTop( IWorkbenchPartReference partRef ) 129 { 130 } 131 }; 132 133 134 140 public LinkWithEditorHierarchyView( HierarchyView view ) 141 { 142 super( Messages.getString( "LinkWithEditorHierarchyView.Link_with_Editor" ), AS_CHECK_BOX ); setToolTipText( getText() ); 144 setId( PluginConstants.CMD_LINK_WITH_EDITOR_SCHEMA_VIEW ); 145 setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, 146 PluginConstants.IMG_LINK_WITH_EDITOR ) ); 147 setEnabled( true ); 148 this.view = view; 149 150 if ( Activator.getDefault().getDialogSettings().get( LINK_WITH_EDITOR_HIERARCHY_VIEW_DS_KEY ) == null ) 152 { 153 Activator.getDefault().getDialogSettings().put( LINK_WITH_EDITOR_HIERARCHY_VIEW_DS_KEY, false ); 154 } 155 156 setChecked( Activator.getDefault().getDialogSettings().getBoolean( LINK_WITH_EDITOR_HIERARCHY_VIEW_DS_KEY ) ); 158 159 if ( isChecked() ) 161 { 162 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().addPartListener( editorListener ); 163 } 164 } 165 166 167 170 public void run() 171 { 172 setChecked( isChecked() ); 173 Activator.getDefault().getDialogSettings().put( LINK_WITH_EDITOR_HIERARCHY_VIEW_DS_KEY, isChecked() ); 174 175 if ( isChecked() ) { 177 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().addPartListener( editorListener ); 178 179 IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() 180 .getActiveEditor(); 181 if ( activeEditor instanceof ObjectClassEditor ) 182 { 183 linkViewWithEditor( ( ( ObjectClassEditor ) activeEditor ).getOriginalObjectClass() ); 184 } 185 else if ( activeEditor instanceof AttributeTypeEditor ) 186 { 187 linkViewWithEditor( ( ( AttributeTypeEditor ) activeEditor ).getOriginalAttributeType() ); 188 } 189 } 190 else 191 { 193 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().removePartListener( editorListener ); 194 } 195 } 196 197 198 204 private void linkViewWithEditor( SchemaElement schemaElement ) 205 { 206 if ( schemaElement instanceof AttributeType ) 207 { 208 view.setInput( schemaElement ); 209 } 210 else if ( schemaElement instanceof ObjectClass ) 211 { 212 view.setInput( schemaElement ); 213 } 214 } 215 } 216 | Popular Tags |