1 20 21 package org.apache.directory.ldapstudio.browser.ui.editors.schemabrowser; 22 23 24 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 25 import org.apache.directory.ldapstudio.browser.core.model.schema.Schema; 26 import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaPart; 27 import org.eclipse.jface.action.Separator; 28 import org.eclipse.jface.resource.JFaceResources; 29 import org.eclipse.jface.viewers.ISelection; 30 import org.eclipse.jface.viewers.ISelectionChangedListener; 31 import org.eclipse.jface.viewers.IStructuredContentProvider; 32 import org.eclipse.jface.viewers.ITableLabelProvider; 33 import org.eclipse.jface.viewers.SelectionChangedEvent; 34 import org.eclipse.jface.viewers.StructuredSelection; 35 import org.eclipse.jface.viewers.TableViewer; 36 import org.eclipse.jface.viewers.ViewerFilter; 37 import org.eclipse.jface.viewers.ViewerSorter; 38 import org.eclipse.swt.SWT; 39 import org.eclipse.swt.custom.SashForm; 40 import org.eclipse.swt.events.ModifyEvent; 41 import org.eclipse.swt.events.ModifyListener; 42 import org.eclipse.swt.layout.FillLayout; 43 import org.eclipse.swt.layout.GridData; 44 import org.eclipse.swt.layout.GridLayout; 45 import org.eclipse.swt.widgets.Composite; 46 import org.eclipse.swt.widgets.Control; 47 import org.eclipse.swt.widgets.Table; 48 import org.eclipse.swt.widgets.Text; 49 import org.eclipse.ui.forms.FormColors; 50 import org.eclipse.ui.forms.widgets.Form; 51 import org.eclipse.ui.forms.widgets.FormToolkit; 52 import org.eclipse.ui.forms.widgets.ScrolledForm; 53 import org.eclipse.ui.forms.widgets.Section; 54 55 56 62 public abstract class SchemaPage 63 { 64 65 66 protected ConnectionComboContributionItem connectionCombo; 67 68 69 protected ShowDefaultSchemaAction showDefaultSchemaAction; 70 71 72 protected ReloadSchemaAction reloadSchemaAction; 73 74 75 protected SchemaBrowser schemaBrowser; 76 77 78 protected FormToolkit toolkit; 79 80 81 protected Form form; 82 83 84 protected SashForm sashForm; 85 86 87 protected ScrolledForm masterForm; 88 89 90 protected ScrolledForm detailForm; 91 92 93 protected SchemaDetailsPage detailsPage; 94 95 96 protected Section section; 97 98 99 protected Text filterText; 100 101 102 protected TableViewer viewer; 103 104 105 protected boolean inChange; 106 107 108 113 public SchemaPage( SchemaBrowser schemaBrowser ) 114 { 115 this.schemaBrowser = schemaBrowser; 116 this.inChange = false; 117 } 118 119 120 123 public void refresh() 124 { 125 Schema schema = null; 126 if ( showDefaultSchemaAction.isChecked() ) 127 { 128 schema = Schema.DEFAULT_SCHEMA; 129 } 130 else if ( getConnection() != null ) 131 { 132 schema = getConnection().getSchema(); 133 } 134 135 if ( viewer.getInput() != schema ) 136 { 137 viewer.setInput( schema ); 138 viewer.setSelection( StructuredSelection.EMPTY ); 139 } 140 141 form.setText( getTitle() ); 142 viewer.refresh(); 143 } 144 145 146 151 protected abstract String getTitle(); 152 153 154 159 protected abstract String getFilterDescription(); 160 161 162 167 protected abstract IStructuredContentProvider getContentProvider(); 168 169 170 175 protected abstract ITableLabelProvider getLabelProvider(); 176 177 178 183 protected abstract ViewerSorter getSorter(); 184 185 186 191 protected abstract ViewerFilter getFilter(); 192 193 194 199 protected abstract SchemaDetailsPage getDetailsPage(); 200 201 202 207 private void createMaster( Composite parent ) 209 { 210 section = toolkit.createSection( parent, Section.DESCRIPTION ); 212 section.marginWidth = 10; 213 section.marginHeight = 12; 214 section.setText( getTitle() ); 215 section.setDescription( getFilterDescription() ); 216 toolkit.createCompositeSeparator( section ); 217 218 Composite client = toolkit.createComposite( section, SWT.WRAP ); 220 GridLayout layout = new GridLayout( 2, false ); 221 layout.marginWidth = 5; 222 layout.marginHeight = 5; 223 client.setLayout( layout ); 224 section.setClient( client ); 225 226 toolkit.createLabel( client, "Filter:" ); 228 this.filterText = toolkit.createText( client, "", SWT.NONE ); 229 this.filterText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 230 this.filterText.setData( FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER ); 231 this.filterText.addModifyListener( new ModifyListener() 232 { 233 public void modifyText( ModifyEvent e ) 234 { 235 viewer.refresh(); 236 } 237 } ); 238 239 Table t = toolkit.createTable( client, SWT.NONE ); 241 GridData gd = new GridData( GridData.FILL_BOTH ); 242 gd.horizontalSpan = 2; 243 gd.heightHint = 20; 244 gd.widthHint = 100; 245 t.setLayoutData( gd ); 246 toolkit.paintBordersFor( client ); 247 248 viewer = new TableViewer( t ); 250 viewer.setContentProvider( getContentProvider() ); 251 viewer.setLabelProvider( getLabelProvider() ); 252 viewer.setSorter( getSorter() ); 253 viewer.addFilter( getFilter() ); 254 } 255 256 257 262 private void createDetail( Composite body ) 263 { 264 detailsPage = getDetailsPage(); 265 detailsPage.createContents( this.detailForm ); 266 } 267 268 269 275 public void select( Object obj ) 276 { 277 ISelection newSelection = new StructuredSelection( obj ); 278 ISelection oldSelection = this.viewer.getSelection(); 279 280 if ( !newSelection.equals( oldSelection ) ) 281 { 282 inChange = true; 283 this.viewer.setSelection( newSelection, true ); 284 if ( this.viewer.getSelection().isEmpty() ) 285 { 286 this.filterText.setText( "" ); 287 this.viewer.setSelection( newSelection, true ); 288 } 289 inChange = false; 290 } 291 } 292 293 294 297 public void dispose() 298 { 299 this.detailsPage.dispose(); 300 301 this.schemaBrowser = null; 302 this.toolkit.dispose(); 303 this.toolkit = null; 304 } 305 306 307 313 Control createControl( Composite parent ) 314 { 315 this.toolkit = new FormToolkit( parent.getDisplay() ); 316 this.form = this.toolkit.createForm( parent ); 317 this.form.getBody().setLayout( new FillLayout() ); 318 319 this.sashForm = new SashForm( this.form.getBody(), SWT.HORIZONTAL ); 320 this.sashForm.setLayout( new FillLayout() ); 321 322 this.masterForm = this.toolkit.createScrolledForm( this.sashForm ); 323 this.detailForm = new ScrolledForm( this.sashForm, SWT.V_SCROLL | this.toolkit.getOrientation() ); 324 this.detailForm.setExpandHorizontal( true ); 325 this.detailForm.setExpandVertical( true ); 326 this.detailForm.setBackground( this.toolkit.getColors().getBackground() ); 327 this.detailForm.setForeground( this.toolkit.getColors().getColor( FormColors.TITLE ) ); 328 this.detailForm.setFont( JFaceResources.getHeaderFont() ); 329 this.sashForm.setWeights( new int[] 330 { 50, 50 } ); 331 332 this.masterForm.getBody().setLayout( new FillLayout() ); 333 this.createMaster( this.masterForm.getBody() ); 334 335 this.detailForm.getBody().setLayout( new FillLayout() ); 336 this.createDetail( this.detailForm.getBody() ); 337 viewer.addSelectionChangedListener( new ISelectionChangedListener() 338 { 339 public void selectionChanged( SelectionChangedEvent event ) 340 { 341 ISelection selection = event.getSelection(); 342 if ( selection.isEmpty() ) 343 { 344 detailsPage.setInput( null ); 345 } 346 else 347 { 348 Object obj = ( ( StructuredSelection ) selection ).getFirstElement(); 349 detailsPage.setInput( obj ); 350 351 if ( !inChange && obj instanceof SchemaPart ) 354 { 355 schemaBrowser.setInput( new SchemaBrowserInput( getConnection(), ( SchemaPart ) obj ) ); 356 } 357 } 358 } 359 } ); 360 361 connectionCombo = new ConnectionComboContributionItem( this ); 362 this.form.getToolBarManager().add( connectionCombo ); 363 this.form.getToolBarManager().add( new Separator() ); 364 showDefaultSchemaAction = new ShowDefaultSchemaAction( schemaBrowser ); 365 this.form.getToolBarManager().add( showDefaultSchemaAction ); 366 this.form.getToolBarManager().add( new Separator() ); 367 reloadSchemaAction = new ReloadSchemaAction( this ); 368 this.form.getToolBarManager().add( reloadSchemaAction ); 369 this.form.updateToolBar(); 370 371 this.refresh(); 372 373 return this.form; 374 } 375 376 377 382 public SchemaBrowser getSchemaBrowser() 383 { 384 return schemaBrowser; 385 } 386 387 388 393 public IConnection getConnection() 394 { 395 return connectionCombo.getConnection(); 396 } 397 398 399 404 public void setConnection( IConnection connection ) 405 { 406 connectionCombo.setConnection( connection ); 407 reloadSchemaAction.updateEnabledState(); 408 refresh(); 409 } 410 411 412 417 public boolean isShowDefaultSchema() 418 { 419 return showDefaultSchemaAction.isChecked(); 420 } 421 422 423 428 public void setShowDefaultSchema( boolean b ) 429 { 430 showDefaultSchemaAction.setChecked( b ); 431 connectionCombo.updateEnabledState(); 432 reloadSchemaAction.updateEnabledState(); 433 refresh(); 434 } 435 } 436 | Popular Tags |