KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > schemas > view > wizards > CreateANewObjectClassWizardPage


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.schemas.view.wizards;
22
23
24 import org.apache.directory.ldapstudio.schemas.Activator;
25 import org.apache.directory.ldapstudio.schemas.Messages;
26 import org.apache.directory.ldapstudio.schemas.PluginConstants;
27 import org.apache.directory.ldapstudio.schemas.model.SchemaPool;
28 import org.apache.directory.ldapstudio.schemas.view.ViewUtils;
29 import org.apache.directory.shared.asn1.primitives.OID;
30 import org.eclipse.jface.preference.IPreferenceStore;
31 import org.eclipse.jface.wizard.WizardPage;
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.VerifyEvent;
38 import org.eclipse.swt.events.VerifyListener;
39 import org.eclipse.swt.layout.GridData;
40 import org.eclipse.swt.layout.GridLayout;
41 import org.eclipse.swt.widgets.Button;
42 import org.eclipse.swt.widgets.Composite;
43 import org.eclipse.swt.widgets.Label;
44 import org.eclipse.swt.widgets.Text;
45 import org.eclipse.ui.plugin.AbstractUIPlugin;
46
47
48 /**
49  * Default Page for new attribute type wizard
50  *
51  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
52  * @version $Rev$, $Date$
53  */

54 public class CreateANewObjectClassWizardPage extends WizardPage
55 {
56     // UI Fields
57
private Text oidField;
58     private Text nameField;
59
60
61     /**
62      * Creates a new instance of CreateANewObjectClassWizardPage.
63      */

64     public CreateANewObjectClassWizardPage()
65     {
66         super( "CreateANewObjecClassWizardPage" ); //$NON-NLS-1$
67
setTitle( Messages.getString( "CreateANewObjectClassWizardPage.Page_Title" ) ); //$NON-NLS-1$
68
setDescription( Messages.getString( "CreateANewObjectClassWizardPage.Page_Description" ) ); //$NON-NLS-1$
69
setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
70             PluginConstants.IMG_OBJECT_CLASS_NEW_WIZARD ) );
71     }
72
73
74     /**
75      * OID field getter
76      *
77      * @return the value of the OID field
78      */

79     public String JavaDoc getOidField()
80     {
81         return this.oidField.getText();
82     }
83
84
85     /**
86      * Name field getter
87      *
88      * @return the value of the Name field
89      */

90     public String JavaDoc getNameField()
91     {
92         return this.nameField.getText();
93     }
94
95
96     /* (non-Javadoc)
97      * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
98      */

