1 19 package org.netbeans.modules.j2ee.weblogic9.ui.wizard; 20 21 import java.io.File ; 22 import java.util.*; 23 import java.awt.*; 24 import java.awt.event.*; 25 import javax.swing.*; 26 import javax.swing.event.*; 27 import javax.swing.filechooser.*; 28 import org.netbeans.modules.j2ee.weblogic9.WLPluginProperties; 29 30 import org.openide.*; 31 import org.openide.util.*; 32 33 40 public class ServerLocationPanel extends JPanel implements WizardDescriptor.Panel { 41 45 private final static String PROP_ERROR_MESSAGE = "WizardPanel_errorMessage"; 47 50 private transient WizardDescriptor wizardDescriptor; 51 52 55 private transient WLInstantiatingIterator instantiatingIterator; 56 57 67 public ServerLocationPanel(String [] steps, int index, ChangeListener listener, WLInstantiatingIterator instantiatingIterator) { 68 this.instantiatingIterator = instantiatingIterator; 70 71 putClientProperty("WizardPanel_contentData", steps); putClientProperty("WizardPanel_contentSelectedIndex", new Integer (index)); 76 addChangeListener(listener); 78 79 setName(steps[index]); 81 82 init(); 84 } 85 86 91 public HelpCtx getHelp() { 92 return new HelpCtx("j2eeplugins_registering_app_server_weblogic_location"); } 94 95 101 public Component getComponent() { 102 return this; 103 } 104 105 111 public boolean isValid() { 112 wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, ""); 114 115 if (!WLPluginProperties.runningOnCorrectJdk()) { 117 String msg = NbBundle.getMessage(ServerLocationPanel.class, "ERR_INVALID_JDK"); 118 wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, msg); 119 return false; 120 } 121 122 File serverRoot = new File (locationField.getText()); 125 126 if (!WLPluginProperties.isSupportedVersion(serverRoot)) { 127 String msg = NbBundle.getMessage(ServerLocationPanel.class, "ERR_INVALID_SERVER_VERSION"); 128 wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, msg); 129 return false; 130 } 131 132 if (!WLPluginProperties.isGoodServerLocation(serverRoot)) { 133 String msg = NbBundle.getMessage(ServerLocationPanel.class, "ERR_INVALID_SERVER_ROOT"); 134 wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, msg); 135 return false; 136 } 137 138 if (!WLPluginProperties.domainListExists(serverRoot)) { 139 String msg = NbBundle.getMessage(ServerLocationPanel.class, "ERR_INVALID_SERVER_ROOT") + 140 " " + 141 NbBundle.getMessage(ServerLocationPanel.class, "DOMAIN_LIST_NOT_FOUND", 142 serverRoot.getPath() + File.separator + WLPluginProperties.DOMAIN_LIST 143 ); 144 wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, msg); 145 return false; 146 } 147 148 149 WLPluginProperties.getInstance().setInstallLocation(locationField.getText()); 150 WLPluginProperties.getInstance().saveProperties(); 151 instantiatingIterator.setServerRoot(locationField.getText()); 153 154 return true; 156 } 157 158 private JButton locationBrowseButton; 162 private JLabel locationLabel; 163 private JTextField locationField; 164 private JPanel formattingPanel; 165 166 169 private void init() { 170 GridBagConstraints gridBagConstraints; 173 174 locationLabel = new JLabel(); 176 locationField = new JTextField(); 177 locationBrowseButton = new JButton(); 178 formattingPanel = new JPanel(); 179 180 setLayout(new GridBagLayout()); 182 183 locationLabel.setText(NbBundle.getMessage(ServerLocationPanel.class, "LBL_SERVER_LOCATION")); gridBagConstraints = new GridBagConstraints(); 186 gridBagConstraints.gridx = 0; 187 gridBagConstraints.gridy = 0; 188 gridBagConstraints.anchor = GridBagConstraints.EAST; 189 locationLabel.setLabelFor(locationField); 190 add(locationLabel, gridBagConstraints); 191 192 locationField.setColumns(15); 194 locationField.addKeyListener(new LocationKeyListener()); 195 String loc = WLPluginProperties.getInstance().getInstallLocation(); 196 if (loc != null) { locationField.setText(loc); 198 } 199 gridBagConstraints = new GridBagConstraints(); 200 gridBagConstraints.gridx = 1; 201 gridBagConstraints.gridy = 0; 202 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 203 gridBagConstraints.weightx = 1.0; 204 gridBagConstraints.insets = new Insets(0, 10, 0, 10); 205 locationField.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ServerLocationPanel.class, "ACSD_ServerLocationPanel_locationField")); add(locationField, gridBagConstraints); 207 208 org.openide.awt.Mnemonics.setLocalizedText(locationBrowseButton, NbBundle.getMessage(ServerLocationPanel.class, "LBL_BROWSE_BUTTON")); 210 locationBrowseButton.addActionListener(new BrowseActionListener()); 211 gridBagConstraints = new GridBagConstraints(); 212 gridBagConstraints.gridx = 2; 213 gridBagConstraints.gridy = 0; 214 gridBagConstraints.anchor = GridBagConstraints.WEST; 215 locationBrowseButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ServerLocationPanel.class, "ACSD_ServerLocationPanel_locationBrowseButton")); add(locationBrowseButton, gridBagConstraints); 217 218 gridBagConstraints = new GridBagConstraints(); 220 gridBagConstraints.gridx = 0; 221 gridBagConstraints.gridy = 1; 222 gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; 223 gridBagConstraints.weighty = 1.0; 224 add(formattingPanel, gridBagConstraints); 225 } 226 227 231 private JFileChooser fileChooser; 232 233 237 private void showFileChooser() { 238 239 if (fileChooser == null) { 240 fileChooser = new JFileChooser(); 241 } 242 243 fileChooser.setFileFilter(new DirectoryFileFilter()); 245 fileChooser.setMultiSelectionEnabled(false); 246 fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 247 248 File currentLocation = new File (locationField.getText()); 250 if (currentLocation.exists() && currentLocation.isDirectory()) { 251 fileChooser.setCurrentDirectory(currentLocation.getParentFile()); 252 fileChooser.setSelectedFile(currentLocation); 253 } 254 255 if (fileChooser.showOpenDialog(this) == fileChooser.APPROVE_OPTION) { 258 locationField.setText(fileChooser.getSelectedFile().getPath()); 259 fireChangeEvent(); 260 } 261 } 262 263 272 public void readSettings(Object object) { 273 this.wizardDescriptor = (WizardDescriptor) object; 274 } 275 276 280 public void storeSettings(Object object) {} 281 282 288 private Vector listeners = new Vector(); 289 290 295 public void removeChangeListener(ChangeListener listener) { 296 if (listeners != null) { 297 synchronized (listeners) { 298 listeners.remove(listener); 299 } 300 } 301 } 302 303 308 public void addChangeListener(ChangeListener listener) { 309 synchronized (listeners) { 310 listeners.add(listener); 311 } 312 } 313 314 317 private void fireChangeEvent() { 318 ChangeEvent event = new ChangeEvent(this); 319 fireChangeEvent(event); 320 } 321 322 327 private void fireChangeEvent(ChangeEvent event) { 328 Vector targetListeners; 329 synchronized (listeners) { 330 targetListeners = (Vector) listeners.clone(); 331 } 332 333 for (int i = 0; i < targetListeners.size(); i++) { 334 ChangeListener listener = (ChangeListener) targetListeners.elementAt(i); 335 listener.stateChanged(event); 336 } 337 } 338 339 347 private class LocationKeyListener extends KeyAdapter { 348 351 public void keyTyped(KeyEvent event) { 352 fireChangeEvent(); 353 } 354 355 358 public void keyReleased(KeyEvent event) { 359 fireChangeEvent(); 360 } 361 } 362 363 368 private class BrowseActionListener implements ActionListener { 369 373 public void actionPerformed(ActionEvent event) { 374 showFileChooser(); 375 } 376 } 377 378 384 private static class DirectoryFileFilter extends FileFilter { 385 391 public boolean accept(File file) { 392 if (file.exists() && file.isDirectory()) { 394 return true; 395 } 396 397 return false; 399 } 400 401 406 public String getDescription() { 407 return NbBundle.getMessage(ServerLocationPanel.class, "DIRECTORIES_FILTER_NAME"); } 409 } 410 } 411 | Popular Tags |