1 19 24 25 package org.netbeans.modules.j2ee.sun.ide.sunresources.wizards; 26 27 31 32 import java.awt.Component ; 33 import java.util.Set ; 34 import javax.swing.JComponent ; 35 import java.io.InputStream ; 36 import javax.swing.event.ChangeListener ; 37 38 import org.openide.util.NbBundle; 39 import org.openide.WizardDescriptor; 40 import org.netbeans.api.project.Project; 41 import org.openide.filesystems.FileObject; 42 import org.netbeans.spi.project.ui.templates.support.Templates; 43 44 import org.netbeans.modules.j2ee.sun.ide.sunresources.beans.ResourceUtils; 45 46 import org.netbeans.modules.j2ee.sun.sunresources.beans.Wizard; 47 import org.netbeans.modules.j2ee.sun.sunresources.beans.WizardConstants; 48 import org.openide.ErrorManager; 49 50 public final class ConnPoolWizard implements WizardDescriptor.InstantiatingIterator, WizardConstants{ 51 52 private static Project project; 53 54 private static final String DATAFILE = "org/netbeans/modules/j2ee/sun/sunresources/beans/CPWizard.xml"; 56 57 private transient WizardDescriptor.Panel[] panels; 58 private transient String [] steps; 60 private transient int index; 61 private ResourceConfigHelper helper; 62 private Wizard wizardInfo; 63 64 65 public static ConnPoolWizard create () { 66 return new ConnPoolWizard (); 67 } 68 69 private WizardDescriptor.Panel[] createPanels() { 70 return new WizardDescriptor.Panel[] { 71 new CPVendorPanel(this.helper, this.wizardInfo), 72 new CPPropertiesPanelPanel(this.helper, this.wizardInfo), 73 new CommonAttributePanel(this.helper, this.wizardInfo, new String [] {"pool-setting", "pool-setting-2", "pool-setting-3"}), }; 75 } 76 77 private String [] createSteps() { 78 return new String [] { 79 NbBundle.getMessage(ConnPoolWizard.class, __FirstStepChoose), 80 NbBundle.getMessage(ConnPoolWizard.class, "TITLE_ConnPoolWizardPanel_dbConn"), NbBundle.getMessage(ConnPoolWizard.class, "TITLE_ConnPoolWizardPanel_properties"), NbBundle.getMessage(ConnPoolWizard.class, "TITLE_ConnPoolWizardPanel_optionalProps") }; 84 } 85 86 public Set instantiate(){ 87 try{ 88 ResourceUtils.saveConnPoolDatatoXml(this.helper.getData()); 89 }catch (Exception ex){ 90 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, 91 ex); 92 } 93 return java.util.Collections.EMPTY_SET; 94 } 95 96 public void initialize(WizardDescriptor wiz){ 97 this.wizardInfo = getWizardInfo(); 98 this.helper = new ResourceConfigHelperHolder().getConnPoolHelper(); 99 100 wiz.putProperty("NewFileWizard_Title", NbBundle.getMessage(ConnPoolWizard.class, "Templates/SunResources/JDBC_Connection_Pool")); index = 0; 103 104 project = Templates.getProject(wiz); 105 106 panels = createPanels(); 107 steps = createSteps(); 109 110 try{ 111 FileObject pkgLocation = project.getProjectDirectory(); 112 if (pkgLocation != null) { 113 this.helper.getData().setTargetFileObject(pkgLocation); 114 } 115 }catch (Exception ex){ 116 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, 117 ex); 118 } 119 120 for (int i = 0; i < panels.length; i++) { 121 Component c = panels[i].getComponent(); 122 if (c instanceof JComponent ) { JComponent jc = (JComponent )c; 124 jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer (i)); jc.putClientProperty("WizardPanel_contentData", steps); } 129 } 130 } 131 132 public void uninitialize(WizardDescriptor wiz){ 133 panels = null; 135 } 136 137 public Wizard getWizardInfo(){ 138 try{ 139 InputStream in = Wizard.class.getClassLoader().getResourceAsStream(DATAFILE); 140 this.wizardInfo = Wizard.createGraph(in); 141 }catch(Exception ex){ 142 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, 143 ex); 144 } 145 return this.wizardInfo; 146 } 147 148 public String name(){ 149 return NbBundle.getMessage(ConnPoolWizard.class, "Templates/SunResources/JDBC_Connection_Pool"); } 151 152 public boolean hasNext(){ 153 return index < panels.length - 1; 154 } 155 156 public boolean hasPrevious(){ 157 return index > 0; 158 } 159 160 public synchronized void nextPanel(){ 161 if (index + 1 == panels.length) { 162 throw new java.util.NoSuchElementException (); 163 } 164 165 if (index == 0) { 166 ((CPPropertiesPanelPanel) panels[1]).refreshFields(); 167 }else if (index == 1){ 168 ((CommonAttributePanel) panels[2]).setPropInitialFocus(); 169 } 170 index ++; 171 } 172 173 public synchronized void previousPanel(){ 174 if (index == 0) { 175 throw new java.util.NoSuchElementException (); 176 } 177 178 index--; 179 } 180 181 public WizardDescriptor.Panel current(){ 182 return (WizardDescriptor.Panel)panels[index]; 183 } 184 185 public void addChangeListener(ChangeListener l){ 186 } 187 188 public void removeChangeListener(ChangeListener l){ 189 } 190 191 192 public void setResourceConfigHelper(ResourceConfigHelper helper){ 193 this.helper = helper; 194 } 195 196 public ResourceConfigHelper getResourceConfigHelper(){ 197 return this.helper; 198 } 199 200 } 201 | Popular Tags |