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 ImportLdifMainWizardPage extends WizardPage 48 { 49 50 51 public static final String CONTINUE_ON_ERROR_DIALOGSETTING_KEY = ImportLdifMainWizardPage.class.getName() 52 + ".continueOnError"; 53 54 55 private static final String [] EXTENSIONS = new String [] 56 { "*.ldif", "*.*" }; 57 58 59 private ImportLdifWizard wizard; 60 61 62 private FileBrowserWidget ldifFileBrowserWidget; 63 64 65 private ConnectionWidget connectionWidget; 66 67 68 private Button enableLoggingButton; 69 70 71 private Button useDefaultLogfileButton; 72 73 74 private Button useCustomLogfileButton; 75 76 77 private String customLogfileName; 78 79 80 private FileBrowserWidget logFileBrowserWidget; 81 82 83 private Button overwriteLogfileButton; 84 85 86 private Button continueOnErrorButton; 87 88 89 95 public ImportLdifMainWizardPage( String pageName, ImportLdifWizard wizard ) 96 { 97 super( pageName ); 98 setTitle( "LDIF Import" ); 99 setDescription( "Please select a connection and the LDIF to import" ); 100 setImageDescriptor( BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_IMPORT_LDIF_WIZARD ) ); 101 setPageComplete( false ); 102 103 this.wizard = wizard; 104 } 105 106 107 111 private void validate() 112 { 113 boolean ok = true; 114 115 File ldifFile = new File ( ldifFileBrowserWidget.getFilename() ); 116 if ( "".equals( ldifFileBrowserWidget.getFilename() ) ) 117 { 118 setErrorMessage( null ); 119 ok = false; 120 } 121 else if ( !ldifFile.isFile() || !ldifFile.exists() ) 122 { 123 setErrorMessage( "Selected LDIF file doesn't exist." ); 124 ok = false; 125 } 126 else if ( !ldifFile.canRead() ) 127 { 128 setErrorMessage( "Selected LDIF file is not readable." ); 129 ok = false; 130 } 131 else if ( enableLoggingButton.getSelection() ) 132 { 133 File logFile = new File ( logFileBrowserWidget.getFilename() ); 134 File logFileDirectory = logFile.getParentFile(); 135 136 if ( logFile.equals( ldifFile ) ) 137 { 138 setErrorMessage( "LDIF file and Logfile must not be equal." ); 139 ok = false; 140 } 141 else if ( logFile.isDirectory() ) 142 { 143 setErrorMessage( "Selected logfile is no file." ); 144 ok = false; 145 } 146 else if ( logFile.exists() && !overwriteLogfileButton.getSelection() ) 147 { 148 setErrorMessage( "Selected logfile already exists. Select option 'Overwrite existing logfile' if you want to overwrite the logfile." ); 149 ok = false; 150 } 151 else if ( logFile.exists() && !logFile.canWrite() ) 152 { 153 setErrorMessage( "Selected logfile is not writeable." ); 154 ok = false; 155 } 156 else if ( logFile.getParentFile() == null ) 157 { 158 setErrorMessage( "Selected logfile directory is not writeable." ); 159 ok = false; 160 } 161 else if ( !logFile.exists() && ( logFileDirectory == null || !logFileDirectory.canWrite() ) ) 162 { 163 setErrorMessage( "Selected logfile directory is not writeable." ); 164 ok = false; 165 } 166 } 167 168 if ( wizard.getImportConnection() == null ) 169 { 170 ok = false; 171 } 172 173 if ( ok ) 174 { 175 setErrorMessage( null ); 176 } 177 setPageComplete( ok ); 178 getContainer().updateButtons(); 179 } 180 181 182 185 public void createControl( Composite parent ) 186 { 187 Composite composite = BaseWidgetUtils.createColumnContainer( parent, 3, 1 ); 188 189 BaseWidgetUtils.createLabel( composite, "LDIF file:", 1 ); 191 ldifFileBrowserWidget = new FileBrowserWidget( "Select LDIF File", EXTENSIONS, FileBrowserWidget.TYPE_OPEN ); 192 ldifFileBrowserWidget.createWidget( composite ); 193 ldifFileBrowserWidget.addWidgetModifyListener( new WidgetModifyListener() 194 { 195 public void widgetModified( WidgetModifyEvent event ) 196 { 197 wizard.setLdifFilename( ldifFileBrowserWidget.getFilename() ); 198 if ( useDefaultLogfileButton.getSelection() ) 199 { 200 logFileBrowserWidget.setFilename( ldifFileBrowserWidget.getFilename() + ".log" ); 201 } 202 validate(); 203 } 204 } ); 205 206 BaseWidgetUtils.createLabel( composite, "Import into:", 1 ); 208 connectionWidget = new ConnectionWidget( wizard.getImportConnection() ); 209 connectionWidget.createWidget( composite ); 210 connectionWidget.addWidgetModifyListener( new WidgetModifyListener() 211 { 212 public void widgetModified( WidgetModifyEvent event ) 213 { 214 wizard.setImportConnection( connectionWidget.getConnection() ); 215 validate(); 216 } 217 } ); 218 219 Composite loggingOuterComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 3 ); 221 Group loggingGroup = BaseWidgetUtils.createGroup( loggingOuterComposite, "Logging", 1 ); 222 Composite loggingContainer = BaseWidgetUtils.createColumnContainer( loggingGroup, 3, 1 ); 223 224 enableLoggingButton = BaseWidgetUtils.createCheckbox( loggingContainer, "Enable logging", 3 ); 225 enableLoggingButton.setSelection( true ); 226 wizard.setEnableLogging( enableLoggingButton.getSelection() ); 227 enableLoggingButton.addSelectionListener( new SelectionAdapter() 228 { 229 public void widgetSelected( SelectionEvent event ) 230 { 231 wizard.setEnableLogging( enableLoggingButton.getSelection() ); 232 useDefaultLogfileButton.setEnabled( enableLoggingButton.getSelection() ); 233 useCustomLogfileButton.setEnabled( enableLoggingButton.getSelection() ); 234 logFileBrowserWidget.setEnabled( enableLoggingButton.getSelection() 235 && useCustomLogfileButton.getSelection() ); 236 overwriteLogfileButton.setEnabled( enableLoggingButton.getSelection() ); 237 validate(); 238 } 239 } ); 240 241 BaseWidgetUtils.createRadioIndent( loggingContainer, 1 ); 242 useDefaultLogfileButton = BaseWidgetUtils.createRadiobutton( loggingContainer, "Use default logfile", 2 ); 243 useDefaultLogfileButton.setSelection( true ); 244 useDefaultLogfileButton.addSelectionListener( new SelectionAdapter() 245 { 246 public void widgetSelected( SelectionEvent event ) 247 { 248 String temp = customLogfileName; 249 logFileBrowserWidget.setFilename( ldifFileBrowserWidget.getFilename() + ".log" ); 250 logFileBrowserWidget.setEnabled( false ); 251 customLogfileName = temp; 252 validate(); 253 } 254 } ); 255 256 BaseWidgetUtils.createRadioIndent( loggingContainer, 1 ); 257 useCustomLogfileButton = BaseWidgetUtils.createRadiobutton( loggingContainer, "Use custom logfile", 2 ); 258 useCustomLogfileButton.setSelection( false ); 259 useCustomLogfileButton.addSelectionListener( new SelectionAdapter() 260 { 261 public void widgetSelected( SelectionEvent event ) 262 { 263 logFileBrowserWidget.setFilename( customLogfileName != null ? customLogfileName : "" ); 264 logFileBrowserWidget.setEnabled( true ); 265 validate(); 266 } 267 } ); 268 269 BaseWidgetUtils.createRadioIndent( loggingContainer, 1 ); 270 logFileBrowserWidget = new FileBrowserWidget( "Select Logfile", null, FileBrowserWidget.TYPE_SAVE ); 271 logFileBrowserWidget.createWidget( loggingContainer ); 272 logFileBrowserWidget.addWidgetModifyListener( new WidgetModifyListener() 273 { 274 public void widgetModified( WidgetModifyEvent event ) 275 { 276 customLogfileName = logFileBrowserWidget.getFilename(); 277 wizard.setLogFilename( customLogfileName ); 278 validate(); 279 } 280 } ); 281 logFileBrowserWidget.setEnabled( false ); 282 283 BaseWidgetUtils.createRadioIndent( loggingContainer, 1 ); 284 overwriteLogfileButton = BaseWidgetUtils.createCheckbox( loggingContainer, "Overwrite existing logfile", 2 ); 285 overwriteLogfileButton.addSelectionListener( new SelectionAdapter() 286 { 287 public void widgetSelected( SelectionEvent event ) 288 { 289 validate(); 290 } 291 } ); 292 293 continueOnErrorButton = BaseWidgetUtils.createCheckbox( composite, "Continue on error", 3 ); 295 if ( BrowserUIPlugin.getDefault().getDialogSettings().get( CONTINUE_ON_ERROR_DIALOGSETTING_KEY ) == null ) 296 { 297 BrowserUIPlugin.getDefault().getDialogSettings().put( CONTINUE_ON_ERROR_DIALOGSETTING_KEY, false ); 298 } 299 continueOnErrorButton.setSelection( BrowserUIPlugin.getDefault().getDialogSettings().getBoolean( 300 CONTINUE_ON_ERROR_DIALOGSETTING_KEY ) ); 301 wizard.setContinueOnError( continueOnErrorButton.getSelection() ); 302 continueOnErrorButton.addSelectionListener( new SelectionAdapter() 303 { 304 public void widgetSelected( SelectionEvent event ) 305 { 306 wizard.setContinueOnError( continueOnErrorButton.getSelection() ); 307 validate(); 308 } 309 } ); 310 311 setControl( composite ); 312 } 314 315 316 319 public void saveDialogSettings() 320 { 321 ldifFileBrowserWidget.saveDialogSettings(); 322 BrowserUIPlugin.getDefault().getDialogSettings().put( CONTINUE_ON_ERROR_DIALOGSETTING_KEY, 323 continueOnErrorButton.getSelection() ); 324 } 325 326 } | Popular Tags |