KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > widgets > search > SearchPageWrapper


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
21 package org.apache.directory.ldapstudio.browser.common.widgets.search;
22
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.Arrays JavaDoc;
26 import java.util.List JavaDoc;
27
28 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
29 import org.apache.directory.ldapstudio.browser.common.widgets.BrowserWidget;
30 import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyEvent;
31 import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyListener;
32 import org.apache.directory.ldapstudio.browser.core.jobs.SearchJob;
33 import org.apache.directory.ldapstudio.browser.core.model.Control;
34 import org.apache.directory.ldapstudio.browser.core.model.DN;
35 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
36 import org.apache.directory.ldapstudio.browser.core.model.ISearch;
37 import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterParser;
38 import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeTypeDescription;
39 import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaUtils;
40 import org.eclipse.swt.events.ModifyEvent;
41 import org.eclipse.swt.events.ModifyListener;
42 import org.eclipse.swt.events.SelectionAdapter;
43 import org.eclipse.swt.events.SelectionEvent;
44 import org.eclipse.swt.events.SelectionListener;
45 import org.eclipse.swt.widgets.Button;
46 import org.eclipse.swt.widgets.Composite;
47 import org.eclipse.swt.widgets.Label;
48 import org.eclipse.swt.widgets.Text;
49
50
51 /**
52  * The SearchPageWrapper is used to arrange all input elements of a
53  * search page. It is used by the search page, the search properties page,
54  * the batch operation wizard and the export wizards.
55  *
56  * The style is used to specify the invisible and readonly elements.
57  *
58  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
59  * @version $Rev$, $Date$
60  */

