KickJava   Java API By Example, From Geeks To Geeks.

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


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 ReferralsHandlingWidget could be used to select the
36  * referrals handling method. It is composed of a group with
37  * two radio buttons.
38  *
39  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
40  * @version $Rev$, $Date$
41  */

42 public class ReferralsHandlingWidget extends BrowserWidget
43 {
44
45     /** The initial referrals handling method. */
46     private int initialReferralsHandlingMethod;
47
48     /** The group. */
49     private Group group;
50
51     /** The ignore button. */
52     private Button ignoreButton;
53
54     /** The follow button. */
55     private Button followButton;
56
57
58     /**
59      * Creates a new instance of ReferralsHandlingWidget with the given
60      * referrals handling method. This must be one of
61      * {@link IConnection#HANDLE_REFERRALS_IGNORE} or
62      * {@link IConnection#HANDLE_REFERRALS_FOLLOW}.
63      *
64      * @param initialReferralsHandlingMethod the initial referrals handling method
65      */

66     public ReferralsHandlingWidget( int initialReferralsHandlingMethod )
67     {
68         this.initialReferralsHandlingMethod = initialReferralsHandlingMethod;
69     }
70
71
72     /**
73      * Creates a new instance of ReferralsHandlingWidget with initial
74      * referrals handling method {@link IConnection#HANDLE_REFERRALS_IGNORE}.
75      */

76     public ReferralsHandlingWidget()
77     {
78         this.initialReferralsHandlingMethod = IConnection.HANDLE_REFERRALS_IGNORE;
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, "Referrals Handling", 1 );
91         Composite groupComposite = BaseWidgetUtils.createColumnContainer( group, 1, 1 );
92
93         ignoreButton = BaseWidgetUtils.createRadiobutton( groupComposite, "Ignore", 1 );
94         ignoreButton.addSelectionListener( new SelectionAdapter()
95         {
96             public void widgetSelected( SelectionEvent e )
97             {
98                 notifyListeners();
99             }
100         } );
101
102         followButton = BaseWidgetUtils.createRadiobutton( groupComposite, "Follow", 1 );
103         followButton.addSelectionListener( new SelectionAdapter()
104         {
105             public void widgetSelected( SelectionEvent e )
106             {
107                 notifyListeners();
108             }
109         } );
110
111         setReferralsHandlingMethod( initialReferralsHandlingMethod );
112     }
113
114
115     /**
116      * Sets the referrals handling method must be one of
117      * {@link IConnection#HANDLE_REFERRALS_IGNORE} or
118      * {@link IConnection#HANDLE_REFERRALS_FOLLOW}.
119      *
120      * @param referralsHandlingMethod the referrals handling method
121      */

122     public void setReferralsHandlingMethod( int referralsHandlingMethod )
123     {
124         initialReferralsHandlingMethod = referralsHandlingMethod;
125         ignoreButton.setSelection( initialReferralsHandlingMethod == IConnection.HANDLE_REFERRALS_IGNORE );
126         followButton.setSelection( initialReferralsHandlingMethod == IConnection.HANDLE_REFERRALS_FOLLOW );
127     }
128
129
130     /**
131      * Gets the referrals handling method, one of
132      * {@link IConnection#HANDLE_REFERRALS_IGNORE} or
133      * {@link IConnection#HANDLE_REFERRALS_FOLLOW}.
134      *
135      * @return the referrals handling method
136      */

137     public int getReferralsHandlingMethod()
138     {
139         if ( ignoreButton.getSelection() )
140         {
141             return IConnection.HANDLE_REFERRALS_IGNORE;
142         }
143         else
144         {
145             return IConnection.HANDLE_REFERRALS_FOLLOW;
146         }
147     }
148
149
150     /**
151      * Sets the enabled state of the widget.
152      *
153      * @param b true to enable the widget, false to disable the widget
154      */

155     public void setEnabled( boolean b )
156     {
157         group.setEnabled( b );
158         ignoreButton.setEnabled( b );
159         followButton.setEnabled( b );
160     }
161
162 }
163
Popular Tags