1 20 21 package org.apache.directory.ldapstudio.browser.ui.editors.schemabrowser; 22 23 24 import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeTypeDescription; 25 import org.apache.directory.ldapstudio.browser.core.model.schema.ObjectClassDescription; 26 import org.eclipse.swt.SWT; 27 import org.eclipse.swt.layout.GridData; 28 import org.eclipse.swt.layout.GridLayout; 29 import org.eclipse.swt.widgets.Composite; 30 import org.eclipse.swt.widgets.Text; 31 import org.eclipse.ui.forms.events.ExpansionAdapter; 32 import org.eclipse.ui.forms.events.ExpansionEvent; 33 import org.eclipse.ui.forms.widgets.FormToolkit; 34 import org.eclipse.ui.forms.widgets.Hyperlink; 35 import org.eclipse.ui.forms.widgets.ScrolledForm; 36 import org.eclipse.ui.forms.widgets.Section; 37 38 39 46 public class ObjectClassDescriptionDetailsPage extends SchemaDetailsPage 47 { 48 49 50 private Section mainSection; 51 52 53 private Text numericOidText; 54 55 56 private Text namesText; 57 58 59 private Text descText; 60 61 62 private Text kindText; 63 64 65 private Section superclassesSection; 66 67 68 private Hyperlink[] superLinks; 69 70 71 private Section subclassesSection; 72 73 74 private Hyperlink[] subLinks; 75 76 77 private Section mustSection; 78 79 80 private Hyperlink[] mustLinks; 81 82 83 private Section maySection; 84 85 86 private Hyperlink[] mayLinks; 87 88 89 95 public ObjectClassDescriptionDetailsPage( SchemaPage schemaPage, FormToolkit toolkit ) 96 { 97 super( schemaPage, toolkit ); 98 } 99 100 101 104 public void createContents( final ScrolledForm detailForm ) 105 { 106 this.detailForm = detailForm; 107 detailForm.getBody().setLayout( new GridLayout() ); 108 109 mainSection = toolkit.createSection( detailForm.getBody(), SWT.NONE ); 111 mainSection.setText( "Details" ); 112 mainSection.marginWidth = 0; 113 mainSection.marginHeight = 0; 114 mainSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 115 toolkit.createCompositeSeparator( mainSection ); 116 117 mustSection = toolkit.createSection( detailForm.getBody(), Section.TWISTIE ); 119 mustSection.setText( "MUST Attributes" ); 120 mustSection.marginWidth = 0; 121 mustSection.marginHeight = 0; 122 mustSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 123 toolkit.createCompositeSeparator( mustSection ); 124 mustSection.addExpansionListener( new ExpansionAdapter() 125 { 126 public void expansionStateChanged( ExpansionEvent e ) 127 { 128 detailForm.reflow( true ); 129 } 130 } ); 131 132 maySection = toolkit.createSection( detailForm.getBody(), Section.TWISTIE ); 134 maySection.setText( "MAY Attributes" ); 135 maySection.marginWidth = 0; 136 maySection.marginHeight = 0; 137 maySection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 138 toolkit.createCompositeSeparator( maySection ); 139 maySection.addExpansionListener( new ExpansionAdapter() 140 { 141 public void expansionStateChanged( ExpansionEvent e ) 142 { 143 detailForm.reflow( true ); 144 } 145 } ); 146 147 superclassesSection = toolkit.createSection( detailForm.getBody(), Section.TWISTIE ); 149 superclassesSection.setText( "Superclasses" ); 150 superclassesSection.marginWidth = 0; 151 superclassesSection.marginHeight = 0; 152 superclassesSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 153 toolkit.createCompositeSeparator( superclassesSection ); 154 superclassesSection.addExpansionListener( new ExpansionAdapter() 155 { 156 public void expansionStateChanged( ExpansionEvent e ) 157 { 158 detailForm.reflow( true ); 159 } 160 } ); 161 162 subclassesSection = toolkit.createSection( detailForm.getBody(), Section.TWISTIE ); 164 subclassesSection.setText( "Subclasses" ); 165 subclassesSection.marginWidth = 0; 166 subclassesSection.marginHeight = 0; 167 subclassesSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 168 toolkit.createCompositeSeparator( subclassesSection ); 169 subclassesSection.addExpansionListener( new ExpansionAdapter() 170 { 171 public void expansionStateChanged( ExpansionEvent e ) 172 { 173 detailForm.reflow( true ); 174 } 175 } ); 176 177 createRawSection(); 179 } 180 181 182 185 public void setInput( Object input ) 186 { 187 ObjectClassDescription ocd = null; 188 if ( input instanceof ObjectClassDescription ) 189 { 190 ocd = ( ObjectClassDescription ) input; 191 } 192 193 this.createMainContent( ocd ); 195 196 this.createSuperclassContents( ocd ); 198 this.createSubclassContents( ocd ); 199 this.createMustContents( ocd ); 200 this.createMayContents( ocd ); 201 super.createRawContents( ocd ); 202 203 this.detailForm.reflow( true ); 204 } 205 206 207 214 private void createMainContent( ObjectClassDescription ocd ) 215 { 216 if ( mainSection.getClient() != null ) 218 { 219 mainSection.getClient().dispose(); 220 } 221 222 Composite mainClient = toolkit.createComposite( mainSection, SWT.WRAP ); 224 GridLayout mainLayout = new GridLayout( 2, false ); 225 mainClient.setLayout( mainLayout ); 226 mainSection.setClient( mainClient ); 227 228 if ( ocd != null ) 230 { 231 toolkit.createLabel( mainClient, "Numeric OID:", SWT.NONE ); 232 numericOidText = toolkit.createText( mainClient, getNonNullString( ocd.getNumericOID() ), SWT.NONE ); 233 numericOidText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 234 numericOidText.setEditable( false ); 235 236 toolkit.createLabel( mainClient, "Objectclass names:", SWT.NONE ); 237 namesText = toolkit.createText( mainClient, getNonNullString( ocd.toString() ), SWT.NONE ); 238 namesText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 239 namesText.setEditable( false ); 240 241 toolkit.createLabel( mainClient, "Descripton:", SWT.NONE ); 242 descText = toolkit.createText( mainClient, getNonNullString( ocd.getDesc() ), SWT.WRAP | SWT.MULTI ); 243 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 244 gd.widthHint = detailForm.getForm().getSize().x - 100 - 60; 245 descText.setLayoutData( gd ); 246 descText.setEditable( false ); 247 248 String kind = ""; 249 if ( ocd.isStructural() ) 250 { 251 kind = "structural"; 252 } 253 else if ( ocd.isAbstract() ) 254 { 255 kind = "abstract"; 256 } 257 else if ( ocd.isAuxiliary() ) 258 { 259 kind = "auxiliary"; 260 } 261 if ( ocd.isObsolete() ) 262 { 263 kind += " (obsolete)"; 264 } 265 toolkit.createLabel( mainClient, "Objectclass kind:", SWT.NONE ); 266 kindText = toolkit.createText( mainClient, getNonNullString( kind ), SWT.NONE ); 267 kindText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 268 kindText.setEditable( false ); 269 } 270 271 mainSection.layout(); 272 } 273 274 275 282 private void createMustContents( ObjectClassDescription ocd ) 283 { 284 if ( mustSection.getClient() != null ) 286 { 287 mustSection.getClient().dispose(); 288 } 289 290 Composite mustClient = toolkit.createComposite( mustSection, SWT.WRAP ); 292 mustClient.setLayout( new GridLayout() ); 293 mustSection.setClient( mustClient ); 294 295 if ( ocd != null ) 297 { 298 String [] names = ocd.getMustAttributeTypeDescriptionNamesTransitive(); 299 if ( names != null && names.length > 0 ) 300 { 301 mustSection.setText( "MUST Attributes (" + names.length + ")" ); 302 mustLinks = new Hyperlink[names.length]; 303 for ( int i = 0; i < names.length; i++ ) 304 { 305 if ( ocd.getSchema().hasAttributeTypeDescription( names[i] ) ) 306 { 307 AttributeTypeDescription mustAtd = ocd.getSchema().getAttributeTypeDescription( names[i] ); 308 mustLinks[i] = toolkit.createHyperlink( mustClient, mustAtd.toString(), SWT.WRAP ); 309 mustLinks[i].setHref( mustAtd ); 310 mustLinks[i].setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 311 mustLinks[i].setUnderlined( true ); 312 mustLinks[i].setEnabled( true ); 313 mustLinks[i].addHyperlinkListener( this ); 314 } 315 else 316 { 317 mustLinks[i] = toolkit.createHyperlink( mustClient, names[i], SWT.WRAP ); 318 mustLinks[i].setHref( null ); 319 mustLinks[i].setUnderlined( false ); 320 mustLinks[i].setEnabled( false ); 321 } 322 } 323 } 324 else 325 { 326 mustSection.setText( "MUST Attributes (0)" ); 327 mustLinks = new Hyperlink[0]; 328 Text mustText = toolkit.createText( mustClient, getNonNullString( null ), SWT.NONE ); 329 mustText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 330 mustText.setEditable( false ); 331 } 332 } 333 else 334 { 335 mustSection.setText( "MUST Attributes" ); 336 } 337 338 mustSection.layout(); 339 } 340 341 342 349 private void createMayContents( ObjectClassDescription ocd ) 350 { 351 if ( maySection.getClient() != null ) 353 { 354 maySection.getClient().dispose(); 355 } 356 357 Composite mayClient = toolkit.createComposite( maySection, SWT.WRAP ); 359 mayClient.setLayout( new GridLayout() ); 360 maySection.setClient( mayClient ); 361 362 if ( ocd != null ) 364 { 365 String [] names = ocd.getMayAttributeTypeDescriptionNamesTransitive(); 366 if ( names != null && names.length > 0 ) 367 { 368 maySection.setText( "MAY Attributes (" + names.length + ")" ); 369 mayLinks = new Hyperlink[names.length]; 370 for ( int i = 0; i < names.length; i++ ) 371 { 372 if ( ocd.getSchema().hasAttributeTypeDescription( names[i] ) ) 373 { 374 AttributeTypeDescription mayAtd = ocd.getSchema().getAttributeTypeDescription( names[i] ); 375 mayLinks[i] = toolkit.createHyperlink( mayClient, mayAtd.toString(), SWT.WRAP ); 376 mayLinks[i].setHref( mayAtd ); 377 mayLinks[i].setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 378 mayLinks[i].setUnderlined( true ); 379 mayLinks[i].setEnabled( true ); 380 mayLinks[i].addHyperlinkListener( this ); 381 } 382 else 383 { 384 mayLinks[i] = toolkit.createHyperlink( mayClient, names[i], SWT.WRAP ); 385 mayLinks[i].setHref( null ); 386 mayLinks[i].setUnderlined( false ); 387 mayLinks[i].setEnabled( false ); 388 } 389 } 390 } 391 else 392 { 393 maySection.setText( "MAY Attributes (0)" ); 394 mayLinks = new Hyperlink[0]; 395 Text mayText = toolkit.createText( mayClient, getNonNullString( null ), SWT.NONE ); 396 mayText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 397 mayText.setEditable( false ); 398 } 399 } 400 else 401 { 402 maySection.setText( "MAY Attributes" ); 403 } 404 maySection.layout(); 405 } 406 407 408 415 private void createSubclassContents( ObjectClassDescription ocd ) 416 { 417 if ( subclassesSection.getClient() != null ) 419 { 420 subclassesSection.getClient().dispose(); 421 } 422 423 Composite subClient = toolkit.createComposite( subclassesSection, SWT.WRAP ); 425 subClient.setLayout( new GridLayout() ); 426 subclassesSection.setClient( subClient ); 427 428 if ( ocd != null ) 430 { 431 ObjectClassDescription[] subOCDs = ocd.getSubObjectClassDescriptions(); 432 if ( subOCDs != null && subOCDs.length > 0 ) 433 { 434 subclassesSection.setText( "Subclasses (" + subOCDs.length + ")" ); 435 subLinks = new Hyperlink[subOCDs.length]; 436 for ( int i = 0; i < subOCDs.length; i++ ) 437 { 438 subLinks[i] = toolkit.createHyperlink( subClient, subOCDs[i].toString(), SWT.WRAP ); 439 subLinks[i].setHref( subOCDs[i] ); 440 subLinks[i].setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 441 subLinks[i].setUnderlined( true ); 442 subLinks[i].setEnabled( true ); 443 subLinks[i].addHyperlinkListener( this ); 444 } 445 } 446 else 447 { 448 subclassesSection.setText( "Subclasses (0)" ); 449 subLinks = new Hyperlink[0]; 450 Text derivedText = toolkit.createText( subClient, getNonNullString( null ), SWT.NONE ); 451 derivedText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 452 derivedText.setEditable( false ); 453 } 454 } 455 else 456 { 457 subclassesSection.setText( "Subclasses" ); 458 } 459 460 subclassesSection.layout(); 461 } 462 463 464 471 private void createSuperclassContents( ObjectClassDescription ocd ) 472 { 473 if ( superclassesSection.getClient() != null ) 475 { 476 superclassesSection.getClient().dispose(); 477 } 478 479 Composite superClient = toolkit.createComposite( superclassesSection, SWT.WRAP ); 481 superClient.setLayout( new GridLayout() ); 482 superclassesSection.setClient( superClient ); 483 484 if ( ocd != null ) 486 { 487 String [] names = ocd.getSuperiorObjectClassDescriptionNames(); 488 if ( names != null && names.length > 0 ) 489 { 490 superclassesSection.setText( "Superclasses (" + names.length + ")" ); 491 Composite supClient = toolkit.createComposite( superClient, SWT.WRAP ); 492 GridLayout gl = new GridLayout(); 493 gl.marginWidth = 0; 494 gl.marginHeight = 0; 495 supClient.setLayout( gl ); 496 superLinks = new Hyperlink[names.length]; 497 for ( int i = 0; i < names.length; i++ ) 498 { 499 if ( ocd.getSchema().hasObjectClassDescription( names[i] ) ) 500 { 501 ObjectClassDescription supOcd = ocd.getSchema().getObjectClassDescription( names[i] ); 502 superLinks[i] = toolkit.createHyperlink( supClient, supOcd.toString(), SWT.WRAP ); 503 superLinks[i].setHref( supOcd ); 504 superLinks[i].setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 505 superLinks[i].setUnderlined( true ); 506 superLinks[i].setEnabled( true ); 507 superLinks[i].addHyperlinkListener( this ); 508 } 509 else 510 { 511 superLinks[i] = toolkit.createHyperlink( supClient, names[i], SWT.WRAP ); 512 superLinks[i].setHref( null ); 513 superLinks[i].setUnderlined( false ); 514 superLinks[i].setEnabled( false ); 515 } 516 } 517 } 518 else 519 { 520 superclassesSection.setText( "Superlasses (0)" ); 521 superLinks = new Hyperlink[0]; 522 Text superText = toolkit.createText( superClient, getNonNullString( null ), SWT.NONE ); 523 superText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 524 superText.setEditable( false ); 525 } 526 } 527 else 528 { 529 superclassesSection.setText( "Superclasses" ); 530 } 531 532 superclassesSection.layout(); 533 } 534 535 } 536 | Popular Tags |