1 20 21 package org.apache.directory.ldapstudio.browser.ui.wizards; 22 23 24 import org.apache.directory.ldapstudio.browser.common.widgets.ModWidget; 25 import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyEvent; 26 import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyListener; 27 import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants; 28 import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifFile; 29 import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContainer; 30 import org.apache.directory.ldapstudio.browser.core.model.ldif.parser.LdifParser; 31 import org.apache.directory.ldapstudio.browser.core.model.schema.Schema; 32 import org.eclipse.jface.wizard.WizardPage; 33 import org.eclipse.swt.SWT; 34 import org.eclipse.swt.layout.GridData; 35 import org.eclipse.swt.layout.GridLayout; 36 import org.eclipse.swt.widgets.Composite; 37 38 39 public class BatchOperationModifyWizardPage extends WizardPage implements WidgetModifyListener 40 { 41 42 private BatchOperationWizard wizard; 43 44 private ModWidget modWidget; 45 46 47 public BatchOperationModifyWizardPage( String pageName, BatchOperationWizard wizard ) 48 { 49 super( pageName ); 50 super.setTitle( "Define Modification" ); 51 super.setDescription( "Please define the modifcations." ); 52 super.setPageComplete( false ); 54 55 this.wizard = wizard; 56 } 57 58 59 private void validate() 60 { 61 62 String dummyLdif = "dn: cn=dummy" + BrowserCoreConstants.LINE_SEPARATOR + modWidget.getLdifFragment(); 63 LdifFile model = new LdifParser().parse( dummyLdif ); 64 LdifContainer[] containers = model.getContainers(); 65 if ( containers.length == 0 ) 66 { 67 setPageComplete( false ); 68 return; 69 } 70 for ( int i = 0; i < containers.length; i++ ) 71 { 72 if ( !containers[i].isValid() ) 73 { 74 setPageComplete( false ); 75 return; 76 } 77 } 78 79 setPageComplete( true ); 80 81 } 82 83 84 public void createControl( Composite parent ) 85 { 86 87 Composite composite = new Composite( parent, SWT.NONE ); 88 GridLayout gl = new GridLayout( 1, false ); 89 composite.setLayout( gl ); 90 composite.setLayoutData( new GridData( GridData.FILL_BOTH ) ); 91 92 modWidget = new ModWidget( wizard.getConnection() != null ? wizard.getConnection().getSchema() 93 : Schema.DEFAULT_SCHEMA ); 94 modWidget.createContents( composite ); 95 modWidget.addWidgetModifyListener( this ); 96 97 validate(); 98 99 setControl( composite ); 100 101 } 102 103 104 public String getLdifFragment() 105 { 106 return modWidget.getLdifFragment(); 107 } 108 109 public void widgetModified( WidgetModifyEvent event ) 110 { 111 validate(); 112 } 113 114 } 115 | Popular Tags |