KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > aciitemeditor > valueeditors > SubtreeSpecificationDialog


1 package org.apache.directory.ldapstudio.aciitemeditor.valueeditors;
2
3 import java.text.ParseException JavaDoc;
4 import java.util.ArrayList JavaDoc;
5 import java.util.Iterator JavaDoc;
6 import java.util.List JavaDoc;
7 import java.util.Set JavaDoc;
8
9 import org.apache.directory.ldapstudio.aciitemeditor.Activator;
10 import org.apache.directory.ldapstudio.browser.common.dialogs.TextDialog;
11 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
12 import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyEvent;
13 import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyListener;
14 import org.apache.directory.ldapstudio.browser.common.widgets.search.EntryWidget;
15 import org.apache.directory.ldapstudio.browser.common.widgets.search.FilterWidget;
16 import org.apache.directory.ldapstudio.browser.core.model.DN;
17 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
18 import org.apache.directory.ldapstudio.browser.core.model.NameException;
19 import org.apache.directory.shared.ldap.name.LdapDN;
20 import org.apache.directory.shared.ldap.subtree.BaseSubtreeSpecification;
21 import org.apache.directory.shared.ldap.subtree.SubtreeSpecification;
22 import org.apache.directory.shared.ldap.subtree.SubtreeSpecificationParser;
23 import org.eclipse.jface.dialogs.Dialog;
24 import org.eclipse.jface.dialogs.IDialogConstants;
25 import org.eclipse.jface.viewers.ArrayContentProvider;
26 import org.eclipse.jface.viewers.DoubleClickEvent;
27 import org.eclipse.jface.viewers.IDoubleClickListener;
28 import org.eclipse.jface.viewers.ISelectionChangedListener;
29 import org.eclipse.jface.viewers.IStructuredSelection;
30 import org.eclipse.jface.viewers.LabelProvider;
31 import org.eclipse.jface.viewers.SelectionChangedEvent;
32 import org.eclipse.jface.viewers.TableViewer;
33 import org.eclipse.swt.SWT;
34 import org.eclipse.swt.events.ModifyEvent;
35 import org.eclipse.swt.events.ModifyListener;
36 import org.eclipse.swt.events.SelectionAdapter;
37 import org.eclipse.swt.events.SelectionEvent;
38 import org.eclipse.swt.layout.GridData;
39 import org.eclipse.swt.layout.GridLayout;
40 import org.eclipse.swt.widgets.Button;
41 import org.eclipse.swt.widgets.Composite;
42 import org.eclipse.swt.widgets.Control;
43 import org.eclipse.swt.widgets.Shell;
44 import org.eclipse.swt.widgets.Spinner;
45 import org.eclipse.swt.widgets.Table;
46 import org.eclipse.swt.widgets.Text;
47
48 /**
49  * This class provides a dialog to enter the Subtree Specification value.
50  *
51  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
52  * @version $Rev$, $Date$
53  */

