1 20 21 package org.apache.directory.ldapstudio.browser.ui.editors.entry; 22 23 24 import org.apache.directory.ldapstudio.browser.common.widgets.entryeditor.EntryEditorWidget; 25 import org.apache.directory.ldapstudio.browser.core.model.IEntry; 26 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin; 27 import org.apache.directory.ldapstudio.browser.ui.views.browser.BrowserView; 28 import org.eclipse.core.runtime.IProgressMonitor; 29 import org.eclipse.swt.SWT; 30 import org.eclipse.swt.layout.GridData; 31 import org.eclipse.swt.layout.GridLayout; 32 import org.eclipse.swt.widgets.Composite; 33 import org.eclipse.ui.IEditorInput; 34 import org.eclipse.ui.IEditorPart; 35 import org.eclipse.ui.IEditorSite; 36 import org.eclipse.ui.INavigationLocation; 37 import org.eclipse.ui.INavigationLocationProvider; 38 import org.eclipse.ui.IReusableEditor; 39 import org.eclipse.ui.PartInitException; 40 import org.eclipse.ui.PlatformUI; 41 import org.eclipse.ui.part.EditorPart; 42 import org.eclipse.ui.part.IShowInSource; 43 import org.eclipse.ui.part.IShowInTargetList; 44 import org.eclipse.ui.part.ShowInContext; 45 import org.eclipse.ui.views.contentoutline.IContentOutlinePage; 46 47 48 54 public class EntryEditor extends EditorPart implements INavigationLocationProvider, IReusableEditor 55 { 56 57 58 private EntryEditorConfiguration configuration; 59 60 61 private EntryEditorActionGroup actionGroup; 62 63 64 private EntryEditorWidget mainWidget; 65 66 67 private EntryEditorUniversalListener universalListener; 68 69 70 private EntryEditorOutlinePage outlinePage; 71 72 73 78 public static String getId() 79 { 80 return EntryEditor.class.getName(); 81 } 82 83 84 87 public void setInput( IEditorInput input ) 88 { 89 super.setInput( input ); 90 91 if ( input instanceof EntryEditorInput && universalListener != null ) 92 { 93 EntryEditorInput eei = ( EntryEditorInput ) input; 94 IEntry entry = eei.getResolvedEntry(); 95 96 universalListener.setInput( entry ); 98 99 if ( entry != null ) 101 { 102 EntryEditorInput.enableOneInstanceHack( true ); 105 firePropertyChange( IEditorPart.PROP_INPUT ); 106 107 EntryEditorInput.enableOneInstanceHack( false ); 109 getSite().getPage().getNavigationHistory().markLocation( this ); 110 } 111 112 if ( outlinePage != null ) 114 { 115 outlinePage.refresh(); 116 } 117 118 EntryEditorInput.enableOneInstanceHack( true ); 120 } 121 } 122 123 124 127 public void init( IEditorSite site, IEditorInput input ) throws PartInitException 128 { 129 super.setSite( site ); 130 131 setInput( new EntryEditorInput( ( IEntry ) null ) ); 134 getSite().getPage().getNavigationHistory().markLocation( this ); 135 136 setInput( input ); 137 } 138 139 140 143 public void createPartControl( Composite parent ) 144 { 145 Composite composite = new Composite( parent, SWT.NONE ); 146 composite.setLayoutData( new GridData( GridData.FILL_BOTH ) ); 147 GridLayout layout = new GridLayout(); 148 layout.marginWidth = 0; 149 layout.marginHeight = 0; 150 layout.verticalSpacing = 0; 151 composite.setLayout( layout ); 152 153 PlatformUI.getWorkbench().getHelpSystem().setHelp( composite, 154 BrowserUIPlugin.PLUGIN_ID + "." + "tools_entry_editor" ); 155 156 configuration = new EntryEditorConfiguration(); 158 159 mainWidget = new EntryEditorWidget( this.configuration ); 161 mainWidget.createWidget( composite ); 162 163 actionGroup = new EntryEditorActionGroup( this ); 165 actionGroup.fillToolBar( mainWidget.getToolBarManager() ); 166 actionGroup.fillMenu( mainWidget.getMenuManager() ); 167 actionGroup.enableGlobalActionHandlers( getEditorSite().getActionBars() ); 168 actionGroup.fillContextMenu( mainWidget.getContextMenuManager() ); 169 170 getSite().setSelectionProvider( mainWidget.getViewer() ); 172 universalListener = new EntryEditorUniversalListener( this ); 173 setInput( getEditorInput() ); 174 } 175 176 177 180 public void setFocus() 181 { 182 mainWidget.setFocus(); 183 } 184 185 186 189 public Object getAdapter( Class required ) 190 { 191 if ( IContentOutlinePage.class.equals( required ) ) 192 { 193 if ( outlinePage == null || outlinePage.getControl() == null || outlinePage.getControl().isDisposed() ) 194 { 195 outlinePage = new EntryEditorOutlinePage( this ); 196 } 197 return outlinePage; 198 } 199 200 if ( IShowInTargetList.class.equals( required ) ) 201 { 202 return new IShowInTargetList() 203 { 204 public String [] getShowInTargetIds() 205 { 206 return new String [] 207 { BrowserView.getId() }; 208 } 209 }; 210 } 211 212 if ( IShowInSource.class.equals( required ) ) 213 { 214 return new IShowInSource() 215 { 216 public ShowInContext getShowInContext() 217 { 218 return new ShowInContext( getMainWidget().getViewer().getInput(), getMainWidget().getViewer() 219 .getSelection() ); 220 } 221 }; 222 } 223 224 return super.getAdapter( required ); 225 } 226 227 228 231 public void dispose() 232 { 233 if ( configuration != null ) 234 { 235 universalListener.dispose(); 236 universalListener = null; 237 mainWidget.dispose(); 238 mainWidget = null; 239 actionGroup.dispose(); 240 actionGroup = null; 241 configuration.dispose(); 242 configuration = null; 243 getSite().setSelectionProvider( null ); 244 } 245 246 super.dispose(); 247 } 248 249 250 253 public void doSave( IProgressMonitor monitor ) 254 { 255 } 256 257 258 261 public void doSaveAs() 262 { 263 } 264 265 266 269 public boolean isDirty() 270 { 271 return false; 272 } 273 274 275 278 public boolean isSaveAsAllowed() 279 { 280 return false; 281 } 282 283 284 289 public EntryEditorActionGroup getActionGroup() 290 { 291 return actionGroup; 292 } 293 294 295 300 public EntryEditorConfiguration getConfiguration() 301 { 302 return configuration; 303 } 304 305 306 311 public EntryEditorWidget getMainWidget() 312 { 313 return mainWidget; 314 } 315 316 317 322 public EntryEditorOutlinePage getOutlinePage() 323 { 324 return outlinePage; 325 } 326 327 328 333 public EntryEditorUniversalListener getUniversalListener() 334 { 335 return universalListener; 336 } 337 338 339 342 public INavigationLocation createEmptyNavigationLocation() 343 { 344 return null; 345 } 346 347 348 351 public INavigationLocation createNavigationLocation() 352 { 353 return new EntryEditorNavigationLocation( this ); 354 } 355 356 } 357 | Popular Tags |