61 public class SearchPageWrapper extends BrowserWidget
62 {
63
64     /** The default style */
65     public static final int NONE = 0;
66
67     /** Style for invisible name field */
68     public static final int NAME_INVISIBLE = 1 << 1;
69
70     /** Style for read-only name field */
71     public static final int NAME_READONLY = 1 << 2;
72
73     /** Style for invisible connection field */
74     public static final int CONNECTION_INVISIBLE = 1 << 3;
75
76     /** Style for read-only connection field */
77     public static final int CONNECTION_READONLY = 1 << 4;
78
79     /** Style for invisible search base field */
80     public static final int SEARCHBASE_INVISIBLE = 1 << 5;
81
82     /** Style for read-only search base field */
83     public static final int SEARCHBASE_READONLY = 1 << 6;
84
85     /** Style for invisible filter field */
86     public static final int FILTER_INVISIBLE = 1 << 7;
87
88     /** Style for read-only filter field */
89     public static final int FILTER_READONLY = 1 << 8;
90
91     /** Style for invisible returning attributes field */
92     public static final int RETURNINGATTRIBUTES_INVISIBLE = 1 << 9;
93
94     /** Style for read-only returning attributes field */
95     public static final int RETURNINGATTRIBUTES_READONLY = 1 << 10;
96
97     /** Style for visible return DN checkbox */
98     public static final int RETURN_DN_VISIBLE = 1 << 11;
99
100     /** Style for checked return DN checkbox */
101     public static final int RETURN_DN_CHECKED = 1 << 12;
102
103     /** Style for visible return all attributes checkbox */
104     public static final int RETURN_ALLATTRIBUTES_VISIBLE = 1 << 13;
105
106     /** Style for checked return all attributes checkbox */
107     public static final int RETURN_ALLATTRIBUTES_CHECKED = 1 << 14;
108
109     /** Style for visible return operational attributes checkbox */
110     public static final int RETURN_OPERATIONALATTRIBUTES_VISIBLE = 1 << 15;
111
112     /** Style for checked return operational attributes checkbox */
113     public static final int RETURN_OPERATIONALATTRIBUTES_CHECKED = 1 << 16;
114
115     /** Style for invisible options */
116     public static final int OPTIONS_INVISIBLE = 1 << 21;
117
118     /** Style for read-only scope options */
119     public static final int SCOPEOPTIONS_READONLY = 1 << 22;
120
121     /** Style for read-only limit options */
122     public static final int LIMITOPTIONS_READONLY = 1 << 23;
123
124     /** Style for read-only alias options */
125     public static final int ALIASOPTIONS_READONLY = 1 << 24;
126
127     /** Style for read-only referrals options */
128     public static final int REFERRALOPTIONS_READONLY = 1 << 25;
129
130     /** Style for invisible controls fields */
131     public static final int CONTROLS_INVISIBLE = 1 << 30;
132
133     /** The style. */
134     protected int style;
135
136     /** The filter parser. */
137     protected LdapFilterParser parser;
138
139     /** The search name label. */
140     protected Label searchNameLabel;
141
142     /** The search name text. */
143     protected Text searchNameText;
144
145     /** The connection label. */
146     protected Label connectionLabel;
147
148     /** The connection widget. */
149     protected ConnectionWidget connectionWidget;
150
151     /** The search base label. */
152     protected Label searchBaseLabel;
153
154     /** The search base widget. */
155     protected EntryWidget searchBaseWidget;
156
157     /** The filter label. */
158     protected Label filterLabel;
159
160     /** The filter widget. */
161     protected FilterWidget filterWidget;
162
163     /** The returning attributes label. */
164     protected Label returningAttributesLabel;
165
166     /** The returning attributes widget. */
167     protected ReturningAttributesWidget returningAttributesWidget;
168
169     /** The return dn button. */
170     protected Button returnDnButton;
171
172     /** The return all attributes button. */
173     protected Button returnAllAttributesButton;
174
175     /** The return operational attributes button. */
176     protected Button returnOperationalAttributesButton;
177
178     /** The scope widget. */
179     protected ScopeWidget scopeWidget;
180
181     /** The limit widget. */
182     protected LimitWidget limitWidget;
183
184     /** The aliases dereferencing widget. */
185     protected AliasesDereferencingWidget aliasesDereferencingWidget;
186
187     /** The referrals handling widget. */
188     protected ReferralsHandlingWidget referralsHandlingWidget;
189
190     /** The control label. */
191     protected Label controlLabel;
192
193     /** The subentries control button. */
194     protected Button subentriesControlButton;
195
196
197     /**
198      * Creates a new instance of SearchPageWrapper.
199      *
200      * @param style the style
201      */

202     public SearchPageWrapper( int style )
203     {
204         this.parser = new LdapFilterParser();
205         this.style = style;
206     }
207
208
209     /**
210      * Creates the contents.
211      *
212      * @param composite the composite
213      */

214     public void createContents( final Composite composite )
215     {
216         // Search Name
217
createSearchNameLine( composite );
218
219         // Connection
220
createConnectionLine( composite );
221
222         // Search Base
223
createSearchBaseLine( composite );
224
225         // Filter
226
createFilterLine( composite );
227
228         // Returning Attributes
229
createReturningAttributesLine( composite );
230
231         // control
232
createControlComposite( composite );
233
234         // scope, limit, alias, referral
235
createOptionsComposite( composite );
236     }
237
238
239     /**
240      * Checks if the given style is active.
241      *
242      * @param requiredStyle the required style to check
243      *
244      * @return true, if the required style is active
245      */

246     protected boolean isActive( int requiredStyle )
247     {
248         return ( style & requiredStyle ) != 0;
249     }
250
251
252     /**
253      * Creates the search name line.
254      *
255      * @param composite the composite
256      */

257     protected void createSearchNameLine( final Composite composite )
258     {
259         if ( isActive( NAME_INVISIBLE ) )
260         {
261             return;
262         }
263
264         searchNameLabel = BaseWidgetUtils.createLabel( composite, "Search Name:", 1 );
265         if ( isActive( NAME_READONLY ) )
266         {
267             searchNameText = BaseWidgetUtils.createReadonlyText( composite, "", 2 );
268         }
269         else
270         {
271             searchNameText = BaseWidgetUtils.createText( composite, "", 2 );
272         }
273         searchNameText.addModifyListener( new ModifyListener()
274         {
275             public void modifyText( ModifyEvent e )
276             {
277                 validate();
278             }
279         } );
280
281         BaseWidgetUtils.createSpacer( composite, 3 );
282     }
283
284
285     /**
286      * Creates the connection line.
287      *
288      * @param composite the composite
289      */

290     protected void createConnectionLine( final Composite composite )
291     {
292         if ( isActive( CONNECTION_INVISIBLE ) )
293         {
294             return;
295         }
296
297         connectionLabel = BaseWidgetUtils.createLabel( composite, "Connection:", 1 );
298         connectionWidget = new ConnectionWidget();
299         connectionWidget.createWidget( composite );
300         connectionWidget.setEnabled( !isActive( CONNECTION_READONLY ) );
301         connectionWidget.addWidgetModifyListener( new WidgetModifyListener()
302         {
303             public void widgetModified( WidgetModifyEvent event )
304             {
305                 validate();
306             }
307         } );
308         BaseWidgetUtils.createSpacer( composite, 3 );
309     }
310
311
312     /**
313      * Creates the search base line.
314      *
315      * @param composite the composite
316      */

317     protected void createSearchBaseLine( final Composite composite )
318     {
319         if ( isActive( SEARCHBASE_INVISIBLE ) )
320         {
321             return;
322         }
323
324         searchBaseLabel = BaseWidgetUtils.createLabel( composite, "Search Base:", 1 );
325         searchBaseWidget = new EntryWidget();
326         searchBaseWidget.createWidget( composite );
327         searchBaseWidget.setEnabled( !isActive( SEARCHBASE_READONLY ) );
328         searchBaseWidget.addWidgetModifyListener( new WidgetModifyListener()
329         {
330             public void widgetModified( WidgetModifyEvent event )
331             {
332                 validate();
333             }
334         } );
335         BaseWidgetUtils.createSpacer( composite, 3 );
336     }
337
338
339     /**
340      * Creates the filter line.
341      *
342      * @param composite the composite
343      */

344     protected void createFilterLine( final Composite composite )
345     {
346         if ( isActive( FILTER_INVISIBLE ) )
347         {
348             return;
349         }
350
351         filterLabel = BaseWidgetUtils.createLabel( composite, "Filter:", 1 );
352         filterWidget = new FilterWidget();
353         filterWidget.createWidget( composite );
354         filterWidget.setEnabled( !isActive( FILTER_READONLY ) );
355         filterWidget.addWidgetModifyListener( new WidgetModifyListener()
356         {
357             public void widgetModified( WidgetModifyEvent event )
358             {
359                 validate();
360             }
361         } );
362         BaseWidgetUtils.createSpacer( composite, 3 );
363     }
364
365
366     /**
367      * Creates the returning attributes line.
368      *
369      * @param composite the composite
370      */

371     protected void createReturningAttributesLine( final Composite composite )
372     {
373         if ( isActive( RETURNINGATTRIBUTES_INVISIBLE ) )
374         {
375             return;
376         }
377
378         BaseWidgetUtils.createLabel( composite, "Returning Attributes:", 1 );
379         Composite retComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 2 );
380         returningAttributesWidget = new ReturningAttributesWidget();
381         returningAttributesWidget.createWidget( retComposite );
382         returningAttributesWidget.setEnabled( !isActive( RETURNINGATTRIBUTES_READONLY ) );
383         returningAttributesWidget.addWidgetModifyListener( new WidgetModifyListener()
384         {
385             public void widgetModified( WidgetModifyEvent event )
386             {
387                 validate();
388             }
389         } );
390
391         // special returning attributes options
392
if ( isActive( RETURN_DN_VISIBLE ) || isActive( RETURN_ALLATTRIBUTES_VISIBLE )
393             || isActive( RETURN_OPERATIONALATTRIBUTES_VISIBLE ) )
394         {
395             BaseWidgetUtils.createSpacer( composite, 1 );
396             Composite buttonComposite = BaseWidgetUtils.createColumnContainer( composite, 3, 1 );
397             if ( isActive( RETURN_DN_VISIBLE ) )
398             {
399                 returnDnButton = BaseWidgetUtils.createCheckbox( buttonComposite, "Export DN", 1 );
400                 returnDnButton.addSelectionListener( new SelectionAdapter()
401                 {
402                     public void widgetSelected( SelectionEvent e )
403                     {
404                         validate();
405                     }
406                 } );
407                 returnDnButton.setSelection( isActive( RETURN_DN_CHECKED ) );
408             }
409             if ( isActive( RETURN_ALLATTRIBUTES_VISIBLE ) )
410             {
411                 returnAllAttributesButton = BaseWidgetUtils.createCheckbox( buttonComposite, "All user attributes", 1 );
412                 returnAllAttributesButton.addSelectionListener( new SelectionAdapter()
413                 {
414                     public void widgetSelected( SelectionEvent e )
415                     {
416                         validate();
417                     }
418                 } );
419                 returnAllAttributesButton.setSelection( isActive( RETURN_ALLATTRIBUTES_CHECKED ) );
420             }
421             if ( isActive( RETURN_OPERATIONALATTRIBUTES_VISIBLE ) )
422             {
423                 returnOperationalAttributesButton = BaseWidgetUtils.createCheckbox( buttonComposite,
424                     "Operational attributes", 1 );
425                 returnOperationalAttributesButton.addSelectionListener( new SelectionAdapter()
426                 {
427                     public void widgetSelected( SelectionEvent e )
428                     {
429                         validate();
430                     }
431                 } );
432                 returnOperationalAttributesButton.setSelection( isActive( RETURN_OPERATIONALATTRIBUTES_CHECKED ) );
433             }
434         }
435
436         BaseWidgetUtils.createSpacer( composite, 3 );
437     }
438
439
440     /**
441      * Creates the options composite, this includes the
442      * scope, limit, alias and referral widgets.
443      *
444      * @param composite the composite
445      */

