1 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 43 public class CreateANewSchemaWizardPage extends WizardPage 44 { 45 private Text nameField; 47 48 49 52 public CreateANewSchemaWizardPage() 53 { 54 super( "CreateANewSchemaWizardPage" ); setTitle( Messages.getString( "CreateANewSchemaWizardPage.Page_Title" ) ); setDescription( Messages.getString( "CreateANewSchemaWizardPage.Page_Description" ) ); setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, 58 PluginConstants.IMG_SCHEMA_NEW_WIZARD ) ); 59 } 60 61 62 67 public String getNameField() 68 { 69 return this.nameField.getText(); 70 } 71 72 73 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" ) ); 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 105 private void dialogChanged() 106 { 107 if ( getNameField().length() == 0 ) 108 { 109 updateStatus( Messages.getString( "CreateANewSchemaWizardPage.A_name_must_be_specified" ) ); 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" ) ); return; 118 } 119 120 updateStatus( null ); 121 } 122 123 124 130 private void updateStatus( String message ) 131 { 132 setErrorMessage( message ); 133 setPageComplete( message == null ); 134 } 135 } 136 | Popular Tags |