1 20 package org.apache.directory.ldapstudio.apacheds.configuration.editor; 21 22 23 import java.util.ArrayList ; 24 import java.util.List ; 25 26 import javax.naming.NamingEnumeration ; 27 import javax.naming.NamingException ; 28 import javax.naming.directory.Attribute ; 29 import javax.naming.directory.Attributes ; 30 import javax.naming.directory.BasicAttribute ; 31 32 import org.apache.directory.ldapstudio.apacheds.configuration.dialogs.AttributeValueDialog; 33 import org.apache.directory.ldapstudio.apacheds.configuration.dialogs.IndexedAttributeDialog; 34 import org.apache.directory.ldapstudio.apacheds.configuration.model.IndexedAttribute; 35 import org.apache.directory.ldapstudio.apacheds.configuration.model.Partition; 36 import org.eclipse.jface.dialogs.Dialog; 37 import org.eclipse.jface.dialogs.IDialogConstants; 38 import org.eclipse.jface.viewers.ArrayContentProvider; 39 import org.eclipse.jface.viewers.DoubleClickEvent; 40 import org.eclipse.jface.viewers.IDoubleClickListener; 41 import org.eclipse.jface.viewers.ILabelProviderListener; 42 import org.eclipse.jface.viewers.ISelection; 43 import org.eclipse.jface.viewers.ISelectionChangedListener; 44 import org.eclipse.jface.viewers.IStructuredContentProvider; 45 import org.eclipse.jface.viewers.IStructuredSelection; 46 import org.eclipse.jface.viewers.ITableLabelProvider; 47 import org.eclipse.jface.viewers.LabelProvider; 48 import org.eclipse.jface.viewers.SelectionChangedEvent; 49 import org.eclipse.jface.viewers.StructuredSelection; 50 import org.eclipse.jface.viewers.TableViewer; 51 import org.eclipse.jface.viewers.Viewer; 52 import org.eclipse.swt.SWT; 53 import org.eclipse.swt.events.ModifyEvent; 54 import org.eclipse.swt.events.ModifyListener; 55 import org.eclipse.swt.events.SelectionAdapter; 56 import org.eclipse.swt.events.SelectionEvent; 57 import org.eclipse.swt.events.SelectionListener; 58 import org.eclipse.swt.events.VerifyEvent; 59 import org.eclipse.swt.events.VerifyListener; 60 import org.eclipse.swt.graphics.Image; 61 import org.eclipse.swt.layout.GridData; 62 import org.eclipse.swt.layout.GridLayout; 63 import org.eclipse.swt.widgets.Button; 64 import org.eclipse.swt.widgets.Composite; 65 import org.eclipse.swt.widgets.Table; 66 import org.eclipse.swt.widgets.TableColumn; 67 import org.eclipse.swt.widgets.Text; 68 import org.eclipse.ui.forms.IDetailsPage; 69 import org.eclipse.ui.forms.IFormPart; 70 import org.eclipse.ui.forms.IManagedForm; 71 import org.eclipse.ui.forms.widgets.FormToolkit; 72 import org.eclipse.ui.forms.widgets.Section; 73 import org.eclipse.ui.forms.widgets.TableWrapData; 74 import org.eclipse.ui.forms.widgets.TableWrapLayout; 75 76 77 83 public class PartitionDetailsPage implements IDetailsPage 84 { 85 86 private PartitionsMasterDetailsBlock masterDetailsBlock; 87 88 89 private IManagedForm mform; 90 91 92 private Partition input; 93 94 95 private Attributes contextEntry; 96 97 98 private List <IndexedAttribute> indexedAttributes; 99 100 101 private boolean dirty = false; 102 103 private Text nameText; 105 private Text cacheSizeText; 106 private Text suffixText; 107 private Button enableOptimizerCheckbox; 108 private Button synchOnWriteCheckbox; 109 private Table contextEntryTable; 110 private TableViewer contextEntryTableViewer; 111 private Button contextEntryAddButton; 112 private Button contextEntryEditButton; 113 private Button contextEntryDeleteButton; 114 private TableViewer indexedAttributesTableViewer; 115 private Button indexedAttributeAddButton; 116 private Button indexedAttributeEditButton; 117 private Button indexedAttributeDeleteButton; 118 119 121 private ModifyListener textModifyListener = new ModifyListener() 122 { 123 public void modifyText( ModifyEvent e ) 124 { 125 masterDetailsBlock.setEditorDirty(); 126 dirty = true; 127 } 128 }; 129 130 131 private SelectionListener checkboxSelectionListener = new SelectionAdapter() 132 { 133 public void widgetSelected( SelectionEvent e ) 134 { 135 masterDetailsBlock.setEditorDirty(); 136 dirty = true; 137 } 138 }; 139 140 141 private ISelectionChangedListener contextEntryTableViewerListener = new ISelectionChangedListener() 142 { 143 public void selectionChanged( SelectionChangedEvent event ) 144 { 145 contextEntryEditButton.setEnabled( !event.getSelection().isEmpty() ); 146 contextEntryDeleteButton.setEnabled( !event.getSelection().isEmpty() ); 147 } 148 }; 149 150 151 private IDoubleClickListener contextEntryTableViewerDoubleClickListener = new IDoubleClickListener() 152 { 153 public void doubleClick( DoubleClickEvent event ) 154 { 155 editSelectedContextEntry(); 156 } 157 }; 158 159 160 private SelectionListener contextEntryAddButtonListener = new SelectionAdapter() 161 { 162 public void widgetSelected( SelectionEvent e ) 163 { 164 AttributeValueDialog dialog = new AttributeValueDialog( new AttributeValueObject( "", "" ) ); 165 if ( Dialog.OK == dialog.open() && dialog.isDirty() ) 166 { 167 AttributeValueObject newAttributeValueObject = dialog.getAttributeValueObject(); 168 Attribute attribute = contextEntry.get( newAttributeValueObject.getAttribute() ); 169 if ( attribute != null ) 170 { 171 attribute.add( newAttributeValueObject.getValue() ); 172 } 173 else 174 { 175 contextEntry.put( new BasicAttribute ( newAttributeValueObject.getAttribute(), 176 newAttributeValueObject.getValue() ) ); 177 } 178 179 contextEntryTableViewer.refresh(); 180 resizeContextEntryTableColumnsToFit(); 181 masterDetailsBlock.setEditorDirty(); 182 dirty = true; 183 } 184 } 185 }; 186 187 188 private SelectionListener contextEntryEditButtonListener = new SelectionAdapter() 189 { 190 public void widgetSelected( SelectionEvent e ) 191 { 192 editSelectedContextEntry(); 193 } 194 }; 195 196 197 private SelectionListener contextEntryDeleteButtonListener = new SelectionAdapter() 198 { 199 public void widgetSelected( SelectionEvent e ) 200 { 201 StructuredSelection selection = ( StructuredSelection ) contextEntryTableViewer.getSelection(); 202 if ( !selection.isEmpty() ) 203 { 204 AttributeValueObject attributeValueObject = ( AttributeValueObject ) selection.getFirstElement(); 205 206 Attribute attribute = contextEntry.get( attributeValueObject.getAttribute() ); 207 if ( attribute != null ) 208 { 209 attribute.remove( attributeValueObject.getValue() ); 210 contextEntryTableViewer.refresh(); 211 resizeContextEntryTableColumnsToFit(); 212 masterDetailsBlock.setEditorDirty(); 213 dirty = true; 214 } 215 } 216 } 217 }; 218 219 220 private ISelectionChangedListener indexedAttributesTableViewerListener = new ISelectionChangedListener() 221 { 222 public void selectionChanged( SelectionChangedEvent event ) 223 { 224 indexedAttributeEditButton.setEnabled( !event.getSelection().isEmpty() ); 225 indexedAttributeDeleteButton.setEnabled( !event.getSelection().isEmpty() ); 226 } 227 }; 228 229 230 private IDoubleClickListener indexedAttributesTableViewerDoubleClickListener = new IDoubleClickListener() 231 { 232 public void doubleClick( DoubleClickEvent event ) 233 { 234 editSelectedIndexedAttribute(); 235 } 236 }; 237 238 239 private SelectionListener indexedAttributeAddButtonListener = new SelectionAdapter() 240 { 241 public void widgetSelected( SelectionEvent e ) 242 { 243 IndexedAttributeDialog dialog = new IndexedAttributeDialog( new IndexedAttribute( "", 0 ) ); 244 if ( Dialog.OK == dialog.open() ) 245 { 246 indexedAttributes.add( dialog.getIndexedAttribute() ); 247 indexedAttributesTableViewer.refresh(); 248 masterDetailsBlock.setEditorDirty(); 249 dirty = true; 250 } 251 } 252 }; 253 254 255 private SelectionListener indexedAttributeEditButtonListener = new SelectionAdapter() 256 { 257 public void widgetSelected( SelectionEvent e ) 258 { 259 editSelectedIndexedAttribute(); 260 } 261 }; 262 263 264 private SelectionListener indexedAttributeDeleteButtonListener = new SelectionAdapter() 265 { 266 public void widgetSelected( SelectionEvent e ) 267 { 268 StructuredSelection selection = ( StructuredSelection ) indexedAttributesTableViewer.getSelection(); 269 if ( !selection.isEmpty() ) 270 { 271 IndexedAttribute indexedAttribute = ( IndexedAttribute ) selection.getFirstElement(); 272 273 indexedAttributes.remove( indexedAttribute ); 274 indexedAttributesTableViewer.refresh(); 275 masterDetailsBlock.setEditorDirty(); 276 dirty = true; 277 } 278 } 279 }; 280 281 282 288 public PartitionDetailsPage( PartitionsMasterDetailsBlock pmdb ) 289 { 290 masterDetailsBlock = pmdb; 291 } 292 293 294 297 public void createContents( Composite parent ) 298 { 299 FormToolkit toolkit = mform.getToolkit(); 300 TableWrapLayout layout = new TableWrapLayout(); 301 layout.topMargin = 5; 302 layout.leftMargin = 5; 303 layout.rightMargin = 2; 304 layout.bottomMargin = 2; 305 parent.setLayout( layout ); 306 307 createDetailsSection( parent, toolkit ); 308 createContextEntrySection( parent, toolkit ); 309 createIndexedAttributesSection( parent, toolkit ); 310 } 311 312 313 321 private void createDetailsSection( Composite parent, FormToolkit toolkit ) 322 { 323 Section section = toolkit.createSection( parent, Section.DESCRIPTION | Section.TITLE_BAR ); 324 section.marginWidth = 10; 325 section.setText( "Partition Details" ); section.setDescription( "Set the properties of the partition." ); TableWrapData td = new TableWrapData( TableWrapData.FILL, TableWrapData.TOP ); 328 td.grabHorizontal = true; 329 section.setLayoutData( td ); 330 Composite client = toolkit.createComposite( section ); 331 toolkit.paintBordersFor( client ); 332 GridLayout glayout = new GridLayout( 3, false ); 333 client.setLayout( glayout ); 334 section.setClient( client ); 335 336 toolkit.createLabel( client, "Name:" ); 338 nameText = toolkit.createText( client, "" ); 339 nameText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); 340 341 toolkit.createLabel( client, "Cache Size:" ); 343 cacheSizeText = toolkit.createText( client, "" ); 344 cacheSizeText.addVerifyListener( 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 cacheSizeText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); 355 356 toolkit.createLabel( client, "Suffix:" ); 358 suffixText = toolkit.createText( client, "" ); 359 suffixText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); 360 361 enableOptimizerCheckbox = toolkit.createButton( client, "Enable optimizer", SWT.CHECK ); 363 enableOptimizerCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 3, 1 ) ); 364 365 synchOnWriteCheckbox = toolkit.createButton( client, "Synchronization on write", SWT.CHECK ); 367 synchOnWriteCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 3, 1 ) ); 368 } 369 370 371 379 private void createContextEntrySection( Composite parent, FormToolkit toolkit ) 380 { 381 Section section = toolkit.createSection( parent, Section.DESCRIPTION | Section.TITLE_BAR ); 382 section.marginWidth = 10; 383 section.setText( "Context Entry" ); section.setDescription( "Set the attribute/value pairs for the Context Entry of the partition." ); section.setLayoutData( new TableWrapData( TableWrapData.FILL ) ); 386 Composite client = toolkit.createComposite( section ); 387 toolkit.paintBordersFor( client ); 388 client.setLayout( new GridLayout( 2, false ) ); 389 section.setClient( client ); 390 391 contextEntryTable = toolkit.createTable( client, SWT.NONE ); 392 GridData gd = new GridData( SWT.FILL, SWT.NONE, true, false, 1, 3 ); 393 gd.heightHint = 103; 394 contextEntryTable.setLayoutData( gd ); 395 TableColumn idColumn = new TableColumn( contextEntryTable, SWT.LEFT, 0 ); 396 idColumn.setText( "Attribute" ); 397 idColumn.setWidth( 100 ); 398 TableColumn valueColumn = new TableColumn( contextEntryTable, SWT.LEFT, 1 ); 399 valueColumn.setText( "Value" ); 400 valueColumn.setWidth( 100 ); 401 contextEntryTable.setHeaderVisible( true ); 402 contextEntryTableViewer = new TableViewer( contextEntryTable ); 403 contextEntryTableViewer.setContentProvider( new IStructuredContentProvider() 404 { 405 public Object [] getElements( Object inputElement ) 406 { 407 List <AttributeValueObject> elements = new ArrayList <AttributeValueObject>(); 408 409 Attributes attributes = ( Attributes ) inputElement; 410 411 NamingEnumeration <? extends Attribute > ne = attributes.getAll(); 412 while ( ne.hasMoreElements() ) 413 { 414 Attribute attribute = ( Attribute ) ne.nextElement(); 415 try 416 { 417 NamingEnumeration <?> values = attribute.getAll(); 418 while ( values.hasMoreElements() ) 419 { 420 elements.add( new AttributeValueObject( attribute.getID(), values.nextElement() ) ); 421 } 422 } 423 catch ( NamingException e ) 424 { 425 } 426 } 427 428 return elements.toArray(); 429 } 430 431 432 public void dispose() 433 { 434 } 435 436 437 public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) 438 { 439 } 440 } ); 441 contextEntryTableViewer.setLabelProvider( new ITableLabelProvider() 442 { 443 public String getColumnText( Object element, int columnIndex ) 444 { 445 if ( element != null ) 446 { 447 switch ( columnIndex ) 448 { 449 case 0: 450 return ( ( AttributeValueObject ) element ).getAttribute(); 451 case 1: 452 return ( ( AttributeValueObject ) element ).getValue().toString(); 453 default: 454 break; 455 } 456 } 457 458 return null; 459 } 460 461 462 public Image getColumnImage( Object element, int columnIndex ) 463 { 464 return null; 465 } 466 467 468 public void addListener( ILabelProviderListener listener ) 469 { 470 } 471 472 473 public void dispose() 474 { 475 } 476 477 478 public boolean isLabelProperty( Object element, String property ) 479 { 480 return false; 481 } 482 483 484 public void removeListener( ILabelProviderListener listener ) 485 { 486 } 487 } ); 488 489 GridData buttonsGD = new GridData( SWT.FILL, SWT.BEGINNING, false, false ); 490 buttonsGD.widthHint = IDialogConstants.BUTTON_WIDTH; 491 492 contextEntryAddButton = toolkit.createButton( client, "Add...", SWT.PUSH ); 493 contextEntryAddButton.setLayoutData( buttonsGD ); 494 495 contextEntryEditButton = toolkit.createButton( client, "Edit...", SWT.PUSH ); 496 contextEntryEditButton.setEnabled( false ); 497 contextEntryEditButton.setLayoutData( buttonsGD ); 498 499 contextEntryDeleteButton = toolkit.createButton( client, "Delete", SWT.PUSH ); 500 contextEntryDeleteButton.setEnabled( false ); 501 contextEntryDeleteButton.setLayoutData( buttonsGD ); 502 } 503 504 505 513 private void createIndexedAttributesSection( Composite parent, FormToolkit toolkit ) 514 { 515 Section indexedAttributesSection = toolkit.createSection( parent, Section.DESCRIPTION | Section.TITLE_BAR ); 516 indexedAttributesSection.marginWidth = 10; 517 indexedAttributesSection.setText( "Indexed Attributes" ); indexedAttributesSection.setDescription( "Set the indexed attributes of the partition." ); indexedAttributesSection.setLayoutData( new TableWrapData( TableWrapData.FILL ) ); 520 Composite indexedAttributesClient = toolkit.createComposite( indexedAttributesSection ); 521 toolkit.paintBordersFor( indexedAttributesClient ); 522 indexedAttributesClient.setLayout( new GridLayout( 2, false ) ); 523 indexedAttributesSection.setClient( indexedAttributesClient ); 524 525 Table indexedAttributesTable = toolkit.createTable( indexedAttributesClient, SWT.NONE ); 526 GridData gd = new GridData( SWT.FILL, SWT.NONE, true, false, 1, 3 ); 527 gd.heightHint = 80; 528 indexedAttributesTable.setLayoutData( gd ); 529 indexedAttributesTableViewer = new TableViewer( indexedAttributesTable ); 530 indexedAttributesTableViewer.setContentProvider( new ArrayContentProvider() ); 531 indexedAttributesTableViewer.setLabelProvider( new LabelProvider() ); 532 533 GridData buttonsGD = new GridData( SWT.FILL, SWT.BEGINNING, false, false ); 534 buttonsGD.widthHint = IDialogConstants.BUTTON_WIDTH; 535 536 indexedAttributeAddButton = toolkit.createButton( indexedAttributesClient, "Add...", SWT.PUSH ); 537 indexedAttributeAddButton.setLayoutData( buttonsGD ); 538 539 indexedAttributeEditButton = toolkit.createButton( indexedAttributesClient, "Edit...", SWT.PUSH ); 540 indexedAttributeEditButton.setEnabled( false ); 541 indexedAttributeEditButton.setLayoutData( buttonsGD ); 542 543 indexedAttributeDeleteButton = toolkit.createButton( indexedAttributesClient, "Delete", SWT.PUSH ); 544 indexedAttributeDeleteButton.setEnabled( false ); 545 indexedAttributeDeleteButton.setLayoutData( buttonsGD ); 546 } 547 548 549 552 private void addListeners() 553 { 554 nameText.addModifyListener( textModifyListener ); 555 cacheSizeText.addModifyListener( textModifyListener ); 556 suffixText.addModifyListener( textModifyListener ); 557 enableOptimizerCheckbox.addSelectionListener( checkboxSelectionListener ); 558 synchOnWriteCheckbox.addSelectionListener( checkboxSelectionListener ); 559 560 contextEntryTableViewer.addDoubleClickListener( contextEntryTableViewerDoubleClickListener ); 561 contextEntryTableViewer.addSelectionChangedListener( contextEntryTableViewerListener ); 562 contextEntryAddButton.addSelectionListener( contextEntryAddButtonListener ); 563 contextEntryEditButton.addSelectionListener( contextEntryEditButtonListener ); 564 contextEntryDeleteButton.addSelectionListener( contextEntryDeleteButtonListener ); 565 566 indexedAttributesTableViewer.addSelectionChangedListener( indexedAttributesTableViewerListener ); 567 indexedAttributesTableViewer.addDoubleClickListener( indexedAttributesTableViewerDoubleClickListener ); 568 indexedAttributeAddButton.addSelectionListener( indexedAttributeAddButtonListener ); 569 indexedAttributeEditButton.addSelectionListener( indexedAttributeEditButtonListener ); 570 indexedAttributeDeleteButton.addSelectionListener( indexedAttributeDeleteButtonListener ); 571 } 572 573 574 577 private void removeListeners() 578 { 579 nameText.removeModifyListener( textModifyListener ); 580 cacheSizeText.removeModifyListener( textModifyListener ); 581 suffixText.removeModifyListener( textModifyListener ); 582 enableOptimizerCheckbox.removeSelectionListener( checkboxSelectionListener ); 583 synchOnWriteCheckbox.removeSelectionListener( checkboxSelectionListener ); 584 585 contextEntryTableViewer.removeDoubleClickListener( contextEntryTableViewerDoubleClickListener ); 586 contextEntryTableViewer.removeSelectionChangedListener( contextEntryTableViewerListener ); 587 contextEntryAddButton.removeSelectionListener( contextEntryAddButtonListener ); 588 contextEntryEditButton.removeSelectionListener( contextEntryEditButtonListener ); 589 contextEntryDeleteButton.removeSelectionListener( contextEntryDeleteButtonListener ); 590 591 indexedAttributesTableViewer.removeSelectionChangedListener( indexedAttributesTableViewerListener ); 592 indexedAttributesTableViewer.removeDoubleClickListener( indexedAttributesTableViewerDoubleClickListener ); 593 indexedAttributeAddButton.removeSelectionListener( indexedAttributeAddButtonListener ); 594 indexedAttributeEditButton.removeSelectionListener( indexedAttributeEditButtonListener ); 595 indexedAttributeDeleteButton.removeSelectionListener( indexedAttributeDeleteButtonListener ); 596 } 597 598 599 602 public void selectionChanged( IFormPart part, ISelection selection ) 603 { 604 IStructuredSelection ssel = ( IStructuredSelection ) selection; 605 if ( ssel.size() == 1 ) 606 { 607 input = ( Partition ) ssel.getFirstElement(); 608 } 609 else 610 { 611 input = null; 612 } 613 refresh(); 614 } 615 616 617 620 public void commit( boolean onSave ) 621 { 622 if ( input != null ) 623 { 624 input.setName( nameText.getText() ); 625 input.setCacheSize( Integer.parseInt( cacheSizeText.getText() ) ); 626 input.setSuffix( suffixText.getText() ); 627 input.setEnableOptimizer( enableOptimizerCheckbox.getSelection() ); 628 input.setSynchronizationOnWrite( synchOnWriteCheckbox.getSelection() ); 629 } 630 } 631 632 633 636 public void dispose() 637 { 638 } 639 640 641 644 public void initialize( IManagedForm form ) 645 { 646 this.mform = form; 647 } 648 649 650 653 public boolean isDirty() 654 { 655 return dirty; 656 } 657 658 659 662 public boolean isStale() 663 { 664 return false; 665 } 666 667 668 671 public void refresh() 672 { 673 removeListeners(); 674 675 String name = input.getName(); 677 nameText.setText( ( name == null ) ? "" : name ); 678 679 cacheSizeText.setText( "" + input.getCacheSize() ); 681 682 String suffix = input.getSuffix(); 684 suffixText.setText( ( suffix == null ) ? "" : suffix ); 685 686 enableOptimizerCheckbox.setSelection( input.isEnableOptimizer() ); 688 689 synchOnWriteCheckbox.setSelection( input.isSynchronizationOnWrite() ); 691 692 contextEntry = input.getContextEntry(); 694 contextEntryTableViewer.setInput( contextEntry ); 695 resizeContextEntryTableColumnsToFit(); 696 697 indexedAttributes = input.getIndexedAttributes(); 699 indexedAttributesTableViewer.setInput( indexedAttributes ); 700 701 addListeners(); 702 } 703 704 705 708 private void resizeContextEntryTableColumnsToFit() 709 { 710 contextEntryTable.getColumn( 0 ).pack(); 712 contextEntryTable.getColumn( 0 ).setWidth( contextEntryTable.getColumn( 0 ).getWidth() + 5 ); 714 contextEntryTable.getColumn( 1 ).pack(); 716 } 717 718 719 722 public void setFocus() 723 { 724 nameText.setFocus(); 725 } 726 727 728 731 public boolean setFormInput( Object input ) 732 { 733 return false; 734 } 735 736 737 741 private void editSelectedIndexedAttribute() 742 { 743 StructuredSelection selection = ( StructuredSelection ) indexedAttributesTableViewer.getSelection(); 744 if ( !selection.isEmpty() ) 745 { 746 IndexedAttribute indexedAttribute = ( IndexedAttribute ) selection.getFirstElement(); 747 748 IndexedAttributeDialog dialog = new IndexedAttributeDialog( indexedAttribute ); 749 if ( Dialog.OK == dialog.open() && dialog.isDirty() ) 750 { 751 indexedAttributesTableViewer.refresh(); 752 masterDetailsBlock.setEditorDirty(); 753 dirty = true; 754 } 755 } 756 } 757 758 759 763 private void editSelectedContextEntry() 764 { 765 StructuredSelection selection = ( StructuredSelection ) contextEntryTableViewer.getSelection(); 766 if ( !selection.isEmpty() ) 767 { 768 AttributeValueObject attributeValueObject = ( AttributeValueObject ) selection.getFirstElement(); 769 770 String oldId = attributeValueObject.getAttribute(); 771 Object oldValue = attributeValueObject.getValue(); 772 773 AttributeValueDialog dialog = new AttributeValueDialog( attributeValueObject ); 774 if ( Dialog.OK == dialog.open() && dialog.isDirty() ) 775 { 776 Attribute attribute = contextEntry.get( oldId ); 777 if ( attribute != null ) 778 { 779 attribute.remove( oldValue ); 780 } 781 782 AttributeValueObject newAttributeValueObject = dialog.getAttributeValueObject(); 783 attribute = contextEntry.get( newAttributeValueObject.getAttribute() ); 784 if ( attribute != null ) 785 { 786 attribute.add( newAttributeValueObject.getValue() ); 787 } 788 else 789 { 790 contextEntry.put( new BasicAttribute ( newAttributeValueObject.getAttribute(), 791 newAttributeValueObject.getValue() ) ); 792 } 793 794 contextEntryTableViewer.refresh(); 795 resizeContextEntryTableColumnsToFit(); 796 masterDetailsBlock.setEditorDirty(); 797 dirty = true; 798 } 799 } 800 } 801 } 802 | Popular Tags |