446     protected void createOptionsComposite( final Composite composite )
447     {
448         if ( isActive( OPTIONS_INVISIBLE ) )
449         {
450             return;
451         }
452
453         Composite optionsComposite = BaseWidgetUtils.createColumnContainer( composite, 2, 3 );
454
455         scopeWidget = new ScopeWidget();
456         scopeWidget.createWidget( optionsComposite );
457         scopeWidget.setEnabled( !isActive( SCOPEOPTIONS_READONLY ) );
458         scopeWidget.addWidgetModifyListener( new WidgetModifyListener()
459         {
460             public void widgetModified( WidgetModifyEvent event )
461             {
462                 validate();
463             }
464         } );
465
466         limitWidget = new LimitWidget();
467         limitWidget.createWidget( optionsComposite );
468         limitWidget.setEnabled( !isActive( LIMITOPTIONS_READONLY ) );
469         limitWidget.addWidgetModifyListener( new WidgetModifyListener()
470         {
471             public void widgetModified( WidgetModifyEvent event )
472             {
473                 validate();
474             }
475         } );
476
477         aliasesDereferencingWidget = new AliasesDereferencingWidget();
478         aliasesDereferencingWidget.createWidget( optionsComposite );
479         aliasesDereferencingWidget.setEnabled( !isActive( ALIASOPTIONS_READONLY ) );
480         aliasesDereferencingWidget.addWidgetModifyListener( new WidgetModifyListener()
481         {
482             public void widgetModified( WidgetModifyEvent event )
483             {
484                 validate();
485             }
486         } );
487
488         referralsHandlingWidget = new ReferralsHandlingWidget();
489         referralsHandlingWidget.createWidget( optionsComposite );
490         referralsHandlingWidget.setEnabled( !isActive( REFERRALOPTIONS_READONLY ) );
491         referralsHandlingWidget.addWidgetModifyListener( new WidgetModifyListener()
492         {
493             public void widgetModified( WidgetModifyEvent event )
494             {
495                 validate();
496             }
497         } );
498     }
499
500
501     /**
502      * Creates the control composite.
503      *
504      * @param composite the composite
505      */

