KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > aciitemeditor > widgets > ACIItemGeneralComposite


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 package org.apache.directory.ldapstudio.aciitemeditor.widgets;
21
22
23 import java.util.ArrayList JavaDoc;
24 import java.util.List JavaDoc;
25
26 import org.apache.directory.shared.ldap.aci.AuthenticationLevel;
27 import org.eclipse.jface.viewers.ArrayContentProvider;
28 import org.eclipse.jface.viewers.ComboViewer;
29 import org.eclipse.jface.viewers.IStructuredSelection;
30 import org.eclipse.jface.viewers.LabelProvider;
31 import org.eclipse.jface.viewers.StructuredSelection;
32 import org.eclipse.swt.SWT;
33 import org.eclipse.swt.events.ModifyEvent;
34 import org.eclipse.swt.events.ModifyListener;
35 import org.eclipse.swt.events.SelectionAdapter;
36 import org.eclipse.swt.events.SelectionEvent;
37 import org.eclipse.swt.events.TypedEvent;
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.Combo;
42 import org.eclipse.swt.widgets.Composite;
43 import org.eclipse.swt.widgets.Label;
44 import org.eclipse.swt.widgets.Spinner;
45 import org.eclipse.swt.widgets.Text;
46
47
48 /**
49  * This is used to edit general ACI item properties:
50  * <ul>
51  * <li>identification tag
52  * <li>precedence
53  * <li>authentication level
54  * <li>selection for userFirst or itemFirst
55  * </ul>
56  *
57  *
58  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
59  * @version $Rev$, $Date$
60  */