54 class SubtreeSpecificationDialog extends Dialog
55 {
56
57     /** The parser. */
58     private final SubtreeSpecificationParser parser = new SubtreeSpecificationParser( null );
59
60     /** The connection */
61     private IConnection connection;
62
63     /** The subentry's DN */
64     private DN subentryDN;
65
66     /** Flag indicating if the refinement or filter widget should be visible */
67     private boolean refinementOrFilterVisible;
68
69     /** The initial SubtreeSpecification */
70     private SubtreeSpecification subtreeSpecification;
71
72     /** The Exclusions List */
73     private List JavaDoc<String JavaDoc> exclusions;
74
75     /** The returned SubtreeSpecification */
76     private String JavaDoc returnValue;
77
78     // UI Fields
79
private EntryWidget entryWidget;
80     private Spinner minimumSpinner;
81     private Spinner maximumSpinner;
82     private TableViewer exclusionsTableViewer;
83     private Button exclusionsTableAddButton;
84     private Button exclusionsTableEditButton;
85     private Button exclusionsTableDeleteButton;
86     private Button refinementButton;
87     private Text refinementText;
88     private Button filterButton;
89     private FilterWidget filterWidget;
90
91
92     /**
93      * Creates a new instance of SubtreeSpecificationDialog.
94      *
95      * @param shell
96      * the shell to use
97      * @param connection
98      * the connection to use
99      * @param subentryDN
100      * the subentry's DN
101      * @param initialSubtreeSpecification
102      * the initial SubtreeSpecification
103      * @param refinementOrFilterVisible
104      * true if the refinement of filter widget should be visible
105      */

106     SubtreeSpecificationDialog( Shell shell, IConnection connection, DN subentryDN,
107         String JavaDoc initialSubtreeSpecification, boolean refinementOrFilterVisible )
108     {
109         super( shell );
110         this.connection = connection;
111         this.subentryDN = subentryDN;
112         this.refinementOrFilterVisible = refinementOrFilterVisible;
113
114         // parse
115
try
116         {
117             subtreeSpecification = parser.parse( initialSubtreeSpecification );
118             if ( subtreeSpecification == null )
119             {
120                 subtreeSpecification = new BaseSubtreeSpecification();
121             }
122         }
123         catch ( ParseException JavaDoc pe )
124         {
125             // TODO
126
pe.printStackTrace();
127             subtreeSpecification = new BaseSubtreeSpecification();
128         }
129
130         exclusions = new ArrayList JavaDoc<String JavaDoc>();
131         Set JavaDoc chopBeforeExclusions = subtreeSpecification.getChopBeforeExclusions();
132         for ( Object JavaDoc chopBeforeExclusion : chopBeforeExclusions )
133         {
134             LdapDN dn = ( LdapDN ) chopBeforeExclusion;
135             exclusions.add( "chopBefore: \"" + dn.toNormName() + "\"" ); //$NON-NLS-1$ //$NON-NLS-2$
136
}
137
138         Set JavaDoc chopAfterExclusions = subtreeSpecification.getChopAfterExclusions();
139         for ( Object JavaDoc chopAfterExclusion : chopAfterExclusions )
140         {
141             LdapDN dn = ( LdapDN ) chopAfterExclusion;
142             exclusions.add( "chopAfter: \"" + dn.toNormName() + "\"" ); //$NON-NLS-1$ //$NON-NLS-2$
143
}
144
145         returnValue = null;
146     }
147
148
149     /* (non-Javadoc)
150      * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
151      */

152     protected void configureShell( Shell newShell )
153     {
154         super.configureShell( newShell );
155         newShell.setText( Messages.getString( "SubtreeValueEditor.title" ) ); //$NON-NLS-1$
156
newShell.setImage( Activator.getDefault().getImage( Messages.getString( "SubtreeValueEditor.icon" ) ) ); //$NON-NLS-1$
157
}
158
159
160     /* (non-Javadoc)
161      * @see org.eclipse.jface.dialogs.Dialog#okPressed()
162      */

163     protected void okPressed()
164     {
165         // set return value
166
//returnValue = buildSubreeSpecification();
167
StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
168         subtreeSpecification.printToBuffer( sb );
169         returnValue = sb.toString();
170
171         // save filter and dn history
172
if ( refinementOrFilterVisible )
173         {
174             filterWidget.saveDialogSettings();
175         }
176         entryWidget.saveDialogSettings();
177
178         super.okPressed();
179     }
180
181
182     /* (non-Javadoc)
183      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
184      */

185     protected Control createDialogArea( Composite parent )
186     {
187         Composite outer = ( Composite ) super.createDialogArea( parent );
188         GridData gd = new GridData( GridData.FILL_BOTH );
189         gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
190         outer.setLayoutData( gd );
191
192         Composite composite = BaseWidgetUtils.createColumnContainer( outer, 3, 1 );
193
194         BaseWidgetUtils.createLabel( composite, Messages.getString( "SubtreeValueEditor.label.base" ), 1 ); //$NON-NLS-1$
195

196         DN base = null;
197         DN suffix = null;
198         try
199         {
200             base = new DN( subtreeSpecification.getBase().toNormName() );
201             suffix = subentryDN != null ? subentryDN.getParentDn() : null;
202         }
203         catch ( NameException e )
204         {
205         }
206         entryWidget = new EntryWidget( connection, base, suffix );
207         entryWidget.createWidget( composite );
208         entryWidget.addWidgetModifyListener( new WidgetModifyListener()
209         {
210             public void widgetModified( WidgetModifyEvent event )
211             {
212                 validate();
213             }
214         } );
215
216         GridData spinnersGridData = new GridData();
217         spinnersGridData.grabExcessHorizontalSpace = true;
218         spinnersGridData.verticalAlignment = GridData.CENTER;
219         spinnersGridData.horizontalSpan = 2;
220         spinnersGridData.horizontalAlignment = GridData.BEGINNING;
221         spinnersGridData.widthHint = 3 * 12;
222
223         BaseWidgetUtils.createLabel( composite, Messages.getString( "SubtreeValueEditor.label.minimum" ), 1 ); //$NON-NLS-1$
224
minimumSpinner = new Spinner( composite, SWT.BORDER );
225         minimumSpinner.setMinimum( 0 );
226         minimumSpinner.setMaximum( Integer.MAX_VALUE );
227         minimumSpinner.setDigits( 0 );
228         minimumSpinner.setIncrement( 1 );
229         minimumSpinner.setPageIncrement( 100 );
230         minimumSpinner.setSelection( subtreeSpecification.getMinBaseDistance() );
231         minimumSpinner.setLayoutData( spinnersGridData );
232         minimumSpinner.addModifyListener( new ModifyListener()
233         {
234             public void modifyText( ModifyEvent event )
235             {
236                 validate();
237             }
238         } );
239
240         BaseWidgetUtils.createLabel( composite, Messages.getString( "SubtreeValueEditor.label.maximum" ), 1 ); //$NON-NLS-1$
241
maximumSpinner = new Spinner( composite, SWT.BORDER );
242         maximumSpinner.setMinimum( 0 );
243         maximumSpinner.setMaximum( Integer.MAX_VALUE );
244         maximumSpinner.setDigits( 0 );
245         maximumSpinner.setIncrement( 1 );
246         maximumSpinner.setPageIncrement( 100 );
247         maximumSpinner.setSelection( subtreeSpecification.getMaxBaseDistance() );
248         maximumSpinner.setLayoutData( spinnersGridData );
249         maximumSpinner.addModifyListener( new ModifyListener()
250         {
251             public void modifyText( ModifyEvent event )
252             {
253                 validate();
254             }
255         } );
256
257         createExclusionsTable( composite );
258
259         if ( refinementOrFilterVisible )
260         {
261             BaseWidgetUtils.createSpacer( composite, 3 );
262             createRefinementOrFilterWidgets( composite );
263         }
264
265         applyDialogFont( outer );
266
267         initFromInput();
268
269         validate();
270
271         return outer;
272     }
273
274
275     /**
276      * Initializes the Value Editor from the input.
277      */

278     private void initFromInput()
279     {
280
281     }
282
283
284     /**
285      * Creates the Exclusions Table.
286      *
287      * @param composite
288      * the composite
289      */

290     private void createExclusionsTable( Composite composite )
291     {
292         GridData tableGridData = new GridData();
293         tableGridData.grabExcessHorizontalSpace = true;
294         tableGridData.verticalAlignment = GridData.FILL;
295         tableGridData.horizontalAlignment = GridData.FILL;
296         tableGridData.heightHint = 100;
297
298         BaseWidgetUtils.createLabel( composite, Messages.getString( "SubtreeValueEditor.label.exclusions" ), 1 ); //$NON-NLS-1$
299
Table exclusionsTable = new Table( composite, SWT.BORDER );
300         exclusionsTable.setHeaderVisible( false );
301         exclusionsTable.setLayoutData( tableGridData );
302         exclusionsTable.setLinesVisible( false );
303         exclusionsTableViewer = new TableViewer( exclusionsTable );
304         exclusionsTableViewer.setContentProvider( new ArrayContentProvider() );
305         exclusionsTableViewer.setLabelProvider( new LabelProvider() );
306         exclusionsTableViewer.setInput( exclusions );
307         exclusionsTableViewer.addSelectionChangedListener( new ISelectionChangedListener()
308         {
309             public void selectionChanged( SelectionChangedEvent event )
310             {
311                 valueSelectedExclusionsTable();
312             }
313         } );
314         exclusionsTableViewer.addDoubleClickListener( new IDoubleClickListener()
315         {
316             public void doubleClick( DoubleClickEvent event )
317             {
318                 editValueExclusionsTable();
319             }
320         } );
321
322         GridLayout gridLayout = new GridLayout();
323         gridLayout.marginWidth = 0;
324         gridLayout.marginHeight = 0;
325         GridData gridData = new GridData();
326         gridData.horizontalAlignment = GridData.CENTER;
327         gridData.grabExcessHorizontalSpace = false;
328         gridData.grabExcessVerticalSpace = false;
329         gridData.verticalAlignment = GridData.FILL;
330
331         Composite buttonComposite = new Composite( composite, SWT.NONE );
332         buttonComposite.setLayoutData( gridData );
333         buttonComposite.setLayout( gridLayout );
334
335         GridData buttonGridData = new GridData();
336         buttonGridData.horizontalAlignment = GridData.FILL;
337         buttonGridData.grabExcessHorizontalSpace = false;
338         buttonGridData.verticalAlignment = GridData.BEGINNING;
339         buttonGridData.widthHint = Activator.getButtonWidth( buttonComposite );
340
341         exclusionsTableAddButton = new Button( buttonComposite, SWT.PUSH );
342         exclusionsTableAddButton.setText( Messages.getString( "SubtreeValueEditor.button.add" ) ); //$NON-NLS-1$
343
exclusionsTableAddButton.setLayoutData( buttonGridData );
344         exclusionsTableAddButton.addSelectionListener( new SelectionAdapter()
345         {
346             public void widgetSelected( SelectionEvent e )
347             {
348                 addValueExclusionsTable();
349             }
350         } );
351
352         exclusionsTableEditButton = new Button( buttonComposite, SWT.PUSH );
353         exclusionsTableEditButton.setText( Messages.getString( "SubtreeValueEditor.button.edit" ) ); //$NON-NLS-1$
354
exclusionsTableEditButton.setLayoutData( buttonGridData );
355         exclusionsTableEditButton.addSelectionListener( new SelectionAdapter()
356         {
357             public void widgetSelected( SelectionEvent e )
358             {
359                 editValueExclusionsTable();
360             }
361         } );
362         exclusionsTableEditButton.setEnabled( false );
363
364         exclusionsTableDeleteButton = new Button( buttonComposite, SWT.PUSH );
365         exclusionsTableDeleteButton.setText( Messages.getString( "SubtreeValueEditor.button.delete" ) ); //$NON-NLS-1$
366
exclusionsTableDeleteButton.setLayoutData( buttonGridData );
367         exclusionsTableDeleteButton.addSelectionListener( new SelectionAdapter()
368         {
369             public void widgetSelected( SelectionEvent e )
370             {
371                 deleteValueExclusionsTable();
372             }
373         } );
374         exclusionsTableDeleteButton.setEnabled( false );
375     }
376
377
378     /**
379      * Creates the refinement or filter widgets
380      *
381      * @param composite
382      * the composite
383      */

384     private void createRefinementOrFilterWidgets( Composite parent )
385     {
386         // Messages.getString( "SubtreeValueEditor.label.exclusions" )
387
BaseWidgetUtils.createLabel( parent, Messages
388             .getString( "SubtreeValueEditor.SubtreeValueEditor.label.refinementOrFilter" ), 1 ); //$NON-NLS-1$
389

390         Composite composite = BaseWidgetUtils.createColumnContainer( parent, 2, 2 );
391
392         // refinement redio button
393
refinementButton = BaseWidgetUtils.createRadiobutton( composite, Messages
394             .getString( "SubtreeValueEditor.SubtreeValueEditor.label.refinement" ), 2 ); //$NON-NLS-1$
395

396         // refinement text
397
refinementText = new Text( composite, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL );
398         GridData gd = new GridData( GridData.FILL_BOTH );
399         gd.horizontalSpan = 2;
400         gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
401         gd.heightHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH / 6 );
402         refinementText.setLayoutData( gd );
403         try
404         {
405             StringBuffer JavaDoc refinementBuffer = new StringBuffer JavaDoc();
406             if ( subtreeSpecification.getRefinement() != null )
407             {
408                 subtreeSpecification.getRefinement().printRefinementToBuffer( refinementBuffer );
409             }
410             refinementText.setText( refinementBuffer.toString().trim() );
411             refinementText.setEnabled( true );
412             refinementButton.setSelection( true );
413         }
414         catch ( UnsupportedOperationException JavaDoc e )
415         {
416             // thrown if the ExprNode doesn't represent a valid refinement
417
refinementText.setText( "" ); //$NON-NLS-1$
418
refinementText.setEnabled( false );
419             refinementButton.setSelection( false );
420         }
421
422         // filter radio button
423
filterButton = BaseWidgetUtils.createRadiobutton( composite, Messages
424             .getString( "SubtreeValueEditor.SubtreeValueEditor.label.filter" ), 2 ); //$NON-NLS-1$
425

426         // filter widget
427
StringBuffer JavaDoc filterBuffer = new StringBuffer JavaDoc();
428         if ( subtreeSpecification.getRefinement() != null )
429         {
430             subtreeSpecification.getRefinement().printToBuffer( filterBuffer );
431         }
432         filterWidget = new FilterWidget( connection, filterBuffer.toString().trim() );
433         filterWidget.createWidget( composite );
434         filterButton.setSelection( !refinementButton.getSelection() );
435         filterWidget.setEnabled( !refinementButton.getSelection() );
436
437         // add listeners
438
refinementButton.addSelectionListener( new SelectionAdapter()
439         {
440             public void widgetSelected( SelectionEvent arg0 )
441             {
442                 refinementText.setEnabled( true );
443                 //filterButton.setSelection( false );
444
filterWidget.setEnabled( false );
445                 validate();
446             }
447         } );
448         refinementText.addModifyListener( new ModifyListener()
449         {
450             public void modifyText( ModifyEvent event )
451             {
452                 validate();
453             }
454         } );
455         filterButton.addSelectionListener( new SelectionAdapter()
456         {
457             public void widgetSelected( SelectionEvent arg0 )
458             {
459                 //refinementButton.setSelection( false );
460
refinementText.setEnabled( false );
461                 filterWidget.setEnabled( true );
462                 validate();
463             }
464         } );
465         filterWidget.addWidgetModifyListener( new WidgetModifyListener()
466         {
467             public void widgetModified( WidgetModifyEvent event )
468             {
469                 validate();
470             }
471         } );
472     }
473
474
475     /**
476      * Validates if the composed subtree specification is valid.
477      */