506     protected void createControlComposite( final Composite composite )
507     {
508         if ( isActive( CONTROLS_INVISIBLE ) )
509         {
510             return;
511         }
512
513         controlLabel = BaseWidgetUtils.createLabel( composite, "Controls:", 1 );
514
515         subentriesControlButton = BaseWidgetUtils.createCheckbox( composite, Control.SUBENTRIES_CONTROL.getName(), 2 );
516         subentriesControlButton.addSelectionListener( new SelectionListener()
517         {
518             public void widgetDefaultSelected( SelectionEvent e )
519             {
520             }
521
522
523             public void widgetSelected( SelectionEvent e )
524             {
525                 validate();
526             }
527         } );
528     }
529
530
531     /**
532      * Validates all elements.
533      */

534     protected void validate()
535     {
536
537         if ( connectionWidget.getConnection() != null )
538         {
539             if ( searchBaseWidget.getDn() == null
540                 || searchBaseWidget.getConnection() != connectionWidget.getConnection() )
541             {
542                 searchBaseWidget.setInput( connectionWidget.getConnection(), null );
543             }
544         }
545
546         filterWidget.setConnection( connectionWidget.getConnection() );
547
548         super.notifyListeners();
549     }
550
551
552     /**
553      * Checks if the DNs should be returned/exported.
554      *
555      * @return true, if DNs should be returnde/exported
556      */

