KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > ui > wizards > NewBookmarkWizard


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

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 /**
49  * The NewConnectionWizard is used to create a new bookmark.
50  *
51  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
52  * @version $Rev$, $Date$
53  */

54 public class NewBookmarkWizard extends Wizard implements INewWizard
55 {
56
57     /** The main page. */
58     private NewBookmarkMainWizardPage mainPage;
59
60     /** The selected entry. */
61     private IEntry selectedEntry;
62
63
64     /**
65      * Creates a new instance of NewBookmarkWizard.
66      */

67     public NewBookmarkWizard()
68     {
69         setWindowTitle( "New Bookmark" );
70         setNeedsProgressMonitor( false );
71     }
72
73
74     /**
75      * Gets the id.
76      *
77      * @return the id
78      */

79     public static String JavaDoc getId()
80     {
81         return NewBookmarkWizard.class.getName();
82     }
83
84
85     /**
86      * {@inheritDoc}
87      */

88     public void init( IWorkbench workbench, IStructuredSelection selection )
89     {
90         // determine the currently selected entry, used
91
// to preset the bookmark target DN
92
Object JavaDoc 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     /**
142      * {@inheritDoc}
143      */

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     /**
159      * Just a dummy page.
160      *
161      * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
162      * @version $Rev$, $Date$
163      */

164     class DummyWizardPage extends WizardPage
165     {
166
167         /**
168          * Creates a new instance of DummyWizardPage.
169          */

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             // setImageDescriptor(BrowserUIPlugin.getDefault().getImageDescriptor(BrowserUIConstants.IMG_ATTRIBUTE_WIZARD));
176
setPageComplete( true );
177         }
178
179
180         /**
181          * {@inheritDoc}
182          */

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     /**
196      * {@inheritDoc}
197      */

198     public boolean performFinish()
199     {
200         if ( selectedEntry != null )
201         {
202             String JavaDoc 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