1 20 21 package org.apache.directory.ldapstudio.browser.ui.actions; 22 23 24 import org.apache.directory.ldapstudio.browser.common.actions.BrowserAction; 25 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 26 import org.apache.directory.ldapstudio.browser.core.model.IEntry; 27 import org.apache.directory.ldapstudio.browser.core.model.ISearch; 28 import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants; 29 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin; 30 import org.apache.directory.ldapstudio.browser.ui.wizards.ExportCsvWizard; 31 import org.apache.directory.ldapstudio.browser.ui.wizards.ExportDsmlWizard; 32 import org.apache.directory.ldapstudio.browser.ui.wizards.ExportExcelWizard; 33 import org.apache.directory.ldapstudio.browser.ui.wizards.ExportLdifWizard; 34 import org.apache.directory.ldapstudio.browser.ui.wizards.ImportDsmlWizard; 35 import org.apache.directory.ldapstudio.browser.ui.wizards.ImportLdifWizard; 36 37 import org.eclipse.jface.resource.ImageDescriptor; 38 import org.eclipse.jface.wizard.IWizard; 39 import org.eclipse.jface.wizard.WizardDialog; 40 41 42 48 public class ImportExportAction extends BrowserAction 49 { 50 53 public static final int TYPE_IMPORT_LDIF = 0; 54 55 58 public static final int TYPE_EXPORT_LDIF = 1; 59 60 63 public static final int TYPE_EXPORT_CSV = 2; 64 65 68 public static final int TYPE_EXPORT_EXCEL = 3; 69 70 73 public static final int TYPE_IMPORT_DSML = 4; 74 75 78 public static final int TYPE_EXPORT_DSML = 5; 79 80 private int type; 81 82 83 89 public ImportExportAction( int type ) 90 { 91 super(); 92 this.type = type; 93 } 94 95 96 99 public String getText() 100 { 101 if ( this.type == TYPE_IMPORT_LDIF ) 102 { 103 return "LDIF Import..."; 104 } 105 else if ( this.type == TYPE_EXPORT_LDIF ) 106 { 107 return "LDIF Export..."; 108 } 109 else if ( this.type == TYPE_EXPORT_CSV ) 110 { 111 return "CSV Export..."; 112 } 113 else if ( this.type == TYPE_EXPORT_EXCEL ) 114 { 115 return "Excel Export..."; 116 } 117 else if ( this.type == TYPE_IMPORT_DSML ) 118 { 119 return "DSML Import..."; 120 } 121 else if ( this.type == TYPE_EXPORT_DSML ) 122 { 123 return "DSML Export..."; 124 } 125 else 126 { 127 return "Export..."; 128 } 129 } 130 131 132 135 public ImageDescriptor getImageDescriptor() 136 { 137 if ( this.type == TYPE_IMPORT_LDIF ) 138 { 139 return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_IMPORT_LDIF ); 140 } 141 else if ( this.type == TYPE_EXPORT_LDIF ) 142 { 143 return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_EXPORT_LDIF ); 144 } 145 else if ( this.type == TYPE_EXPORT_CSV ) 146 { 147 return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_EXPORT_CSV ); 148 } 149 else if ( this.type == TYPE_EXPORT_EXCEL ) 150 { 151 return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_EXPORT_XLS ); 152 } 153 else if ( this.type == TYPE_IMPORT_DSML ) 154 { 155 return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_IMPORT_DSML ); 156 } 157 else if ( this.type == TYPE_EXPORT_DSML ) 158 { 159 return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_EXPORT_DSML ); 160 } 161 else 162 { 163 return null; 164 } 165 } 166 167 168 171 public String getCommandId() 172 { 173 return null; 174 } 175 176 177 180 public boolean isEnabled() 181 { 182 return getEntry() != null || getConnection() != null || getSearch() != null || getConnectionInput() != null; 183 184 } 185 186 187 190 public void run() 191 { 192 IWizard wizard = null; 193 194 if ( this.type == TYPE_IMPORT_LDIF ) 195 { 196 if ( getEntry() != null ) 197 { 198 wizard = new ImportLdifWizard( getEntry().getConnection() ); 199 } 200 else if ( getSearch() != null ) 201 { 202 wizard = new ImportLdifWizard( getSearch().getConnection() ); 203 } 204 else if ( getConnectionInput() != null ) 205 { 206 wizard = new ImportLdifWizard( getConnectionInput() ); 207 } 208 else if ( getConnection() != null ) 209 { 210 wizard = new ImportLdifWizard( getConnection() ); 211 } 212 } 213 else if ( this.type == TYPE_IMPORT_DSML ) 214 { 215 if ( getEntry() != null ) 216 { 217 wizard = new ImportDsmlWizard( getEntry().getConnection() ); 218 } 219 else if ( getSearch() != null ) 220 { 221 wizard = new ImportDsmlWizard( getSearch().getConnection() ); 222 } 223 else if ( getConnectionInput() != null ) 224 { 225 wizard = new ImportDsmlWizard( getConnectionInput() ); 226 } 227 else if ( getConnection() != null ) 228 { 229 wizard = new ImportDsmlWizard( getConnection() ); 230 } 231 } 232 else if ( this.type == TYPE_EXPORT_LDIF ) 233 { 234 wizard = new ExportLdifWizard(); 235 } 236 else if ( this.type == TYPE_EXPORT_CSV ) 237 { 238 wizard = new ExportCsvWizard(); 239 } 240 else if ( this.type == TYPE_EXPORT_EXCEL ) 241 { 242 wizard = new ExportExcelWizard(); 243 } 244 else if ( this.type == TYPE_EXPORT_DSML ) 245 { 246 wizard = new ExportDsmlWizard(); 247 } 248 249 if ( wizard != null ) 250 { 251 WizardDialog dialog = new WizardDialog( getShell(), wizard ); 252 dialog.setBlockOnOpen( true ); 253 dialog.create(); 254 dialog.open(); 255 } 256 257 } 258 259 260 266 protected IEntry getEntry() 267 { 268 IEntry entry = null; 269 if ( getSelectedEntries().length > 0 ) 270 { 271 entry = getSelectedEntries()[0]; 272 } 273 else if ( getSelectedSearchResults().length > 0 ) 274 { 275 entry = getSelectedSearchResults()[0].getEntry(); 276 } 277 else if ( getSelectedBookmarks().length > 0 ) 278 { 279 entry = getSelectedBookmarks()[0].getEntry(); 280 } 281 282 return entry != null && entry.getConnection().isOpened() ? entry : null; 283 } 284 285 286 292 protected IConnection getConnection() 293 { 294 return getSelectedConnections().length > 0 && getSelectedConnections()[0].isOpened() ? getSelectedConnections()[0] 295 : null; 296 } 297 298 299 305 protected ISearch getSearch() 306 { 307 return getSelectedSearches().length > 0 && getSelectedSearches()[0].getConnection().isOpened() ? getSelectedSearches()[0] 308 : null; 309 } 310 311 312 318 protected IConnection getConnectionInput() 319 { 320 321 if ( getInput() != null && ( getInput() instanceof IConnection ) && ( ( IConnection ) getInput() ).isOpened() ) 322 { 323 return ( IConnection ) getInput(); 324 } 325 else 326 { 327 return null; 328 } 329 } 330 } 331 | Popular Tags |