KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > wizards > NewConnectionWizard


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.common.wizards;
22
23
24 import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
25 import org.apache.directory.ldapstudio.browser.common.widgets.connection.ConnectionPageWrapper;
26 import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
27 import org.apache.directory.ldapstudio.browser.core.jobs.OpenConnectionsJob;
28 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
29 import org.eclipse.jface.viewers.IStructuredSelection;
30 import org.eclipse.jface.wizard.Wizard;
31 import org.eclipse.swt.widgets.Composite;
32 import org.eclipse.ui.INewWizard;
33 import org.eclipse.ui.IWorkbench;
34 import org.eclipse.ui.PlatformUI;
35
36
37 /**
38  * The NewConnectionWizard is used to create a new connection.
39  *
40  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
41  * @version $Rev$, $Date$
42  */

43 public class NewConnectionWizard extends Wizard implements INewWizard
44 {
45
46     /** The connection page wrapper. */
47     private ConnectionPageWrapper cpw;
48
49     /** The main page. */
50     private NewConnectionMainWizardPage mainPage;
51
52     /** The auth page. */
53     private NewConnectionAuthWizardPage authPage;
54
55     /** The options page. */
56     private NewConnectionOptionsWizardPage optionsPage;
57
58
59     /**
60      * Creates a new instance of NewConnectionWizard.
61      */

62     public NewConnectionWizard()
63     {
64         setWindowTitle( "New LDAP Connection" );
65         setNeedsProgressMonitor( true );
66     }
67
68
69     /**
70      * Gets the id.
71      *
72      * @return the id
73      */

74     public static String JavaDoc getId()
75     {
76         return NewConnectionWizard.class.getName();
77     }
78
79
80     /**
81      * {@inheritDoc}
82      */

83     public void init( IWorkbench workbench, IStructuredSelection selection )
84     {
85     }
86
87
88     /**
89      * {@inheritDoc}
90      */

91     public void addPages()
92     {
93         cpw = new ConnectionPageWrapper( null, getContainer() );
94
95         mainPage = new NewConnectionMainWizardPage( NewConnectionMainWizardPage.class.getName(), this );
96         addPage( mainPage );
97
98         authPage = new NewConnectionAuthWizardPage( NewConnectionAuthWizardPage.class.getName(), this );
99         addPage( authPage );
100
101         optionsPage = new NewConnectionOptionsWizardPage( NewConnectionOptionsWizardPage.class.getName(), this );
102         addPage( optionsPage );
103     }
104
105
106     /**
107      * {@inheritDoc}
108      */

109     public void createPageControls( Composite pageContainer )
110     {
111         super.createPageControls( pageContainer );
112
113         // set help context ID
114
PlatformUI.getWorkbench().getHelpSystem().setHelp( mainPage.getControl(),
115             BrowserCommonActivator.PLUGIN_ID + "." + "tools_newconnection_wizard" );
116         PlatformUI.getWorkbench().getHelpSystem().setHelp( authPage.getControl(),
117             BrowserCommonActivator.PLUGIN_ID + "." + "tools_newconnection_wizard" );
118         PlatformUI.getWorkbench().getHelpSystem().setHelp( optionsPage.getControl(),
119             BrowserCommonActivator.PLUGIN_ID + "." + "tools_newconnection_wizard" );
120     }
121
122
123     /**
124      * {@inheritDoc}
125      */

126     public boolean canFinish()
127     {
128         if ( cpw.getAuthenticationMethod() == IConnection.AUTH_ANONYMOUS )
129         {
130             return mainPage.isPageComplete() && optionsPage.isPageComplete();
131         }
132         else if ( cpw.getAuthenticationMethod() == IConnection.AUTH_SIMPLE )
133         {
134             return mainPage.isPageComplete() && authPage.isPageComplete() && optionsPage.isPageComplete();
135         }
136         else
137         {
138             return false;
139         }
140     }
141
142
143     /**
144      * {@inheritDoc}
145      */

146     public boolean performFinish()
147     {
148         final IConnection conn = cpw.getTestConnection();
149         conn.setName( cpw.getName() );
150         if ( conn != null )
151         {
152             BrowserCorePlugin.getDefault().getConnectionManager().addConnection( conn );
153             if ( cpw.isOpenConnectionOnFinish() )
154             {
155                 new OpenConnectionsJob( conn ).execute();
156             }
157             cpw.saveDialogSettings();
158             return true;
159         }
160         return false;
161     }
162
163
164     /**
165      * Gets the connection page wrapper.
166      *
167      * @return the connection page wrapper
168      */

169     public ConnectionPageWrapper getCpw()
170     {
171         return cpw;
172     }
173
174 }
175
Popular Tags