KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > apacheds > configuration > editor > PartitionDetailsPage


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20 package org.apache.directory.ldapstudio.apacheds.configuration.editor;
21
22
23 import java.util.ArrayList JavaDoc;
24 import java.util.List JavaDoc;
25
26 import javax.naming.NamingEnumeration JavaDoc;
27 import javax.naming.NamingException JavaDoc;
28 import javax.naming.directory.Attribute JavaDoc;
29 import javax.naming.directory.Attributes JavaDoc;
30 import javax.naming.directory.BasicAttribute JavaDoc;
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 /**
78  * This class represents the Details Page of the Server Configuration Editor for the Partition type
79  *
80  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
81  * @version $Rev$, $Date$
82  */

83 public class PartitionDetailsPage implements IDetailsPage
84 {
85     /** The associated Master Details Block */
86     private PartitionsMasterDetailsBlock masterDetailsBlock;
87
88     /** The Managed Form */
89     private IManagedForm mform;
90
91     /** The input Partition */
92     private Partition input;
93
94     /** The Context Entry */
95     private Attributes JavaDoc contextEntry;
96
97     /** The Indexed Attributes List */
98     private List JavaDoc<IndexedAttribute> indexedAttributes;
99
100     /** The dirty flag */
101     private boolean dirty = false;
102
103     // UI fields
104
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     // Listeners
120
/** The Text Modify Listener */
121     private ModifyListener textModifyListener = new ModifyListener()
122     {
123         public void modifyText( ModifyEvent e )
124         {
125             masterDetailsBlock.setEditorDirty();
126             dirty = true;
127         }
128     };
129
130     /** The Checkbox Selection Listener */
131     private SelectionListener checkboxSelectionListener = new SelectionAdapter()
132     {
133         public void widgetSelected( SelectionEvent e )
134         {
135             masterDetailsBlock.setEditorDirty();
136             dirty = true;
137         }
138     };
139
140     /** The Selection Changed Listener for the Context Entry Table Viewer */
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     /** The Double Click Listener for the Indexed Attributes Table Viewer */
151     private IDoubleClickListener contextEntryTableViewerDoubleClickListener = new IDoubleClickListener()
152     {
153         public void doubleClick( DoubleClickEvent event )
154         {
155             editSelectedContextEntry();
156         }
157     };
158
159     /** The Listener for the Add button of the Context Entry Section */
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 JavaDoc attribute = contextEntry.get( newAttributeValueObject.getAttribute() );
169                 if ( attribute != null )
170                 {
171                     attribute.add( newAttributeValueObject.getValue() );
172                 }
173                 else
174                 {
175                     contextEntry.put( new BasicAttribute JavaDoc( newAttributeValueObject.getAttribute(),
176                         newAttributeValueObject.getValue() ) );
177                 }
178
179                 contextEntryTableViewer.refresh();
180                 resizeContextEntryTableColumnsToFit();
181                 masterDetailsBlock.setEditorDirty();
182                 dirty = true;
183             }
184         }
185     };
186
187     /** The Listener for the Edit button of the Context Entry Section */
188     private SelectionListener contextEntryEditButtonListener = new SelectionAdapter()
189     {
190         public void widgetSelected( SelectionEvent e )
191         {
192             editSelectedContextEntry();
193         }
194     };
195
196     /** The Listener for the Delete button of the Context Entry Section */
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 JavaDoc 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     /** The Selection Changed Listener for the Indexed Attributes Table Viewer */
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     /** The Double Click Listener for the Indexed Attributes Table Viewer */
230     private IDoubleClickListener indexedAttributesTableViewerDoubleClickListener = new IDoubleClickListener()
231     {
232         public void doubleClick( DoubleClickEvent event )
233         {
234             editSelectedIndexedAttribute();
235         }
236     };
237
238     /** The Listener for the Add button of the Indexed Attributes Section */
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     /** The Listener for the Edit button of the Indexed Attributes Section */
255     private SelectionListener indexedAttributeEditButtonListener = new SelectionAdapter()
256     {
257         public void widgetSelected( SelectionEvent e )
258         {
259             editSelectedIndexedAttribute();
260         }
261     };
262
263     /** The Listener for the Delete button of the Indexed Attributes Section */
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     /**
283      * Creates a new instance of PartitionDetailsPage.
284      *
285      * @param pmdb
286      * the associated Master Details Block
287      */

