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.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 54 public class CreateANewObjectClassWizardPage extends WizardPage 55 { 56 private Text oidField; 58 private Text nameField; 59 60 61 64 public CreateANewObjectClassWizardPage() 65 { 66 super( "CreateANewObjecClassWizardPage" ); setTitle( Messages.getString( "CreateANewObjectClassWizardPage.Page_Title" ) ); setDescription( Messages.getString( "CreateANewObjectClassWizardPage.Page_Description" ) ); setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, 70 PluginConstants.IMG_OBJECT_CLASS_NEW_WIZARD ) ); 71 } 72 73 74 79 public String getOidField() 80 { 81 return this.oidField.getText(); 82 } 83 84 85 90 public String getNameField() 91 { 92 return this.nameField.getText(); 93 } 94 95 96 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 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" ) ); 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 temp = store.getString( PluginConstants.PREFS_SCHEMAS_EDITOR_COMPANY_OID ); 125 oidField.setText( temp + "." ); } 127 else 128 { 129 oidField.setText( "" ); } 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" ) ); oidField = new Text( container, SWT.BORDER | SWT.SINGLE ); 141 if ( auto_oid ) 142 { 143 String temp = store.getString( PluginConstants.PREFS_SCHEMAS_EDITOR_COMPANY_OID ); 144 oidField.setText( temp + "." ); } 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]*\\.?)*" ) ) { 160 e.doit = false; 161 } 162 } 163 } ); 164 165 Label label2 = new Label( container, SWT.NULL ); 167 label2.setText( Messages.getString( "CreateANewObjectClassWizardPage.Name" ) ); 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 187 private void dialogChanged() 188 { 189 if ( getOidField().length() == 0 ) 190 { 191 updateStatus( Messages.getString( "CreateANewObjectClassWizardPage.An_OID_must_be_specified" ) ); return; 193 } 194 195 if ( !OID.isOID( getOidField() ) ) 196 { 197 updateStatus( Messages.getString( "CreateANewObjectClassWizardPage.Malforme_OID" ) ); return; 199 } 200 201 if ( getNameField().length() == 0 ) 202 { 203 updateStatus( Messages.getString( "CreateANewObjectClassWizardPage.A_name_must_be_specified" ) ); return; 205 } 206 207 if ( SchemaPool.getInstance().containsSchemaElement( getOidField() ) ) 208 { 209 updateStatus( Messages 210 .getString( "CreateANewObjectClassWizardPage.An_element_of_the_same_OID_already_exists" ) ); return; 212 } 213 214 if ( !ViewUtils.verifyName( getNameField() ) ) 215 { 216 updateStatus( Messages.getString( "CreateANewObjectClassWizardPage.Name_is_not_valid." ) ); return; 218 } 219 220 if ( SchemaPool.getInstance().containsSchemaElement( getNameField() ) ) 221 { 222 updateStatus( Messages 223 .getString( "CreateANewObjectClassWizardPage.An_element_of_the_same_name_already_exists" ) ); return; 225 } 226 227 updateStatus( null ); 228 } 229 230 231 237 private void updateStatus( String message ) 238 { 239 setErrorMessage( message ); 240 setPageComplete( message == null ); 241 } 242 } 243 | Popular Tags |