557     public boolean isReturnDn()
558     {
559         return returnDnButton != null && returnDnButton.getSelection();
560     }
561
562
563     /**
564      * Initializes all search page widgets from the given search.
565      *
566      * @param search the search
567      */

568     public void loadFromSearch( ISearch search )
569     {
570         if ( searchNameText != null )
571         {
572             searchNameText.setText( search.getName() );
573         }
574
575         if ( search.getConnection() != null )
576         {
577             IConnection connection = search.getConnection();
578             DN searchBase = search.getSearchBase();
579
580             if ( connectionWidget != null )
581             {
582                 connectionWidget.setConnection( connection );
583             }
584
585             if ( searchBase != null )
586             {
587                 searchBaseWidget.setInput( connection, searchBase );
588             }
589
590             if ( filterWidget != null )
591             {
592                 filterWidget.setConnection( connection );
593                 filterWidget.setFilter( search.getFilter() );
594             }
595
596             if ( returningAttributesWidget != null )
597             {
598                 returningAttributesWidget.setConnection( connection );
599                 returningAttributesWidget.setInitialReturningAttributes( search.getReturningAttributes() );
600             }
601
602             if ( scopeWidget != null )
603             {
604                 scopeWidget.setScope( search.getScope() );
605             }
606             if ( limitWidget != null )
607             {
608                 limitWidget.setCountLimit( search.getCountLimit() );
609                 limitWidget.setTimeLimit( search.getTimeLimit() );
610             }
611             if ( aliasesDereferencingWidget != null )
612             {
613                 aliasesDereferencingWidget.setAliasesDereferencingMethod( search.getAliasesDereferencingMethod() );
614             }
615             if ( referralsHandlingWidget != null )
616             {
617                 referralsHandlingWidget.setReferralsHandlingMethod( search.getReferralsHandlingMethod() );
618             }
619             if ( subentriesControlButton != null )
620             {
621                 Control[] searchControls = search.getControls();
622                 if ( searchControls != null && searchControls.length > 0 )
623                 {
624                     for ( int i = 0; i < searchControls.length; i++ )
625                     {
626                         Control c = searchControls[i];
627                         if ( Control.SUBENTRIES_CONTROL.equals( c ) )
628                         {
629                             subentriesControlButton.setSelection( true );
630                         }
631                     }
632                 }
633             }
634         }
635     }
636
637
638     /**
639      * Saves all search pages element to the given search.
640      *
641      * @param search the search
642      *
643      * @return true, if the given search has been modified.
644      */