478     private void validate()
479     {
480         boolean valid = true;
481
482         DN base = entryWidget.getDn();
483         valid &= base != null;
484
485         String JavaDoc ss = buildSubreeSpecification();
486
487         try
488         {
489             subtreeSpecification = parser.parse( ss );
490             valid &= true;
491         }
492         catch ( ParseException JavaDoc pe )
493         {
494             subtreeSpecification = null;
495             valid &= false;
496         }
497
498         if ( getButton( IDialogConstants.OK_ID ) != null )
499         {
500             getButton( IDialogConstants.OK_ID ).setEnabled( valid );
501         }
502
503         //System.out.println("1:" + ss);
504
//StringBuffer sb = new StringBuffer();
505
//subtreeSpecification.printToBuffer( sb );
506
//System.out.println("2:" + sb.toString());
507
}
508
509
510     private String JavaDoc buildSubreeSpecification()
511     {
512         // build subtree specification tree
513
StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
514         sb.append( "{" ); //$NON-NLS-1$
515

516         // Adding base
517
DN base = entryWidget.getDn();
518         if ( base != null && !SubtreeValueEditor.EMPTY.equals( base.toString() ) )
519         {
520             sb.append( " base \"" + base.toString() + "\"," ); //$NON-NLS-1$ //$NON-NLS-2$
521
}
522
523         // Adding Minimum
524
int minimum = minimumSpinner.getSelection();
525         if ( minimum != 0 )
526         {
527             sb.append( " minimum " + minimum + "," ); //$NON-NLS-1$ //$NON-NLS-2$
528
}
529
530         // Adding Maximum
531
int maximum = maximumSpinner.getSelection();
532         if ( maximum != 0 )
533         {
534             sb.append( " maximum " + maximum + "," ); //$NON-NLS-1$ //$NON-NLS-2$
535
}
536
537         // Adding Exclusions
538
if ( !exclusions.isEmpty() )
539         {
540             sb.append( " specificExclusions {" ); //$NON-NLS-1$
541

542             for ( Iterator JavaDoc<String JavaDoc> it = exclusions.iterator(); it.hasNext(); )
543             {
544                 sb.append( " " + it.next() ); //$NON-NLS-1$
545

546                 if ( it.hasNext() )
547                 {
548                     sb.append( "," ); //$NON-NLS-1$
549
}
550             }
551
552             sb.append( " }," ); //$NON-NLS-1$
553
}
554
555         // Add Refinement or Filter
556
String JavaDoc refinementOrFilter = ""; //$NON-NLS-1$
557
if ( refinementOrFilterVisible )
558         {
559             if ( refinementButton.getSelection() )
560             {
561                 refinementOrFilter = refinementText.getText();
562             }
563             else
564             {
565                 refinementOrFilter = filterWidget.getFilter();
566             }
567         }
568         else
569         {
570             refinementOrFilter = ""; //$NON-NLS-1$
571
}
572         if ( refinementOrFilter != null && !SubtreeValueEditor.EMPTY.equals( refinementOrFilter ) )
573         {
574             sb.append( " specificationFilter " + refinementOrFilter + "," ); //$NON-NLS-1$ //$NON-NLS-2$
575
}
576
577         // Removing the last ','
578
if ( sb.charAt( sb.length() - 1 ) == ',' )
579         {
580             sb.deleteCharAt( sb.length() - 1 );
581         }
582
583         sb.append( " }" ); //$NON-NLS-1$
584

585         return sb.toString();
586     }
587
588
589     /**
590      * Called when value is selected in Exclusions table viewer.
591      * Updates the enabled/disabled state of the buttons.
592      */