61 public class ACIItemGeneralComposite extends Composite
62 {
63     /** The inner composite for all the content */
64     private Composite composite = null;
65
66     /** The identification tag label */
67     private Label identificationTagLabel = null;
68
69     /** The identification tag text field */
70     private Text identificationTagText = null;
71
72     /** The precedence label */
73     private Label precedenceLabel = null;
74
75     /** The spinner to select a valid precedence between 0 and 255 */
76     private Spinner precedenceSpinner = null;
77
78     /** The authentication level label */
79     private Label authenticationLevelLabel = null;
80
81     /** The combo to select a valid uthentication level */
82     private Combo authenticationLevelCombo = null;
83
84     /**
85      * The combo viewer is attached to authenticationLevelCombo to work with
86      * AuthenticationLevel objects rather than Strings
87      */

88     private ComboViewer authenticationLevelComboViewer = null;
89
90     /** The user or item first label */
91     private Label userOrItemFirstLabel = null;
92
93     /** The user first radio button */
94     private Button userFirstRadioButton = null;
95
96     /** The item first radio button */
97     private Button itemFirstRadioButton = null;
98
99     /** The list with listers */
100     private List JavaDoc<WidgetModifyListener> listenerList = new ArrayList JavaDoc<WidgetModifyListener>();
101
102
103     /**
104      * Creates a new instance of ACIItemGeneralComposite.
105      *
106      * @param parent
107      * @param style
108      */

109     public ACIItemGeneralComposite( Composite parent, int style )
110     {
111         super( parent, style );
112
113         GridLayout layout = new GridLayout();
114         layout.horizontalSpacing = 0;
115         layout.verticalSpacing = 0;
116         layout.marginHeight = 0;
117         layout.marginWidth = 0;
118         setLayout( layout );
119
120         GridData layoutData = new GridData();
121         layoutData.horizontalAlignment = GridData.FILL;
122         layoutData.grabExcessHorizontalSpace = true;
123         layoutData.verticalAlignment = GridData.CENTER;
124         setLayoutData( layoutData );
125
126         createComposite();
127     }
128
129
130     /**
131      * This method initializes composite
132      *
133      */

134     private void createComposite()
135     {
136
137         GridData identificationTagGridData = new GridData();
138         identificationTagGridData.grabExcessHorizontalSpace = true;
139         identificationTagGridData.verticalAlignment = GridData.CENTER;
140         identificationTagGridData.horizontalSpan = 2;
141         identificationTagGridData.horizontalAlignment = GridData.FILL;
142
143         GridData precedenceGridData = new GridData();
144         precedenceGridData.grabExcessHorizontalSpace = true;
145         precedenceGridData.verticalAlignment = GridData.CENTER;
146         precedenceGridData.horizontalSpan = 2;
147         precedenceGridData.horizontalAlignment = GridData.BEGINNING;
148         precedenceGridData.widthHint = 3 * 12;
149
150         GridData authenticationLevelGridData = new GridData();
151         authenticationLevelGridData.grabExcessHorizontalSpace = true;
152         authenticationLevelGridData.verticalAlignment = GridData.CENTER;
153         authenticationLevelGridData.horizontalSpan = 2;
154         authenticationLevelGridData.horizontalAlignment = GridData.FILL;
155
156         GridLayout gridLayout = new GridLayout();
157         gridLayout.numColumns = 3;
158         GridData gridData = new GridData();
159         gridData.horizontalAlignment = GridData.FILL;
160         gridData.grabExcessHorizontalSpace = true;
161         gridData.verticalAlignment = GridData.CENTER;
162
163         composite = new Composite( this, SWT.NONE );
164         composite.setLayout( gridLayout );
165         composite.setLayoutData( gridData );
166
167         identificationTagLabel = new Label( composite, SWT.NONE );
168         identificationTagLabel.setText( Messages.getString( "ACIItemGeneralComposite.idTag.label" ) ); //$NON-NLS-1$
169
identificationTagText = new Text( composite, SWT.BORDER );
170         identificationTagText.setLayoutData( identificationTagGridData );
171         identificationTagText.addModifyListener( new ModifyListener()
172         {
173             public void modifyText( ModifyEvent event )
174             {
175                 fire( event );
176             }
177         } );
178
179         precedenceLabel = new Label( composite, SWT.NONE );
180         precedenceLabel.setText( Messages.getString( "ACIItemGeneralComposite.precedence.label" ) ); //$NON-NLS-1$
181
precedenceSpinner = new Spinner( composite, SWT.BORDER );
182         precedenceSpinner.setMinimum( 0 );
183         precedenceSpinner.setMaximum( 255 );
184         precedenceSpinner.setDigits( 0 );
185         precedenceSpinner.setIncrement( 1 );
186         precedenceSpinner.setPageIncrement( 10 );
187         precedenceSpinner.setSelection( 0 );
188         precedenceSpinner.setLayoutData( precedenceGridData );
189         precedenceSpinner.addModifyListener( new ModifyListener()
190         {
191             public void modifyText( ModifyEvent event )
192             {
193                 fire( event );
194             }
195         } );
196
197         authenticationLevelLabel = new Label( composite, SWT.NONE );
198         authenticationLevelLabel.setText( Messages.getString( "ACIItemGeneralComposite.authLevel.label" ) ); //$NON-NLS-1$
199
authenticationLevelCombo = new Combo( composite, SWT.READ_ONLY );
200         authenticationLevelCombo.setLayoutData( authenticationLevelGridData );
201         AuthenticationLevel[] authenticationLevels = new AuthenticationLevel[3];
202         authenticationLevels[0] = AuthenticationLevel.NONE;
203         authenticationLevels[1] = AuthenticationLevel.SIMPLE;
204         authenticationLevels[2] = AuthenticationLevel.STRONG;
205         authenticationLevelComboViewer = new ComboViewer( authenticationLevelCombo );
206         authenticationLevelComboViewer.setContentProvider( new ArrayContentProvider() );
207         authenticationLevelComboViewer.setLabelProvider( new LabelProvider() );
208         authenticationLevelComboViewer.setInput( authenticationLevels );
209         authenticationLevelComboViewer.setSelection( new StructuredSelection( AuthenticationLevel.NONE ) );
210         authenticationLevelCombo.addModifyListener( new ModifyListener()
211         {
212             public void modifyText( ModifyEvent event )
213             {
214                 fire( event );
215             }
216         } );
217
218         userOrItemFirstLabel = new Label( composite, SWT.NONE );
219         userOrItemFirstLabel.setText( Messages.getString( "ACIItemGeneralComposite.userOrItemFirst.label" ) ); //$NON-NLS-1$
220
userFirstRadioButton = new Button( composite, SWT.RADIO );
221         userFirstRadioButton.setText( Messages.getString( "ACIItemGeneralComposite.userFirst.label" ) ); //$NON-NLS-1$
222
userFirstRadioButton.addSelectionListener( new SelectionAdapter()
223         {
224             public void widgetSelected( SelectionEvent event )
225             {
226                 fire( event );
227             }
228         } );
229         itemFirstRadioButton = new Button( composite, SWT.RADIO );
230         itemFirstRadioButton.setText( Messages.getString( "ACIItemGeneralComposite.itemFirst.label" ) ); //$NON-NLS-1$
231
itemFirstRadioButton.addSelectionListener( new SelectionAdapter()
232         {
233             public void widgetSelected( SelectionEvent event )
234             {
235                 fire( event );
236             }
237         } );
238
239     }
240
241
242     /**
243      * Add the listener to the list of listeners.
244      *
245      * @param listener
246      */

247     public void addWidgetModifyListener( WidgetModifyListener listener )
248     {
249         checkWidget();
250         if ( listener == null )
251             SWT.error( SWT.ERROR_NULL_ARGUMENT );
252         listenerList.add( listener );
253     }
254
255
256     /**
257      * Removes the listener from the list of listeners.
258      *
259      * @param listener
260      */

261     public void removeWidgetModifyListener( WidgetModifyListener listener )
262     {
263         checkWidget();
264         if ( listener == null )
265             SWT.error( SWT.ERROR_NULL_ARGUMENT );
266         listenerList.remove( listener );
267     }
268
269
270     /**
271      * Fires WidgetModifyEvents.
272      *
273      * @param event the original event
274      */

275     private void fire( TypedEvent event )
276     {
277         for ( WidgetModifyListener listener : listenerList )
278         {
279             listener.widgetModified( new WidgetModifyEvent( this ) );
280         }
281     }
282
283
284     /**
285      * Returns the identification tag.
286      *
287      * @return the identification tag
288      */

289     public String JavaDoc getIdentificationTag()
290     {
291         return identificationTagText.getText();
292     }
293
294
295     /**
296      * Sets the identification tag
297      *
298      * @param identificationTag the identification tag
299      */

300     public void setIdentificationTag( String JavaDoc identificationTag )
301     {
302         identificationTagText.setText( identificationTag );
303     }
304
305
306     /**
307      * Returns the selected precedence.
308      *
309      * @return the selected precedence
310      */

311     public int getPrecedence()
312     {
313         return precedenceSpinner.getSelection();
314     }
315
316
317     /**
318      * Sets the precedence
319      *
320      * @param precedence the precedence
321      */

322     public void setPrecedence( int precedence )
323     {
324         precedenceSpinner.setSelection( precedence );
325     }
326
327
328     /**
329      * Returns the selected authentication level.
330      *
331      * @return the selected authentication level
332      */

333     public AuthenticationLevel getAuthenticationLevel()
334     {
335         IStructuredSelection selection = ( IStructuredSelection ) authenticationLevelComboViewer.getSelection();
336         return ( AuthenticationLevel ) selection.getFirstElement();
337     }
338
339
340     /**
341      * Sets the authentication level.
342      *
343      * @param authenticationLevel the authentication level
344      */

345     public void setAuthenticationLevel( AuthenticationLevel authenticationLevel )
346     {
347         IStructuredSelection selection = new StructuredSelection( authenticationLevel );
348         authenticationLevelComboViewer.setSelection( selection );
349     }
350
351
352     /**
353      * Returns true if user first is selected.
354      *
355      * @return true if user first is selected
356      */

357     public boolean isUserFirst()
358     {
359         return userFirstRadioButton.getSelection();
360     }
361
362
363     /**
364      * Selects user first.
365      */

366     public void setUserFirst()
367     {
368         userFirstRadioButton.setSelection( true );
369         itemFirstRadioButton.setSelection( false );
370     }
371
372
373     /**
374      * Returns true if item first is selected.
375      *
376      * @return true if item first is selected
377      */

378     public boolean isItemFirst()
379     {
380         return itemFirstRadioButton.getSelection();
381     }
382
383
384     /**
385      * Selects item first.
386      */

387     public void setItemFirst()
388     {
389         itemFirstRadioButton.setSelection( true );
390         userFirstRadioButton.setSelection( false );
391     }
392
393 }
394
Popular Tags