1 20 21 package org.apache.directory.ldapstudio.browser.ui.wizards; 22 23 24 import org.apache.directory.ldapstudio.browser.common.jobs.RunnableContextJobAdapter; 25 import org.apache.directory.ldapstudio.browser.common.widgets.browser.BrowserCategory; 26 import org.apache.directory.ldapstudio.browser.common.widgets.browser.BrowserEntryPage; 27 import org.apache.directory.ldapstudio.browser.common.widgets.browser.BrowserSearchResultPage; 28 import org.apache.directory.ldapstudio.browser.core.events.EventRegistry; 29 import org.apache.directory.ldapstudio.browser.core.internal.model.DummyEntry; 30 import org.apache.directory.ldapstudio.browser.core.jobs.CreateEntryJob; 31 import org.apache.directory.ldapstudio.browser.core.model.DN; 32 import org.apache.directory.ldapstudio.browser.core.model.IAttribute; 33 import org.apache.directory.ldapstudio.browser.core.model.IBookmark; 34 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 35 import org.apache.directory.ldapstudio.browser.core.model.IEntry; 36 import org.apache.directory.ldapstudio.browser.core.model.ISearch; 37 import org.apache.directory.ldapstudio.browser.core.model.ISearchResult; 38 import org.apache.directory.ldapstudio.browser.core.model.IValue; 39 import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants; 40 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin; 41 import org.eclipse.jface.viewers.IStructuredSelection; 42 import org.eclipse.jface.wizard.IWizardPage; 43 import org.eclipse.jface.wizard.Wizard; 44 import org.eclipse.jface.wizard.WizardPage; 45 import org.eclipse.swt.SWT; 46 import org.eclipse.swt.layout.GridData; 47 import org.eclipse.swt.layout.GridLayout; 48 import org.eclipse.swt.widgets.Composite; 49 import org.eclipse.ui.INewWizard; 50 import org.eclipse.ui.IWorkbench; 51 import org.eclipse.ui.PlatformUI; 52 53 54 61 public class NewEntryWizard extends Wizard implements INewWizard 62 { 63 64 65 private NewEntryTypeWizardPage typePage; 66 67 68 private NewEntryObjectclassWizardPage ocPage; 69 70 71 private NewEntryDnWizardPage dnPage; 72 73 74 private NewEntryAttributesWizardPage attributePage; 75 76 77 private IEntry selectedEntry; 78 79 80 private IConnection selectedConnection; 81 82 83 private DummyEntry prototypeEntry; 84 85 86 89 public NewEntryWizard() 90 { 91 setWindowTitle( "New Entry" ); 92 setNeedsProgressMonitor( true ); 93 } 94 95 96 101 public static String getId() 102 { 103 return NewEntryWizard.class.getName(); 104 } 105 106 107 110 public void init( IWorkbench workbench, IStructuredSelection selection ) 111 { 112 Object o = selection.getFirstElement(); 114 if ( o instanceof IEntry ) 115 { 116 selectedEntry = ( ( IEntry ) o ); 117 selectedConnection = selectedEntry.getConnection(); 118 } 119 else if ( o instanceof ISearchResult ) 120 { 121 selectedEntry = ( ( ISearchResult ) o ).getEntry(); 122 selectedConnection = selectedEntry.getConnection(); 123 } 124 else if ( o instanceof IBookmark ) 125 { 126 selectedEntry = ( ( IBookmark ) o ).getEntry(); 127 selectedConnection = selectedEntry.getConnection(); 128 } 129 else if ( o instanceof IAttribute ) 130 { 131 selectedEntry = ( ( IAttribute ) o ).getEntry(); 132 selectedConnection = selectedEntry.getConnection(); 133 } 134 else if ( o instanceof IValue ) 135 { 136 selectedEntry = ( ( IValue ) o ).getAttribute().getEntry(); 137 selectedConnection = selectedEntry.getConnection(); 138 } 139 else if ( o instanceof ISearch ) 140 { 141 selectedEntry = null; 142 selectedConnection = ( ( ISearch ) o ).getConnection(); 143 } 144 else if ( o instanceof IConnection ) 145 { 146 selectedEntry = null; 147 selectedConnection = ( IConnection ) o; 148 } 149 else if ( o instanceof BrowserCategory ) 150 { 151 selectedEntry = null; 152 selectedConnection = ( ( BrowserCategory ) o ).getParent(); 153 } 154 else if ( o instanceof BrowserSearchResultPage ) 155 { 156 selectedEntry = null; 157 selectedConnection = ( ( BrowserSearchResultPage ) o ).getSearch().getConnection(); 158 } 159 else if ( o instanceof BrowserEntryPage ) 160 { 161 selectedEntry = null; 162 selectedConnection = ( ( BrowserEntryPage ) o ).getEntry().getConnection(); 163 } 164 else 165 { 166 selectedEntry = null; 167 selectedConnection = null; 168 } 169 170 if ( selectedConnection != null ) 171 { 172 selectedConnection.suspend(); 173 prototypeEntry = new DummyEntry( new DN(), selectedConnection ); 174 } 175 } 176 177 178 181 public void addPages() 182 { 183 if ( selectedConnection != null ) 184 { 185 typePage = new NewEntryTypeWizardPage( NewEntryTypeWizardPage.class.getName(), this ); 186 addPage( typePage ); 187 188 ocPage = new NewEntryObjectclassWizardPage( NewEntryObjectclassWizardPage.class.getName(), this ); 189 addPage( ocPage ); 190 191 dnPage = new NewEntryDnWizardPage( NewEntryDnWizardPage.class.getName(), this ); 192 addPage( dnPage ); 193 194 attributePage = new NewEntryAttributesWizardPage( NewEntryAttributesWizardPage.class.getName(), this ); 195 addPage( attributePage ); 196 } 197 else 198 { 199 IWizardPage page = new DummyWizardPage(); 200 addPage( page ); 201 } 202 } 203 204 205 208 public void createPageControls( Composite pageContainer ) 209 { 210 super.createPageControls( pageContainer ); 211 212 if ( selectedConnection != null ) 214 { 215 PlatformUI.getWorkbench().getHelpSystem().setHelp( typePage.getControl(), 216 BrowserUIPlugin.PLUGIN_ID + "." + "tools_newentry_wizard" ); 217 PlatformUI.getWorkbench().getHelpSystem().setHelp( ocPage.getControl(), 218 BrowserUIPlugin.PLUGIN_ID + "." + "tools_newentry_wizard" ); 219 PlatformUI.getWorkbench().getHelpSystem().setHelp( dnPage.getControl(), 220 BrowserUIPlugin.PLUGIN_ID + "." + "tools_newentry_wizard" ); 221 PlatformUI.getWorkbench().getHelpSystem().setHelp( attributePage.getControl(), 222 BrowserUIPlugin.PLUGIN_ID + "." + "tools_newentry_wizard" ); 223 } 224 } 225 226 232 class DummyWizardPage extends WizardPage 233 { 234 235 238 protected DummyWizardPage() 239 { 240 super( "" ); 241 setTitle( "No connection selected or connection is closed" ); 242 setDescription( "In order to use the entry creation wizard please select an entry or connection." ); 243 setImageDescriptor( BrowserUIPlugin.getDefault().getImageDescriptor( 244 BrowserUIConstants.IMG_ENTRY_WIZARD ) ); 245 setPageComplete( true ); 246 } 247 248 249 252 public void createControl( Composite parent ) 253 { 254 Composite composite = new Composite( parent, SWT.NONE ); 255 GridLayout gl = new GridLayout( 1, false ); 256 composite.setLayout( gl ); 257 composite.setLayoutData( new GridData( GridData.FILL_BOTH ) ); 258 259 setControl( composite ); 260 } 261 } 262 263 264 267 public boolean performCancel() 268 { 269 if ( selectedConnection != null && selectedConnection.isOpened() ) 270 { 271 EventRegistry.suspendEventFireingInCurrentThread(); 272 selectedConnection.reset(); 273 EventRegistry.resumeEventFireingInCurrentThread(); 274 selectedConnection.reset(); 275 } 276 277 return true; 278 } 279 280 281 284 public boolean performFinish() 285 { 286 try 287 { 288 if ( selectedConnection != null && selectedConnection.isOpened() ) 289 { 290 typePage.saveDialogSettings(); 291 ocPage.saveDialogSettings(); 292 dnPage.saveDialogSettings(); 293 294 getSelectedConnection().reset(); 295 296 CreateEntryJob job = new CreateEntryJob( new IEntry[] 297 { getPrototypeEntry() } ); 298 RunnableContextJobAdapter.execute( job, getContainer() ); 299 300 if ( !job.getExternalResult().isOK() ) 301 { 302 getSelectedConnection().suspend(); 303 return false; 304 } 305 else 306 { 307 return true; 308 } 309 } 310 else 311 { 312 return true; 313 } 314 } 315 catch ( Throwable t ) 316 { 317 t.printStackTrace(); 318 return false; 319 } 320 } 321 322 323 328 public IEntry getSelectedEntry() 329 { 330 return selectedEntry; 331 } 332 333 334 339 public IConnection getSelectedConnection() 340 { 341 return selectedConnection; 342 } 343 344 345 350 public DummyEntry getPrototypeEntry() 351 { 352 return prototypeEntry; 353 } 354 355 356 361 public void setPrototypeEntry( DummyEntry getPrototypeEntry ) 362 { 363 this.prototypeEntry = getPrototypeEntry; 364 } 365 366 } 367 | Popular Tags |