1 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 36 public class ConnectWizard extends Wizard 37 { 38 39 private ConnectWizardBrowserAvailablePage browserAvailablePage; 40 private ConnectWizardBrowserNotAvailablePage browserNotAvailablePage; 41 42 43 private boolean isBrowserPluginAvailable; 44 45 46 private int localPort = 0; 47 48 49 private String remoteHost = ""; 50 51 52 private int remotePort = 0; 53 54 55 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 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 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 120 public boolean isPluginAvailable( String 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 155 public int getLocalPort() 156 { 157 return localPort; 158 } 159 160 161 167 public String getRemoteHost() 168 { 169 return remoteHost; 170 } 171 172 173 179 public int getRemotePort() 180 { 181 return remotePort; 182 } 183 } 184 | Popular Tags |