KickJava   Java API By Example, From Geeks To Geeks.

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


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.eclipse.jface.wizard.WizardPage;
29 import org.eclipse.swt.SWT;
30 import org.eclipse.swt.events.ModifyEvent;
31 import org.eclipse.swt.events.ModifyListener;
32 import org.eclipse.swt.layout.GridData;
33 import org.eclipse.swt.layout.GridLayout;
34 import org.eclipse.swt.widgets.Composite;
35 import org.eclipse.swt.widgets.Label;
36 import org.eclipse.swt.widgets.Text;
37 import org.eclipse.ui.plugin.AbstractUIPlugin;
38
39
40 /**
41  * Default Page for new schema wizard
42  */

43 public class CreateANewSchemaWizardPage extends WizardPage
44 {
45     // UI Fields
46
private Text nameField;
47
48
49     /**
50      * Creates a new instance of CreateANewSchemaWizardPage.
51      */

52     public CreateANewSchemaWizardPage()
53     {
54         super( "CreateANewSchemaWizardPage" ); //$NON-NLS-1$
55
setTitle( Messages.getString( "CreateANewSchemaWizardPage.Page_Title" ) ); //$NON-NLS-1$
56
setDescription( Messages.getString( "CreateANewSchemaWizardPage.Page_Description" ) ); //$NON-NLS-1$
57
setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
58             PluginConstants.IMG_SCHEMA_NEW_WIZARD ) );
59     }
60
61
62     /**
63      * Name field getter
64      *
65      * @return
66      */

67     public String JavaDoc getNameField()
68     {
69         return this.nameField.getText();
70     }
71
72
73     /* (non-Javadoc)
74      * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
75      */

76     public void createControl( Composite parent )
77     {
78         Composite container = new Composite( parent, SWT.NULL );
79         GridLayout layout = new GridLayout();
80         container.setLayout( layout );
81         layout.numColumns = 2;
82         layout.verticalSpacing = 1;
83         Label label = new Label( container, SWT.NULL );
84         label.setText( Messages.getString( "CreateANewSchemaWizardPage.Name" ) ); //$NON-NLS-1$
85
nameField = new Text( container, SWT.BORDER | SWT.SINGLE );
86         GridData gd = new GridData( GridData.FILL_HORIZONTAL );
87         nameField.setLayoutData( gd );
88         nameField.addModifyListener( new ModifyListener()
89         {
90             public void modifyText( ModifyEvent e )
91             {
92                 dialogChanged();
93             }
94         } );
95         dialogChanged();
96         setControl( container );
97         setErrorMessage( null );
98         setPageComplete( false );
99     }
100
101
102     /**
103      * This method is called when the user modifies something in the UI.
104      */

105     private void dialogChanged()
106     {
107         if ( getNameField().length() == 0 )
108         {
109             updateStatus( Messages.getString( "CreateANewSchemaWizardPage.A_name_must_be_specified" ) ); //$NON-NLS-1$
110
return;
111         }
112
113         if ( SchemaPool.getInstance().getSchema( getNameField() ) != null )
114         {
115             updateStatus( Messages
116                 .getString( "CreateANewSchemaWizardPage.A_schema_of_the_same_name_is_already_loaded_in_the_pool" ) ); //$NON-NLS-1$
117
return;
118         }
119
120         updateStatus( null );
121     }
122
123
124     /**
125      * Updates the status of the page.
126      *
127      * @param message
128      * the message to display
129      */

130     private void updateStatus( String JavaDoc message )
131     {
132         setErrorMessage( message );
133         setPageComplete( message == null );
134     }
135 }
136
Popular Tags