1 19 20 package org.netbeans.modules.j2ee.deployment.impl.ui.wizard; 21 22 import java.text.MessageFormat ; 23 import java.util.HashMap ; 24 import javax.swing.JComponent ; 25 import javax.swing.event.ChangeListener ; 26 import org.netbeans.modules.j2ee.deployment.impl.Server; 27 import org.netbeans.modules.j2ee.deployment.plugins.api.OptionalDeploymentManagerFactory; 28 import org.openide.WizardDescriptor; 29 import org.openide.util.NbBundle; 30 31 35 public class AddServerInstanceWizard extends WizardDescriptor { 36 public final static String PROP_DISPLAY_NAME = "ServInstWizard_displayName"; public final static String PROP_SERVER = "ServInstWizard_server"; 39 private final static String PROP_AUTO_WIZARD_STYLE = "WizardPanel_autoWizardStyle"; private final static String PROP_CONTENT_DISPLAYED = "WizardPanel_contentDisplayed"; private final static String PROP_CONTENT_NUMBERED = "WizardPanel_contentNumbered"; private final static String PROP_CONTENT_DATA = "WizardPanel_contentData"; private final static String PROP_CONTENT_SELECTED_INDEX = "WizardPanel_contentSelectedIndex"; private final static String PROP_ERROR_MESSAGE = "WizardPanel_errorMessage"; 46 private AddServerInstanceWizardIterator iterator; 47 private ServerChooserPanel chooser; 48 49 public AddServerInstanceWizard() { 50 this(new AddServerInstanceWizardIterator()); 51 52 putProperty(PROP_AUTO_WIZARD_STYLE, Boolean.TRUE); 53 putProperty(PROP_CONTENT_DISPLAYED, Boolean.TRUE); 54 putProperty(PROP_CONTENT_NUMBERED, Boolean.TRUE); 55 56 setTitle(NbBundle.getMessage(AddServerInstanceWizard.class, "LBL_ASIW_Title")); 57 setTitleFormat(new MessageFormat (NbBundle.getMessage(AddServerInstanceWizard.class, "LBL_ASIW_TitleFormat"))); 58 59 initialize(); 60 } 61 62 private AddServerInstanceWizard(AddServerInstanceWizardIterator iterator) { 63 super(iterator); 64 this.iterator = iterator; 65 } 66 67 public void setErrorMessage(String message) { 68 putProperty(PROP_ERROR_MESSAGE, message); 69 } 70 71 protected void updateState() { 72 super.updateState(); 73 74 String [] contentData = getContentData(); 75 if (contentData != null) { 76 putProperty(PROP_CONTENT_DATA, contentData); 77 putProperty(PROP_CONTENT_SELECTED_INDEX, new Integer (getContentSelectedIndex())); 78 } 79 } 80 81 private ServerChooserPanel getChooser() { 82 if (chooser == null) 83 chooser = new ServerChooserPanel(); 84 85 return chooser; 86 } 87 88 private String [] getContentData() { 89 JComponent first; 90 String [] firstContentData; 91 92 first = (JComponent )getChooser().getComponent(); 93 firstContentData = (String [])first.getClientProperty(PROP_CONTENT_DATA); 94 95 if (iterator.current().equals(getChooser())) { 96 return firstContentData; 97 } else { 98 JComponent component = (JComponent )iterator.current().getComponent(); 99 String [] componentContentData = (String [])component.getClientProperty(PROP_CONTENT_DATA); 100 if (componentContentData == null) 101 return firstContentData; 102 103 String [] contentData = new String [componentContentData.length + 1]; 104 contentData[0] = firstContentData[0]; 105 System.arraycopy(componentContentData, 0, contentData, 1, componentContentData.length); 106 return contentData; 107 } 108 } 109 110 private int getContentSelectedIndex() { 111 if (iterator.current().equals(getChooser())) { 112 return 0; 113 } else { 114 JComponent component = (JComponent )iterator.current().getComponent(); 115 Integer componentIndex = (Integer )component.getClientProperty(PROP_CONTENT_SELECTED_INDEX); 116 if (componentIndex != null) 117 return componentIndex.intValue() + 1; 118 else 119 return 1; 120 } 121 } 122 123 private static class AddServerInstanceWizardIterator implements WizardDescriptor.InstantiatingIterator { 124 private AddServerInstanceWizard wd; 125 public boolean showingChooser; 126 private WizardDescriptor.InstantiatingIterator iterator; 127 private HashMap iterators; 128 129 public AddServerInstanceWizardIterator() { 130 showingChooser = true; 131 iterators = new HashMap (); 132 } 133 134 public void addChangeListener(ChangeListener l) { 135 } 136 137 public WizardDescriptor.Panel current() { 138 if (showingChooser) 139 return wd.getChooser(); 140 else 141 if (iterator != null) 142 return iterator.current(); 143 else 144 return null; 145 } 146 147 public boolean hasNext() { 148 if (showingChooser) 149 return true; 150 else 151 if (iterator != null) 152 return iterator.hasNext(); 153 else 154 return false; 155 } 156 157 public boolean hasPrevious() { 158 if (showingChooser) 159 return false; 160 else 161 return true; 162 } 163 164 public String name() { 165 return null; 166 } 167 168 public void nextPanel() { 169 if (iterator == null) 170 iterator = getServerIterator(); 171 else { 172 if (!showingChooser) 173 iterator.nextPanel(); 174 } 175 showingChooser = false; 176 } 177 178 public void previousPanel() { 179 if (iterator.hasPrevious()) 180 iterator.previousPanel(); 181 else { 182 showingChooser = true; 183 iterator = null; 184 } 185 } 186 187 public void removeChangeListener(ChangeListener l) { 188 } 189 190 public void uninitialize(WizardDescriptor wizard) { 191 } 192 193 public void initialize(WizardDescriptor wizard) { 194 wd = (AddServerInstanceWizard)wizard; 195 196 JComponent chooser = (JComponent )wd.getChooser().getComponent(); 197 chooser.putClientProperty(PROP_CONTENT_DATA, new String [] { 198 NbBundle.getMessage(AddServerInstanceWizard.class, "LBL_ASIW_ChooseServer"), 199 NbBundle.getMessage(AddServerInstanceWizard.class, "LBL_ASIW_Ellipsis") 200 }); 201 } 202 203 public java.util.Set instantiate() throws java.io.IOException { 204 if (iterator != null) { 205 return iterator.instantiate(); 206 } 207 else 208 return null; 209 } 210 211 private WizardDescriptor.InstantiatingIterator getServerIterator() { 212 Server server = getSelectedServer(); 213 if (server == null) 214 return null; 215 216 WizardDescriptor.InstantiatingIterator iterator = (WizardDescriptor.InstantiatingIterator)iterators.get(server); 217 if (iterator != null) 218 return iterator; 219 220 OptionalDeploymentManagerFactory factory = server.getOptionalFactory(); 221 if (factory != null) { 222 iterator = factory.getAddInstanceIterator(); 223 iterator.initialize(wd); 224 iterators.put(server, iterator); 225 return iterator; 226 } 227 else 228 return null; 229 } 230 231 private Server getSelectedServer() { 232 return (Server)wd.getProperty(PROP_SERVER); 233 } 234 } 235 } 236 | Popular Tags |