99     public void createControl( Composite parent )
100     {
101         Composite container = new Composite( parent, SWT.NULL );
102         GridLayout layout = new GridLayout();
103         layout.numColumns = 2;
104         layout.verticalSpacing = 1;
105         container.setLayout( layout );
106
107         GridData gd = new GridData( GridData.FILL_HORIZONTAL );
108
109         // Setting up the OID section
110
new Label( container, SWT.NULL );
111
112         final Button autoOID = new Button( container, SWT.CHECK );
113         autoOID.setText( Messages.getString( "CreateANewObjectClassWizardPage.Prefix_with_the_default_OID" ) ); //$NON-NLS-1$
114

115         autoOID.addSelectionListener( new SelectionAdapter()
116         {
117             public void widgetSelected( SelectionEvent e )
118             {
119                 IPreferenceStore store = Activator.getDefault().getPreferenceStore();
120
121                 store.setValue( PluginConstants.PREFS_SCHEMAS_EDITOR_AUTO_OID, autoOID.getSelection() );
122                 if ( autoOID.getSelection() )
123                 {
124                     String JavaDoc temp = store.getString( PluginConstants.PREFS_SCHEMAS_EDITOR_COMPANY_OID );
125                     oidField.setText( temp + "." ); //$NON-NLS-1$
126
}
127                 else
128                 {
129                     oidField.setText( "" ); //$NON-NLS-1$
130
}
131             }
132         } );
133
134         IPreferenceStore store = Activator.getDefault().getPreferenceStore();
135         boolean auto_oid = store.getBoolean( PluginConstants.PREFS_SCHEMAS_EDITOR_AUTO_OID );
136         autoOID.setSelection( auto_oid );
137
138         Label label = new Label( container, SWT.NULL );
139         label.setText( Messages.getString( "CreateANewObjectClassWizardPage.OID" ) ); //$NON-NLS-1$
140
oidField = new Text( container, SWT.BORDER | SWT.SINGLE );
141         if ( auto_oid )
142         {
143             String JavaDoc temp = store.getString( PluginConstants.PREFS_SCHEMAS_EDITOR_COMPANY_OID );
144             oidField.setText( temp + "." ); //$NON-NLS-1$
145
}
146         oidField.setLayoutData( gd );
147         oidField.addModifyListener( new ModifyListener()
148         {
149             public void modifyText( ModifyEvent e )
150             {
151                 dialogChanged();
152             }
153         } );
154         oidField.addVerifyListener( new VerifyListener()
155         {
156             public void verifyText( VerifyEvent e )
157             {
158                 if ( !e.text.matches( "([0-9]*\\.?)*" ) ) //$NON-NLS-1$
159
{
160                     e.doit = false;
161                 }
162             }
163         } );
164
165         // Setting up the Name section
166
Label label2 = new Label( container, SWT.NULL );
167         label2.setText( Messages.getString( "CreateANewObjectClassWizardPage.Name" ) ); //$NON-NLS-1$
168
nameField = new Text( container, SWT.BORDER | SWT.SINGLE );
169         nameField.setLayoutData( gd );
170         nameField.addModifyListener( new ModifyListener()
171         {
172             public void modifyText( ModifyEvent e )
173             {
174                 dialogChanged();
175             }
176         } );
177         dialogChanged();
178         setControl( container );
179         setErrorMessage( null );
180         setPageComplete( false );
181     }
182
183
184     /**
185      * This method is called when the user modifies something in the UI.
186      */

187     private void dialogChanged()
188     {
189         if ( getOidField().length() == 0 )
190         {
191             updateStatus( Messages.getString( "CreateANewObjectClassWizardPage.An_OID_must_be_specified" ) ); //$NON-NLS-1$
192
return;
193         }
194
195         if ( !OID.isOID( getOidField() ) )
196         {
197             updateStatus( Messages.getString( "CreateANewObjectClassWizardPage.Malforme_OID" ) ); //$NON-NLS-1$
198
return;
199         }
200
201         if ( getNameField().length() == 0 )
202         {
203             updateStatus( Messages.getString( "CreateANewObjectClassWizardPage.A_name_must_be_specified" ) ); //$NON-NLS-1$
204
return;
205         }
206
207         if ( SchemaPool.getInstance().containsSchemaElement( getOidField() ) )
208         {
209             updateStatus( Messages
210                 .getString( "CreateANewObjectClassWizardPage.An_element_of_the_same_OID_already_exists" ) ); //$NON-NLS-1$
211
return;
212         }
213
214         if ( !ViewUtils.verifyName( getNameField() ) )
215         {
216             updateStatus( Messages.getString( "CreateANewObjectClassWizardPage.Name_is_not_valid." ) ); //$NON-NLS-1$
217
return;
218         }
219
220         if ( SchemaPool.getInstance().containsSchemaElement( getNameField() ) )
221         {
222             updateStatus( Messages
223                 .getString( "CreateANewObjectClassWizardPage.An_element_of_the_same_name_already_exists" ) ); //$NON-NLS-1$
224
return;
225         }
226
227         updateStatus( null );
228     }
229
230
231     /**
232      * Updates the status of the page.
233      *
234      * @param message
235      * the message to display
236      */

237     private void updateStatus( String JavaDoc message )
238     {
239         setErrorMessage( message );
240         setPageComplete( message == null );
241     }
242 }
243
Popular Tags