593     private void valueSelectedExclusionsTable()
594     {
595         String JavaDoc value = getSelectedValueExclusionsTable();
596
597         if ( value == null )
598         {
599             exclusionsTableEditButton.setEnabled( false );
600             exclusionsTableDeleteButton.setEnabled( false );
601         }
602         else
603         {
604             exclusionsTableEditButton.setEnabled( true );
605             exclusionsTableDeleteButton.setEnabled( true );
606         }
607     }
608
609
610     /**
611      * Retuns the current selection in the Exclusions table viewer.
612      *
613      * @return
614      * the value that is selected in the Exclusions table viewer, or null.
615      */

616     private String JavaDoc getSelectedValueExclusionsTable()
617     {
618         String JavaDoc value = null;
619
620         IStructuredSelection selection = ( IStructuredSelection ) exclusionsTableViewer.getSelection();
621         if ( !selection.isEmpty() )
622         {
623             Object JavaDoc element = selection.getFirstElement();
624             if ( element instanceof String JavaDoc )
625             {
626                 value = ( String JavaDoc ) element;
627             }
628         }
629
630         return value;
631     }
632
633
634     /**
635      * Opens the editor and adds the new Exclusion value to the list.
636      */

637     private void addValueExclusionsTable()
638     {
639         DN chopBase = null;
640         try
641         {
642             chopBase = new DN( subtreeSpecification.getBase().toNormName() );
643         }
644         catch ( NameException e )
645         {
646         }
647         if ( subentryDN != null && subentryDN.getParentDn() != null )
648         {
649             DN suffix = subentryDN != null ? subentryDN.getParentDn() : null;
650             chopBase = new DN( chopBase, suffix );
651         }
652
653         ExclusionDialog dialog = new ExclusionDialog( getShell(), connection, chopBase, "" ); //$NON-NLS-1$
654
if ( dialog.open() == TextDialog.OK && !SubtreeValueEditor.EMPTY.equals( dialog.getType() ) && !SubtreeValueEditor.EMPTY.equals( dialog.getDN() ) )
655         {
656             String JavaDoc newValue = dialog.getType() + ": \"" + dialog.getDN() + "\""; //$NON-NLS-1$ //$NON-NLS-2$
657
exclusions.add( newValue );
658             exclusionsTableViewer.refresh();
659             validate();
660         }
661     }
662
663
664     /**
665      * Opens the editor with the currently selected Exclusion
666      * value and puts the modified value into the list.
667      */

