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.eclipse.jface.wizard.WizardPage; 31 import org.eclipse.swt.events.SelectionAdapter; 32 import org.eclipse.swt.events.SelectionEvent; 33 import org.eclipse.swt.widgets.Button; 34 import org.eclipse.swt.widgets.Composite; 35 36 37 43 public abstract class ExportBaseToPage extends WizardPage 44 { 45 46 47 protected ExportBaseWizard wizard; 48 49 50 protected FileBrowserWidget fileBrowserWidget; 51 52 53 protected Button overwriteFileButton; 54 55 56 62 public ExportBaseToPage( String pageName, ExportBaseWizard wizard ) 63 { 64 super( pageName ); 65 setPageComplete( false ); 66 setTitle( getFileType() + " File" ); 67 setDescription( "Please enter the target " + getFileType() + " file." ); 68 69 this.wizard = wizard; 70 } 71 72 73 77 protected void validate() 78 { 79 boolean ok = true; 80 File file = new File ( fileBrowserWidget.getFilename() ); 81 File fileDirectory = file.getParentFile(); 82 if ( "".equals( fileBrowserWidget.getFilename() ) ) 83 { 84 setErrorMessage( null ); 85 ok = false; 86 } 87 else if ( file.isDirectory() ) 88 { 89 setErrorMessage( "Selected " + getFileType() + " is no file." ); 90 ok = false; 91 } 92 else if ( file.exists() && !overwriteFileButton.getSelection() ) 93 { 94 setErrorMessage( "Selected " + getFileType() + " file already exists. Select option 'Overwrite existing " 95 + getFileType() + " file' if you want to overwrite the " + getFileType() + " file." ); 96 ok = false; 97 } 98 else if ( file.exists() && !file.canWrite() ) 99 { 100 setErrorMessage( "Selected " + getFileType() + " file is not writeable." ); 101 ok = false; 102 } 103 else if ( file.getParentFile() == null ) 104 { 105 setErrorMessage( "Selected " + getFileType() + " file directory is not writeable." ); 106 ok = false; 107 } 108 else if ( !file.exists() && ( fileDirectory == null || !fileDirectory.canWrite() ) ) 109 { 110 setErrorMessage( "Selected " + getFileType() + " file directory is not writeable." ); 111 ok = false; 112 } 113 114 if ( ok ) 115 { 116 setErrorMessage( null ); 117 } 118 119 setPageComplete( ok && wizard.getExportFilename() != null && !"".equals( wizard.getExportFilename() ) ); 120 } 121 122 123 126 public void createControl( Composite composite ) 127 { 128 BaseWidgetUtils.createLabel( composite, getFileType() + " File:", 1 ); 130 fileBrowserWidget = new FileBrowserWidget( "Select " + getFileType() + " File", getExtensions(), 131 FileBrowserWidget.TYPE_SAVE ); 132 fileBrowserWidget.createWidget( composite ); 133 fileBrowserWidget.addWidgetModifyListener( new WidgetModifyListener() 134 { 135 public void widgetModified( WidgetModifyEvent event ) 136 { 137 wizard.setExportFilename( fileBrowserWidget.getFilename() ); 138 validate(); 139 } 140 } ); 141 BaseWidgetUtils.createRadioIndent( composite, 1 ); 142 overwriteFileButton = BaseWidgetUtils.createCheckbox( composite, "O&verwrite existing " + getFileType() 143 + " file", 2 ); 144 overwriteFileButton.addSelectionListener( new SelectionAdapter() 145 { 146 public void widgetSelected( SelectionEvent event ) 147 { 148 validate(); 149 } 150 } ); 151 152 fileBrowserWidget.setFocus(); 153 setControl( composite ); 154 validate(); 155 } 156 157 158 163 protected abstract String [] getExtensions(); 164 165 166 171 protected abstract String getFileType(); 172 173 174 177 public void saveDialogSettings() 178 { 179 fileBrowserWidget.saveDialogSettings(); 180 } 181 182 } 183 | Popular Tags |