1 20 21 package org.apache.directory.ldapstudio.schemas.view.editors.objectClass; 22 23 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 import org.apache.directory.ldapstudio.schemas.Messages; 28 import org.apache.directory.ldapstudio.schemas.model.AttributeType; 29 import org.apache.directory.ldapstudio.schemas.model.LDAPModelEvent; 30 import org.apache.directory.ldapstudio.schemas.model.ObjectClass; 31 import org.apache.directory.ldapstudio.schemas.model.PoolListener; 32 import org.apache.directory.ldapstudio.schemas.model.Schema; 33 import org.apache.directory.ldapstudio.schemas.model.SchemaPool; 34 import org.apache.directory.ldapstudio.schemas.view.ViewUtils; 35 import org.apache.directory.ldapstudio.schemas.view.dialogs.AttributeTypeSelectionDialog; 36 import org.apache.directory.ldapstudio.schemas.view.dialogs.EditAliasesDialog; 37 import org.apache.directory.ldapstudio.schemas.view.dialogs.ObjectClassSelectionDialog; 38 import org.apache.directory.ldapstudio.schemas.view.editors.NonExistingAttributeType; 39 import org.apache.directory.ldapstudio.schemas.view.editors.NonExistingObjectClass; 40 import org.apache.directory.ldapstudio.schemas.view.editors.attributeType.AttributeTypeEditor; 41 import org.apache.directory.ldapstudio.schemas.view.editors.attributeType.AttributeTypeEditorInput; 42 import org.apache.directory.ldapstudio.schemas.view.editors.schema.SchemaEditor; 43 import org.apache.directory.ldapstudio.schemas.view.editors.schema.SchemaEditorInput; 44 import org.apache.directory.shared.asn1.primitives.OID; 45 import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum; 46 import org.apache.log4j.Logger; 47 import org.eclipse.jface.viewers.StructuredSelection; 48 import org.eclipse.jface.viewers.TableViewer; 49 import org.eclipse.jface.window.Window; 50 import org.eclipse.swt.SWT; 51 import org.eclipse.swt.events.ModifyEvent; 52 import org.eclipse.swt.events.ModifyListener; 53 import org.eclipse.swt.events.MouseAdapter; 54 import org.eclipse.swt.events.MouseEvent; 55 import org.eclipse.swt.events.MouseListener; 56 import org.eclipse.swt.events.SelectionAdapter; 57 import org.eclipse.swt.events.SelectionEvent; 58 import org.eclipse.swt.events.VerifyEvent; 59 import org.eclipse.swt.events.VerifyListener; 60 import org.eclipse.swt.layout.GridData; 61 import org.eclipse.swt.layout.GridLayout; 62 import org.eclipse.swt.widgets.Button; 63 import org.eclipse.swt.widgets.Combo; 64 import org.eclipse.swt.widgets.Composite; 65 import org.eclipse.swt.widgets.Label; 66 import org.eclipse.swt.widgets.Table; 67 import org.eclipse.swt.widgets.Text; 68 import org.eclipse.ui.IWorkbenchPage; 69 import org.eclipse.ui.PartInitException; 70 import org.eclipse.ui.PlatformUI; 71 import org.eclipse.ui.forms.IManagedForm; 72 import org.eclipse.ui.forms.editor.FormEditor; 73 import org.eclipse.ui.forms.editor.FormPage; 74 import org.eclipse.ui.forms.events.HyperlinkAdapter; 75 import org.eclipse.ui.forms.events.HyperlinkEvent; 76 import org.eclipse.ui.forms.widgets.FormToolkit; 77 import org.eclipse.ui.forms.widgets.Hyperlink; 78 import org.eclipse.ui.forms.widgets.ScrolledForm; 79 import org.eclipse.ui.forms.widgets.Section; 80 81 82 85 public class ObjectClassEditorOverviewPage extends FormPage implements PoolListener 86 { 87 88 public static final String ID = ObjectClassEditor.ID + "overviewPage"; 90 91 public static final String TITLE = Messages.getString( "ObjectClassEditorOverviewPage.Overview" ); 93 94 private ObjectClass originalObjectClass; 95 96 97 private ObjectClass modifiedObjectClass; 98 99 100 private SchemaPool schemaPool; 101 102 private Label aliasesLabel; 104 private Button aliasesButton; 105 private Text oidText; 106 private Hyperlink schemaLink; 107 private Label schemaLabel; 108 private Text descriptionText; 109 private Table superiorsTable; 110 private TableViewer superiorsTableViewer; 111 private Button addButtonSuperiorsTable; 112 private Button removeButtonSuperiorsTable; 113 private Combo classTypeCombo; 114 private Button obsoleteCheckbox; 115 private Table mandatoryAttributesTable; 116 private TableViewer mandatoryAttributesTableViewer; 117 private Button addButtonMandatoryTable; 118 private Button removeButtonMandatoryTable; 119 private Table optionalAttributesTable; 120 private TableViewer optionalAttributesTableViewer; 121 private Button addButtonOptionalTable; 122 private Button removeButtonOptionalTable; 123 124 126 private SelectionAdapter aliasesButtonListener = new SelectionAdapter() 127 { 128 public void widgetSelected( SelectionEvent e ) 129 { 130 EditAliasesDialog editDialog = new EditAliasesDialog( modifiedObjectClass.getNames() ); 131 if ( editDialog.open() != Window.OK ) 132 { 133 return; 134 } 135 if ( editDialog.isDirty() ) 136 { 137 modifiedObjectClass.setNames( editDialog.getAliases() ); 138 if ( ( modifiedObjectClass.getNames() != null ) && ( modifiedObjectClass.getNames().length != 0 ) ) 139 { 140 aliasesLabel.setText( ViewUtils.concateAliases( modifiedObjectClass.getNames() ) ); 141 } 142 else 143 { 144 aliasesLabel.setText( Messages.getString( "ObjectClassEditorOverviewPage.(None)" ) ); } 146 setEditorDirty(); 147 } 148 } 149 }; 150 151 152 private ModifyListener oidTextModifyListener = new ModifyListener() 153 { 154 public void modifyText( ModifyEvent e ) 155 { 156 oidText.setForeground( ViewUtils.COLOR_BLACK ); 157 oidText.setToolTipText( "" ); 159 String oid = oidText.getText(); 160 161 if ( OID.isOID( oid ) ) 162 { 163 if ( ( originalObjectClass.getOid().equals( oid ) ) || !( schemaPool.containsSchemaElement( oid ) ) ) 164 { 165 modifiedObjectClass.setOid( oid ); 166 setEditorDirty(); 167 } 168 else 169 { 170 oidText.setForeground( ViewUtils.COLOR_RED ); 171 oidText.setToolTipText( Messages 172 .getString( "ObjectClassEditorOverviewPage.An_element_with_same_oid_already_exists." ) ); } 174 } 175 else 176 { 177 oidText.setForeground( ViewUtils.COLOR_RED ); 178 oidText.setToolTipText( Messages.getString( "ObjectClassEditorOverviewPage.Malformed_OID." ) ); } 180 } 181 }; 182 183 184 private VerifyListener oidTextVerifyListener = new VerifyListener() 185 { 186 public void verifyText( VerifyEvent e ) 187 { 188 if ( !e.text.matches( "([0-9]*\\.?)*" ) ) { 190 e.doit = false; 191 } 192 } 193 }; 194 195 196 private HyperlinkAdapter schemaLinkListener = new HyperlinkAdapter() 197 { 198 public void linkActivated( HyperlinkEvent e ) 199 { 200 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); 201 202 SchemaEditorInput input = new SchemaEditorInput( modifiedObjectClass.getOriginatingSchema() ); 203 String editorId = SchemaEditor.ID; 204 try 205 { 206 page.openEditor( input, editorId ); 207 } 208 catch ( PartInitException exception ) 209 { 210 Logger.getLogger( AttributeTypeEditorInput.class ).debug( "error when opening the editor" ); } 212 } 213 }; 214 215 216 private ModifyListener descriptionTextListener = new ModifyListener() 217 { 218 public void modifyText( ModifyEvent e ) 219 { 220 int caretPosition = descriptionText.getCaretPosition(); 221 modifiedObjectClass.setDescription( descriptionText.getText() ); 222 descriptionText.setSelection( caretPosition ); 223 setEditorDirty(); 224 } 225 }; 226 227 228 private ModifyListener classTypeListener = new ModifyListener() 229 { 230 public void modifyText( ModifyEvent e ) 231 { 232 if ( classTypeCombo.getSelectionIndex() == 0 ) 233 { 234 modifiedObjectClass.setClassType( ObjectClassTypeEnum.ABSTRACT ); 235 } 236 else if ( classTypeCombo.getSelectionIndex() == 1 ) 237 { 238 modifiedObjectClass.setClassType( ObjectClassTypeEnum.AUXILIARY ); 239 } 240 else if ( classTypeCombo.getSelectionIndex() == 2 ) 241 { 242 modifiedObjectClass.setClassType( ObjectClassTypeEnum.STRUCTURAL ); 243 } 244 setEditorDirty(); 245 } 246 }; 247 248 249 private SelectionAdapter obsoleteListener = new SelectionAdapter() 250 { 251 public void widgetSelected( SelectionEvent e ) 252 { 253 modifiedObjectClass.setObsolete( obsoleteCheckbox.getSelection() ); 254 setEditorDirty(); 255 } 256 }; 257 258 259 private MouseListener mandatoryAttributesTableListener = new MouseListener() 260 { 261 public void mouseDoubleClick( MouseEvent e ) 262 { 263 StructuredSelection selection = ( StructuredSelection ) mandatoryAttributesTableViewer.getSelection(); 264 if ( selection.isEmpty() ) 265 { 266 return; 267 } 268 269 Object selectedElement = selection.getFirstElement(); 270 if ( selectedElement != null ) 271 { 272 if ( selectedElement instanceof AttributeType ) 273 { 274 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); 275 try 276 { 277 page.openEditor( new AttributeTypeEditorInput( ( AttributeType ) selectedElement ), 278 AttributeTypeEditor.ID ); 279 } 280 catch ( PartInitException exception ) 281 { 282 Logger.getLogger( ObjectClassEditorOverviewPage.class ).debug( "error when opening the editor" ); } 284 } 285 } 286 } 287 288 289 public void mouseDown( MouseEvent e ) 290 { 291 } 292 293 294 public void mouseUp( MouseEvent e ) 295 { 296 if ( modifiedObjectClass.getOriginatingSchema().type != Schema.SchemaType.coreSchema ) 297 { 298 removeButtonMandatoryTable.setEnabled( mandatoryAttributesTable.getSelection().length != 0 ); 299 } 300 } 301 }; 302 303 304 private SelectionAdapter addButtonMandatoryTableListener = new SelectionAdapter() 305 { 306 public void widgetSelected( SelectionEvent e ) 307 { 308 AttributeTypeSelectionDialog dialog = new AttributeTypeSelectionDialog(); 309 List <AttributeType> hiddenATs = new ArrayList <AttributeType>(); 310 for ( String must : modifiedObjectClass.getMust() ) 311 { 312 AttributeType at = schemaPool.getAttributeType( must ); 313 if ( at != null ) 314 { 315 hiddenATs.add( at ); 316 } 317 } 318 for ( String may : modifiedObjectClass.getMay() ) 319 { 320 AttributeType at = schemaPool.getAttributeType( may ); 321 if ( at != null ) 322 { 323 hiddenATs.add( at ); 324 } 325 } 326 dialog.setHiddenAttributeTypes( hiddenATs.toArray( new AttributeType[0] ) ); 327 328 if ( dialog.open() != Window.OK ) 329 { 330 return; 331 } 332 333 AttributeType at = dialog.getSelectedAttributeType(); 334 if ( at == null ) 335 { 336 return; 337 } 338 339 List <String > newMusts = new ArrayList <String >(); 340 String [] musts = modifiedObjectClass.getMust(); 341 for ( String must : musts ) 342 { 343 newMusts.add( must ); 344 } 345 newMusts.add( at.getNames()[0] ); 346 modifiedObjectClass.setMust( newMusts.toArray( new String [0] ) ); 347 348 fillInMandatoryAttributesTable(); 349 setEditorDirty(); 350 } 351 }; 352 353 354 private SelectionAdapter removeButtonMandatoryTableListener = new SelectionAdapter() 355 { 356 public void widgetSelected( SelectionEvent e ) 357 { 358 StructuredSelection selection = ( StructuredSelection ) mandatoryAttributesTableViewer.getSelection(); 359 if ( selection.isEmpty() ) 360 { 361 return; 362 } 363 364 Object selectedElement = selection.getFirstElement(); 365 if ( selectedElement != null ) 366 { 367 List <String > newMusts = new ArrayList <String >(); 368 String [] musts = modifiedObjectClass.getMust(); 369 for ( String must : musts ) 370 { 371 newMusts.add( must ); 372 } 373 374 if ( selectedElement instanceof AttributeType ) 375 { 376 for ( String name : ( ( AttributeType ) selectedElement ).getNames() ) 377 { 378 newMusts.remove( name ); 379 } 380 } 381 else if ( selectedElement instanceof NonExistingAttributeType ) 382 { 383 newMusts.remove( ( ( NonExistingAttributeType ) selectedElement ).getName() ); 384 } 385 386 modifiedObjectClass.setMust( newMusts.toArray( new String [0] ) ); 387 388 fillInMandatoryAttributesTable(); 389 addButtonMandatoryTable.setFocus(); 390 removeButtonMandatoryTable.setEnabled( mandatoryAttributesTable.getSelection().length != 0 ); 391 setEditorDirty(); 392 } 393 } 394 }; 395 396 397 private MouseListener optionalAttributesTableListener = new MouseAdapter() 398 { 399 public void mouseDoubleClick( MouseEvent e ) 400 { 401 StructuredSelection selection = ( StructuredSelection ) optionalAttributesTableViewer.getSelection(); 402 if ( selection.isEmpty() ) 403 { 404 return; 405 } 406 407 Object selectedElement = selection.getFirstElement(); 408 if ( selectedElement != null ) 409 { 410 if ( selectedElement instanceof AttributeType ) 411 { 412 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); 413 try 414 { 415 page.openEditor( new AttributeTypeEditorInput( ( AttributeType ) selectedElement ), 416 AttributeTypeEditor.ID ); 417 } 418 catch ( PartInitException exception ) 419 { 420 Logger.getLogger( ObjectClassEditorOverviewPage.class ).debug( "error when opening the editor" ); } 422 } 423 } 424 } 425 426 427 public void mouseUp( MouseEvent e ) 428 { 429 if ( modifiedObjectClass.getOriginatingSchema().type != Schema.SchemaType.coreSchema ) 430 { 431 removeButtonOptionalTable.setEnabled( optionalAttributesTable.getSelection().length != 0 ); 432 } 433 } 434 }; 435 436 437 private SelectionAdapter addButtonOptionalTableListener = new SelectionAdapter() 438 { 439 public void widgetSelected( SelectionEvent e ) 440 { 441 AttributeTypeSelectionDialog dialog = new AttributeTypeSelectionDialog(); 442 List <AttributeType> hiddenATs = new ArrayList <AttributeType>(); 443 for ( String must : modifiedObjectClass.getMust() ) 444 { 445 AttributeType at = schemaPool.getAttributeType( must ); 446 if ( at != null ) 447 { 448 hiddenATs.add( at ); 449 } 450 } 451 for ( String may : modifiedObjectClass.getMay() ) 452 { 453 AttributeType at = schemaPool.getAttributeType( may ); 454 if ( at != null ) 455 { 456 hiddenATs.add( at ); 457 } 458 } 459 dialog.setHiddenAttributeTypes( hiddenATs.toArray( new AttributeType[0] ) ); 460 461 if ( dialog.open() != Window.OK ) 462 { 463 return; 464 } 465 466 AttributeType at = dialog.getSelectedAttributeType(); 467 if ( at == null ) 468 { 469 return; 470 } 471 472 List <String > newMays = new ArrayList <String >(); 473 String [] mays = modifiedObjectClass.getMay(); 474 for ( String may : mays ) 475 { 476 newMays.add( may ); 477 } 478 newMays.add( at.getNames()[0] ); 479 modifiedObjectClass.setMay( newMays.toArray( new String [0] ) ); 480 481 fillInOptionalAttributesTable(); 482 setEditorDirty(); 483 } 484 }; 485 486 487 private SelectionAdapter removeButtonOptionalTableListener = new SelectionAdapter() 488 { 489 public void widgetSelected( SelectionEvent e ) 490 { 491 StructuredSelection selection = ( StructuredSelection ) optionalAttributesTableViewer.getSelection(); 492 if ( selection.isEmpty() ) 493 { 494 return; 495 } 496 497 Object selectedElement = selection.getFirstElement(); 498 if ( selectedElement != null ) 499 { 500 List <String > newMays = new ArrayList <String >(); 501 String [] mays = modifiedObjectClass.getMay(); 502 for ( String may : mays ) 503 { 504 newMays.add( may ); 505 } 506 507 if ( selectedElement instanceof AttributeType ) 508 { 509 for ( String name : ( ( AttributeType ) selectedElement ).getNames() ) 510 { 511 newMays.remove( name ); 512 } 513 } 514 else if ( selectedElement instanceof NonExistingAttributeType ) 515 { 516 newMays.remove( ( ( NonExistingAttributeType ) selectedElement ).getName() ); 517 } 518 519 modifiedObjectClass.setMay( newMays.toArray( new String [0] ) ); 520 521 fillInOptionalAttributesTable(); 522 addButtonOptionalTable.setFocus(); 523 removeButtonOptionalTable.setEnabled( optionalAttributesTable.getSelection().length != 0 ); 524 setEditorDirty(); 525 } 526 } 527 }; 528 529 530 private MouseListener superiorsTableListener = new MouseAdapter() 531 { 532 public void mouseDoubleClick( MouseEvent e ) 533 { 534 StructuredSelection selection = ( StructuredSelection ) superiorsTableViewer.getSelection(); 535 if ( selection.isEmpty() ) 536 { 537 return; 538 } 539 540 Object selectedElement = selection.getFirstElement(); 541 if ( selectedElement != null ) 542 { 543 if ( selectedElement instanceof ObjectClass ) 544 { 545 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); 546 try 547 { 548 page.openEditor( new ObjectClassEditorInput( ( ObjectClass ) selectedElement ), 549 ObjectClassEditor.ID ); 550 } 551 catch ( PartInitException exception ) 552 { 553 Logger.getLogger( ObjectClassEditorOverviewPage.class ).debug( "error when opening the editor" ); } 555 } 556 } 557 } 558 559 560 public void mouseUp( MouseEvent e ) 561 { 562 if ( modifiedObjectClass.getOriginatingSchema().type != Schema.SchemaType.coreSchema ) 563 { 564 removeButtonSuperiorsTable.setEnabled( superiorsTable.getSelection().length != 0 ); 565 } 566 } 567 }; 568 569 570 private SelectionAdapter addButtonSuperiorsTableListener = new SelectionAdapter() 571 { 572 public void widgetSelected( SelectionEvent e ) 573 { 574 ObjectClassSelectionDialog dialog = new ObjectClassSelectionDialog(); 575 List <ObjectClass> hiddenOCs = new ArrayList <ObjectClass>(); 576 for ( String sup : modifiedObjectClass.getSuperiors() ) 577 { 578 ObjectClass oc = schemaPool.getObjectClass( sup ); 579 if ( oc != null ) 580 { 581 hiddenOCs.add( oc ); 582 } 583 } 584 hiddenOCs.add( originalObjectClass ); 585 dialog.setHiddenObjectClasses( hiddenOCs.toArray( new ObjectClass[0] ) ); 586 587 if ( dialog.open() != Window.OK ) 588 { 589 return; 590 } 591 592 ObjectClass oc = dialog.getSelectedObjectClass(); 593 if ( oc == null ) 594 { 595 return; 596 } 597 598 List <String > superiors = new ArrayList <String >(); 599 String [] sups = modifiedObjectClass.getSuperiors(); 600 for ( String sup : sups ) 601 { 602 superiors.add( sup ); 603 } 604 superiors.add( oc.getNames()[0] ); 605 modifiedObjectClass.setSuperiors( superiors.toArray( new String [0] ) ); 606 607 fillInSuperiorsTable(); 608 setEditorDirty(); 609 } 610 }; 611 612 613 private SelectionAdapter removeButtonSuperiorsTableListener = new SelectionAdapter() 614 { 615 public void widgetSelected( SelectionEvent e ) 616 { 617 StructuredSelection selection = ( StructuredSelection ) superiorsTableViewer.getSelection(); 618 if ( selection.isEmpty() ) 619 { 620 return; 621 } 622 623 Object selectedElement = selection.getFirstElement(); 624 if ( selectedElement != null ) 625 { 626 List <String > superiors = new ArrayList <String >(); 627 String [] sups = modifiedObjectClass.getSuperiors(); 628 for ( String sup : sups ) 629 { 630 superiors.add( sup ); 631 } 632 633 if ( selectedElement instanceof ObjectClass ) 634 { 635 for ( String name : ( ( ObjectClass ) selectedElement ).getNames() ) 636 { 637 superiors.remove( name ); 638 } 639 } 640 else if ( selectedElement instanceof NonExistingObjectClass ) 641 { 642 superiors.remove( ( ( NonExistingObjectClass ) selectedElement ).getName() ); 643 } 644 645 modifiedObjectClass.setSuperiors( superiors.toArray( new String [0] ) ); 646 647 fillInSuperiorsTable(); 648 addButtonSuperiorsTable.setFocus(); 649 removeButtonSuperiorsTable.setEnabled( superiorsTable.getSelection().length != 0 ); 650 setEditorDirty(); 651 } 652 } 653 }; 654 655 656 661 public ObjectClassEditorOverviewPage( FormEditor editor ) 662 { 663 super( editor, ID, TITLE ); 664 schemaPool = SchemaPool.getInstance(); 665 schemaPool.addListener( this ); 666 } 667 668 669 672 protected void createFormContent( IManagedForm managedForm ) 673 { 674 modifiedObjectClass = ( ( ObjectClassEditor ) getEditor() ).getModifiedObjectClass(); 676 originalObjectClass = ( ( ObjectClassEditor ) getEditor() ).getOriginalObjectClass(); 677 678 ScrolledForm form = managedForm.getForm(); 680 FormToolkit toolkit = managedForm.getToolkit(); 681 form.getBody().setLayout( new GridLayout() ); 682 683 createGeneralInformationSection( form.getBody(), toolkit ); 685 686 Composite bottomComposite = toolkit.createComposite( form.getBody() ); 687 bottomComposite.setLayout( new GridLayout( 2, true ) ); 688 bottomComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 689 690 createMandatoryAttributesSection( bottomComposite, toolkit ); 692 693 createOptionalAttributesSection( bottomComposite, toolkit ); 695 696 setFieldsEditableState(); 698 699 fillInUiFields(); 701 702 addListeners(); 704 } 705 706 707 715 private void createGeneralInformationSection( Composite parent, FormToolkit toolkit ) 716 { 717 Section section_general_information = toolkit.createSection( parent, Section.DESCRIPTION | Section.TITLE_BAR ); 719 section_general_information.setDescription( Messages 720 .getString( "ObjectClassEditorOverviewPage.General_Information_Section_Description" ) ); section_general_information.setText( Messages 722 .getString( "ObjectClassEditorOverviewPage.General_Information_Section_Text" ) ); section_general_information.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, true ) ); 724 725 Composite client_general_information = toolkit.createComposite( section_general_information ); 727 client_general_information.setLayout( new GridLayout( 3, false ) ); 728 toolkit.paintBordersFor( client_general_information ); 729 section_general_information.setClient( client_general_information ); 730 731 toolkit.createLabel( client_general_information, Messages.getString( "ObjectClassEditorOverviewPage.Aliases" ) ); aliasesLabel = toolkit.createLabel( client_general_information, "" ); aliasesLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); 735 toolkit.createLabel( client_general_information, "" ); aliasesButton = toolkit.createButton( client_general_information, Messages 737 .getString( "ObjectClassEditorOverviewPage.Edit_Aliases" ), SWT.PUSH ); aliasesButton.setLayoutData( new GridData( SWT.NONE, SWT.NONE, false, false, 2, 1 ) ); 739 740 toolkit.createLabel( client_general_information, Messages.getString( "ObjectClassEditorOverviewPage.OID" ) ); oidText = toolkit.createText( client_general_information, "" ); oidText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); 744 745 schemaLink = toolkit.createHyperlink( client_general_information, Messages 747 .getString( "ObjectClassEditorOverviewPage.Schema" ), SWT.WRAP ); schemaLabel = toolkit.createLabel( client_general_information, "" ); schemaLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); 750 751 toolkit.createLabel( client_general_information, Messages 753 .getString( "ObjectClassEditorOverviewPage.Description" ) ); descriptionText = toolkit.createText( client_general_information, "", SWT.MULTI | SWT.V_SCROLL ); GridData descriptionGridData = new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ); 756 descriptionGridData.heightHint = 42; 757 descriptionText.setLayoutData( descriptionGridData ); 758 759 toolkit.createLabel( client_general_information, Messages 761 .getString( "ObjectClassEditorOverviewPage.Superior_classes" ) ); superiorsTable = toolkit.createTable( client_general_information, SWT.SINGLE | SWT.V_SCROLL ); 763 GridData gridData = new GridData( SWT.FILL, SWT.NONE, true, false ); 764 gridData.heightHint = 45; 765 gridData.minimumHeight = 45; 766 superiorsTable.setLayoutData( gridData ); 767 superiorsTableViewer = new TableViewer( superiorsTable ); 768 superiorsTableViewer.setContentProvider( new ObjectClassEditorSuperiorsTableContentProvider() ); 769 superiorsTableViewer.setLabelProvider( new ObjectClassEditorSuperiorsTableLabelProvider() ); 770 Composite superiorsButtonComposite = toolkit.createComposite( client_general_information ); 771 superiorsButtonComposite.setLayout( new GridLayout() ); 772 addButtonSuperiorsTable = toolkit.createButton( superiorsButtonComposite, Messages 773 .getString( "ObjectClassEditorOverviewPage.Add..." ), SWT.PUSH ); addButtonSuperiorsTable.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false ) ); 775 removeButtonSuperiorsTable = toolkit.createButton( superiorsButtonComposite, Messages 776 .getString( "ObjectClassEditorOverviewPage.Remove" ), SWT.PUSH ); removeButtonSuperiorsTable.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false ) ); 778 779 toolkit.createLabel( client_general_information, Messages 781 .getString( "ObjectClassEditorOverviewPage.Class_type" ) ); classTypeCombo = new Combo( client_general_information, SWT.READ_ONLY | SWT.SINGLE ); 783 classTypeCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); 784 initClassTypeCombo(); 785 786 toolkit.createLabel( client_general_information, "" ); obsoleteCheckbox = toolkit.createButton( client_general_information, Messages 789 .getString( "ObjectClassEditorOverviewPage.Obsolete" ), SWT.CHECK ); obsoleteCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); 791 } 792 793 794 802 private void createMandatoryAttributesSection( Composite parent, FormToolkit toolkit ) 803 { 804 Section section = toolkit.createSection( parent, Section.DESCRIPTION | Section.TITLE_BAR ); 806 section.setText( Messages.getString( "ObjectClassEditorOverviewPage.Mandatory_Attribute_Section_Text" ) ); section.setDescription( Messages 808 .getString( "ObjectClassEditorOverviewPage.Mandatory_Attribute_Section_Description" ) ); section.setExpanded( true ); 810 Composite client = toolkit.createComposite( section ); 811 section.setClient( client ); 812 GridData gd = new GridData( SWT.FILL, SWT.NONE, true, false ); 813 section.setLayoutData( gd ); 814 toolkit.paintBordersFor( client ); 815 816 GridLayout layout = new GridLayout(); 817 layout.numColumns = 2; 818 client.setLayout( layout ); 819 820 mandatoryAttributesTable = toolkit.createTable( client, SWT.NULL ); 821 gd = new GridData( SWT.FILL, SWT.NONE, true, false ); 822 gd.verticalSpan = 2; 823 gd.heightHint = 108; 824 mandatoryAttributesTable.setLayoutData( gd ); 825 mandatoryAttributesTableViewer = new TableViewer( mandatoryAttributesTable ); 826 mandatoryAttributesTableViewer.setContentProvider( new ObjectClassEditorAttributesTableContentProvider() ); 827 mandatoryAttributesTableViewer.setLabelProvider( new ObjectClassEditorAttributesTableLabelProvider() ); 828 829 addButtonMandatoryTable = toolkit.createButton( client, Messages 830 .getString( "ObjectClassEditorOverviewPage.Add..." ), SWT.PUSH ); removeButtonMandatoryTable = toolkit.createButton( client, Messages 832 .getString( "ObjectClassEditorOverviewPage.Remove" ), SWT.PUSH ); gd = new GridData( GridData.VERTICAL_ALIGN_BEGINNING ); 834 addButtonMandatoryTable.setLayoutData( gd ); 835 removeButtonMandatoryTable.setLayoutData( gd ); 836 837 removeButtonMandatoryTable.setEnabled( false ); 839 } 840 841 842 850 private void createOptionalAttributesSection( Composite parent, FormToolkit toolkit ) 851 { 852 Section section = toolkit.createSection( parent, Section.DESCRIPTION | Section.TITLE_BAR ); 854 section.setText( Messages.getString( "ObjectClassEditorOverviewPage.Optionnal_Attributes_Section_Text" ) ); section.setDescription( Messages 856 .getString( "ObjectClassEditorOverviewPage.Optionnal_Attributes_Section_Description" ) ); section.setExpanded( true ); 858 Composite client = toolkit.createComposite( section ); 859 section.setClient( client ); 860 GridData gd = new GridData( SWT.FILL, SWT.NONE, true, false ); 861 section.setLayoutData( gd ); 862 toolkit.paintBordersFor( client ); 863 864 GridLayout layout = new GridLayout(); 865 layout.numColumns = 2; 866 client.setLayout( layout ); 867 868 optionalAttributesTable = toolkit.createTable( client, SWT.SINGLE | SWT.V_SCROLL ); 869 gd = new GridData( SWT.FILL, SWT.NONE, true, false ); 870 gd.verticalSpan = 2; 871 gd.heightHint = 108; 872 optionalAttributesTable.setLayoutData( gd ); 873 optionalAttributesTableViewer = new TableViewer( optionalAttributesTable ); 874 optionalAttributesTableViewer.setContentProvider( new ObjectClassEditorAttributesTableContentProvider() ); 875 optionalAttributesTableViewer.setLabelProvider( new ObjectClassEditorAttributesTableLabelProvider() ); 876 877 addButtonOptionalTable = toolkit.createButton( client, Messages 878 .getString( "ObjectClassEditorOverviewPage.Add..." ), SWT.PUSH ); removeButtonOptionalTable = toolkit.createButton( client, Messages 880 .getString( "ObjectClassEditorOverviewPage.Remove" ), SWT.PUSH ); gd = new GridData( GridData.VERTICAL_ALIGN_BEGINNING ); 882 addButtonOptionalTable.setLayoutData( gd ); 883 removeButtonOptionalTable.setLayoutData( gd ); 884 885 removeButtonOptionalTable.setEnabled( false ); 887 } 888 889 890 893 private void fillInUiFields() 894 { 895 if ( ( modifiedObjectClass.getNames() != null ) && ( modifiedObjectClass.getNames().length != 0 ) ) 897 { 898 aliasesLabel.setText( ViewUtils.concateAliases( modifiedObjectClass.getNames() ) ); 899 } 900 else 901 { 902 aliasesLabel.setText( Messages.getString( "ObjectClassEditorOverviewPage.(None)" ) ); } 904 905 if ( modifiedObjectClass.getOid() != null ) 907 { 908 oidText.setText( modifiedObjectClass.getOid() ); 909 } 910 911 if ( modifiedObjectClass.getOriginatingSchema() != null ) 913 { 914 this.schemaLabel.setText( modifiedObjectClass.getOriginatingSchema().getName() ); 915 } 916 917 if ( modifiedObjectClass.getDescription() != null ) 919 { 920 descriptionText.setText( modifiedObjectClass.getDescription() ); 921 } 922 923 fillInSuperiorsTable(); 925 926 fillInClassType(); 928 929 obsoleteCheckbox.setSelection( modifiedObjectClass.isObsolete() ); 931 932 fillInMandatoryAttributesTable(); 934 935 fillInOptionalAttributesTable(); 937 } 938 939 940 943 private void fillInSuperiorsTable() 944 { 945 superiorsTableViewer.setInput( modifiedObjectClass.getSuperiors() ); 946 } 947 948 949 952 private void initClassTypeCombo() 953 { 954 classTypeCombo.add( Messages.getString( "ObjectClassEditorOverviewPage.Abstract" ), 0 ); classTypeCombo.add( Messages.getString( "ObjectClassEditorOverviewPage.Auxiliary" ), 1 ); classTypeCombo.add( Messages.getString( "ObjectClassEditorOverviewPage.Structural" ), 2 ); } 958 959 960 963 private void fillInClassType() 964 { 965 if ( modifiedObjectClass.getClassType() == ObjectClassTypeEnum.ABSTRACT ) 966 { 967 classTypeCombo.select( 0 ); 968 } 969 else if ( modifiedObjectClass.getClassType() == ObjectClassTypeEnum.AUXILIARY ) 970 { 971 classTypeCombo.select( 1 ); 972 } 973 else if ( modifiedObjectClass.getClassType() == ObjectClassTypeEnum.STRUCTURAL ) 974 { 975 classTypeCombo.select( 2 ); 976 } 977 } 978 979 980 983 private void fillInMandatoryAttributesTable() 984 { 985 mandatoryAttributesTableViewer.setInput( modifiedObjectClass.getMust() ); 986 } 987 988 989 992 private void fillInOptionalAttributesTable() 993 { 994 optionalAttributesTableViewer.setInput( modifiedObjectClass.getMay() ); 995 } 996 997 998 1001 private void setFieldsEditableState() 1002 { 1003 if ( modifiedObjectClass.getOriginatingSchema().type == Schema.SchemaType.coreSchema ) 1004 { 1005 aliasesButton.setEnabled( false ); 1007 oidText.setEditable( false ); 1008 descriptionText.setEditable( false ); 1009 addButtonSuperiorsTable.setEnabled( false ); 1010 removeButtonSuperiorsTable.setEnabled( false ); 1011 classTypeCombo.setEnabled( false ); 1012 obsoleteCheckbox.setEnabled( false ); 1013 addButtonMandatoryTable.setEnabled( false ); 1014 removeButtonMandatoryTable.setEnabled( false ); 1015 addButtonOptionalTable.setEnabled( false ); 1016 removeButtonOptionalTable.setEnabled( false ); 1017 } 1018 else 1019 { 1020 removeButtonSuperiorsTable.setEnabled( superiorsTable.getSelectionIndex() != -1 ); 1021 removeButtonMandatoryTable.setEnabled( mandatoryAttributesTable.getSelectionIndex() != -1 ); 1022 removeButtonOptionalTable.setEnabled( optionalAttributesTable.getSelectionIndex() != -1 ); 1023 } 1024 } 1025 1026 1027 1030 private void addListeners() 1031 { 1032 if ( modifiedObjectClass.getOriginatingSchema().type == Schema.SchemaType.userSchema ) 1033 { 1034 aliasesButton.addSelectionListener( aliasesButtonListener ); 1035 oidText.addModifyListener( oidTextModifyListener ); 1036 oidText.addVerifyListener( oidTextVerifyListener ); 1037 descriptionText.addModifyListener( descriptionTextListener ); 1038 addButtonSuperiorsTable.addSelectionListener( addButtonSuperiorsTableListener ); 1039 removeButtonSuperiorsTable.addSelectionListener( removeButtonSuperiorsTableListener ); 1040 classTypeCombo.addModifyListener( classTypeListener ); 1041 obsoleteCheckbox.addSelectionListener( obsoleteListener ); 1042 addButtonMandatoryTable.addSelectionListener( addButtonMandatoryTableListener ); 1043 removeButtonMandatoryTable.addSelectionListener( removeButtonMandatoryTableListener ); 1044 addButtonOptionalTable.addSelectionListener( addButtonOptionalTableListener ); 1045 removeButtonOptionalTable.addSelectionListener( removeButtonOptionalTableListener ); 1046 } 1047 1048 schemaLink.addHyperlinkListener( schemaLinkListener ); 1049 1050 superiorsTable.addMouseListener( superiorsTableListener ); 1052 1053 mandatoryAttributesTable.addMouseListener( mandatoryAttributesTableListener ); 1055 1056 optionalAttributesTable.addMouseListener( optionalAttributesTableListener ); 1058 } 1059 1060 1061 1064 private void removeListeners() 1065 { 1066 aliasesButton.removeSelectionListener( aliasesButtonListener ); 1067 oidText.removeModifyListener( oidTextModifyListener ); 1068 oidText.removeVerifyListener( oidTextVerifyListener ); 1069 schemaLink.removeHyperlinkListener( schemaLinkListener ); 1070 descriptionText.removeModifyListener( descriptionTextListener ); 1071 superiorsTable.removeMouseListener( superiorsTableListener ); 1072 addButtonSuperiorsTable.removeSelectionListener( addButtonSuperiorsTableListener ); 1073 removeButtonSuperiorsTable.removeSelectionListener( removeButtonSuperiorsTableListener ); 1074 classTypeCombo.removeModifyListener( classTypeListener ); 1075 obsoleteCheckbox.removeSelectionListener( obsoleteListener ); 1076 mandatoryAttributesTable.removeMouseListener( mandatoryAttributesTableListener ); 1077 addButtonMandatoryTable.removeSelectionListener( addButtonMandatoryTableListener ); 1078 removeButtonMandatoryTable.removeSelectionListener( removeButtonMandatoryTableListener ); 1079 optionalAttributesTable.removeMouseListener( optionalAttributesTableListener ); 1080 addButtonOptionalTable.removeSelectionListener( addButtonOptionalTableListener ); 1081 removeButtonOptionalTable.removeSelectionListener( removeButtonOptionalTableListener ); 1082 } 1083 1084 1085 1088 private void setEditorDirty() 1089 { 1090 ( ( ObjectClassEditor ) getEditor() ).setDirty( true ); 1091 } 1092 1093 1094 1097 public void refreshUI() 1098 { 1099 removeListeners(); 1100 fillInUiFields(); 1101 addListeners(); 1102 setFieldsEditableState(); 1103 } 1104 1105 1106 1109 public void poolChanged( SchemaPool p, LDAPModelEvent e ) 1110 { 1111 removeListeners(); 1112 fillInSuperiorsTable(); 1113 fillInMandatoryAttributesTable(); 1114 fillInOptionalAttributesTable(); 1115 addListeners(); 1116 setFieldsEditableState(); 1117 } 1118 1119 1120 1123 public void dispose() 1124 { 1125 schemaPool.removeListener( this ); 1126 removeListeners(); 1127 1128 super.dispose(); 1129 } 1130} 1131 | Popular Tags |