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