1 2 24 package org.enhydra.tool.codegen.wizard; 25 26 import org.enhydra.tool.ToolBoxInfo; 28 import org.enhydra.tool.codegen.internal.ServiceOptionSet; 29 import org.enhydra.tool.codegen.GeneratorOption; 30 import org.enhydra.tool.codegen.GeneratorException; 31 import org.enhydra.tool.codegen.ValidationException; 32 import org.enhydra.tool.codegen.ValidationUtil; 33 import org.enhydra.tool.common.ToolException; 34 import org.enhydra.tool.common.PathHandle; 35 import org.enhydra.tool.common.SwingUtil; 36 37 import javax.swing.*; 39 import javax.swing.border.*; 40 import java.awt.*; 41 import java.awt.event.ActionEvent ; 42 import java.awt.event.ActionListener ; 43 import java.beans.*; 44 import java.io.File ; 45 import java.util.Properties ; 46 import java.util.ResourceBundle ; 47 48 54 public class ServiceOptionPanel1 extends CodeGenPanel { 55 56 private final String DEF_PACKAGE = "untitled"; private final String DEF_PROJECT = "Untitled1"; private final String DEF_SERVICE = "Untitled1"; 61 63 66 transient public JLabel labelProjectName; 67 68 71 transient public JTextField textProjectName; 72 73 76 transient public JLabel labelServiceName; 77 78 81 transient public JTextField textServiceName; 82 83 84 87 transient public JLabel labelPackage; 88 89 92 transient public JTextField textPackage; 93 94 97 transient public JPanel panelDest; 98 99 102 transient public JButton buttonSet; 103 104 107 transient public JTextField textDest; 108 109 transient private JPanel panelFiller; 111 transient private GridBagLayout layoutMain; 112 transient private GridBagLayout layoutDest; 113 transient private LocalButtonListener buttonListener; 114 transient private TitledBorder borderDest; 115 transient private JPanel panelEnhydraRoot; 116 transient private JTextField textEnhydraRoot; 117 transient private GridBagLayout layoutEnhydraRoot; 118 transient private Border borderEnhydraRoot; 119 transient private JButton buttonEnhydraRoot; 120 121 126 public ServiceOptionPanel1() { 127 try { 128 jbInit(); 129 pmInit(); 130 } catch (Exception ex) { 131 ex.printStackTrace(); 132 } 133 } 134 135 public boolean isAllowRootEdit() { 137 return textProjectName.isEnabled(); 138 } 139 140 public void setAllowRootEdit(boolean allow) { 142 textProjectName.setEnabled(allow); 143 textDest.setEnabled(allow); 144 } 145 146 153 public void readOptionSet() throws GeneratorException { 154 GeneratorOption option = null; 155 PathHandle handle = null; 156 157 option = getOptionSet().lookup(ServiceOptionSet.SERVICE); 159 textServiceName.setText(option.getValue()); 160 161 162 option = getOptionSet().lookup(ServiceOptionSet.PROJECT); 164 textProjectName.setText(option.getValue()); 165 166 option = getOptionSet().lookup(ServiceOptionSet.PACKAGE); 168 textPackage.setText(option.getValue()); 169 170 option = getOptionSet().lookup(ServiceOptionSet.ROOT); 172 handle = PathHandle.createPathHandle(option.getValue()); 173 textDest.setText(handle.getPath()); 174 } 175 176 183 public void writeOptionSet() throws GeneratorException { 184 String value = new String (); 185 boolean bool = false; 186 187 value = textServiceName.getText().trim(); 189 getOptionSet().lookup(ServiceOptionSet.SERVICE).setValue(value); 190 191 value = textProjectName.getText().trim(); 193 getOptionSet().lookup(ServiceOptionSet.PROJECT).setValue(value); 194 195 value = textPackage.getText().trim(); 197 getOptionSet().lookup(ServiceOptionSet.PACKAGE).setValue(value); 198 199 value = textDest.getText().trim(); 201 getOptionSet().lookup(ServiceOptionSet.ROOT).setValue(value); 202 } 203 204 212 public void validateOptionSet() throws ValidationException { 213 String value = new String (); 214 215 216 value = textServiceName.getText().trim(); 218 if (!ValidationUtil.isJavaIdentifier(value)) { 219 throw new ValidationException("Invalid service name"); 220 } 221 222 value = textProjectName.getText().trim(); 224 if (!ValidationUtil.isJavaIdentifier(value)) { 225 throw new ValidationException(res.getString("Project_directory")); 226 } 227 228 value = textPackage.getText().trim(); 230 if (!ValidationUtil.isJavaPackage(value)) { 231 throw new ValidationException(res.getString("Package_is_not_valid")); 232 } 233 234 value = textDest.getText().trim(); 236 if (!ValidationUtil.isParentDirectory(value)) { 237 throw new ValidationException("Invalid Project Root"); 238 } 239 if (ToolBoxInfo.isRootSettable()) { 240 if (!ToolBoxInfo.isEnhydraRoot(ToolBoxInfo.getEnhydraRoot())) { 241 throw new ValidationException("Invalid Application Server Root"); 242 } 243 } 244 } 245 246 252 public String getPageTitle() { 253 return res.getString("Client_type_and"); 254 } 255 256 263 public String getInstructions() { 264 StringBuffer buf = new StringBuffer (); 265 266 buf.append(res.getString("Instruct1")); 267 buf.append(res.getString("Instruct2")); 268 buf.append(res.getString("Instruct3")); 269 buf.append(res.getString("Instruct4")); 270 return buf.toString(); 271 } 272 273 private void chooseEnhydraRoot() { 277 File choice = null; 278 PathHandle path = null; 279 Properties props = null; 280 String message = null; 281 282 choice = SwingUtil.getDirectoryChoice(this, 283 ToolBoxInfo.getEnhydraRoot(), 284 "Select Application Server Root"); 285 path = PathHandle.createPathHandle(choice); 286 if (path.isDirectory() && ToolBoxInfo.isEnhydraRoot(path.getPath())) { 287 try { 288 props = ToolBoxInfo.loadProperties(); 289 props.setProperty(ToolBoxInfo.ENHYDRA_ROOT, path.getPath()); 290 ToolBoxInfo.storeProperties(props); 291 textEnhydraRoot.setText(ToolBoxInfo.getEnhydraRoot()); 292 textEnhydraRoot.setToolTipText(textEnhydraRoot.getText()); 293 } catch (ToolException e) { 294 message = e.getMessage(); 295 } 296 } else { 297 message = "Invalid Application Server Root"; 298 } 299 if (message != null) { 300 JOptionPane.showMessageDialog(this, message, "Kelp Error", 301 JOptionPane.ERROR_MESSAGE); 302 } 303 } 304 305 private void jbInit() throws Exception { 306 labelServiceName = 307 (JLabel) Beans.instantiate(getClass().getClassLoader(), 308 JLabel.class.getName()); 309 310 textServiceName = 311 (JTextField) Beans.instantiate(getClass().getClassLoader(), 312 JTextField.class.getName()); 313 314 labelProjectName = 315 (JLabel) Beans.instantiate(getClass().getClassLoader(), 316 JLabel.class.getName()); 317 318 textProjectName = 319 (JTextField) Beans.instantiate(getClass().getClassLoader(), 320 JTextField.class.getName()); 321 labelPackage = (JLabel) Beans.instantiate(getClass().getClassLoader(), 322 JLabel.class.getName()); 323 textPackage = 324 (JTextField) Beans.instantiate(getClass().getClassLoader(), 325 JTextField.class.getName()); 326 panelDest = (JPanel) Beans.instantiate(getClass().getClassLoader(), 327 JPanel.class.getName()); 328 layoutDest = 329 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 330 GridBagLayout.class.getName()); 331 buttonSet = (JButton) Beans.instantiate(getClass().getClassLoader(), 332 JButton.class.getName()); 333 textDest = (JTextField) Beans.instantiate(getClass().getClassLoader(), 334 JTextField.class.getName()); 335 layoutMain = 336 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 337 GridBagLayout.class.getName()); 338 panelFiller = (JPanel) Beans.instantiate(getClass().getClassLoader(), 339 JPanel.class.getName()); 340 341 panelEnhydraRoot = 342 (JPanel) Beans.instantiate(getClass().getClassLoader(), 343 JPanel.class.getName()); 344 textEnhydraRoot = 345 (JTextField) Beans.instantiate(getClass().getClassLoader(), 346 JTextField.class.getName()); 347 buttonEnhydraRoot = 348 (JButton) Beans.instantiate(getClass().getClassLoader(), 349 JButton.class.getName()); 350 layoutEnhydraRoot = 351 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 352 GridBagLayout.class.getName()); 353 borderEnhydraRoot = BorderFactory.createTitledBorder("Application Server Root"); 354 labelProjectName.setMaximumSize(new Dimension(120, 17)); 355 labelProjectName.setMinimumSize(new Dimension(120, 17)); 356 labelProjectName.setPreferredSize(new Dimension(120, 17)); 357 labelProjectName.setText(res.getString("Project_directory1")); 358 labelPackage.setText(res.getString("Package_")); 359 buttonSet.setText(res.getString("Set_")); 360 panelDest.setBorder(BorderFactory.createTitledBorder("Project Root")); 361 panelDest.setLayout(layoutDest); 362 labelServiceName.setText("Service name:"); 363 panelDest.add(textDest, 364 new GridBagConstraints(0, 0, 1, 1, 0.1, 0.0, 365 GridBagConstraints.WEST, 366 GridBagConstraints.HORIZONTAL, 367 new Insets(4, 5, 3, 5), 0, 0)); 368 panelDest.add(buttonSet, 369 new GridBagConstraints(1, 0, 1, 2, 0.0, 0.0, 370 GridBagConstraints.CENTER, 371 GridBagConstraints.NONE, 372 new Insets(4, 5, 3, 10), 0, 0)); 373 textEnhydraRoot.setEnabled(false); 374 buttonEnhydraRoot.setText(res.getString("Set_")); 375 panelEnhydraRoot.setLayout(layoutEnhydraRoot); 376 panelEnhydraRoot.setBorder(borderEnhydraRoot); 377 panelEnhydraRoot.add(textEnhydraRoot, 378 new GridBagConstraints(0, 0, 1, 1, 0.1, 0.0, 379 GridBagConstraints.WEST, 380 GridBagConstraints.HORIZONTAL, 381 new Insets(4, 5, 3, 5), 382 0, 0)); 383 panelEnhydraRoot.add(buttonEnhydraRoot, 384 new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, 385 GridBagConstraints.CENTER, 386 GridBagConstraints.NONE, 387 new Insets(4, 5, 3, 10), 388 0, 0)); 389 this.setLayout(layoutMain); 390 this.add(labelProjectName, new GridBagConstraints(0, 0, 1, 1, 0.1, 0.0 391 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(3, 5, 3, 5), 50, 0)); 392 this.add(labelPackage, new GridBagConstraints(0, 1, 1, 1, 0.1, 0.0 393 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(3, 5, 3, 5), 50, 0)); 394 this.add(textProjectName, new GridBagConstraints(1, 0, 1, 1, 0.1, 0.0 395 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(3, 5, 3, 5), 150, 0)); 396 this.add(panelDest, 397 new GridBagConstraints(0, 3, 2, 1, 0.1, 0.0, 398 GridBagConstraints.CENTER, 399 GridBagConstraints.BOTH, 400 new Insets(3, 5, 3, 5), 0, 0)); 401 this.add(textPackage, new GridBagConstraints(1, 1, 1, 1, 0.1, 0.0 402 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(3, 5, 3, 5), 150, 0)); 403 this.add(panelFiller, 404 new GridBagConstraints(0, 5, 2, 1, 0.4, 0.4, 405 GridBagConstraints.CENTER, 406 GridBagConstraints.BOTH, 407 new Insets(0, 0, 0, 0), 0, 0)); 408 this.add(labelServiceName, new GridBagConstraints(0, 2, 1, 1, 0.1, 0.0 409 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 3, 5), 50, 0)); 410 this.add(textServiceName, new GridBagConstraints(1, 2, 1, 1, 0.1, 0.0 411 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 3, 5), 50, 0)); 412 413 this.add(panelEnhydraRoot, 414 new GridBagConstraints(0, 4, 4, 1, 0.1, 0.0, 415 GridBagConstraints.CENTER, 416 GridBagConstraints.BOTH, 417 new Insets(3, 5, 5, 5), 0, 0)); 418 } 419 420 private void pmInit() { 421 String [] docTypes = new String [0]; 422 423 buttonListener = new LocalButtonListener(); 424 buttonSet.addActionListener(buttonListener); 425 textDest.setText(new String ()); 426 textPackage.setText(DEF_PACKAGE); 427 textProjectName.setText(DEF_PROJECT); 428 textServiceName.setText(DEF_SERVICE); 429 docTypes = ToolBoxInfo.getSupportedDocTypes(); 430 textEnhydraRoot.setText(ToolBoxInfo.getEnhydraRoot()); 431 textEnhydraRoot.setToolTipText(textEnhydraRoot.getText()); 432 textEnhydraRoot.setEnabled(false); 433 if (ToolBoxInfo.isRootSettable()) { 434 buttonListener = new LocalButtonListener(); 435 buttonEnhydraRoot.addActionListener(buttonListener); 436 buttonEnhydraRoot.setEnabled(true); 437 } else { 438 buttonEnhydraRoot.setVisible(false); 439 panelEnhydraRoot.remove(buttonEnhydraRoot); 440 } 441 } 442 443 private void browseForFile() { 444 File destDir = null; 445 446 destDir = 447 SwingUtil.getDirectoryChoice(this, textDest.getText(), 448 res.getString("Choose_the_root_path")); 449 if (destDir != null) { 450 textDest.setText(PathHandle.createPathString(destDir)); 451 } 452 } 453 454 private class LocalButtonListener implements ActionListener { 455 public void actionPerformed(ActionEvent event) { 456 Object source = event.getSource(); 457 458 if (source == buttonSet) { 459 browseForFile(); 460 } else if (source == buttonEnhydraRoot) { 461 chooseEnhydraRoot(); 462 } 463 } 464 465 } 466 } 467 | Popular Tags |