KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > apacheds > configuration > dialogs > IndexedAttributeDialog


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.apacheds.configuration.dialogs;
21
22
23 import org.apache.directory.ldapstudio.apacheds.configuration.model.IndexedAttribute;
24 import org.eclipse.jface.dialogs.Dialog;
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.events.ModifyEvent;
27 import org.eclipse.swt.events.ModifyListener;
28 import org.eclipse.swt.events.VerifyEvent;
29 import org.eclipse.swt.events.VerifyListener;
30 import org.eclipse.swt.layout.GridData;
31 import org.eclipse.swt.layout.GridLayout;
32 import org.eclipse.swt.widgets.Composite;
33 import org.eclipse.swt.widgets.Control;
34 import org.eclipse.swt.widgets.Label;
35 import org.eclipse.swt.widgets.Shell;
36 import org.eclipse.swt.widgets.Text;
37 import org.eclipse.ui.PlatformUI;
38
39
40 /**
41  * This class implements the Dialog for Indexed Attribute.
42  *
43  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
44  * @version $Rev$, $Date$
45  */

46 public class IndexedAttributeDialog extends Dialog
47 {
48     /** The Indexed Attribute */
49     private IndexedAttribute indexedAttribute;
50
51     /** The dirty flag */
52     private boolean dirty = false;
53
54     // UI Fields
55
private Text attributeIdText;
56     private Text cacheSizeText;
57
58
59     /**
60      * Creates a new instance of IndexedAttributeDialog.
61      */

62     public IndexedAttributeDialog( IndexedAttribute indexedAttribute )
63     {
64         super( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() );
65         this.indexedAttribute = indexedAttribute;
66     }
67
68
69     /* (non-Javadoc)
70      * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
71      */

72     protected void configureShell( Shell newShell )
73     {
74         super.configureShell( newShell );
75         newShell.setText( "Indexed Attribute Dialog" );
76     }
77
78
79     /* (non-Javadoc)
80      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
81      */

82     protected Control createDialogArea( Composite parent )
83     {
84         Composite composite = new Composite( parent, SWT.NONE );
85         GridLayout layout = new GridLayout( 2, false );
86         composite.setLayout( layout );
87         composite.setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, true ) );
88
89         Label attributeIdLabel = new Label( composite, SWT.NONE );
90         attributeIdLabel.setText( "Attribute ID:" );
91
92         attributeIdText = new Text( composite, SWT.BORDER );
93         attributeIdText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
94
95         Label cacheSizeLabel = new Label( composite, SWT.NONE );
96         cacheSizeLabel.setText( "Cache Size:" );
97
98         cacheSizeText = new Text( composite, SWT.BORDER );
99         cacheSizeText.addVerifyListener( new VerifyListener()
100         {
101             public void verifyText( VerifyEvent e )
102             {
103                 if ( !e.text.matches( "[0-9]*" ) ) //$NON-NLS-1$
104
{
105                     e.doit = false;
106                 }
107             }
108         } );
109         cacheSizeText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
110
111         initFromInput();
112         addListeners();
113
114         return composite;
115     }
116
117
118     /**
119      * Initializes the UI from the input.
120      */

121     private void initFromInput()
122     {
123         String JavaDoc attributeId = indexedAttribute.getAttributeId();
124         attributeIdText.setText( ( attributeId == null ) ? "" : attributeId );
125         cacheSizeText.setText( "" + indexedAttribute.getCacheSize() );
126     }
127
128
129     /**
130      * Adds listeners to the UI Fields.
131      */

132     private void addListeners()
133     {
134         attributeIdText.addModifyListener( new ModifyListener()
135         {
136             public void modifyText( ModifyEvent e )
137             {
138                 dirty = true;
139             }
140         } );
141
142         cacheSizeText.addModifyListener( new ModifyListener()
143         {
144             public void modifyText( ModifyEvent e )
145             {
146                 dirty = true;
147             }
148         } );
149     }
150
151
152     /* (non-Javadoc)
153      * @see org.eclipse.jface.dialogs.Dialog#okPressed()
154      */

155     protected void okPressed()
156     {
157         indexedAttribute.setAttributeId( attributeIdText.getText() );
158         try
159         {
160             indexedAttribute.setCacheSize( Integer.parseInt( cacheSizeText.getText() ) );
161         }
162         catch ( NumberFormatException JavaDoc e )
163         {
164             // Nothing to do, it won't happen
165
}
166
167         super.okPressed();
168     }
169
170
171     /**
172      * Gets the Indexed Attribute.
173      *
174      * @return
175      * the Indexed Attribute
176      */

177     public IndexedAttribute getIndexedAttribute()
178     {
179         return indexedAttribute;
180     }
181
182
183     /**
184      * Returns the dirty flag of the dialog.
185      *
186      * @return
187      * the dirty flag of the dialog
188      */

189     public boolean isDirty()
190     {
191         return dirty;
192     }
193 }
194
Popular Tags