645     public boolean saveToSearch( ISearch search )
646     {
647         boolean searchModified = false;
648
649         if ( searchNameText != null && !searchNameText.getText().equals( search.getName() ) )
650         {
651             search.getSearchParameter().setName( searchNameText.getText() );
652             searchModified = true;
653         }
654         if ( connectionWidget != null && connectionWidget.getConnection() != null
655             && connectionWidget.getConnection() != search.getConnection() )
656         {
657             search.setConnection( connectionWidget.getConnection() );
658             searchModified = true;
659         }
660         if ( searchBaseWidget != null && searchBaseWidget.getDn() != null
661             && !searchBaseWidget.getDn().equals( search.getSearchBase() ) )
662         {
663             search.getSearchParameter().setSearchBase( searchBaseWidget.getDn() );
664             searchModified = true;
665             searchBaseWidget.saveDialogSettings();
666         }
667         if ( filterWidget != null )
668         {
669             parser.parse( filterWidget.getFilter() );
670             if ( !parser.getModel().toString().equals( search.getFilter() ) )
671             {
672                 search.getSearchParameter().setFilter( parser.getModel().toString() );
673                 searchModified = true;
674             }
675             filterWidget.saveDialogSettings();
676         }
677
678         if ( returningAttributesWidget != null )
679         {
680             if ( !Arrays.equals( returningAttributesWidget.getReturningAttributes(), search.getReturningAttributes() ) )
681             {
682                 search.getSearchParameter().setReturningAttributes( returningAttributesWidget.getReturningAttributes() );
683                 searchModified = true;
684             }
685             returningAttributesWidget.saveDialogSettings();
686
687             if ( returnAllAttributesButton != null || returnOperationalAttributesButton != null )
688             {
689                 List JavaDoc<String JavaDoc> raList = new ArrayList JavaDoc<String JavaDoc>();
690                 raList.addAll( Arrays.asList( search.getReturningAttributes() ) );
691                 if ( returnAllAttributesButton != null )
692                 {
693                     if ( returnAllAttributesButton.getSelection() )
694                     {
695                         raList.add( ISearch.ALL_USER_ATTRIBUTES );
696                     }
697                     if ( returnAllAttributesButton.getSelection() != isActive( RETURN_ALLATTRIBUTES_CHECKED ) )
698                     {
699                         searchModified = true;
700                     }
701                 }
702                 if ( returnOperationalAttributesButton != null )
703                 {
704                     if ( returnOperationalAttributesButton.getSelection() )
705                     {
706                         AttributeTypeDescription[] opAtds = SchemaUtils
707                             .getOperationalAttributeDescriptions( connectionWidget.getConnection().getSchema() );
708                         String JavaDoc[] attributeTypeDescriptionNames = SchemaUtils.getAttributeTypeDescriptionNames( opAtds );
709                         raList.addAll( Arrays.asList( attributeTypeDescriptionNames ) );
710                         raList.add( ISearch.ALL_OPERATIONAL_ATTRIBUTES );
711                     }
712                     if ( returnOperationalAttributesButton.getSelection() != isActive( RETURN_OPERATIONALATTRIBUTES_CHECKED ) )
713                     {
714                         searchModified = true;
715                     }
716                 }
717                 String JavaDoc[] returningAttributes = raList.toArray( new String JavaDoc[raList.size()] );
718                 search.getSearchParameter().setReturningAttributes( returningAttributes );
719             }
720         }
721
722         if ( scopeWidget != null )
723         {
724             int scope = scopeWidget.getScope();;
725             if ( scope != search.getScope() )
726             {
727                 search.getSearchParameter().setScope( scope );
728                 searchModified = true;
729             }
730         }
731         if ( limitWidget != null )
732         {
733             int countLimit = limitWidget.getCountLimit();
734             int timeLimit = limitWidget.getTimeLimit();
735             if ( countLimit != search.getCountLimit() )
736             {
737                 search.getSearchParameter().setCountLimit( countLimit );
738                 searchModified = true;
739             }
740             if ( timeLimit != search.getTimeLimit() )
741             {
742                 search.getSearchParameter().setTimeLimit( timeLimit );
743                 searchModified = true;
744             }
745         }
746         if ( aliasesDereferencingWidget != null )
747         {
748             int aliasesDereferencingMethod = aliasesDereferencingWidget.getAliasesDereferencingMethod();
749             if ( aliasesDereferencingMethod != search.getAliasesDereferencingMethod() )
750             {
751                 search.getSearchParameter().setAliasesDereferencingMethod( aliasesDereferencingMethod );
752                 searchModified = true;
753             }
754         }
755         if ( referralsHandlingWidget != null )
756         {
757             int referralsHandlingMethod = referralsHandlingWidget.getReferralsHandlingMethod();
758             if ( referralsHandlingMethod != search.getReferralsHandlingMethod() )
759             {
760                 search.getSearchParameter().setReferralsHandlingMethod( referralsHandlingMethod );
761                 searchModified = true;
762             }
763         }
764         if ( subentriesControlButton != null )
765         {
766             Control selectedSubControl = subentriesControlButton.getSelection() ? Control.SUBENTRIES_CONTROL : null;
767             Control searchSubentriesControl = null;
768             Control[] searchControls = search.getControls();
769             if ( searchControls != null && searchControls.length > 0 )
770             {
771                 for ( int i = 0; i < searchControls.length; i++ )
772                 {
773                     Control c = searchControls[i];
774                     if ( Control.SUBENTRIES_CONTROL.equals( c ) )
775                     {
776                         searchSubentriesControl = Control.SUBENTRIES_CONTROL;
777                         break;
778                     }
779                 }
780             }
781             if ( selectedSubControl != searchSubentriesControl )
782             {
783                 if ( selectedSubControl == null )
784                 {
785                     search.getSearchParameter().setControls( null );
786                 }
787                 else
788                 {
789                     search.getSearchParameter().setControls( new Control[]
790                         { selectedSubControl } );
791                 }
792                 searchModified = true;
793             }
794
795         }
796
797         return searchModified;
798     }
799
800
801     /**
802      * Performs the search.
803      *
804      * @param search the search
805      *
806      * @return true, if perform search
807      */