288     public PartitionDetailsPage( PartitionsMasterDetailsBlock pmdb )
289     {
290         masterDetailsBlock = pmdb;
291     }
292
293
294     /* (non-Javadoc)
295      * @see org.eclipse.ui.forms.IDetailsPage#createContents(org.eclipse.swt.widgets.Composite)
296      */

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     /**
314      * Creates the Details Section
315      *
316      * @param parent
317      * the parent composite
318      * @param toolkit
319      * the toolkit to use
320      */

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" ); //$NON-NLS-1$
326
section.setDescription( "Set the properties of the partition." ); //$NON-NLS-1$
327
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         // Name
337
toolkit.createLabel( client, "Name:" );
338         nameText = toolkit.createText( client, "" );
339         nameText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
340
341         // Cache Size
342
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]*" ) ) //$NON-NLS-1$
349
{
350                     e.doit = false;
351                 }
352             }
353         } );
354         cacheSizeText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
355
356         // Suffix
357
toolkit.createLabel( client, "Suffix:" );
358         suffixText = toolkit.createText( client, "" );
359         suffixText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
360
361         // Enable Optimizer
362
enableOptimizerCheckbox = toolkit.createButton( client, "Enable optimizer", SWT.CHECK );
363         enableOptimizerCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 3, 1 ) );
364
365         // Synchronisation On Write
366
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     /**
372      * Creates the Context Entry Section.
373      *
374      * @param parent
375      * the parent composite
376      * @param toolkit
377      * the toolkit to use
378      */

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" ); //$NON-NLS-1$
384
section.setDescription( "Set the attribute/value pairs for the Context Entry of the partition." ); //$NON-NLS-1$
385
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 JavaDoc[] getElements( Object JavaDoc inputElement )
406             {
407                 List JavaDoc<AttributeValueObject> elements = new ArrayList JavaDoc<AttributeValueObject>();
408
409                 Attributes JavaDoc attributes = ( Attributes JavaDoc ) inputElement;
410
411                 NamingEnumeration JavaDoc<? extends Attribute JavaDoc> ne = attributes.getAll();
412                 while ( ne.hasMoreElements() )
413                 {
414                     Attribute JavaDoc attribute = ( Attribute JavaDoc ) ne.nextElement();
415                     try
416                     {
417                         NamingEnumeration JavaDoc<?> values = attribute.getAll();
418                         while ( values.hasMoreElements() )
419                         {
420                             elements.add( new AttributeValueObject( attribute.getID(), values.nextElement() ) );
421                         }
422                     }
423                     catch ( NamingException JavaDoc 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 JavaDoc oldInput, Object JavaDoc newInput )
438             {
439             }
440         } );
441         contextEntryTableViewer.setLabelProvider( new ITableLabelProvider()
442         {
443             public String JavaDoc getColumnText( Object JavaDoc 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 JavaDoc 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 JavaDoc element, String JavaDoc 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     /**
506      * Creates the Indexed Attributes Section
507      *
508      * @param parent
509      * the parent composite
510      * @param toolkit
511      * the toolkit to use
512      */

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" ); //$NON-NLS-1$
518
indexedAttributesSection.setDescription( "Set the indexed attributes of the partition." ); //$NON-NLS-1$
519
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     /**
550      * Adds listeners to UI fields.
551      */

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     /**
575      * Removes listeners to UI fields.
576      */

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     /* (non-Javadoc)
600      * @see org.eclipse.ui.forms.IPartSelectionListener#selectionChanged(org.eclipse.ui.forms.IFormPart, org.eclipse.jface.viewers.ISelection)
601      */

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     /* (non-Javadoc)
618      * @see org.eclipse.ui.forms.IFormPart#commit(boolean)
619      */

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     /* (non-Javadoc)
634      * @see org.eclipse.ui.forms.IFormPart#dispose()
635      */

636     public void dispose()
637     {
638     }
639
640
641     /* (non-Javadoc)
642      * @see org.eclipse.ui.forms.IFormPart#initialize(org.eclipse.ui.forms.IManagedForm)
643      */

644     public void initialize( IManagedForm form )
645     {
646         this.mform = form;
647     }
648
649
650     /* (non-Javadoc)
651      * @see org.eclipse.ui.forms.IFormPart#isDirty()
652      */

653     public boolean isDirty()
654     {
655         return dirty;
656     }
657
658
659     /* (non-Javadoc)
660      * @see org.eclipse.ui.forms.IFormPart#isStale()
661      */

662     public boolean isStale()
663     {
664         return false;
665     }
666
667
668     /* (non-Javadoc)
669      * @see org.eclipse.ui.forms.IFormPart#refresh()
670      */

671     public void refresh()
672     {
673         removeListeners();
674
675         // Name
676
String JavaDoc name = input.getName();
677         nameText.setText( ( name == null ) ? "" : name );
678
679         // Cache Size
680
cacheSizeText.setText( "" + input.getCacheSize() );
681
682         // Suffix
683
String JavaDoc suffix = input.getSuffix();
684         suffixText.setText( ( suffix == null ) ? "" : suffix );
685
686         // Enable Optimizer
687
enableOptimizerCheckbox.setSelection( input.isEnableOptimizer() );
688
689         // Synchronization on write
690
synchOnWriteCheckbox.setSelection( input.isSynchronizationOnWrite() );
691
692         // Context Entry
693
contextEntry = input.getContextEntry();
694         contextEntryTableViewer.setInput( contextEntry );
695         resizeContextEntryTableColumnsToFit();
696
697         // Indexed Attributes
698
indexedAttributes = input.getIndexedAttributes();
699         indexedAttributesTableViewer.setInput( indexedAttributes );
700
701         addListeners();
702     }
703
704
705     /**
706      * Resizes the columns to fit the size of the cells.
707      */

708     private void resizeContextEntryTableColumnsToFit()
709     {
710         // Resizing the first column
711
contextEntryTable.getColumn( 0 ).pack();
712         // Adding a little space to the first column
713
contextEntryTable.getColumn( 0 ).setWidth( contextEntryTable.getColumn( 0 ).getWidth() + 5 );
714         // Resizing the second column
715
contextEntryTable.getColumn( 1 ).pack();
716     }
717
718
719     /* (non-Javadoc)
720      * @see org.eclipse.ui.forms.IFormPart#setFocus()
721      */

722     public void setFocus()
723     {
724         nameText.setFocus();
725     }
726
727
728     /* (non-Javadoc)
729      * @see org.eclipse.ui.forms.IFormPart#setFormInput(java.lang.Object)
730      */

731     public boolean setFormInput( Object JavaDoc input )
732     {
733         return false;
734     }
735
736
737     /**
738      * Opens an Indexed Attribute Dialog with the selected Indexed Attribute in the
739      * Indexed Attributes Table Viewer.
740      */

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     /**
760      * Opens a Context Entry Dialog with the selected Attribute Value Object in the
761      * Context Entry Table Viewer.
762      */

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 JavaDoc oldId = attributeValueObject.getAttribute();
771             Object JavaDoc oldValue = attributeValueObject.getValue();
772
773             AttributeValueDialog dialog = new AttributeValueDialog( attributeValueObject );
774             if ( Dialog.OK == dialog.open() && dialog.isDirty() )
775             {
776                 Attribute JavaDoc 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 JavaDoc( 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