1 19 20 package org.netbeans.modules.ruby.railsprojects.ui.wizards; 21 22 import java.awt.Component ; 23 import java.util.HashSet ; 24 import java.util.Iterator ; 25 import java.util.Set ; 26 import javax.swing.JComponent ; 27 import javax.swing.event.ChangeEvent ; 28 import javax.swing.event.ChangeListener ; 29 import org.netbeans.modules.ruby.rubyproject.api.RubyInstallation; 30 import org.openide.WizardDescriptor; 31 import org.openide.WizardValidationException; 32 import org.openide.util.HelpCtx; 33 34 38 public final class PanelConfigureProject implements WizardDescriptor.Panel, WizardDescriptor.ValidatingPanel, WizardDescriptor.FinishablePanel { 39 40 private WizardDescriptor wizardDescriptor; 41 private int type; 42 private PanelConfigureProjectVisual component; 43 44 45 public PanelConfigureProject( int type ) { 46 this.type = type; 47 } 48 49 public Component getComponent() { 50 if (component == null) { 51 component = new PanelConfigureProjectVisual(this, this.type); 52 } 53 return component; 54 } 55 56 public HelpCtx getHelp() { 57 58 switch ( type ) { 59 case NewRailsProjectWizardIterator.TYPE_APP: 60 return new HelpCtx( this.getClass().getName() + "_APP" ); case NewRailsProjectWizardIterator.TYPE_EXT: 64 return new HelpCtx( this.getClass().getName() + "_EXT" ); } 66 return new HelpCtx( PanelConfigureProject.class ); 67 } 68 69 public boolean isValid() { 70 getComponent(); 71 return component.valid( wizardDescriptor ); 72 } 73 74 private final Set listeners = new HashSet (1); 75 public final void addChangeListener(ChangeListener l) { 76 synchronized (listeners) { 77 listeners.add(l); 78 } 79 } 80 public final void removeChangeListener(ChangeListener l) { 81 synchronized (listeners) { 82 listeners.remove(l); 83 } 84 } 85 protected final void fireChangeEvent() { 86 Iterator it; 87 synchronized (listeners) { 88 it = new HashSet (listeners).iterator(); 89 } 90 ChangeEvent ev = new ChangeEvent (this); 91 while (it.hasNext()) { 92 ((ChangeListener )it.next()).stateChanged(ev); 93 } 94 } 95 96 public void readSettings(Object settings) { 97 wizardDescriptor = (WizardDescriptor)settings; 98 component.read (wizardDescriptor); 99 100 Object substitute = ((JComponent )component).getClientProperty ("NewProjectWizard_Title"); if (substitute != null) { 104 wizardDescriptor.putProperty ("NewProjectWizard_Title", substitute); } 106 } 107 108 public void storeSettings(Object settings) { 109 WizardDescriptor d = (WizardDescriptor)settings; 110 component.store(d); 111 d.putProperty ("NewProjectWizard_Title", null); d.putProperty( "setAsMain", Boolean.TRUE); } 114 115 public boolean isFinishPanel() { 116 return RubyInstallation.getInstance().isValidRails(false); 119 } 120 121 public void validate () throws WizardValidationException { 122 getComponent (); 123 component.validate (wizardDescriptor); 124 } 125 126 } 127 | Popular Tags |