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.ImportDsmlJob; 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 ImportDsmlWizard extends Wizard implements IImportWizard 49 { 50 51 public static final String WIZARD_TITLE = "DSML Import"; 52 53 54 private IConnection importConnection; 55 56 57 private ImportDsmlMainWizardPage mainPage; 58 59 60 private String dsmlFilename; 61 62 63 private String responseFilename; 64 65 66 private boolean saveResponse; 67 68 69 72 public ImportDsmlWizard() 73 { 74 super(); 75 setWindowTitle( WIZARD_TITLE ); 76 } 77 78 79 84 public ImportDsmlWizard( IConnection selectedConnection ) 85 { 86 setWindowTitle( WIZARD_TITLE ); 87 this.importConnection = selectedConnection; 88 } 89 90 91 95 public static String getId() 96 { 97 return ImportDsmlWizard.class.getName(); 98 } 99 100 101 104 public boolean performFinish() 105 { 106 mainPage.saveDialogSettings(); 107 108 if ( dsmlFilename != null && !"".equals( dsmlFilename ) ) 109 { 110 File dsmlFile = new File ( dsmlFilename ); 111 112 if ( saveResponse ) 113 { 114 File responseFile = new File ( responseFilename ); 115 new ImportDsmlJob( importConnection, dsmlFile, responseFile ).execute(); 116 } 117 else 118 { 119 new ImportDsmlJob( importConnection, dsmlFile ).execute(); 120 } 121 122 return true; 123 } 124 return false; 125 } 126 127 128 131 public void init( IWorkbench workbench, IStructuredSelection selection ) 132 { 133 Object o = selection.getFirstElement(); 134 if ( o instanceof IEntry ) 135 { 136 importConnection = ( ( IEntry ) o ).getConnection(); 137 } 138 else if ( o instanceof ISearchResult ) 139 { 140 importConnection = ( ( ISearchResult ) o ).getEntry().getConnection(); 141 } 142 else if ( o instanceof IBookmark ) 143 { 144 importConnection = ( ( IBookmark ) o ).getConnection(); 145 } 146 else if ( o instanceof IAttribute ) 147 { 148 importConnection = ( ( IAttribute ) o ).getEntry().getConnection(); 149 } 150 else if ( o instanceof IValue ) 151 { 152 importConnection = ( ( IValue ) o ).getAttribute().getEntry().getConnection(); 153 } 154 else if ( o instanceof IConnection ) 155 { 156 importConnection = ( IConnection ) o; 157 } 158 else 159 { 160 importConnection = null; 161 } 162 } 163 164 165 168 public void addPages() 169 { 170 mainPage = new ImportDsmlMainWizardPage( ImportDsmlMainWizardPage.class.getName(), this ); 171 addPage( mainPage ); 172 } 173 174 175 178 public void createPageControls( Composite pageContainer ) 179 { 180 super.createPageControls( pageContainer ); 181 182 PlatformUI.getWorkbench().getHelpSystem().setHelp( mainPage.getControl(), 184 BrowserUIPlugin.PLUGIN_ID + "." + "tools_dsmlimport_wizard" ); 185 } 186 187 188 192 public IConnection getImportConnection() 193 { 194 return importConnection; 195 } 196 197 198 203 public void setImportConnection( IConnection connection ) 204 { 205 this.importConnection = connection; 206 } 207 208 209 214 public void setDsmlFilename( String dsmlFilename ) 215 { 216 this.dsmlFilename = dsmlFilename; 217 } 218 219 220 225 public void setResponseFilename( String saveFilename ) 226 { 227 this.responseFilename = saveFilename; 228 } 229 230 231 236 public void setSaveResponse( boolean b ) 237 { 238 this.saveResponse = b; 239 } 240 } 241 | Popular Tags |