1 20 21 package org.apache.directory.ldapstudio.schemas.view.editors.attributeType; 22 23 24 import org.apache.directory.ldapstudio.schemas.Messages; 25 import org.apache.directory.ldapstudio.schemas.model.AttributeType; 26 import org.apache.directory.ldapstudio.schemas.model.LDAPModelEvent; 27 import org.apache.directory.ldapstudio.schemas.model.MatchingRule; 28 import org.apache.directory.ldapstudio.schemas.model.MatchingRules; 29 import org.apache.directory.ldapstudio.schemas.model.PoolListener; 30 import org.apache.directory.ldapstudio.schemas.model.Schema; 31 import org.apache.directory.ldapstudio.schemas.model.SchemaPool; 32 import org.apache.directory.ldapstudio.schemas.model.Syntax; 33 import org.apache.directory.ldapstudio.schemas.model.Syntaxes; 34 import org.apache.directory.ldapstudio.schemas.view.ViewUtils; 35 import org.apache.directory.ldapstudio.schemas.view.dialogs.EditAliasesDialog; 36 import org.apache.directory.ldapstudio.schemas.view.editors.NonExistingAttributeType; 37 import org.apache.directory.ldapstudio.schemas.view.editors.schema.SchemaEditor; 38 import org.apache.directory.ldapstudio.schemas.view.editors.schema.SchemaEditorInput; 39 import org.apache.directory.shared.asn1.primitives.OID; 40 import org.apache.directory.shared.ldap.schema.UsageEnum; 41 import org.apache.log4j.Logger; 42 import org.eclipse.jface.viewers.ComboViewer; 43 import org.eclipse.jface.viewers.StructuredSelection; 44 import org.eclipse.jface.window.Window; 45 import org.eclipse.swt.SWT; 46 import org.eclipse.swt.events.ModifyEvent; 47 import org.eclipse.swt.events.ModifyListener; 48 import org.eclipse.swt.events.SelectionAdapter; 49 import org.eclipse.swt.events.SelectionEvent; 50 import org.eclipse.swt.events.VerifyEvent; 51 import org.eclipse.swt.events.VerifyListener; 52 import org.eclipse.swt.layout.GridData; 53 import org.eclipse.swt.layout.GridLayout; 54 import org.eclipse.swt.widgets.Button; 55 import org.eclipse.swt.widgets.Combo; 56 import org.eclipse.swt.widgets.Composite; 57 import org.eclipse.swt.widgets.Label; 58 import org.eclipse.swt.widgets.Text; 59 import org.eclipse.ui.IWorkbenchPage; 60 import org.eclipse.ui.PartInitException; 61 import org.eclipse.ui.PlatformUI; 62 import org.eclipse.ui.forms.IManagedForm; 63 import org.eclipse.ui.forms.editor.FormEditor; 64 import org.eclipse.ui.forms.editor.FormPage; 65 import org.eclipse.ui.forms.events.HyperlinkAdapter; 66 import org.eclipse.ui.forms.events.HyperlinkEvent; 67 import org.eclipse.ui.forms.widgets.FormToolkit; 68 import org.eclipse.ui.forms.widgets.Hyperlink; 69 import org.eclipse.ui.forms.widgets.ScrolledForm; 70 import org.eclipse.ui.forms.widgets.Section; 71 72 73 76 public class AttributeTypeEditorOverviewPage extends FormPage implements PoolListener 77 { 78 79 public static final String ID = AttributeTypeEditor.ID + ".overviewPage"; 81 82 public static String TITLE = Messages.getString( "AttributeTypeEditorOverviewPage.Overview" ); 84 85 private AttributeType originalAttributeType; 86 87 88 private AttributeType modifiedAttributeType; 89 90 91 private SchemaPool schemaPool; 92 93 private Label aliasesLabel; 95 private Button aliasesButton; 96 private Text oidText; 97 private Hyperlink schemaLink; 98 private Label schemaLabel; 99 private Text descriptionText; 100 private Hyperlink supLabel; 101 private Combo supCombo; 102 private ComboViewer supComboViewer; 103 private Combo usageCombo; 104 private Combo syntaxCombo; 105 private ComboViewer syntaxComboViewer; 106 private Text syntaxLengthText; 107 private Button obsoleteCheckbox; 108 private Button singleValueCheckbox; 109 private Button collectiveCheckbox; 110 private Button noUserModificationCheckbox; 111 private Combo equalityCombo; 112 private ComboViewer equalityComboViewer; 113 private Combo orderingCombo; 114 private ComboViewer orderingComboViewer; 115 private Combo substringCombo; 116 private ComboViewer substringComboViewer; 117 118 120 private SelectionAdapter aliasesButtonListener = new SelectionAdapter() 121 { 122 public void widgetSelected( SelectionEvent e ) 123 { 124 EditAliasesDialog editDialog = new EditAliasesDialog( modifiedAttributeType.getNames() ); 125 if ( editDialog.open() != Window.OK ) 126 { 127 return; 128 } 129 if ( editDialog.isDirty() ) 130 { 131 modifiedAttributeType.setNames( editDialog.getAliases() ); 132 if ( ( modifiedAttributeType.getNames() != null ) && ( modifiedAttributeType.getNames().length != 0 ) ) 133 { 134 aliasesLabel.setText( ViewUtils.concateAliases( modifiedAttributeType.getNames() ) ); 135 } 136 else 137 { 138 aliasesLabel.setText( Messages.getString( "AttributeTypeEditorOverviewPage.(None)" ) ); } 140 setEditorDirty(); 141 } 142 } 143 }; 144 145 146 private ModifyListener oidTextModifyListener = new ModifyListener() 147 { 148 public void modifyText( ModifyEvent e ) 149 { 150 oidText.setForeground( ViewUtils.COLOR_BLACK ); 151 oidText.setToolTipText( "" ); 153 String oid = oidText.getText(); 154 155 if ( OID.isOID( oid ) ) 156 { 157 if ( ( originalAttributeType.getOid().equals( oid ) ) || !( schemaPool.containsSchemaElement( oid ) ) ) 158 { 159 modifiedAttributeType.setOid( oid ); 160 setEditorDirty(); 161 } 162 else 163 { 164 oidText.setForeground( ViewUtils.COLOR_RED ); 165 oidText.setToolTipText( Messages 166 .getString( "AttributeTypeEditorOverviewPage.An_element_with_same_oid_already_exists." ) ); } 168 } 169 else 170 { 171 oidText.setForeground( ViewUtils.COLOR_RED ); 172 oidText.setToolTipText( Messages.getString( "AttributeTypeEditorOverviewPage.Malformed_OID." ) ); } 174 } 175 }; 176 177 178 private VerifyListener oidTextVerifyListener = new VerifyListener() 179 { 180 public void verifyText( VerifyEvent e ) 181 { 182 if ( !e.text.matches( "([0-9]*\\.?)*" ) ) { 184 e.doit = false; 185 } 186 } 187 }; 188 189 190 private HyperlinkAdapter schemaLinkListener = new HyperlinkAdapter() 191 { 192 public void linkActivated( HyperlinkEvent e ) 193 { 194 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); 195 196 SchemaEditorInput input = new SchemaEditorInput( modifiedAttributeType.getOriginatingSchema() ); 197 String editorId = SchemaEditor.ID; 198 try 199 { 200 page.openEditor( input, editorId ); 201 } 202 catch ( PartInitException exception ) 203 { 204 Logger.getLogger( AttributeTypeEditorInput.class ).debug( "error when opening the editor" ); } 206 } 207 }; 208 209 210 private ModifyListener descriptionTextListener = new ModifyListener() 211 { 212 public void modifyText( ModifyEvent e ) 213 { 214 int caretPosition = descriptionText.getCaretPosition(); 215 modifiedAttributeType.setDescription( descriptionText.getText() ); 216 descriptionText.setSelection( caretPosition ); 217 setEditorDirty(); 218 } 219 }; 220 221 222 private HyperlinkAdapter supLabelListener = new HyperlinkAdapter() 223 { 224 public void linkActivated( HyperlinkEvent e ) 225 { 226 Object selectedItem = ( ( StructuredSelection ) supComboViewer.getSelection() ).getFirstElement(); 227 228 if ( selectedItem instanceof AttributeType ) 229 { 230 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); 231 232 AttributeTypeEditorInput input = new AttributeTypeEditorInput( ( AttributeType ) selectedItem ); 233 try 234 { 235 page.openEditor( input, AttributeTypeEditor.ID ); 236 } 237 catch ( PartInitException exception ) 238 { 239 Logger.getLogger( AttributeTypeEditorInput.class ).debug( "error when opening the editor" ); } 241 } 242 } 243 }; 244 245 246 private ModifyListener supComboListener = new ModifyListener() 247 { 248 public void modifyText( ModifyEvent e ) 249 { 250 Object selectedItem = ( ( StructuredSelection ) supComboViewer.getSelection() ).getFirstElement(); 251 252 if ( selectedItem instanceof AttributeType ) 253 { 254 modifiedAttributeType.setSuperior( ( ( AttributeType ) selectedItem ).getNames()[0] ); 255 } 256 else if ( selectedItem instanceof NonExistingAttributeType ) 257 { 258 NonExistingAttributeType neat = ( NonExistingAttributeType ) selectedItem; 259 260 if ( NonExistingAttributeType.NONE.equals( neat.getName() ) ) 261 { 262 modifiedAttributeType.setSuperior( null ); 263 } 264 else 265 { 266 modifiedAttributeType.setSuperior( ( ( NonExistingAttributeType ) selectedItem ).getName() ); 267 } 268 } 269 setEditorDirty(); 270 } 271 }; 272 273 274 private ModifyListener usageComboListener = new ModifyListener() 275 { 276 public void modifyText( ModifyEvent e ) 277 { 278 if ( usageCombo.getSelectionIndex() == 0 ) 279 { 280 modifiedAttributeType.setUsage( UsageEnum.DIRECTORY_OPERATION ); 281 } 282 else if ( usageCombo.getSelectionIndex() == 1 ) 283 { 284 modifiedAttributeType.setUsage( UsageEnum.DISTRIBUTED_OPERATION ); 285 } 286 else if ( usageCombo.getSelectionIndex() == 2 ) 287 { 288 modifiedAttributeType.setUsage( UsageEnum.DSA_OPERATION ); 289 } 290 else if ( usageCombo.getSelectionIndex() == 3 ) 291 { 292 modifiedAttributeType.setUsage( UsageEnum.USER_APPLICATIONS ); 293 } 294 setEditorDirty(); 295 } 296 }; 297 298 299 private ModifyListener syntaxComboListener = new ModifyListener() 300 { 301 public void modifyText( ModifyEvent e ) 302 { 303 Object selectedItem = ( ( StructuredSelection ) syntaxComboViewer.getSelection() ).getFirstElement(); 304 305 if ( selectedItem instanceof Syntax ) 306 { 307 modifiedAttributeType.setSyntax( ( ( Syntax ) selectedItem ).getOid() ); 308 } 309 else if ( selectedItem instanceof NonExistingSyntax ) 310 { 311 NonExistingSyntax nes = ( NonExistingSyntax ) selectedItem; 312 313 if ( NonExistingMatchingRule.NONE.equals( nes.getName() ) ) 314 { 315 modifiedAttributeType.setSyntax( null ); 316 } 317 else 318 { 319 modifiedAttributeType.setSyntax( ( ( NonExistingSyntax ) selectedItem ).getName() ); 320 } 321 } 322 setEditorDirty(); 323 } 324 }; 325 326 327 private ModifyListener syntaxLengthTextModifyListener = new ModifyListener() 328 { 329 public void modifyText( ModifyEvent e ) 330 { 331 if ( syntaxLengthText.getText().length() == 0 ) 332 { 333 modifiedAttributeType.setLength( -1 ); 334 } 335 else 336 { 337 modifiedAttributeType.setLength( Integer.parseInt( syntaxLengthText.getText() ) ); 338 } 339 setEditorDirty(); 340 } 341 }; 342 343 344 private VerifyListener syntaxLengthTextVerifyListener = new VerifyListener() 345 { 346 public void verifyText( VerifyEvent e ) 347 { 348 if ( !e.text.matches( "[0-9]*" ) ) { 350 e.doit = false; 351 } 352 } 353 }; 354 355 356 private SelectionAdapter obsoleteCheckboxListener = new SelectionAdapter() 357 { 358 public void widgetSelected( SelectionEvent e ) 359 { 360 modifiedAttributeType.setObsolete( obsoleteCheckbox.getSelection() ); 361 setEditorDirty(); 362 } 363 }; 364 365 366 private SelectionAdapter singleValueCheckboxListener = new SelectionAdapter() 367 { 368 public void widgetSelected( SelectionEvent e ) 369 { 370 modifiedAttributeType.setSingleValue( singleValueCheckbox.getSelection() ); 371 setEditorDirty(); 372 } 373 }; 374 375 376 private SelectionAdapter collectiveCheckboxListener = new SelectionAdapter() 377 { 378 public void widgetSelected( SelectionEvent e ) 379 { 380 modifiedAttributeType.setCollective( collectiveCheckbox.getSelection() ); 381 setEditorDirty(); 382 } 383 }; 384 385 386 private SelectionAdapter noUserModificationCheckboxListener = new SelectionAdapter() 387 { 388 public void widgetSelected( SelectionEvent e ) 389 { 390 modifiedAttributeType.setNoUserModification( noUserModificationCheckbox.getSelection() ); 391 setEditorDirty(); 392 } 393 }; 394 395 396 private ModifyListener equalityComboListener = new ModifyListener() 397 { 398 public void modifyText( ModifyEvent e ) 399 { 400 Object selectedItem = ( ( StructuredSelection ) equalityComboViewer.getSelection() ).getFirstElement(); 401 402 if ( selectedItem instanceof MatchingRule ) 403 { 404 modifiedAttributeType.setEquality( ( ( MatchingRule ) selectedItem ).getName() ); 405 } 406 else if ( selectedItem instanceof NonExistingMatchingRule ) 407 { 408 NonExistingMatchingRule nemr = ( NonExistingMatchingRule ) selectedItem; 409 410 if ( NonExistingMatchingRule.NONE.equals( nemr.getName() ) ) 411 { 412 modifiedAttributeType.setEquality( null ); 413 } 414 else 415 { 416 modifiedAttributeType.setEquality( ( ( NonExistingMatchingRule ) selectedItem ).getName() ); 417 } 418 } 419 setEditorDirty(); 420 } 421 }; 422 423 424 private ModifyListener orderingComboListener = new ModifyListener() 425 { 426 public void modifyText( ModifyEvent e ) 427 { 428 Object selectedItem = ( ( StructuredSelection ) orderingComboViewer.getSelection() ).getFirstElement(); 429 430 if ( selectedItem instanceof MatchingRule ) 431 { 432 modifiedAttributeType.setOrdering( ( ( MatchingRule ) selectedItem ).getName() ); 433 } 434 else if ( selectedItem instanceof NonExistingMatchingRule ) 435 { 436 NonExistingMatchingRule nemr = ( NonExistingMatchingRule ) selectedItem; 437 438 if ( NonExistingMatchingRule.NONE.equals( nemr.getName() ) ) 439 { 440 modifiedAttributeType.setOrdering( null ); 441 } 442 else 443 { 444 modifiedAttributeType.setOrdering( ( ( NonExistingMatchingRule ) selectedItem ).getName() ); 445 } 446 } 447 setEditorDirty(); 448 } 449 }; 450 451 452 private ModifyListener substringComboListener = new ModifyListener() 453 { 454 public void modifyText( ModifyEvent e ) 455 { 456 Object selectedItem = ( ( StructuredSelection ) substringComboViewer.getSelection() ).getFirstElement(); 457 458 if ( selectedItem instanceof MatchingRule ) 459 { 460 modifiedAttributeType.setSubstr( ( ( MatchingRule ) selectedItem ).getName() ); 461 } 462 else if ( selectedItem instanceof NonExistingMatchingRule ) 463 { 464 NonExistingMatchingRule nemr = ( NonExistingMatchingRule ) selectedItem; 465 466 if ( NonExistingMatchingRule.NONE.equals( nemr.getName() ) ) 467 { 468 modifiedAttributeType.setSubstr( null ); 469 } 470 else 471 { 472 modifiedAttributeType.setSubstr( ( ( NonExistingMatchingRule ) selectedItem ).getName() ); 473 } 474 } 475 setEditorDirty(); 476 } 477 }; 478 479 480 486 public AttributeTypeEditorOverviewPage( FormEditor editor ) 487 { 488 super( editor, ID, TITLE ); 489 schemaPool = SchemaPool.getInstance(); 490 schemaPool.addListener( this ); 491 } 492 493 494 497 protected void createFormContent( IManagedForm managedForm ) 498 { 499 modifiedAttributeType = ( ( AttributeTypeEditor ) getEditor() ).getModifiedAttributeType(); 501 originalAttributeType = ( ( AttributeTypeEditor ) getEditor() ).getOriginalAttributeType(); 502 503 ScrolledForm form = managedForm.getForm(); 505 FormToolkit toolkit = managedForm.getToolkit(); 506 GridLayout layout = new GridLayout(); 507 form.getBody().setLayout( layout ); 508 509 createGeneralInformationSection( form.getBody(), toolkit ); 511 512 createMatchingRulesSection( form.getBody(), toolkit ); 514 515 setFieldsEditableState(); 517 518 fillInUiFields(); 520 521 addListeners(); 523 } 524 525 526 534 private void createGeneralInformationSection( Composite parent, FormToolkit toolkit ) 535 { 536 Section section_general_information = toolkit.createSection( parent, Section.DESCRIPTION | Section.EXPANDED 538 | Section.TITLE_BAR ); 539 section_general_information.setDescription( Messages 540 .getString( "AttributeTypeEditorOverviewPage.General_Section_Description" ) ); section_general_information.setText( Messages 542 .getString( "AttributeTypeEditorOverviewPage.General_Section_Text" ) ); 544 Composite client_general_information = toolkit.createComposite( section_general_information ); 546 GridLayout layout_general_information = new GridLayout(); 547 layout_general_information.numColumns = 3; 548 client_general_information.setLayout( layout_general_information ); 549 toolkit.paintBordersFor( client_general_information ); 550 section_general_information.setClient( client_general_information ); 551 section_general_information.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); 552 553 toolkit 556 .createLabel( client_general_information, Messages.getString( "AttributeTypeEditorOverviewPage.Aliases" ) ); aliasesLabel = toolkit.createLabel( client_general_information, "" ); aliasesLabel.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false, 2, 1 ) ); 559 toolkit.createLabel( client_general_information, "" ); aliasesButton = toolkit.createButton( client_general_information, Messages 561 .getString( "AttributeTypeEditorOverviewPage.Edit_Aliases" ), SWT.PUSH ); aliasesButton.setLayoutData( new GridData( SWT.NONE, SWT.NONE, false, false, 2, 1 ) ); 563 564 toolkit.createLabel( client_general_information, Messages.getString( "AttributeTypeEditorOverviewPage.OID" ) ); oidText = toolkit.createText( client_general_information, "" ); oidText.setLayoutData( new GridData( SWT.FILL, 0, true, false, 2, 1 ) ); 568 569 toolkit.createLabel( client_general_information, Messages 571 .getString( "AttributeTypeEditorOverviewPage.Description" ) ); descriptionText = toolkit.createText( client_general_information, "", SWT.MULTI | SWT.V_SCROLL ); GridData descriptionGridData = new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ); 574 descriptionGridData.heightHint = 42; 575 descriptionText.setLayoutData( descriptionGridData ); 576 577 schemaLink = toolkit.createHyperlink( client_general_information, Messages 579 .getString( "AttributeTypeEditorOverviewPage.Schema" ), SWT.WRAP ); schemaLabel = toolkit.createLabel( client_general_information, "" ); schemaLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); 582 583 supLabel = toolkit.createHyperlink( client_general_information, Messages 585 .getString( "AttributeTypeEditorOverviewPage.Superior_type" ), SWT.WRAP ); supCombo = new Combo( client_general_information, SWT.READ_ONLY | SWT.SINGLE ); 587 supCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); 588 supComboViewer = new ComboViewer( supCombo ); 589 supComboViewer.setContentProvider( new ATESuperiorComboContentProvider() ); 590 supComboViewer.setLabelProvider( new ATESuperiorComboLabelProvider() ); 591 592 toolkit.createLabel( client_general_information, Messages.getString( "AttributeTypeEditorOverviewPage.Usage" ) ); usageCombo = new Combo( client_general_information, SWT.READ_ONLY | SWT.SINGLE ); 595 usageCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); 596 initUsageCombo(); 597 598 toolkit 600 .createLabel( client_general_information, Messages.getString( "AttributeTypeEditorOverviewPage.Synatx" ) ); syntaxCombo = new Combo( client_general_information, SWT.READ_ONLY | SWT.SINGLE ); 602 syntaxCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); 603 syntaxComboViewer = new ComboViewer( syntaxCombo ); 604 syntaxComboViewer.setContentProvider( new ATESyntaxComboContentProvider() ); 605 syntaxComboViewer.setLabelProvider( new ATESyntaxComboLabelProvider() ); 606 607 toolkit.createLabel( client_general_information, Messages 609 .getString( "AttributeTypeEditorOverviewPage.Syntax_length" ) ); syntaxLengthText = toolkit.createText( client_general_information, "" ); syntaxLengthText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); 612 613 toolkit.createLabel( client_general_information, "" ); obsoleteCheckbox = toolkit.createButton( client_general_information, Messages 616 .getString( "AttributeTypeEditorOverviewPage.Obsolete" ), SWT.CHECK ); obsoleteCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 618 619 singleValueCheckbox = toolkit.createButton( client_general_information, Messages 621 .getString( "AttributeTypeEditorOverviewPage.Single-Value" ), SWT.CHECK ); singleValueCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 623 624 toolkit.createLabel( client_general_information, "" ); collectiveCheckbox = toolkit.createButton( client_general_information, Messages 627 .getString( "AttributeTypeEditorOverviewPage.Collective" ), SWT.CHECK ); collectiveCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 629 630 noUserModificationCheckbox = toolkit.createButton( client_general_information, Messages 632 .getString( "AttributeTypeEditorOverviewPage.No-User-Modification" ), SWT.CHECK ); noUserModificationCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 634 } 635 636 637 645 private void createMatchingRulesSection( Composite parent, FormToolkit toolkit ) 646 { 647 Section section_matching_rules = toolkit.createSection( parent, Section.DESCRIPTION | Section.EXPANDED 649 | Section.TITLE_BAR ); 650 section_matching_rules.setDescription( Messages 651 .getString( "AttributeTypeEditorOverviewPage.Specify_matching_rules" ) ); section_matching_rules.setText( Messages.getString( "AttributeTypeEditorOverviewPage.Matching_Rules" ) ); 654 Composite client_matching_rules = toolkit.createComposite( section_matching_rules ); 656 GridLayout layout_matching_rules = new GridLayout(); 657 layout_matching_rules.numColumns = 2; 658 client_matching_rules.setLayout( layout_matching_rules ); 659 toolkit.paintBordersFor( client_matching_rules ); 660 section_matching_rules.setClient( client_matching_rules ); 661 section_matching_rules.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); 662 663 toolkit.createLabel( client_matching_rules, Messages.getString( "AttributeTypeEditorOverviewPage.Equility" ) ); equalityCombo = new Combo( client_matching_rules, SWT.READ_ONLY | SWT.SINGLE ); 666 equalityCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 667 equalityComboViewer = new ComboViewer( equalityCombo ); 668 equalityComboViewer.setContentProvider( new ATEEqualityComboContentProvider() ); 669 equalityComboViewer.setLabelProvider( new ATEMatchingRulesComboLabelProvider() ); 670 671 toolkit.createLabel( client_matching_rules, Messages.getString( "AttributeTypeEditorOverviewPage.Ordering" ) ); orderingCombo = new Combo( client_matching_rules, SWT.READ_ONLY | SWT.SINGLE ); 674 orderingCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 675 orderingComboViewer = new ComboViewer( orderingCombo ); 676 orderingComboViewer.setContentProvider( new ATEOrderingComboContentProvider() ); 677 orderingComboViewer.setLabelProvider( new ATEMatchingRulesComboLabelProvider() ); 678 679 toolkit.createLabel( client_matching_rules, Messages.getString( "AttributeTypeEditorOverviewPage.Substring" ) ); substringCombo = new Combo( client_matching_rules, SWT.READ_ONLY | SWT.SINGLE ); 682 substringCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 683 substringComboViewer = new ComboViewer( substringCombo ); 684 substringComboViewer.setContentProvider( new ATESubstringComboContentProvider() ); 685 substringComboViewer.setLabelProvider( new ATEMatchingRulesComboLabelProvider() ); 686 } 687 688 689 692 private void initUsageCombo() 693 { 694 usageCombo.add( "directoryOperation", 0 ); usageCombo.add( "distributedOperation", 1 ); usageCombo.add( "DSAOperation", 2 ); usageCombo.add( "userApplications", 3 ); } 699 700 701 704 private void fillInUiFields() 705 { 706 if ( ( modifiedAttributeType.getNames() != null ) && ( modifiedAttributeType.getNames().length != 0 ) ) 708 { 709 aliasesLabel.setText( ViewUtils.concateAliases( modifiedAttributeType.getNames() ) ); 710 } 711 else 712 { 713 aliasesLabel.setText( Messages.getString( "AttributeTypeEditorOverviewPage.(None)" ) ); } 715 716 if ( modifiedAttributeType.getOid() != null ) 718 { 719 this.oidText.setText( modifiedAttributeType.getOid() ); 720 } 721 722 if ( modifiedAttributeType.getOriginatingSchema() != null ) 724 { 725 this.schemaLabel.setText( modifiedAttributeType.getOriginatingSchema().getName() ); 726 } 727 728 if ( modifiedAttributeType.getDescription() != null ) 730 { 731 this.descriptionText.setText( modifiedAttributeType.getDescription() ); 732 } 733 734 fillSupCombo(); 736 737 fillInUsageCombo(); 739 740 fillSyntaxCombo(); 742 743 if ( modifiedAttributeType.getLength() != -1 ) 745 { 746 this.syntaxLengthText.setText( modifiedAttributeType.getLength() + "" ); } 748 749 this.obsoleteCheckbox.setSelection( modifiedAttributeType.isObsolete() ); 751 752 this.singleValueCheckbox.setSelection( modifiedAttributeType.isSingleValue() ); 754 755 this.collectiveCheckbox.setSelection( modifiedAttributeType.isCollective() ); 757 758 this.noUserModificationCheckbox.setSelection( modifiedAttributeType.isNoUserModification() ); 760 761 fillEqualityCombo(); 763 764 fillOrderingCombo(); 766 767 fillSubstringCombo(); 769 } 770 771 772 775 private void fillSupCombo() 776 { 777 supComboViewer.setInput( new ATESuperiorComboInput( originalAttributeType ) ); 778 779 if ( modifiedAttributeType.getSuperior() == null ) 780 { 781 supComboViewer.setSelection( new StructuredSelection( new NonExistingAttributeType( 782 NonExistingAttributeType.NONE ) ), true ); 783 } 784 else 785 { 786 String supAtName = modifiedAttributeType.getSuperior(); 787 788 AttributeType supAT = schemaPool.getAttributeType( supAtName ); 789 if ( supAT != null ) 790 { 791 supComboViewer.setSelection( new StructuredSelection( supAT ), true ); 792 } 793 else 794 { 795 ATESuperiorComboInput input = ( ATESuperiorComboInput ) supComboViewer.getInput(); 796 NonExistingAttributeType neat = new NonExistingAttributeType( supAtName ); 797 if ( !input.getChildren().contains( neat ) ) 798 { 799 input.addChild( neat ); 800 } 801 supComboViewer.refresh(); 802 supComboViewer.setSelection( new StructuredSelection( neat ), true ); 803 } 804 } 805 } 806 807 808 811 private void fillInUsageCombo() 812 { 813 if ( modifiedAttributeType.getUsage() == UsageEnum.DIRECTORY_OPERATION ) 814 { 815 usageCombo.select( 0 ); 816 } 817 else if ( modifiedAttributeType.getUsage() == UsageEnum.DISTRIBUTED_OPERATION ) 818 { 819 usageCombo.select( 1 ); 820 } 821 else if ( modifiedAttributeType.getUsage() == UsageEnum.DSA_OPERATION ) 822 { 823 usageCombo.select( 2 ); 824 } 825 else if ( modifiedAttributeType.getUsage() == UsageEnum.USER_APPLICATIONS ) 826 { 827 usageCombo.select( 3 ); 828 } 829 } 830 831 832 835 private void fillSyntaxCombo() 836 { 837 syntaxComboViewer.setInput( new ATESyntaxComboInput() ); 838 839 if ( modifiedAttributeType.getSyntax() == null ) 840 { 841 syntaxComboViewer.setSelection( new StructuredSelection( new NonExistingSyntax( NonExistingSyntax.NONE ) ), 842 true ); 843 } 844 else 845 { 846 String syntaxOID = modifiedAttributeType.getSyntax(); 847 848 Syntax syntax = Syntaxes.getSyntaxFromOid( syntaxOID ); 849 if ( syntax != null ) 850 { 851 syntaxComboViewer.setSelection( new StructuredSelection( syntax ), true ); 852 } 853 else 854 { 855 ATESyntaxComboInput input = ( ATESyntaxComboInput ) syntaxComboViewer.getInput(); 856 NonExistingSyntax nes = new NonExistingSyntax( syntaxOID ); 857 if ( !input.getChildren().contains( nes ) ) 858 { 859 input.addChild( nes ); 860 } 861 syntaxComboViewer.refresh(); 862 syntaxComboViewer.setSelection( new StructuredSelection( nes ), true ); 863 } 864 } 865 } 866 867 868 871 private void fillEqualityCombo() 872 { 873 equalityComboViewer.setInput( new ATEMatchingRulesComboInput() ); 874 875 if ( modifiedAttributeType.getEquality() == null ) 876 { 877 equalityComboViewer.setSelection( new StructuredSelection( new NonExistingMatchingRule( 878 NonExistingMatchingRule.NONE ) ), true ); 879 } 880 else 881 { 882 String equalityName = modifiedAttributeType.getEquality(); 883 884 MatchingRule matchingRule = MatchingRules.getMatchingRule( equalityName ); 885 if ( matchingRule != null ) 886 { 887 equalityComboViewer.setSelection( new StructuredSelection( matchingRule ), true ); 888 } 889 else 890 { 891 ATEMatchingRulesComboInput input = ( ATEMatchingRulesComboInput ) equalityComboViewer.getInput(); 892 NonExistingMatchingRule nemr = new NonExistingMatchingRule( equalityName ); 893 if ( !input.getChildren().contains( nemr ) ) 894 { 895 input.addChild( nemr ); 896 } 897 equalityComboViewer.refresh(); 898 equalityComboViewer.setSelection( new StructuredSelection( nemr ), true ); 899 } 900 } 901 } 902 903 904 907 private void fillOrderingCombo() 908 { 909 orderingComboViewer.setInput( new ATEMatchingRulesComboInput() ); 910 911 if ( modifiedAttributeType.getOrdering() == null ) 912 { 913 orderingComboViewer.setSelection( new StructuredSelection( new NonExistingMatchingRule( 914 NonExistingMatchingRule.NONE ) ), true ); 915 } 916 else 917 { 918 String orderingName = modifiedAttributeType.getOrdering(); 919 920 MatchingRule matchingRule = MatchingRules.getMatchingRule( orderingName ); 921 if ( matchingRule != null ) 922 { 923 orderingComboViewer.setSelection( new StructuredSelection( matchingRule ), true ); 924 } 925 else 926 { 927 ATEMatchingRulesComboInput input = ( ATEMatchingRulesComboInput ) orderingComboViewer.getInput(); 928 NonExistingMatchingRule nemr = new NonExistingMatchingRule( orderingName ); 929 if ( !input.getChildren().contains( nemr ) ) 930 { 931 input.addChild( nemr ); 932 } 933 orderingComboViewer.refresh(); 934 orderingComboViewer.setSelection( new StructuredSelection( nemr ), true ); 935 } 936 } 937 938 } 939 940 941 944 private void fillSubstringCombo() 945 { 946 substringComboViewer.setInput( new ATEMatchingRulesComboInput() ); 947 948 if ( modifiedAttributeType.getSubstr() == null ) 949 { 950 substringComboViewer.setSelection( new StructuredSelection( new NonExistingMatchingRule( 951 NonExistingMatchingRule.NONE ) ), true ); 952 } 953 else 954 { 955 String substringName = modifiedAttributeType.getSubstr(); 956 957 MatchingRule matchingRule = MatchingRules.getMatchingRule( substringName ); 958 if ( matchingRule != null ) 959 { 960 substringComboViewer.setSelection( new StructuredSelection( matchingRule ), true ); 961 } 962 else 963 { 964 ATEMatchingRulesComboInput input = ( ATEMatchingRulesComboInput ) substringComboViewer.getInput(); 965 NonExistingMatchingRule nemr = new NonExistingMatchingRule( substringName ); 966 if ( !input.getChildren().contains( nemr ) ) 967 { 968 input.addChild( nemr ); 969 } 970 substringComboViewer.refresh(); 971 substringComboViewer.setSelection( new StructuredSelection( nemr ), true ); 972 } 973 } 974 } 975 976 977 980 private void setFieldsEditableState() 981 { 982 if ( modifiedAttributeType.getOriginatingSchema().type == Schema.SchemaType.coreSchema ) 983 { 984 aliasesButton.setEnabled( false ); 986 oidText.setEditable( false ); 987 descriptionText.setEditable( false ); 988 supCombo.setEnabled( false ); 989 usageCombo.setEnabled( false ); 990 syntaxCombo.setEnabled( false ); 991 syntaxLengthText.setEditable( false ); 992 obsoleteCheckbox.setEnabled( false ); 993 singleValueCheckbox.setEnabled( false ); 994 collectiveCheckbox.setEnabled( false ); 995 noUserModificationCheckbox.setEnabled( false ); 996 equalityCombo.setEnabled( false ); 997 orderingCombo.setEnabled( false ); 998 substringCombo.setEnabled( false ); 999 } 1000 } 1001 1002 1003 1006 private void addListeners() 1007 { 1008 if ( modifiedAttributeType.getOriginatingSchema().type == Schema.SchemaType.userSchema ) 1009 { 1010 aliasesButton.addSelectionListener( aliasesButtonListener ); 1011 oidText.addModifyListener( oidTextModifyListener ); 1012 oidText.addVerifyListener( oidTextVerifyListener ); 1013 descriptionText.addModifyListener( descriptionTextListener ); 1014 supLabel.addHyperlinkListener( supLabelListener ); 1015 supCombo.addModifyListener( supComboListener ); 1016 usageCombo.addModifyListener( usageComboListener ); 1017 syntaxCombo.addModifyListener( syntaxComboListener ); 1018 syntaxLengthText.addModifyListener( syntaxLengthTextModifyListener ); 1019 syntaxLengthText.addVerifyListener( syntaxLengthTextVerifyListener ); 1020 obsoleteCheckbox.addSelectionListener( obsoleteCheckboxListener ); 1021 singleValueCheckbox.addSelectionListener( singleValueCheckboxListener ); 1022 collectiveCheckbox.addSelectionListener( collectiveCheckboxListener ); 1023 noUserModificationCheckbox.addSelectionListener( noUserModificationCheckboxListener ); 1024 equalityCombo.addModifyListener( equalityComboListener ); 1025 orderingCombo.addModifyListener( orderingComboListener ); 1026 substringCombo.addModifyListener( substringComboListener ); 1027 } 1028 1029 schemaLink.addHyperlinkListener( schemaLinkListener ); 1030 supLabel.addHyperlinkListener( supLabelListener ); 1031 } 1032 1033 1034 1037 private void removeListeners() 1038 { 1039 oidText.removeModifyListener( oidTextModifyListener ); 1040 oidText.removeVerifyListener( oidTextVerifyListener ); 1041 aliasesButton.removeSelectionListener( aliasesButtonListener ); 1042 schemaLink.removeHyperlinkListener( schemaLinkListener ); 1043 descriptionText.removeModifyListener( descriptionTextListener ); 1044 supLabel.removeHyperlinkListener( supLabelListener ); 1045 supCombo.removeModifyListener( supComboListener ); 1046 usageCombo.removeModifyListener( usageComboListener ); 1047 syntaxCombo.removeModifyListener( syntaxComboListener ); 1048 syntaxLengthText.removeModifyListener( syntaxLengthTextModifyListener ); 1049 syntaxLengthText.removeVerifyListener( syntaxLengthTextVerifyListener ); 1050 obsoleteCheckbox.removeSelectionListener( obsoleteCheckboxListener ); 1051 singleValueCheckbox.removeSelectionListener( singleValueCheckboxListener ); 1052 collectiveCheckbox.removeSelectionListener( collectiveCheckboxListener ); 1053 noUserModificationCheckbox.removeSelectionListener( noUserModificationCheckboxListener ); 1054 equalityCombo.removeModifyListener( equalityComboListener ); 1055 orderingCombo.removeModifyListener( orderingComboListener ); 1056 substringCombo.removeModifyListener( substringComboListener ); 1057 } 1058 1059 1060 1063 private void setEditorDirty() 1064 { 1065 ( ( AttributeTypeEditor ) getEditor() ).setDirty( true ); 1066 } 1067 1068 1069 1072 public void refreshUI() 1073 { 1074 removeListeners(); 1075 fillInUiFields(); 1076 addListeners(); 1077 } 1078 1079 1080 1083 public void poolChanged( SchemaPool p, LDAPModelEvent e ) 1084 { 1085 removeListeners(); 1086 supComboViewer.setInput( new ATESuperiorComboInput( originalAttributeType ) ); 1087 fillSupCombo(); 1088 addListeners(); 1089 } 1090 1091 1092 1095 public void dispose() 1096 { 1097 schemaPool.removeListener( this ); 1098 removeListeners(); 1099 super.dispose(); 1100 } 1101} 1102 | Popular Tags |