KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
25 import org.apache.directory.ldapstudio.browser.common.widgets.BrowserWidget;
26 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
27 import org.eclipse.swt.events.SelectionAdapter;
28 import org.eclipse.swt.events.SelectionEvent;
29 import org.eclipse.swt.widgets.Button;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.swt.widgets.Group;
32
33
34 /**
35  * The AliasesDereferencingWidget could be used to select the
36  * alias dereferencing method. It is composed of a group with
37  * two check boxes.
38  *
39  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
40  * @version $Rev$, $Date$
41  */

42 public class AliasesDereferencingWidget extends BrowserWidget
43 {
44
45     /** The initial aliases dereferencing method */
46     private int initialAliasesDereferencingMethod;
47
48     /** The group. */
49     private Group group;
50
51     /** The finding button. */
52     private Button findingButton;
53
54     /** The search button. */
55     private Button searchButton;
56
57
58     /**
59      * Creates a new instance of AliasesDereferencingWidget with the given
60      * derefenencing method. This must be one of {@link IConnection#DEREFERENCE_ALIASES_NEVER},
61      * {@link IConnection#DEREFERENCE_ALIASES_SEARCH}, {@link IConnection#DEREFERENCE_ALIASES_FINDING}
62      * or {@link IConnection#DEREFERENCE_ALIASES_ALWAYS}.
63      *
64      * @param initialAliasesDereferencingMethod the initial aliases dereferencing method
65      */

66     public AliasesDereferencingWidget( int initialAliasesDereferencingMethod )
67     {
68         this.initialAliasesDereferencingMethod = initialAliasesDereferencingMethod;
69     }
70
71
72     /**
73      * Creates a new instance of AliasesDereferencingWidget. The initial
74      * dereferncing method is set to {@link IConnection#DEREFERENCE_ALIASES_NEVER}.
75      */

76     public AliasesDereferencingWidget()
77     {
78         this.initialAliasesDereferencingMethod = IConnection.DEREFERENCE_ALIASES_NEVER;
79     }
80
81
82     /**
83      * Creates the widget.
84      *
85      * @param parent the parent
86      */

87     public void createWidget( Composite parent )
88     {
89
90         group = BaseWidgetUtils.createGroup( parent, "Aliases Dereferencing", 1 );
91         Composite groupComposite = BaseWidgetUtils.createColumnContainer( group, 1, 1 );
92
93         findingButton = BaseWidgetUtils.createCheckbox( groupComposite, "Finding Base DN", 1 );
94         findingButton.addSelectionListener( new SelectionAdapter()
95         {
96             public void widgetSelected( SelectionEvent e )
97             {
98                 notifyListeners();
99             }
100         } );
101
102         searchButton = BaseWidgetUtils.createCheckbox( groupComposite, "Search", 1 );
103         searchButton.addSelectionListener( new SelectionAdapter()
104         {
105             public void widgetSelected( SelectionEvent e )
106             {
107                 notifyListeners();
108             }
109         } );
110
111         setAliasesDereferencingMethod( initialAliasesDereferencingMethod );
112     }
113
114
115     /**
116      * Sets the aliases dereferencing method, must be one of {@link IConnection#DEREFERENCE_ALIASES_NEVER},
117      * {@link IConnection#DEREFERENCE_ALIASES_SEARCH}, {@link IConnection#DEREFERENCE_ALIASES_FINDING}
118      * or {@link IConnection#DEREFERENCE_ALIASES_ALWAYS}.
119      *
120      * @param aliasesDereferencingMethod the aliases dereferencing method
121      */

122     public void setAliasesDereferencingMethod( int aliasesDereferencingMethod )
123     {
124         initialAliasesDereferencingMethod = aliasesDereferencingMethod;
125         findingButton.setSelection( initialAliasesDereferencingMethod == IConnection.DEREFERENCE_ALIASES_FINDING
126             || initialAliasesDereferencingMethod == IConnection.DEREFERENCE_ALIASES_ALWAYS );
127         searchButton.setSelection( initialAliasesDereferencingMethod == IConnection.DEREFERENCE_ALIASES_SEARCH
128             || initialAliasesDereferencingMethod == IConnection.DEREFERENCE_ALIASES_ALWAYS );
129     }
130
131
132     /**
133      * Gets the aliases dereferencing method, one of {@link IConnection#DEREFERENCE_ALIASES_NEVER},
134      * {@link IConnection#DEREFERENCE_ALIASES_SEARCH}, {@link IConnection#DEREFERENCE_ALIASES_FINDING}
135      * or {@link IConnection#DEREFERENCE_ALIASES_ALWAYS}.
136      *
137      * @return the aliases dereferencing method
138      */

139     public int getAliasesDereferencingMethod()
140     {
141         if ( findingButton.getSelection() && searchButton.getSelection() )
142         {
143             return IConnection.DEREFERENCE_ALIASES_ALWAYS;
144         }
145         else if ( findingButton.getSelection() )
146         {
147             return IConnection.DEREFERENCE_ALIASES_FINDING;
148         }
149         else if ( searchButton.getSelection() )
150         {
151             return IConnection.DEREFERENCE_ALIASES_SEARCH;
152         }
153         else
154         {
155             return IConnection.DEREFERENCE_ALIASES_NEVER;
156         }
157     }
158
159
160     /**
161      * Sets the enabled state of the widget.
162      *
163      * @param b true to enable the widget, false to disable the widget
164      */

165     public void setEnabled( boolean b )
166     {
167         group.setEnabled( b );
168         findingButton.setEnabled( b );
169         searchButton.setEnabled( b );
170     }
171
172 }
173
Popular Tags