1 20 21 package org.apache.directory.ldapstudio.browser.ui.wizards; 22 23 24 import org.apache.directory.ldapstudio.browser.common.widgets.browser.BrowserCategory; 25 import org.apache.directory.ldapstudio.browser.common.widgets.browser.BrowserEntryPage; 26 import org.apache.directory.ldapstudio.browser.common.widgets.browser.BrowserSearchResultPage; 27 import org.apache.directory.ldapstudio.browser.core.internal.model.Bookmark; 28 import org.apache.directory.ldapstudio.browser.core.model.DN; 29 import org.apache.directory.ldapstudio.browser.core.model.IAttribute; 30 import org.apache.directory.ldapstudio.browser.core.model.IBookmark; 31 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 32 import org.apache.directory.ldapstudio.browser.core.model.IEntry; 33 import org.apache.directory.ldapstudio.browser.core.model.ISearch; 34 import org.apache.directory.ldapstudio.browser.core.model.ISearchResult; 35 import org.apache.directory.ldapstudio.browser.core.model.IValue; 36 import org.eclipse.jface.viewers.IStructuredSelection; 37 import org.eclipse.jface.wizard.IWizardPage; 38 import org.eclipse.jface.wizard.Wizard; 39 import org.eclipse.jface.wizard.WizardPage; 40 import org.eclipse.swt.SWT; 41 import org.eclipse.swt.layout.GridData; 42 import org.eclipse.swt.layout.GridLayout; 43 import org.eclipse.swt.widgets.Composite; 44 import org.eclipse.ui.INewWizard; 45 import org.eclipse.ui.IWorkbench; 46 47 48 54 public class NewBookmarkWizard extends Wizard implements INewWizard 55 { 56 57 58 private NewBookmarkMainWizardPage mainPage; 59 60 61 private IEntry selectedEntry; 62 63 64 67 public NewBookmarkWizard() 68 { 69 setWindowTitle( "New Bookmark" ); 70 setNeedsProgressMonitor( false ); 71 } 72 73 74 79 public static String getId() 80 { 81 return NewBookmarkWizard.class.getName(); 82 } 83 84 85 88 public void init( IWorkbench workbench, IStructuredSelection selection ) 89 { 90 Object o = selection.getFirstElement(); 93 if ( o instanceof IEntry ) 94 { 95 selectedEntry = ( ( IEntry ) o ); 96 } 97 else if ( o instanceof ISearchResult ) 98 { 99 selectedEntry = ( ( ISearchResult ) o ).getEntry(); 100 } 101 else if ( o instanceof IBookmark ) 102 { 103 selectedEntry = ( ( IBookmark ) o ).getEntry(); 104 } 105 else if ( o instanceof IAttribute ) 106 { 107 selectedEntry = ( ( IAttribute ) o ).getEntry(); 108 } 109 else if ( o instanceof IValue ) 110 { 111 selectedEntry = ( ( IValue ) o ).getAttribute().getEntry(); 112 } 113 else if ( o instanceof IConnection ) 114 { 115 selectedEntry = ( ( IConnection ) o ).getRootDSE(); 116 } 117 else if ( o instanceof ISearch ) 118 { 119 selectedEntry = ( ( ISearch ) o ).getConnection().getRootDSE(); 120 } 121 else if ( o instanceof BrowserCategory ) 122 { 123 selectedEntry = ( ( BrowserCategory ) o ).getParent().getRootDSE(); 124 } 125 else if ( o instanceof BrowserSearchResultPage ) 126 { 127 selectedEntry = ( ( BrowserSearchResultPage ) o ).getSearch().getConnection().getRootDSE(); 128 } 129 else if ( o instanceof BrowserEntryPage ) 130 { 131 selectedEntry = ( ( BrowserEntryPage ) o ).getEntry(); 132 } 133 134 else 135 { 136 selectedEntry = null; 137 } 138 } 139 140 141 144 public void addPages() 145 { 146 if ( selectedEntry != null ) 147 { 148 mainPage = new NewBookmarkMainWizardPage( NewBookmarkMainWizardPage.class.getName(), selectedEntry, this ); 149 addPage( mainPage ); 150 } 151 else 152 { 153 IWizardPage page = new DummyWizardPage(); 154 addPage( page ); 155 } 156 } 157 158 164 class DummyWizardPage extends WizardPage 165 { 166 167 170 protected DummyWizardPage() 171 { 172 super( "" ); 173 setTitle( "No entry selected" ); 174 setDescription( "In order to use the bookmark creation wizard please select an entry or connection." ); 175 setPageComplete( true ); 177 } 178 179 180 183 public void createControl( Composite parent ) 184 { 185 Composite composite = new Composite( parent, SWT.NONE ); 186 GridLayout gl = new GridLayout( 1, false ); 187 composite.setLayout( gl ); 188 composite.setLayoutData( new GridData( GridData.FILL_BOTH ) ); 189 190 setControl( composite ); 191 } 192 } 193 194 195 198 public boolean performFinish() 199 { 200 if ( selectedEntry != null ) 201 { 202 String name = mainPage.getBookmarkName(); 203 DN dn = mainPage.getBookmarkDn(); 204 IBookmark bookmark = new Bookmark( selectedEntry.getConnection(), dn, name ); 205 selectedEntry.getConnection().getBookmarkManager().addBookmark( bookmark ); 206 } 207 mainPage.saveDialogSettings(); 208 return true; 209 } 210 211 } 212 | Popular Tags |