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