668     private void editValueExclusionsTable()
669     {
670         String JavaDoc oldValue = getSelectedValueExclusionsTable();
671         if ( oldValue != null )
672         {
673             DN chopBase = null;
674             try
675             {
676                 chopBase = new DN( subtreeSpecification.getBase().toNormName() );
677             }
678             catch ( NameException e )
679             {
680             }
681             if ( subentryDN != null && subentryDN.getParentDn() != null )
682             {
683                 DN suffix = subentryDN != null ? subentryDN.getParentDn() : null;
684                 chopBase = new DN( chopBase, suffix );
685             }
686
687             ExclusionDialog dialog = new ExclusionDialog( getShell(), connection, chopBase, oldValue );
688             if ( dialog.open() == TextDialog.OK && !SubtreeValueEditor.EMPTY.equals( dialog.getType() )
689                 && !SubtreeValueEditor.EMPTY.equals( dialog.getDN() ) )
690             {
691                 String JavaDoc newValue = dialog.getType() + ": \"" + dialog.getDN() + "\""; //$NON-NLS-1$ //$NON-NLS-2$
692
exclusions.remove( oldValue );
693                 exclusions.add( newValue );
694                 exclusionsTableViewer.refresh();
695                 validate();
696             }
697         }
698     }
699
700
701     /**
702      * Deletes the currently selected Exclusion value from list.
703      */

704     private void deleteValueExclusionsTable()
705     {
706         String JavaDoc value = getSelectedValueExclusionsTable();
707         if ( value != null )
708         {
709             exclusions.remove( value );
710             exclusionsTableViewer.refresh();
711             validate();
712         }
713     }
714
715
716     /**
717      * Gets the subtree specification value or null if canceled.
718      *
719      * @return the subtree specification value or null if canceled
720      */

721     public String JavaDoc getSubtreeSpecificationValue()
722     {
723         return returnValue;
724     }
725 }
Popular Tags