1 19 20 package org.netbeans.modules.tomcat5.wizard; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.Enumeration ; 25 import java.util.HashSet ; 26 import java.util.NoSuchElementException ; 27 import java.util.Properties ; 28 import java.util.Set ; 29 import javax.swing.JComponent ; 30 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; 31 import org.netbeans.modules.tomcat5.TomcatManager; 32 import org.netbeans.modules.tomcat5.TomcatManager.TomcatVersion; 33 import org.netbeans.modules.tomcat5.util.TomcatInstallUtil; 34 import org.openide.DialogDisplayer; 35 import org.openide.ErrorManager; 36 import org.openide.NotifyDescriptor; 37 import org.openide.WizardDescriptor; 38 import org.openide.filesystems.FileUtil; 39 import org.openide.util.NbBundle; 40 import org.openide.util.Utilities; 41 import org.netbeans.modules.tomcat5.ide.*; 42 import org.netbeans.modules.tomcat5.util.TomcatProperties; 43 44 49 public class AddInstanceIterator implements WizardDescriptor.InstantiatingIterator { 50 51 public final static String PROP_ERROR_MESSAGE = "WizardPanel_errorMessage"; private final static String PROP_CONTENT_DATA = "WizardPanel_contentData"; private final static String PROP_CONTENT_SELECTED_INDEX = "WizardPanel_contentSelectedIndex"; private final static String PROP_DISPLAY_NAME = "ServInstWizard_displayName"; 56 private final static String [] CONTENT_DATA = new String [] { 57 NbBundle.getMessage(AddInstanceIterator.class, "LBL_InstanceProperties") }; 58 59 private WizardDescriptor wizard; 60 private InstallPanel panel; 61 62 private final TomcatVersion tomcatVersion; 63 64 public AddInstanceIterator(TomcatVersion tomcatVersion) { 65 this.tomcatVersion = tomcatVersion; 66 67 } 68 69 public void removeChangeListener(javax.swing.event.ChangeListener l) { 70 } 71 72 public void addChangeListener(javax.swing.event.ChangeListener l) { 73 } 74 75 public void uninitialize(WizardDescriptor wizard) { 76 } 77 78 public void initialize(WizardDescriptor wizard) { 79 this.wizard = wizard; 80 } 81 82 public void previousPanel() { 83 throw new NoSuchElementException (); 84 } 85 86 public void nextPanel() { 87 throw new NoSuchElementException (); 88 } 89 90 public String name() { 91 return null; 92 } 93 94 public Set instantiate() throws java.io.IOException { 95 Set result = new HashSet (); 96 String displayName = getDisplayName(); 97 String url = panel.getVisual().getUrl(); 98 String username = panel.getVisual().getUsername(); 99 String password = panel.getVisual().getPassword(); 100 try { 101 InstanceProperties ip = InstanceProperties.createInstanceProperties( 102 url, username, password, displayName); 103 Properties prop = panel.getVisual().getProperties (); 104 Enumeration en = prop.propertyNames (); 105 while (en.hasMoreElements ()) { 106 String key = (String ) en.nextElement (); 107 ip.setProperty (key, prop.getProperty (key)); 108 } 109 ip.setProperty(TomcatProperties.PROP_RUNNING_CHECK_TIMEOUT, 110 Integer.toString(TomcatProperties.DEF_VALUE_RUNNING_CHECK_TIMEOUT)); 111 112 result.add(ip); 113 checkStartupScript(panel.getVisual().getHomeDir()); 114 } catch (Exception ex) { 115 ErrorManager.getDefault().log(ErrorManager.EXCEPTION, ex.getMessage()); 116 } 117 return result; 118 } 119 120 public boolean hasPrevious() { 121 return false; 122 } 123 124 public boolean hasNext() { 125 return false; 126 } 127 128 public WizardDescriptor.Panel current() { 129 if (panel == null) { 130 panel = new InstallPanel(tomcatVersion); 131 } 132 setContentData((JComponent )panel.getComponent()); 133 setContentSelectedIndex((JComponent )panel.getComponent()); 134 return panel; 135 } 136 137 private void setContentData(JComponent component) { 138 if (component.getClientProperty(PROP_CONTENT_DATA) == null) { 139 component.putClientProperty(PROP_CONTENT_DATA, CONTENT_DATA); 140 } 141 } 142 143 private void setContentSelectedIndex(JComponent component) { 144 if (component.getClientProperty(PROP_CONTENT_SELECTED_INDEX) == null) { 145 component.putClientProperty(PROP_CONTENT_SELECTED_INDEX, new Integer (0)); 146 } 147 } 148 149 private String getDisplayName() { 150 return (String )wizard.getProperty(PROP_DISPLAY_NAME); 151 } 152 153 154 private void checkStartupScript(File homeDir) { 155 String CATALINA = Utilities.isWindows() ? StartTomcat.CATALINA_BAT 156 : StartTomcat.CATALINA_SH; 157 boolean catalinaOK = new File (homeDir, "bin/" + CATALINA).exists(); 159 String SETCLASSPATH = Utilities.isWindows() ? StartTomcat.SETCLASSPATH_BAT 160 : StartTomcat.SETCLASSPATH_SH; 161 boolean setclasspathOK = new File (homeDir, "bin/" + SETCLASSPATH).exists(); 163 if (!catalinaOK || !setclasspathOK) { 164 File bundledHome = TomcatInstallUtil.getBundledHome(); 165 if (tomcatVersion != TomcatManager.TomcatVersion.TOMCAT_55 168 || bundledHome == null || !bundledHome.exists()) { 169 String msg; 173 if (!catalinaOK && !setclasspathOK) { 174 msg = NbBundle.getMessage(AddInstanceIterator.class, "MSG_no_startup_scripts_fix_by_hand", CATALINA, SETCLASSPATH); 175 } else { 176 msg = NbBundle.getMessage(AddInstanceIterator.class, "MSG_no_startup_script_fix_by_hand", !catalinaOK ? CATALINA : SETCLASSPATH); 177 } 178 NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.WARNING_MESSAGE); 179 DialogDisplayer.getDefault().notify(nd); 180 } else { 181 String msg; 184 if (!catalinaOK && !setclasspathOK) { 185 msg = NbBundle.getMessage(AddInstanceIterator.class, "MSG_no_startup_scripts", CATALINA, SETCLASSPATH); 186 } else { 187 msg = NbBundle.getMessage(AddInstanceIterator.class, "MSG_no_startup_script", !catalinaOK ? CATALINA : SETCLASSPATH); 188 } 189 NotifyDescriptor nd = 190 new NotifyDescriptor.Confirmation(msg, NotifyDescriptor.YES_NO_OPTION); 191 if (DialogDisplayer.getDefault().notify(nd).equals(NotifyDescriptor.YES_OPTION)) { 192 try { 193 if (bundledHome != null) { 194 if (!catalinaOK) { 195 FileUtil.copyFile( 196 FileUtil.toFileObject(new File (bundledHome, "bin/" + CATALINA)), FileUtil.toFileObject(new File (homeDir, "bin")), CATALINA.substring(0, CATALINA.indexOf(".")) ); 200 } 201 if (!setclasspathOK) { 202 FileUtil.copyFile( 203 FileUtil.toFileObject(new File (bundledHome, "bin/" + SETCLASSPATH)), FileUtil.toFileObject(new File (homeDir, "bin")), SETCLASSPATH.substring(0, SETCLASSPATH.indexOf(".")) ); 207 } 208 } 209 } catch (IOException e) { 210 msg = NbBundle.getMessage(AddInstanceIterator.class, "MSG_startup_scripts_copy_failed"); 211 nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.WARNING_MESSAGE); 212 DialogDisplayer.getDefault().notify(nd); 213 } 214 } 215 } 216 } 217 } 218 } 219 | Popular Tags |