808     public boolean performSearch( final ISearch search )
809     {
810         if ( search.getConnection() != null )
811         {
812             new SearchJob( new ISearch[]
813                 { search } ).execute();
814             return true;
815         }
816         else
817         {
818             return false;
819         }
820     }
821
822
823     /**
824      * Checks if is valid.
825      *
826      * @return true, if is valid
827      */

828     public boolean isValid()
829     {
830         if ( connectionWidget != null && connectionWidget.getConnection() == null )
831         {
832             return false;
833         }
834         if ( searchBaseWidget != null && searchBaseWidget.getDn() == null )
835         {
836             return false;
837         }
838         if ( searchNameText != null && "".equals( searchNameText.getText() ) )
839         {
840             return false;
841         }
842         if ( filterWidget != null && "".equals( filterWidget.getFilter() ) )
843         {
844             return false;
845         }
846
847         return true;
848     }
849
850
851     /**
852      * Sets the enabled state of the widget.
853      *
854      * @param b true to enable the widget, false to disable the widget
855      */

856     public void setEnabled( boolean b )
857     {
858         if ( searchNameText != null )
859         {
860             searchNameLabel.setEnabled( b );
861             searchNameText.setEnabled( b );
862         }
863         if ( connectionWidget != null )
864         {
865             connectionLabel.setEnabled( b );
866             connectionWidget.setEnabled( b && !isActive( CONNECTION_READONLY ) );
867         }
868         if ( searchBaseWidget != null )
869         {
870             searchBaseLabel.setEnabled( b );
871             searchBaseWidget.setEnabled( b && !isActive( SEARCHBASE_READONLY ) );
872         }
873         if ( filterWidget != null )
874         {
875             filterLabel.setEnabled( b );
876             filterWidget.setEnabled( b && !isActive( FILTER_READONLY ) );
877         }
878         if ( returningAttributesWidget != null )
879         {
880             returningAttributesLabel.setEnabled( b );
881             returningAttributesWidget.setEnabled( b && !isActive( RETURNINGATTRIBUTES_READONLY ) );
882         }
883         if ( returnDnButton != null )
884         {
885             returnDnButton.setEnabled( b );
886         }
887         if ( returnAllAttributesButton != null )
888         {
889             returnAllAttributesButton.setEnabled( b );
890         }
891         if ( returnOperationalAttributesButton != null )
892         {
893             returnOperationalAttributesButton.setEnabled( b );
894         }
895         if ( scopeWidget != null )
896         {
897             scopeWidget.setEnabled( b && !isActive( SCOPEOPTIONS_READONLY ) );
898         }
899         if ( limitWidget != null )
900         {
901             limitWidget.setEnabled( b && !isActive( LIMITOPTIONS_READONLY ) );
902         }
903         if ( aliasesDereferencingWidget != null )
904         {
905             aliasesDereferencingWidget.setEnabled( b && !isActive( ALIASOPTIONS_READONLY ) );
906         }
907         if ( referralsHandlingWidget != null )
908         {
909             referralsHandlingWidget.setEnabled( b && !isActive( REFERRALOPTIONS_READONLY ) );
910         }
911         if ( controlLabel != null )
912         {
913             controlLabel.setEnabled( b );
914             subentriesControlButton.setEnabled( b );
915         }
916     }
917
918 }
919
Popular Tags