KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > proxy > view > wizards > ConnectWizard


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 package org.apache.directory.ldapstudio.proxy.view.wizards;
21
22
23 import org.eclipse.core.runtime.Platform;
24 import org.eclipse.jface.wizard.Wizard;
25 import org.eclipse.ui.internal.util.BundleUtility;
26 import org.osgi.framework.Bundle;
27 import org.osgi.framework.BundleException;
28
29
30 /**
31  * This class implements the Connect Wizard.
32  *
33  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
34  * @version $Rev$, $Date$
35  */

36 public class ConnectWizard extends Wizard
37 {
38     /** The Settings page*/
39     private ConnectWizardBrowserAvailablePage browserAvailablePage;
40     private ConnectWizardBrowserNotAvailablePage browserNotAvailablePage;
41
42     /** The availability of the BrowserPlugin */
43     private boolean isBrowserPluginAvailable;
44
45     /** The proxy port */
46     private int localPort = 0;
47
48     /** The LDAP Server hostname */
49     private String JavaDoc remoteHost = "";
50
51     /** The LDAP Server port */
52     private int remotePort = 0;
53
54
55     /* (non-Javadoc)
56      * @see org.eclipse.jface.wizard.Wizard#addPages()
57      */

58     public void addPages()
59     {
60         isBrowserPluginAvailable = isBrowserPluginAvailable();
61
62         if ( isBrowserPluginAvailable )
63         {
64             browserAvailablePage = new ConnectWizardBrowserAvailablePage();
65             addPage( browserAvailablePage );
66         }
67         else
68         {
69             browserNotAvailablePage = new ConnectWizardBrowserNotAvailablePage();
70             addPage( browserNotAvailablePage );
71         }
72     }
73
74
75     /**
76      * Checks if the Browser Plugin is available.
77      *
78      * @return
79      * true if the Browser Plugin is available, false if not
80      */

81     private boolean isBrowserPluginAvailable()
82     {
83         return ( isPluginAvailable( "org.apache.directory.ldapstudio.browser.core" ) && isPluginAvailable( "org.apache.directory.ldapstudio.browser.core" ) );
84     }
85
86
87     /* (non-Javadoc)
88      * @see org.eclipse.jface.wizard.Wizard#performFinish()
89      */

90     public boolean performFinish()
91     {
92         if ( isBrowserPluginAvailable )
93         {
94             browserAvailablePage.saveDialogHistory();
95             localPort = browserAvailablePage.getLocalPort();
96             remoteHost = browserAvailablePage.getRemoteHost();
97             remotePort = browserAvailablePage.getRemotePort();
98         }
99         else
100         {
101             browserNotAvailablePage.saveDialogHistory();
102             localPort = browserNotAvailablePage.getLocalPort();
103             remoteHost = browserNotAvailablePage.getRemoteHost();
104             remotePort = browserNotAvailablePage.getRemotePort();
105         }
106
107         return true;
108     }
109
110
111     /**
112      * Checks if the given plugin is available (installed and active).
113      * The plugin is actived if it's not already active.
114      *
115      * @param bundleId
116      * the id of the plugin
117      * @return
118      * true if the given plugin is available, false if not.
119      */

120     public boolean isPluginAvailable( String JavaDoc bundleId )
121     {
122         Bundle pluginBundle = Platform.getBundle( bundleId );
123
124         if ( pluginBundle == null )
125         {
126             return false;
127         }
128
129         if ( BundleUtility.isActive( pluginBundle ) )
130         {
131             return true;
132         }
133         else
134         {
135             try
136             {
137                 pluginBundle.start();
138             }
139             catch ( BundleException e )
140             {
141                 return false;
142             }
143
144             return BundleUtility.isActive( pluginBundle );
145         }
146     }
147
148
149     /**
150      * Gets the local port defined by the user.
151      *
152      * @return
153      * the local port defined by the user
154      */

155     public int getLocalPort()
156     {
157         return localPort;
158     }
159
160
161     /**
162      * Gets the remote host defined by the user.
163      *
164      * @return
165      * the remote host defined by the user
166      */

167     public String JavaDoc getRemoteHost()
168     {
169         return remoteHost;
170     }
171
172
173     /**
174      * Gets the remote port defined by the user.
175      *
176      * @return
177      * the remote port defined by the user
178      */

179     public int getRemotePort()
180     {
181         return remotePort;
182     }
183 }
184
Popular Tags