KickJava   Java API By Example, From Geeks To Geeks.

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


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.BrowserWidget;
25 import org.apache.directory.ldapstudio.browser.core.model.ISearch;
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.events.SelectionAdapter;
28 import org.eclipse.swt.events.SelectionEvent;
29 import org.eclipse.swt.layout.GridData;
30 import org.eclipse.swt.layout.GridLayout;
31 import org.eclipse.swt.widgets.Button;
32 import org.eclipse.swt.widgets.Composite;
33 import org.eclipse.swt.widgets.Group;
34
35
36 /**
37  * The ScopeWidget could be used to select the scope of a search.
38  * It is composed of a group with radio buttons.
39  *
40  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
41  * @version $Rev$, $Date$
42  */

43 public class ScopeWidget extends BrowserWidget
44 {
45
46     /** The initial scope. */
47     private int initialScope;
48
49     /** The scope group. */
50     private Group scopeGroup;
51
52     /** The scope object button. */
53     private Button scopeObjectButton;
54
55     /** The scope onelevel button. */
56     private Button scopeOnelevelButton;
57
58     /** The scope subtree button. */
59     private Button scopeSubtreeButton;
60
61
62     /**
63      * Creates a new instance of ScopeWidget with the given
64      * initial scope. That must be one of {@link ISearch#SCOPE_OBJECT},
65      * {@link ISearch#SCOPE_ONELEVEL} or {@link ISearch#SCOPE_SUBTREE}.
66      *
67      * @param initialScope the initial scope
68      */

69     public ScopeWidget( int initialScope )
70     {
71         this.initialScope = initialScope;
72     }
73
74
75     /**
76      * Creates a new instance of ScopeWidget with initial scope
77      * {@link ISearch#SCOPE_OBJECT}.
78      */

79     public ScopeWidget()
80     {
81         this.initialScope = 0;
82     }
83
84
85     /**
86      * Creates the widget.
87      *
88      * @param parent the parent
89      */

90     public void createWidget( Composite parent )
91     {
92
93         // Scope group
94
scopeGroup = new Group( parent, SWT.NONE );
95         scopeGroup.setText( "Scope" );
96         scopeGroup.setLayout( new GridLayout( 1, false ) );
97         scopeGroup.setLayoutData( new GridData( GridData.FILL_BOTH ) );
98
99         // Object radio
100
scopeObjectButton = new Button( scopeGroup, SWT.RADIO );
101         scopeObjectButton.setText( "&Object" );
102         scopeObjectButton.addSelectionListener( new SelectionAdapter()
103         {
104             public void widgetSelected( SelectionEvent e )
105             {
106                 notifyListeners();
107             }
108         } );
109
110         // Onelevel radio
111
scopeOnelevelButton = new Button( scopeGroup, SWT.RADIO );
112         scopeOnelevelButton.setText( "One &Level" );
113         scopeOnelevelButton.addSelectionListener( new SelectionAdapter()
114         {
115             public void widgetSelected( SelectionEvent e )
116             {
117                 notifyListeners();
118             }
119         } );
120
121         // subtree button
122
scopeSubtreeButton = new Button( scopeGroup, SWT.RADIO );
123         scopeSubtreeButton.setText( "&Subtree" );
124         scopeSubtreeButton.addSelectionListener( new SelectionAdapter()
125         {
126             public void widgetSelected( SelectionEvent e )
127             {
128                 notifyListeners();
129             }
130         } );
131
132         setScope( initialScope );
133     }
134
135
136     /**
137      * Sets the scope, must be one of {@link ISearch#SCOPE_OBJECT},
138      * {@link ISearch#SCOPE_ONELEVEL} or {@link ISearch#SCOPE_SUBTREE}.
139      *
140      * @param scope the scope
141      */

142     public void setScope( int scope )
143     {
144         initialScope = scope;
145         scopeObjectButton.setSelection( initialScope == ISearch.SCOPE_OBJECT );
146         scopeOnelevelButton.setSelection( initialScope == ISearch.SCOPE_ONELEVEL );
147         scopeSubtreeButton.setSelection( initialScope == ISearch.SCOPE_SUBTREE );
148     }
149
150
151     /**
152      * Gets the scope, one of {@link ISearch#SCOPE_OBJECT},
153      * {@link ISearch#SCOPE_ONELEVEL} or {@link ISearch#SCOPE_SUBTREE}.
154      *
155      * @return the scope
156      */

157     public int getScope()
158     {
159         int scope;
160
161         if ( scopeSubtreeButton.getSelection() )
162         {
163             scope = ISearch.SCOPE_SUBTREE;
164         }
165         else if ( scopeOnelevelButton.getSelection() )
166         {
167             scope = ISearch.SCOPE_ONELEVEL;
168         }
169         else if ( scopeObjectButton.getSelection() )
170         {
171             scope = ISearch.SCOPE_OBJECT;
172         }
173         else
174         {
175             scope = ISearch.SCOPE_ONELEVEL;
176         }
177
178         return scope;
179     }
180
181
182     /**
183      * Sets the enabled state of the widget.
184      *
185      * @param b true to enable the widget, false to disable the widget
186      */

187     public void setEnabled( boolean b )
188     {
189         scopeGroup.setEnabled( b );
190         scopeObjectButton.setEnabled( b );
191         scopeOnelevelButton.setEnabled( b );
192         scopeSubtreeButton.setEnabled( b );
193     }
194
195 }
196
Popular Tags