1 20 package org.apache.directory.ldapstudio.apacheds.configuration.editor; 21 22 23 import java.util.List ; 24 25 import org.apache.directory.ldapstudio.apacheds.configuration.dialogs.BinaryAttributeDialog; 26 import org.apache.directory.ldapstudio.apacheds.configuration.model.ServerConfiguration; 27 import org.eclipse.jface.dialogs.Dialog; 28 import org.eclipse.jface.dialogs.IDialogConstants; 29 import org.eclipse.jface.viewers.ArrayContentProvider; 30 import org.eclipse.jface.viewers.DoubleClickEvent; 31 import org.eclipse.jface.viewers.IDoubleClickListener; 32 import org.eclipse.jface.viewers.ISelectionChangedListener; 33 import org.eclipse.jface.viewers.LabelProvider; 34 import org.eclipse.jface.viewers.SelectionChangedEvent; 35 import org.eclipse.jface.viewers.StructuredSelection; 36 import org.eclipse.jface.viewers.TableViewer; 37 import org.eclipse.swt.SWT; 38 import org.eclipse.swt.events.ModifyEvent; 39 import org.eclipse.swt.events.ModifyListener; 40 import org.eclipse.swt.events.SelectionAdapter; 41 import org.eclipse.swt.events.SelectionEvent; 42 import org.eclipse.swt.events.SelectionListener; 43 import org.eclipse.swt.events.VerifyEvent; 44 import org.eclipse.swt.events.VerifyListener; 45 import org.eclipse.swt.layout.GridData; 46 import org.eclipse.swt.layout.GridLayout; 47 import org.eclipse.swt.widgets.Button; 48 import org.eclipse.swt.widgets.Combo; 49 import org.eclipse.swt.widgets.Composite; 50 import org.eclipse.swt.widgets.Table; 51 import org.eclipse.swt.widgets.Text; 52 import org.eclipse.ui.forms.IManagedForm; 53 import org.eclipse.ui.forms.editor.FormEditor; 54 import org.eclipse.ui.forms.editor.FormPage; 55 import org.eclipse.ui.forms.widgets.FormToolkit; 56 import org.eclipse.ui.forms.widgets.ScrolledForm; 57 import org.eclipse.ui.forms.widgets.Section; 58 import org.eclipse.ui.forms.widgets.TableWrapData; 59 import org.eclipse.ui.forms.widgets.TableWrapLayout; 60 61 62 68 public class GeneralPage extends FormPage 69 { 70 71 public static final String ID = ServerConfigurationEditor.ID + ".BasicPage"; 72 73 74 private static final String TITLE = "General"; 75 76 77 private List <String > binaryAttributes; 78 79 private Text portText; 81 private Combo authenticationCombo; 82 private Text principalText; 83 private Text passwordText; 84 private Button showPasswordCheckbox; 85 private Button allowAnonymousAccessCheckbox; 86 private Text maxTimeLimitText; 87 private Text maxSizeLimitText; 88 private Text synchPeriodText; 89 private Text maxThreadsText; 90 private Button enableAccesControlCheckbox; 91 private Button enableNTPCheckbox; 92 private Button enableKerberosCheckbox; 93 private Button enableChangePasswordCheckbox; 94 private Button denormalizeOpAttrCheckbox; 95 private TableViewer binaryAttributesTableViewer; 96 private Button binaryAttributesAddButton; 97 private Button binaryAttributesEditButton; 98 private Button binaryAttributesDeleteButton; 99 100 101 107 public GeneralPage( FormEditor editor ) 108 { 109 super( editor, ID, TITLE ); 110 } 111 112 113 116 protected void createFormContent( IManagedForm managedForm ) 117 { 118 ScrolledForm form = managedForm.getForm(); 119 form.setText( "General" ); 120 121 Composite parent = form.getBody(); 122 TableWrapLayout twl = new TableWrapLayout(); 123 twl.numColumns = 2; 124 parent.setLayout( twl ); 125 FormToolkit toolkit = managedForm.getToolkit(); 126 127 createSettingsSection( parent, toolkit ); 128 createBinaryAttributesSection( parent, toolkit ); 129 createLimitsSection( parent, toolkit ); 130 createOptionsSection( parent, toolkit ); 131 132 initFromInput(); 133 addListeners(); 134 } 135 136 137 145 private void createSettingsSection( Composite parent, FormToolkit toolkit ) 146 { 147 Section section = toolkit.createSection( parent, Section.DESCRIPTION | Section.TITLE_BAR ); 149 section.marginWidth = 4; 150 section.setText( "Settings" ); 151 section.setDescription( "Set the settings of the server." ); 152 TableWrapData td = new TableWrapData( TableWrapData.FILL, TableWrapData.TOP ); 153 td.grabHorizontal = true; 154 section.setLayoutData( td ); 155 Composite client = toolkit.createComposite( section ); 156 toolkit.paintBordersFor( client ); 157 GridLayout glayout = new GridLayout( 2, false ); 158 client.setLayout( glayout ); 159 section.setClient( client ); 160 161 toolkit.createLabel( client, "Port:" ); 163 portText = toolkit.createText( client, "" ); 164 portText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 165 portText.addVerifyListener( new VerifyListener() 166 { 167 public void verifyText( VerifyEvent e ) 168 { 169 if ( !e.text.matches( "[0-9]*" ) ) { 171 e.doit = false; 172 } 173 } 174 } ); 175 176 toolkit.createLabel( client, "Authentication:" ); 178 authenticationCombo = new Combo( client, SWT.SIMPLE ); 179 authenticationCombo.setItems( new String [] 180 { "Simple" } ); 181 authenticationCombo.setText( "Simple" ); 182 authenticationCombo.setEnabled( false ); 183 authenticationCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 184 185 toolkit.createLabel( client, "Principal:" ); 187 principalText = toolkit.createText( client, "" ); 188 principalText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 189 190 toolkit.createLabel( client, "Password:" ); 192 passwordText = toolkit.createText( client, "" ); 193 passwordText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 194 passwordText.setEchoChar( '\u2022' ); 195 196 toolkit.createLabel( client, "" ); 198 showPasswordCheckbox = toolkit.createButton( client, "Show password", SWT.CHECK ); 199 showPasswordCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 200 showPasswordCheckbox.setSelection( false ); 201 showPasswordCheckbox.addSelectionListener( new SelectionAdapter() 202 { 203 public void widgetSelected( SelectionEvent e ) 204 { 205 if ( showPasswordCheckbox.getSelection() ) 206 { 207 passwordText.setEchoChar( '\0' ); 208 } 209 else 210 { 211 passwordText.setEchoChar( '\u2022' ); 212 } 213 } 214 } ); 215 216 allowAnonymousAccessCheckbox = toolkit.createButton( client, "Allow Anonymous Access", SWT.CHECK ); 218 allowAnonymousAccessCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); 219 } 220 221 222 230 private void createLimitsSection( Composite parent, FormToolkit toolkit ) 231 { 232 Section section = toolkit.createSection( parent, Section.DESCRIPTION | Section.TITLE_BAR ); 234 section.marginWidth = 4; 235 section.setText( "Limits" ); 236 section.setDescription( "Set the limits of the server." ); 237 TableWrapData td = new TableWrapData( TableWrapData.FILL, TableWrapData.TOP ); 238 td.grabHorizontal = true; 239 section.setLayoutData( td ); 240 Composite client = toolkit.createComposite( section ); 241 toolkit.paintBordersFor( client ); 242 GridLayout glayout = new GridLayout( 2, false ); 243 client.setLayout( glayout ); 244 section.setClient( client ); 245 246 toolkit.createLabel( client, "Max. Time Limit:" ); 248 maxTimeLimitText = toolkit.createText( client, "" ); 249 maxTimeLimitText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 250 maxTimeLimitText.addVerifyListener( new VerifyListener() 251 { 252 public void verifyText( VerifyEvent e ) 253 { 254 if ( !e.text.matches( "[0-9]*" ) ) { 256 e.doit = false; 257 } 258 } 259 } ); 260 261 toolkit.createLabel( client, "Max. Size Limit:" ); 263 maxSizeLimitText = toolkit.createText( client, "" ); 264 maxSizeLimitText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 265 maxSizeLimitText.addVerifyListener( new VerifyListener() 266 { 267 public void verifyText( VerifyEvent e ) 268 { 269 if ( !e.text.matches( "[0-9]*" ) ) { 271 e.doit = false; 272 } 273 } 274 } ); 275 276 toolkit.createLabel( client, "Synchronization Period:" ); 278 synchPeriodText = toolkit.createText( client, "" ); 279 synchPeriodText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 280 synchPeriodText.addVerifyListener( new VerifyListener() 281 { 282 public void verifyText( VerifyEvent e ) 283 { 284 if ( !e.text.matches( "[0-9]*" ) ) { 286 e.doit = false; 287 } 288 } 289 } ); 290 291 toolkit.createLabel( client, "Max. Threads:" ); 293 maxThreadsText = toolkit.createText( client, "" ); 294 maxThreadsText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 295 maxThreadsText.addVerifyListener( new VerifyListener() 296 { 297 public void verifyText( VerifyEvent e ) 298 { 299 if ( !e.text.matches( "[0-9]*" ) ) { 301 e.doit = false; 302 } 303 } 304 } ); 305 } 306 307 308 316 private void createOptionsSection( Composite parent, FormToolkit toolkit ) 317 { 318 Section section = toolkit.createSection( parent, Section.DESCRIPTION | Section.TITLE_BAR ); 320 section.marginWidth = 4; 321 section.setText( "Options" ); 322 section.setDescription( "Set the options of the server." ); 323 TableWrapData td = new TableWrapData( TableWrapData.FILL, TableWrapData.TOP ); 324 td.grabHorizontal = true; 325 section.setLayoutData( td ); 326 Composite client = toolkit.createComposite( section ); 327 toolkit.paintBordersFor( client ); 328 GridLayout glayout = new GridLayout(); 329 client.setLayout( glayout ); 330 section.setClient( client ); 331 332 enableAccesControlCheckbox = toolkit.createButton( client, "Enable Access Control", SWT.CHECK ); 334 enableAccesControlCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 335 336 enableNTPCheckbox = toolkit.createButton( client, "Enable NTP", SWT.CHECK ); 338 enableNTPCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 339 340 denormalizeOpAttrCheckbox = toolkit.createButton( client, "Denormalize Operational Attributes", SWT.CHECK ); 342 denormalizeOpAttrCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 343 344 enableKerberosCheckbox = toolkit.createButton( client, "Enable Kerberos", SWT.CHECK ); 346 enableKerberosCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 347 enableKerberosCheckbox.setEnabled( false ); 348 349 enableChangePasswordCheckbox = toolkit.createButton( client, "Enable Change Password", SWT.CHECK ); 351 enableChangePasswordCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); 352 enableChangePasswordCheckbox.setEnabled( false ); 353 } 354 355 356 364 private void createBinaryAttributesSection( Composite parent, FormToolkit toolkit ) 365 { 366 Section section = toolkit.createSection( parent, Section.DESCRIPTION | Section.TITLE_BAR ); 368 section.marginWidth = 4; 369 section.setText( "Binary Attributes" ); 370 section 371 .setDescription( "Set attribute type names and OID's if you want an them to be handled as binary content." ); 372 TableWrapData td = new TableWrapData( TableWrapData.FILL, TableWrapData.TOP ); 373 td.grabHorizontal = true; 374 section.setLayoutData( td ); 375 Composite client = toolkit.createComposite( section ); 376 toolkit.paintBordersFor( client ); 377 GridLayout glayout = new GridLayout( 2, false ); 378 client.setLayout( glayout ); 379 section.setClient( client ); 380 381 Table binaryAttributesTable = toolkit.createTable( client, SWT.NONE ); 382 GridData gd = new GridData( SWT.FILL, SWT.NONE, true, false, 1, 3 ); 383 gd.heightHint = 103; 384 binaryAttributesTable.setLayoutData( gd ); 385 binaryAttributesTableViewer = new TableViewer( binaryAttributesTable ); 386 binaryAttributesTableViewer.setContentProvider( new ArrayContentProvider() ); 387 binaryAttributesTableViewer.setLabelProvider( new LabelProvider() ); 388 389 GridData buttonsGD = new GridData( SWT.FILL, SWT.BEGINNING, false, false ); 390 buttonsGD.widthHint = IDialogConstants.BUTTON_WIDTH; 391 392 binaryAttributesAddButton = toolkit.createButton( client, "Add...", SWT.PUSH ); 393 binaryAttributesAddButton.setLayoutData( buttonsGD ); 394 395 binaryAttributesEditButton = toolkit.createButton( client, "Edit...", SWT.PUSH ); 396 binaryAttributesEditButton.setEnabled( false ); 397 binaryAttributesEditButton.setLayoutData( buttonsGD ); 398 399 binaryAttributesDeleteButton = toolkit.createButton( client, "Delete", SWT.PUSH ); 400 binaryAttributesDeleteButton.setEnabled( false ); 401 binaryAttributesDeleteButton.setLayoutData( buttonsGD ); 402 } 403 404 405 408 private void initFromInput() 409 { 410 ServerConfiguration configuration = ( ( ServerConfigurationEditorInput ) getEditorInput() ) 411 .getServerConfiguration(); 412 413 binaryAttributes = configuration.getBinaryAttributes(); 414 binaryAttributesTableViewer.setInput( binaryAttributes ); 415 416 portText.setText( "" + configuration.getPort() ); 418 419 String principal = configuration.getPrincipal(); 421 if ( principal != null ) 422 { 423 principalText.setText( principal ); 424 } 425 426 String password = configuration.getPassword(); 428 if ( password != null ) 429 { 430 passwordText.setText( password ); 431 } 432 433 allowAnonymousAccessCheckbox.setSelection( configuration.isAllowAnonymousAccess() ); 435 436 maxTimeLimitText.setText( "" + configuration.getMaxTimeLimit() ); 438 439 maxSizeLimitText.setText( "" + configuration.getMaxSizeLimit() ); 441 442 synchPeriodText.setText( "" + configuration.getSynchronizationPeriod() ); 444 445 maxThreadsText.setText( "" + configuration.getMaxThreads() ); 447 448 enableAccesControlCheckbox.setSelection( configuration.isEnableAccessControl() ); 450 451 enableNTPCheckbox.setSelection( configuration.isEnableNTP() ); 453 454 enableKerberosCheckbox.setSelection( configuration.isEnableKerberos() ); 456 457 enableChangePasswordCheckbox.setSelection( configuration.isEnableChangePassword() ); 459 460 denormalizeOpAttrCheckbox.setSelection( configuration.isDenormalizeOpAttr() ); 462 } 463 464 465 468 private void addListeners() 469 { 470 ModifyListener modifyListener = new ModifyListener() 472 { 473 public void modifyText( ModifyEvent e ) 474 { 475 setEditorDirty(); 476 } 477 }; 478 479 SelectionListener selectionListener = new SelectionAdapter() 481 { 482 public void widgetSelected( SelectionEvent e ) 483 { 484 setEditorDirty(); 485 } 486 }; 487 488 ISelectionChangedListener binaryAttributesTableViewerListener = new ISelectionChangedListener() 490 { 491 public void selectionChanged( SelectionChangedEvent event ) 492 { 493 binaryAttributesEditButton.setEnabled( !event.getSelection().isEmpty() ); 494 binaryAttributesDeleteButton.setEnabled( !event.getSelection().isEmpty() ); 495 } 496 }; 497 498 IDoubleClickListener binaryAttributesTableViewerDoubleClickListener = new IDoubleClickListener() 500 { 501 public void doubleClick( DoubleClickEvent event ) 502 { 503 editSelectedBinaryAttribute(); 504 } 505 }; 506 507 SelectionListener binaryAttributesAddButtonListener = new SelectionAdapter() 509 { 510 public void widgetSelected( SelectionEvent e ) 511 { 512 BinaryAttributeDialog dialog = new BinaryAttributeDialog( "" ); 513 if ( Dialog.OK == dialog.open() && dialog.isDirty() ) 514 { 515 String newAttribute = dialog.getAttribute(); 516 if ( newAttribute != null && !"".equals( newAttribute ) 517 && !binaryAttributes.contains( newAttribute ) ) 518 { 519 binaryAttributes.add( newAttribute ); 520 521 binaryAttributesTableViewer.refresh(); 522 setEditorDirty(); 523 } 524 } 525 } 526 }; 527 528 SelectionListener binaryAttributesEditButtonListener = new SelectionAdapter() 530 { 531 public void widgetSelected( SelectionEvent e ) 532 { 533 editSelectedBinaryAttribute(); 534 } 535 }; 536 537 SelectionListener binaryAttributesDeleteButtonListener = new SelectionAdapter() 539 { 540 public void widgetSelected( SelectionEvent e ) 541 { 542 StructuredSelection selection = ( StructuredSelection ) binaryAttributesTableViewer.getSelection(); 543 if ( !selection.isEmpty() ) 544 { 545 String attribute = ( String ) selection.getFirstElement(); 546 binaryAttributes.remove( attribute ); 547 548 binaryAttributesTableViewer.refresh(); 549 setEditorDirty(); 550 } 551 } 552 }; 553 554 portText.addModifyListener( modifyListener ); 555 authenticationCombo.addModifyListener( modifyListener ); 556 principalText.addModifyListener( modifyListener ); 557 passwordText.addModifyListener( modifyListener ); 558 allowAnonymousAccessCheckbox.addSelectionListener( selectionListener ); 559 maxTimeLimitText.addModifyListener( modifyListener ); 560 maxSizeLimitText.addModifyListener( modifyListener ); 561 synchPeriodText.addModifyListener( modifyListener ); 562 maxThreadsText.addModifyListener( modifyListener ); 563 enableAccesControlCheckbox.addSelectionListener( selectionListener ); 564 enableNTPCheckbox.addSelectionListener( selectionListener ); 565 enableKerberosCheckbox.addSelectionListener( selectionListener ); 566 enableChangePasswordCheckbox.addSelectionListener( selectionListener ); 567 denormalizeOpAttrCheckbox.addSelectionListener( selectionListener ); 568 binaryAttributesTableViewer.addSelectionChangedListener( binaryAttributesTableViewerListener ); 569 binaryAttributesTableViewer.addDoubleClickListener( binaryAttributesTableViewerDoubleClickListener ); 570 binaryAttributesAddButton.addSelectionListener( binaryAttributesAddButtonListener ); 571 binaryAttributesEditButton.addSelectionListener( binaryAttributesEditButtonListener ); 572 binaryAttributesDeleteButton.addSelectionListener( binaryAttributesDeleteButtonListener ); 573 } 574 575 576 580 private void editSelectedBinaryAttribute() 581 { 582 StructuredSelection selection = ( StructuredSelection ) binaryAttributesTableViewer.getSelection(); 583 if ( !selection.isEmpty() ) 584 { 585 String oldAttribute = ( String ) selection.getFirstElement(); 586 587 BinaryAttributeDialog dialog = new BinaryAttributeDialog( oldAttribute ); 588 if ( Dialog.OK == dialog.open() && dialog.isDirty() ) 589 { 590 binaryAttributes.remove( oldAttribute ); 591 592 String newAttribute = dialog.getAttribute(); 593 if ( newAttribute != null && !"".equals( newAttribute ) && !binaryAttributes.contains( newAttribute ) ) 594 { 595 binaryAttributes.add( newAttribute ); 596 } 597 598 binaryAttributesTableViewer.refresh(); 599 setEditorDirty(); 600 } 601 } 602 } 603 604 605 608 private void setEditorDirty() 609 { 610 ( ( ServerConfigurationEditor ) getEditor() ).setDirty( true ); 611 } 612 613 614 617 public void save() 618 { 619 ServerConfiguration serverConfiguration = ( ( ServerConfigurationEditorInput ) getEditorInput() ) 620 .getServerConfiguration(); 621 622 serverConfiguration.setPort( Integer.parseInt( portText.getText() ) ); 623 serverConfiguration.setPrincipal( principalText.getText() ); 624 serverConfiguration.setPassword( passwordText.getText() ); 625 serverConfiguration.setAllowAnonymousAccess( allowAnonymousAccessCheckbox.getSelection() ); 626 serverConfiguration.setMaxTimeLimit( Integer.parseInt( maxTimeLimitText.getText() ) ); 627 serverConfiguration.setMaxSizeLimit( Integer.parseInt( maxSizeLimitText.getText() ) ); 628 serverConfiguration.setSynchronizationPeriod( Long.parseLong( synchPeriodText.getText() ) ); 629 serverConfiguration.setMaxThreads( Integer.parseInt( maxThreadsText.getText() ) ); 630 serverConfiguration.setEnableAccessControl( enableAccesControlCheckbox.getSelection() ); 631 serverConfiguration.setEnableNTP( enableNTPCheckbox.getSelection() ); 632 serverConfiguration.setEnableKerberos( enableKerberosCheckbox.getSelection() ); 633 serverConfiguration.setEnableChangePassword( enableChangePasswordCheckbox.getSelection() ); 634 serverConfiguration.setDenormalizeOpAttr( denormalizeOpAttrCheckbox.getSelection() ); 635 } 636 } 637 | Popular Tags |