1 20 21 package org.apache.directory.ldapstudio.browser.ui.wizards; 22 23 24 import java.io.File ; 25 26 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils; 27 import org.apache.directory.ldapstudio.browser.common.widgets.FileBrowserWidget; 28 import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyEvent; 29 import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyListener; 30 import org.apache.directory.ldapstudio.browser.common.widgets.search.ConnectionWidget; 31 import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants; 32 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin; 33 import org.eclipse.jface.wizard.WizardPage; 34 import org.eclipse.swt.events.SelectionAdapter; 35 import org.eclipse.swt.events.SelectionEvent; 36 import org.eclipse.swt.widgets.Button; 37 import org.eclipse.swt.widgets.Composite; 38 import org.eclipse.swt.widgets.Group; 39 40 41 47 public class ImportDsmlMainWizardPage extends WizardPage 48 { 49 50 private ImportDsmlWizard wizard; 51 52 53 private static final String [] EXTENSIONS = new String [] 54 { "*.xml", "*.*" }; 55 56 57 private FileBrowserWidget dsmlFileBrowserWidget; 58 59 60 private ConnectionWidget connectionWidget; 61 62 63 private Button saveResponseButton; 64 65 66 private Button useDefaultResponseFileButton; 67 68 69 private Button useCustomResponseFileButton; 70 71 72 private FileBrowserWidget responseFileBrowserWidget; 73 74 75 private Button overwriteResponseFileButton; 76 77 78 private String customResponseFileName; 79 80 81 89 public ImportDsmlMainWizardPage( String pageName, ImportDsmlWizard wizard ) 90 { 91 super( pageName ); 92 setTitle( ImportDsmlWizard.WIZARD_TITLE ); 93 setDescription( "Please select a connection and the DSML file to import" ); 94 setImageDescriptor( BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_IMPORT_DSML_WIZARD ) ); 95 setPageComplete( false ); 96 this.wizard = wizard; 97 } 98 99 100 103 public void createControl( Composite parent ) 104 { 105 Composite composite = BaseWidgetUtils.createColumnContainer( parent, 3, 1 ); 106 107 BaseWidgetUtils.createLabel( composite, "DSML file:", 1 ); 109 dsmlFileBrowserWidget = new FileBrowserWidget( "Select a DSML File", EXTENSIONS, FileBrowserWidget.TYPE_OPEN ); 110 dsmlFileBrowserWidget.createWidget( composite ); 111 dsmlFileBrowserWidget.addWidgetModifyListener( new WidgetModifyListener() 112 { 113 public void widgetModified( WidgetModifyEvent event ) 114 { 115 wizard.setDsmlFilename( dsmlFileBrowserWidget.getFilename() ); 116 if ( useDefaultResponseFileButton.getSelection() ) 117 { 118 responseFileBrowserWidget.setFilename( dsmlFileBrowserWidget.getFilename() + ".response.xml" ); 119 } 120 validate(); 121 } 122 } ); 123 124 BaseWidgetUtils.createLabel( composite, "Import into:", 1 ); 126 connectionWidget = new ConnectionWidget( wizard.getImportConnection() ); 127 connectionWidget.createWidget( composite ); 128 connectionWidget.addWidgetModifyListener( new WidgetModifyListener() 129 { 130 public void widgetModified( WidgetModifyEvent event ) 131 { 132 wizard.setImportConnection( connectionWidget.getConnection() ); 133 validate(); 134 } 135 } ); 136 137 Composite responseOuterComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 3 ); 139 Group responseGroup = BaseWidgetUtils.createGroup( responseOuterComposite, "Response", 1 ); 140 Composite responseContainer = BaseWidgetUtils.createColumnContainer( responseGroup, 3, 1 ); 141 142 saveResponseButton = BaseWidgetUtils.createCheckbox( responseContainer, "Save response", 3 ); 143 saveResponseButton.setSelection( true ); 144 wizard.setSaveResponse( saveResponseButton.getSelection() ); 145 saveResponseButton.addSelectionListener( new SelectionAdapter() 146 { 147 public void widgetSelected( SelectionEvent event ) 148 { 149 wizard.setSaveResponse( saveResponseButton.getSelection() ); 150 useDefaultResponseFileButton.setEnabled( saveResponseButton.getSelection() ); 151 useCustomResponseFileButton.setEnabled( saveResponseButton.getSelection() ); 152 responseFileBrowserWidget.setEnabled( saveResponseButton.getSelection() 153 && useCustomResponseFileButton.getSelection() ); 154 overwriteResponseFileButton.setEnabled( saveResponseButton.getSelection() ); 155 validate(); 156 } 157 } ); 158 159 BaseWidgetUtils.createRadioIndent( responseContainer, 1 ); 160 useDefaultResponseFileButton = BaseWidgetUtils.createRadiobutton( responseContainer, 161 "Use default response file", 2 ); 162 useDefaultResponseFileButton.setSelection( true ); 163 useDefaultResponseFileButton.addSelectionListener( new SelectionAdapter() 164 { 165 public void widgetSelected( SelectionEvent event ) 166 { 167 String temp = customResponseFileName; 168 responseFileBrowserWidget.setFilename( dsmlFileBrowserWidget.getFilename() + ".response.xml" ); 169 responseFileBrowserWidget.setEnabled( false ); 170 customResponseFileName = temp; 171 validate(); 172 } 173 } ); 174 175 BaseWidgetUtils.createRadioIndent( responseContainer, 1 ); 176 useCustomResponseFileButton = BaseWidgetUtils.createRadiobutton( responseContainer, "Use custom response file", 177 2 ); 178 useCustomResponseFileButton.setSelection( false ); 179 useCustomResponseFileButton.addSelectionListener( new SelectionAdapter() 180 { 181 public void widgetSelected( SelectionEvent event ) 182 { 183 responseFileBrowserWidget.setFilename( customResponseFileName != null ? customResponseFileName : "" ); 184 responseFileBrowserWidget.setEnabled( true ); 185 validate(); 186 } 187 } ); 188 189 BaseWidgetUtils.createRadioIndent( responseContainer, 1 ); 190 responseFileBrowserWidget = new FileBrowserWidget( "Select save file", null, FileBrowserWidget.TYPE_SAVE ); 191 responseFileBrowserWidget.createWidget( responseContainer ); 192 responseFileBrowserWidget.addWidgetModifyListener( new WidgetModifyListener() 193 { 194 public void widgetModified( WidgetModifyEvent event ) 195 { 196 customResponseFileName = responseFileBrowserWidget.getFilename(); 197 wizard.setResponseFilename( customResponseFileName ); 198 validate(); 199 } 200 } ); 201 responseFileBrowserWidget.setEnabled( false ); 202 203 BaseWidgetUtils.createRadioIndent( responseContainer, 1 ); 204 overwriteResponseFileButton = BaseWidgetUtils.createCheckbox( responseContainer, 205 "Overwrite existing response file", 2 ); 206 overwriteResponseFileButton.addSelectionListener( new SelectionAdapter() 207 { 208 public void widgetSelected( SelectionEvent event ) 209 { 210 validate(); 211 } 212 } ); 213 214 setControl( composite ); 215 } 216 217 218 221 private void validate() 222 { 223 boolean ok = true; 224 225 File dsmlFile = new File ( dsmlFileBrowserWidget.getFilename() ); 226 if ( "".equals( dsmlFileBrowserWidget.getFilename() ) ) 227 { 228 setErrorMessage( null ); 229 ok = false; 230 } 231 else if ( !dsmlFile.isFile() || !dsmlFile.exists() ) 232 { 233 setErrorMessage( "Selected DSML file doesn't exist." ); 234 ok = false; 235 } 236 else if ( !dsmlFile.canRead() ) 237 { 238 setErrorMessage( "Selected DSML file is not readable." ); 239 ok = false; 240 } 241 else if ( saveResponseButton.getSelection() ) 242 { 243 File responseFile = new File ( responseFileBrowserWidget.getFilename() ); 244 File responseFileDirectory = responseFile.getParentFile(); 245 246 if ( responseFile.equals( dsmlFile ) ) 247 { 248 setErrorMessage( "DSML file and response file must not be equal." ); 249 ok = false; 250 } 251 else if ( responseFile.isDirectory() ) 252 { 253 setErrorMessage( "Selected response file is not a file." ); 254 ok = false; 255 } 256 else if ( responseFile.exists() && !overwriteResponseFileButton.getSelection() ) 257 { 258 setErrorMessage( "Selected response file already exists. Select option 'Overwrite existing response file' if you want to overwrite the response file." ); 259 ok = false; 260 } 261 else if ( responseFile.exists() && !responseFile.canWrite() ) 262 { 263 setErrorMessage( "Selected response file is not writeable." ); 264 ok = false; 265 } 266 else if ( responseFile.getParentFile() == null ) 267 { 268 setErrorMessage( "Selected response file directory is not writeable." ); 269 ok = false; 270 } 271 else if ( !responseFile.exists() && ( responseFileDirectory == null || !responseFileDirectory.canWrite() ) ) 272 { 273 setErrorMessage( "Selected response file directory is not writeable." ); 274 ok = false; 275 } 276 } 277 278 if ( ( wizard.getImportConnection() == null ) || ( connectionWidget.getConnection() == null ) ) 279 { 280 setErrorMessage( "Please select a Connection." ); 281 ok = false; 282 } 283 284 if ( ok ) 285 { 286 setErrorMessage( null ); 287 } 288 setPageComplete( ok ); 289 getContainer().updateButtons(); 290 } 291 292 293 296 public void saveDialogSettings() 297 { 298 dsmlFileBrowserWidget.saveDialogSettings(); 299 } 300 } 301 | Popular Tags |