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.core.jobs.ImportLdifJob; 27 import org.apache.directory.ldapstudio.browser.core.model.IAttribute; 28 import org.apache.directory.ldapstudio.browser.core.model.IBookmark; 29 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 30 import org.apache.directory.ldapstudio.browser.core.model.IEntry; 31 import org.apache.directory.ldapstudio.browser.core.model.ISearchResult; 32 import org.apache.directory.ldapstudio.browser.core.model.IValue; 33 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin; 34 import org.eclipse.jface.viewers.IStructuredSelection; 35 import org.eclipse.jface.wizard.Wizard; 36 import org.eclipse.swt.widgets.Composite; 37 import org.eclipse.ui.IImportWizard; 38 import org.eclipse.ui.IWorkbench; 39 import org.eclipse.ui.PlatformUI; 40 41 42 48 public class ImportLdifWizard extends Wizard implements IImportWizard 49 { 50 51 52 private ImportLdifMainWizardPage mainPage; 53 54 55 private String ldifFilename; 56 57 58 private IConnection importConnection; 59 60 61 private boolean enableLogging; 62 63 64 private String logFilename; 65 66 67 private boolean continueOnError; 68 69 70 73 public ImportLdifWizard() 74 { 75 super(); 76 setWindowTitle( "LDIF Import" ); 77 } 78 79 80 85 public ImportLdifWizard( IConnection importConnection ) 86 { 87 super.setWindowTitle( "LDIF Import" ); 88 this.importConnection = importConnection; 89 } 90 91 92 97 public static String getId() 98 { 99 return ImportLdifWizard.class.getName(); 100 } 101 102 103 106 public void init( IWorkbench workbench, IStructuredSelection selection ) 107 { 108 Object o = selection.getFirstElement(); 109 if ( o instanceof IEntry ) 110 { 111 importConnection = ( ( IEntry ) o ).getConnection(); 112 } 113 else if ( o instanceof ISearchResult ) 114 { 115 importConnection = ( ( ISearchResult ) o ).getEntry().getConnection(); 116 } 117 else if ( o instanceof IBookmark ) 118 { 119 importConnection = ( ( IBookmark ) o ).getConnection(); 120 } 121 else if ( o instanceof IAttribute ) 122 { 123 importConnection = ( ( IAttribute ) o ).getEntry().getConnection(); 124 } 125 else if ( o instanceof IValue ) 126 { 127 importConnection = ( ( IValue ) o ).getAttribute().getEntry().getConnection(); 128 } 129 else if ( o instanceof IConnection ) 130 { 131 importConnection = ( IConnection ) o; 132 } 133 else 134 { 135 importConnection = null; 136 } 137 } 138 139 140 143 public void addPages() 144 { 145 mainPage = new ImportLdifMainWizardPage( ImportLdifMainWizardPage.class.getName(), this ); 146 addPage( mainPage ); 147 } 148 149 150 153 public void createPageControls( Composite pageContainer ) 154 { 155 super.createPageControls( pageContainer ); 156 157 PlatformUI.getWorkbench().getHelpSystem().setHelp( mainPage.getControl(), 158 BrowserUIPlugin.PLUGIN_ID + "." + "tools_ldifimport_wizard" ); 159 } 160 161 162 165 public boolean performFinish() 166 { 167 168 mainPage.saveDialogSettings(); 169 170 if ( ldifFilename != null && !"".equals( ldifFilename ) ) 171 { 172 File ldifFile = new File ( ldifFilename ); 173 174 if ( enableLogging ) 175 { 176 File logFile = new File ( logFilename ); 177 new ImportLdifJob( importConnection, ldifFile, logFile, continueOnError ).execute(); 178 } 179 else 180 { 181 new ImportLdifJob( importConnection, ldifFile, continueOnError ).execute(); 182 } 183 184 return true; 185 } 186 return false; 187 } 188 189 190 195 public IConnection getImportConnection() 196 { 197 return importConnection; 198 } 199 200 201 206 public void setImportConnection( IConnection importConnection ) 207 { 208 this.importConnection = importConnection; 209 } 210 211 212 217 public void setLdifFilename( String ldifFilename ) 218 { 219 this.ldifFilename = ldifFilename; 220 } 221 222 223 228 public void setContinueOnError( boolean continueOnError ) 229 { 230 this.continueOnError = continueOnError; 231 } 232 233 234 239 public void setLogFilename( String logFilename ) 240 { 241 this.logFilename = logFilename; 242 } 243 244 245 250 public void setEnableLogging( boolean b ) 251 { 252 this.enableLogging = b; 253 } 254 255 } 256 | Popular Tags |