1 19 20 package org.netbeans.modules.ruby.railsprojects.ui.wizards; 21 22 import java.io.File ; 23 import java.util.ArrayList ; 24 import java.util.Iterator ; 25 import javax.swing.event.ChangeEvent ; 26 import javax.swing.event.ChangeListener ; 27 import org.netbeans.api.options.OptionsDisplayer; 28 import org.netbeans.modules.ruby.rubyproject.api.RubyInstallation; 29 import org.netbeans.modules.ruby.rubyproject.gems.GemManager; 30 import org.netbeans.modules.ruby.rubyproject.gems.GemManager.Gem; 31 import org.openide.WizardDescriptor; 32 import org.openide.WizardValidationException; 33 import org.openide.util.HelpCtx; 34 import org.openide.util.NbBundle; 35 36 41 public class RailsInstallationPanel extends javax.swing.JPanel { 42 private Panel firer; 43 private WizardDescriptor wizardDescriptor; 44 45 46 public RailsInstallationPanel(Panel panel) { 47 initComponents(); 48 this.firer = panel; 49 initComponents(); 50 this.setName(NbBundle.getMessage(RailsInstallationPanel.class,"LAB_InstallRails")); 51 this.putClientProperty ("NewProjectWizard_Title", NbBundle.getMessage(RailsInstallationPanel.class,"TXT_RailsInstallation")); updateLabel(); 53 54 String gem = RubyInstallation.getInstance().getGem(); 55 56 if (!(new File (gem).exists())) { 57 String msg = NbBundle.getMessage(RailsInstallationPanel.class, "NoGem"); 58 railsButton.setEnabled(false); 59 sslButton.setEnabled(false); 60 } 61 } 62 63 private void updateLabel() { 64 if (RubyInstallation.getInstance().isValidRails(false)) { 65 descLabel.setText(NbBundle.getMessage(RailsInstallationPanel.class, "RailsOk")); 66 railsButton.setText(NbBundle.getMessage(RailsInstallationPanel.class, "UpdateRails")); 67 String version = RubyInstallation.getInstance().getVersion("rails"); if (version == null) { 69 version = "?"; 70 } 71 installedLabel.setText(NbBundle.getMessage(RailsInstallationPanel.class, "RailsVersion", version)); 72 } else { 73 descLabel.setText(NbBundle.getMessage(RailsInstallationPanel.class, "NoRails")); 74 railsButton.setText(NbBundle.getMessage(RailsInstallationPanel.class, "InstallRails")); 75 installedLabel.setText(""); 76 } 77 } 78 79 void read (WizardDescriptor settings) { 80 this.wizardDescriptor = settings; 81 } 82 83 boolean valid (WizardDescriptor settings) { 84 String rails = RubyInstallation.getInstance().getRails(); 86 if (rails != null && !(new File (rails).exists())) { 87 String msg = NbBundle.getMessage(RailsInstallationPanel.class, "NotFound", rails); 88 wizardDescriptor.putProperty( "WizardPanel_errorMessage", msg); return false; 90 } else if (rails == null) { 91 String msg = NbBundle.getMessage(RailsInstallationPanel.class, "NoRails"); 92 wizardDescriptor.putProperty( "WizardPanel_errorMessage", msg); return false; 94 } 95 96 wizardDescriptor.putProperty( "WizardPanel_errorMessage",""); return true; 98 } 99 100 void validate (WizardDescriptor d) throws WizardValidationException { 101 } 102 103 private void initComponents() { 105 106 railsButton = new javax.swing.JButton (); 107 sslButton = new javax.swing.JButton (); 108 descLabel = new javax.swing.JLabel (); 109 jSeparator1 = new javax.swing.JSeparator (); 110 jrubyLabel = new javax.swing.JLabel (); 111 jrubySslLabel = new javax.swing.JLabel (); 112 proxyButton = new javax.swing.JButton (); 113 installedLabel = new javax.swing.JLabel (); 114 115 railsButton.setText(org.openide.util.NbBundle.getMessage(RailsInstallationPanel.class, "InstallRails")); railsButton.addActionListener(new java.awt.event.ActionListener () { 117 public void actionPerformed(java.awt.event.ActionEvent evt) { 118 railsButtonActionPerformed(evt); 119 } 120 }); 121 122 sslButton.setText(org.openide.util.NbBundle.getMessage(RailsInstallationPanel.class, "RailsInstallationPanel.sslButton.text")); sslButton.addActionListener(new java.awt.event.ActionListener () { 124 public void actionPerformed(java.awt.event.ActionEvent evt) { 125 sslButtonActionPerformed(evt); 126 } 127 }); 128 129 descLabel.setText(org.openide.util.NbBundle.getMessage(RailsInstallationPanel.class, "NoRails")); 131 jrubyLabel.setText(org.openide.util.NbBundle.getMessage(RailsInstallationPanel.class, "RailsInstallationPanel.jrubyLabel.text")); 133 jrubySslLabel.setText(org.openide.util.NbBundle.getMessage(RailsInstallationPanel.class, "RailsInstallationPanel.jrubySslLabel.text")); 135 proxyButton.setText(org.openide.util.NbBundle.getMessage(RailsInstallationPanel.class, "RailsInstallationPanel.proxyButton.text")); proxyButton.addActionListener(new java.awt.event.ActionListener () { 137 public void actionPerformed(java.awt.event.ActionEvent evt) { 138 proxyButtonActionPerformed(evt); 139 } 140 }); 141 142 installedLabel.setText(org.openide.util.NbBundle.getMessage(RailsInstallationPanel.class, "RailsInstallationPanel.installedLabel.text")); 144 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 145 this.setLayout(layout); 146 layout.setHorizontalGroup( 147 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 148 .add(layout.createSequentialGroup() 149 .addContainerGap() 150 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 151 .add(descLabel) 152 .add(layout.createSequentialGroup() 153 .add(railsButton) 154 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 155 .add(installedLabel)) 156 .add(org.jdesktop.layout.GroupLayout.TRAILING, jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 405, Short.MAX_VALUE) 157 .add(jrubyLabel) 158 .add(proxyButton) 159 .add(jrubySslLabel) 160 .add(sslButton)) 161 .addContainerGap()) 162 ); 163 layout.setVerticalGroup( 164 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 165 .add(layout.createSequentialGroup() 166 .addContainerGap() 167 .add(descLabel) 168 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 169 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 170 .add(railsButton) 171 .add(installedLabel)) 172 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 173 .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 174 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 175 .add(jrubyLabel) 176 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 177 .add(jrubySslLabel) 178 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 179 .add(sslButton) 180 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 74, Short.MAX_VALUE) 181 .add(proxyButton) 182 .addContainerGap()) 183 ); 184 } 186 private void proxyButtonActionPerformed(java.awt.event.ActionEvent evt) { OptionsDisplayer.getDefault().open("General"); } 190 private void sslButtonActionPerformed(java.awt.event.ActionEvent evt) { Runnable asyncCompletionTask = new InstallationComplete(); 192 Gem gem = new Gem("jruby-openssl", null, null); new GemManager().install(new Gem[] { gem }, this, null, false, false, null, true, true, asyncCompletionTask); 194 195 } 197 private class InstallationComplete implements Runnable { 198 public void run() { 199 RailsInstallationPanel.this.updateLabel(); 200 RailsInstallationPanel.this.firer.fireChangeEvent(); 201 RubyInstallation.getInstance().recomputeRoots(); 202 } 203 } 204 205 private void railsButtonActionPerformed(java.awt.event.ActionEvent evt) { Runnable asyncCompletionTask = new InstallationComplete(); 207 Gem rails = new Gem("rails", null, null); Gem jdbc = new Gem("ActiveRecord-JDBC", null, null); Gem[] gems = new Gem[] { rails, jdbc }; 210 if (RubyInstallation.getInstance().isValidRails((false))) { 211 new GemManager().update(gems, this, null, false, false, true, asyncCompletionTask); 213 } else { 214 new GemManager().install(gems, this, null, false, false, null, true, true, asyncCompletionTask); 215 } 216 } 218 219 private javax.swing.JLabel descLabel; 221 private javax.swing.JLabel installedLabel; 222 private javax.swing.JSeparator jSeparator1; 223 private javax.swing.JLabel jrubyLabel; 224 private javax.swing.JLabel jrubySslLabel; 225 private javax.swing.JButton proxyButton; 226 private javax.swing.JButton railsButton; 227 private javax.swing.JButton sslButton; 228 230 static class Panel implements WizardDescriptor.ValidatingPanel { 231 232 private ArrayList listeners; 233 private RailsInstallationPanel component; 234 private WizardDescriptor settings; 235 236 public synchronized void removeChangeListener(ChangeListener l) { 237 if (this.listeners == null) { 238 return; 239 } 240 this.listeners.remove(l); 241 } 242 243 public void addChangeListener(ChangeListener l) { 244 if (this.listeners == null) { 245 this.listeners = new ArrayList (); 246 } 247 this.listeners.add (l); 248 } 249 250 public void readSettings(Object settings) { 251 this.settings = (WizardDescriptor) settings; 253 this.component.read(this.settings); 254 } 255 256 public void storeSettings(Object settings) { 257 } 259 260 public void validate() throws WizardValidationException { 261 this.component.validate(this.settings); 262 } 263 264 public boolean isValid() { 265 return this.component.valid (this.settings); 266 } 267 268 public synchronized java.awt.Component getComponent() { 269 if (this.component == null) { 270 this.component = new RailsInstallationPanel(this); 271 } 272 return this.component; 273 } 274 275 public HelpCtx getHelp() { 276 return new HelpCtx (RailsInstallationPanel.class); 277 } 278 279 private void fireChangeEvent () { 280 Iterator it = null; 281 synchronized (this) { 282 if (this.listeners == null) { 283 return; 284 } 285 it = ((ArrayList )this.listeners.clone()).iterator(); 286 } 287 ChangeEvent event = new ChangeEvent (this); 288 while (it.hasNext()) { 289 ((ChangeListener )it.next()).stateChanged(event); 290 } 291 } 292 } 293 } 294 | Popular Tags |