1 23 package org.enhydra.kelp.common.deployer; 24 25 import org.enhydra.kelp.common.PathUtil; 27 import org.enhydra.kelp.common.event.ExtensionChangeListener; 28 import org.enhydra.kelp.common.event.WriteListener; 29 import org.enhydra.kelp.common.node.OtterProject; 30 import org.enhydra.kelp.common.Constants; 31 import org.enhydra.kelp.common.DirectoryFilter; 32 33 import org.enhydra.tool.ToolBoxInfo; 35 import org.enhydra.tool.common.DataValidationException; 36 import org.enhydra.tool.common.FileUtil; 37 import org.enhydra.tool.common.SwingUtil; 38 import org.enhydra.tool.common.ToolException; 39 import org.enhydra.tool.common.PathHandle; 40 import org.enhydra.tool.common.ExtensionFilter; 41 42 import java.awt.*; 44 import java.awt.event.ActionEvent ; 45 import java.awt.event.ActionListener ; 46 import java.awt.event.ItemEvent ; 47 import java.awt.event.ItemListener ; 48 import java.beans.*; 49 import java.io.File ; 50 import java.io.PrintWriter ; 51 import java.lang.ref.WeakReference ; 52 import javax.swing.*; 53 import javax.swing.event.ChangeEvent ; 54 import javax.swing.event.ChangeListener ; 55 import javax.swing.border.*; 56 57 import java.awt.event.*; 59 import java.io.File ; 60 import java.util.ResourceBundle ; 61 62 public class RunPanel extends JPanel implements Instructor, DeployStep { 64 static ResourceBundle res = 65 ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); private GridBagLayout layoutMain; 67 private JRadioButton radioAuto; 68 private JRadioButton radioIDE; 69 private JLabel labelAuto; 70 private GridBagLayout layoutAuto; 71 private JTextField textAuto; 72 private JButton buttonAuto; 73 private JLabel labelBoot; 74 private JTextField textBoot; 75 private JButton buttonBoot; 76 private GridBagLayout layoutBoot; 77 private JLabel labelConf; 78 private JTextField textConf; 79 private GridBagLayout layoutConf; 80 private JCheckBox checkStartupJava; 81 private JLabel labelAutoFile; 82 private JTextField textAutoFile; 83 private JButton buttonAutoFile; 84 private JCheckBox checkEnable; 85 private LocalCheckListener checkListener = null; 86 private LocalRadioListener radioListener = null; 87 private LocalButtonListener buttonListener = null; 88 private WeakReference projectRef = null; 89 private boolean ran = false; 90 91 public RunPanel() { 93 try { 94 jbInit(); 95 pmInit(); 96 } catch (Exception ex) { 97 ex.printStackTrace(); 98 } 99 } 100 101 public String getTab() { 103 return "Run"; 104 } 105 106 public String getTitle() { 108 return "Run configuration"; 109 } 110 111 public String getInstructions() { 113 return "The deployer can deploy archives to a running locally server or " 114 + "setup your project so that you can launch the server from your IDE."; 115 } 116 117 public void refresh() { 119 if (getProject() != null) { 120 if (true) { 123 radioAuto.setSelected(true); 124 radioIDE.setEnabled(false); 125 radioIDE.setSelected(false); 126 } 127 } 128 radioRefresh(); 129 } 130 131 public void clearAll() { 133 radioAuto.removeItemListener(radioListener); 134 radioIDE.removeItemListener(radioListener); 135 buttonAuto.removeActionListener(buttonListener); 136 buttonBoot.removeActionListener(buttonListener); 137 checkEnable.removeChangeListener(checkListener); 138 removeAll(); 139 if (projectRef != null) { 140 projectRef.clear(); 141 } 142 projectRef = null; 143 checkListener = null; 144 radioListener = null; 145 buttonListener = null; 146 } 147 148 public boolean isDataValid() { 150 return DeployStepUtil.isDataValid(this); 151 } 152 153 public boolean isDataEqual(OtterProject project) { 155 boolean equal = true; 156 PathHandle projectPath = null; 157 PathHandle panelPath = null; 158 159 projectRef = new WeakReference (project); 160 if (!project.isDeployStartupJavaReadOnly()) { 161 if (project.isDeployStartupJava() 162 != checkStartupJava.isSelected()) { 163 equal = false; 164 } 165 } 166 if (equal) { 167 if (project.isDeployRun() != checkEnable.isSelected()) { 168 equal = false; 169 } 170 } 171 if (equal) { 172 projectPath = 173 PathHandle.createPathHandle(project.getDeployBootstrapPath()); 174 if (radioAuto.isSelected()) { 175 panelPath = PathHandle.createPathHandle(textAuto.getText()); 176 } else { 177 panelPath = PathHandle.createPathHandle(textBoot.getText()); 178 } 179 if (!projectPath.equals(panelPath)) { 180 equal = false; 181 } 182 } 183 if (equal) { 184 projectPath = 185 PathHandle.createPathHandle(project.getAutoDeployFilePath()); 186 panelPath = PathHandle.createPathHandle(textAutoFile.getText()); 187 if (!projectPath.equals(panelPath)) { 188 equal = false; 189 } 190 } 191 return equal; 192 } 193 194 public void validateData() throws DataValidationException { 196 PathHandle path = null; 197 198 if (checkEnable.isSelected()) { 199 if (radioAuto.isSelected()) { 200 path = PathHandle.createPathHandle(textAuto.getText()); 201 if (!path.isDirectory()) { 202 throw new DataValidationException("Invalid auto deployment directory: " 203 + path.getPath()); 204 } 205 } else { 206 path = PathHandle.createPathHandle(textBoot.getText()); 207 if (!path.isFile()) { 208 throw new DataValidationException("Invalid server configuration file: " 209 + path.getPath()); 210 } 211 } 212 } 213 } 214 215 public boolean isBuilt(OtterProject project) { 217 projectRef = new WeakReference (project); 218 ran = DeployStepUtil.isBuilt(this, ran, project); 219 return ran; 220 } 221 222 public boolean isSelectable(OtterProject project, DeployStep[] steps) { 224 boolean able = false; 225 boolean generalBuilt = false; 226 boolean inputBuilt = false; 227 boolean contentBuilt = false; 228 boolean archiveBuilt = false; 229 230 projectRef = new WeakReference (project); 231 for (int i = 0; i < steps.length; i++) { 232 if (steps[i] instanceof GeneralPanel) { 233 generalBuilt = steps[i].isBuilt(project); 234 } else if (steps[i] instanceof InputPanel) { 235 inputBuilt = steps[i].isBuilt(project); 236 } else if (steps[i] instanceof ContentPanel) { 237 contentBuilt = steps[i].isBuilt(project); 238 } else if (steps[i] instanceof ArchivePanel) { 239 archiveBuilt = steps[i].isBuilt(project); 240 } 241 } 242 able = generalBuilt && inputBuilt && contentBuilt && archiveBuilt; 243 return able; 244 } 245 246 public void build(OtterProject project, 248 WriteListener listener) throws DataValidationException { 249 RunBuilder builder = null; 250 251 projectRef = new WeakReference (project); 252 if (!isBuilt(project)) { 253 write(project); 254 builder = new RunBuilder(listener); 255 builder.setProject(project); 256 builder.setEcho(true); 257 builder.buildInCurrentThread(); 258 ran = true; 259 } 260 } 261 262 public void read(OtterProject project) { 264 PathHandle path = null; 265 266 projectRef = new WeakReference (project); 267 refresh(); 268 path = PathHandle.createPathHandle(project.getDeployBootstrapPath()); 269 checkEnable.setSelected(project.isDeployRun()); 270 if (path.isDirectory()) { 271 textAuto.setText(path.getPath()); 272 textBoot.setText(new String ()); 273 radioAuto.setSelected(true); 274 radioIDE.setSelected(false); 275 } else if (path.hasExtension("conf")) { 276 textAuto.setText(new String ()); 277 textBoot.setText(path.getPath()); 278 radioAuto.setSelected(false); 279 radioIDE.setSelected(true); 280 } else { 281 textAuto.setText(new String ()); 282 textBoot.setText(new String ()); 283 radioAuto.setSelected(false); 284 radioIDE.setSelected(true); 285 } 286 textAutoFile.setText(project.getAutoDeployFilePath()); 287 textAutoFile.setToolTipText(textAutoFile.getText()); 288 textAuto.setToolTipText(textAuto.getText()); 289 textBoot.setToolTipText(textBoot.getText()); 290 textConf.setText(PathUtil.getDeployConfPath(project.getDeployRootPath())); 291 textConf.setToolTipText(textConf.getText()); 292 if (project.isDeployStartupJavaReadOnly()) { 293 checkStartupJava.setVisible(false); 294 } else { 295 checkStartupJava.setSelected(project.isDeployStartupJava()); 296 } 297 } 298 299 public void write(OtterProject project) throws DataValidationException { 301 PathHandle path = null; 302 303 projectRef = new WeakReference (project); 304 validateData(); 305 if (!isDataEqual(project)) { 306 if (radioAuto.isSelected()) { 307 path = PathHandle.createPathHandle(textAuto.getText()); 308 } else { 309 path = PathHandle.createPathHandle(textBoot.getText()); 310 } 311 project.setDeployBootstrapPath(path.getPath()); 312 project.setAutoDeployFile(textAutoFile.getText()); 313 if (!project.isDeployStartupJavaReadOnly()) { 314 project.setDeployStartupJava(checkStartupJava.isSelected()); 315 } 316 project.setDeployRun(checkEnable.isSelected()); 317 } 318 } 319 320 private void chooseDirectory(JTextField text, String title) { 322 File choice = null; 323 PathHandle path = null; 324 325 choice = SwingUtil.getDirectoryChoice(this, text.getText(), title); 326 path = PathHandle.createPathHandle(choice); 327 if (path.isDirectory()) { 328 text.setText(path.getPath()); 329 text.setToolTipText(text.getText()); 330 } 331 } 332 333 private void chooseBootFile() { 334 File choice = null; 335 PathHandle path = null; 336 ExtensionFilter filter = null; 337 338 filter = new ExtensionFilter(); 339 filter.setDescriptionTitle("Server Configuration"); 340 filter.addExtension("conf"); 341 choice = 342 SwingUtil.getFileChoice(this, textBoot.getText(), filter, 343 "Select a server bootstrap configuration file"); 344 path = PathHandle.createPathHandle(choice); 345 if (path.isFile()) { 346 textBoot.setText(path.getPath()); 347 textBoot.setToolTipText(textBoot.getText()); 348 } 349 } 350 351 private void chooseAutoFile() { 352 File choice = null; 353 PathHandle path = null; 354 ExtensionFilter filter = null; 355 int type = OtterProject.TYPE_UNKNOWN; 356 357 if (getProject() != null) { 358 type = getProject().getDeployType(); 359 } 360 filter = new ExtensionFilter(); 361 switch (type) { 362 case OtterProject.TYPE_EN3APP: 363 filter.setDescriptionTitle("Enhydra App Configuration"); 364 filter.addExtension("conf"); 365 break; 366 case OtterProject.TYPE_WEBAPP: 367 filter.setDescriptionTitle("Application Archive"); 368 filter.addExtension("war"); 369 filter.addExtension("ear"); 370 break; 371 376 default: 377 filter.setDescriptionTitle("Deployment File"); 378 break; 379 } 380 choice = SwingUtil.getFileChoice(this, textAutoFile.getText(), 381 filter, 382 "Select file to copy to server"); 383 path = PathHandle.createPathHandle(choice); 384 if (path.isFile()) { 385 textAutoFile.setText(path.getPath()); 386 textAutoFile.setToolTipText(textAutoFile.getText()); 387 } 388 } 389 390 private void radioRefresh() { 391 boolean auto = radioAuto.isSelected(); 392 PathHandle ph = null; 393 String def = null; 394 int type = OtterProject.TYPE_UNKNOWN; 395 396 buttonBoot.setEnabled(!auto); 397 labelBoot.setEnabled(!auto); 398 labelConf.setEnabled(!auto); 399 checkStartupJava.setEnabled(!auto); 400 buttonAuto.setEnabled(auto); 401 buttonAutoFile.setEnabled(auto); 402 labelAuto.setEnabled(auto); 403 labelAutoFile.setEnabled(auto); 404 if (auto) { 405 if (getProject() != null) { 406 type = getProject().getDeployType(); 407 } 408 textBoot.setBackground(SystemColor.control); 409 textConf.setBackground(SystemColor.control); 410 textAuto.setBackground(SystemColor.info); 411 textAutoFile.setBackground(SystemColor.info); 412 if (textAuto.getText().trim().length() == 0) { 413 def = PathUtil.getAutoDeployPath(type); 414 ph = PathHandle.createPathHandle(def); 415 if (ph.isDirectory()) { 416 textAuto.setText(ph.getPath()); 417 } 418 } 419 } else { 420 textBoot.setBackground(SystemColor.info); 421 textConf.setBackground(SystemColor.info); 422 textAuto.setBackground(SystemColor.control); 423 textAutoFile.setBackground(SystemColor.control); 424 if (textBoot.getText().trim().length() == 0) { 425 if (getProject() != null) { 426 def = 427 PathUtil.getDefaultDeployBootstrapPath(getProject()); 428 ph = PathHandle.createPathHandle(def); 429 if (ph.isFile()) { 430 textBoot.setText(ph.getPath()); 431 } 432 } 433 } 434 } 435 } 436 437 private OtterProject getProject() { 438 OtterProject project = null; 439 440 if (projectRef != null) { 441 project = (OtterProject) projectRef.get(); 442 } 443 return project; 444 } 445 446 private void pmInit() { 447 ButtonGroup group = null; 448 449 group = new ButtonGroup(); 450 group.add(radioAuto); 451 group.add(radioIDE); 452 453 radioListener = new LocalRadioListener(); 455 radioAuto.addItemListener(radioListener); 456 radioIDE.addItemListener(radioListener); 457 458 buttonListener = new LocalButtonListener(); 460 buttonAuto.addActionListener(buttonListener); 461 buttonAutoFile.addActionListener(buttonListener); 462 buttonBoot.addActionListener(buttonListener); 463 464 if (ToolBoxInfo.isEnhydra3()) { 466 radioAuto.setEnabled(false); 467 radioAuto.setSelected(false); 468 } 469 checkListener = new LocalCheckListener(); 470 checkEnable.addChangeListener(checkListener); 471 } 472 473 private void refreshEnable() { 474 if (checkEnable.isSelected()) { 475 radioAuto.setEnabled(true); 476 if (getProject() == null) { 477 radioIDE.setEnabled(true); 478 482 } else { 483 radioIDE.setEnabled(true); 484 } 485 radioRefresh(); 486 } else { 487 buttonAuto.setEnabled(false); 488 buttonAutoFile.setEnabled(false); 489 buttonBoot.setEnabled(false); 490 checkStartupJava.setEnabled(false); 491 labelAuto.setEnabled(false); 492 labelAutoFile.setEnabled(false); 493 labelBoot.setEnabled(false); 494 labelConf.setEnabled(false); 495 radioAuto.setEnabled(false); 496 radioIDE.setEnabled(false); 497 textAuto.setBackground(SystemColor.control); 498 textAutoFile.setBackground(SystemColor.control); 499 textBoot.setBackground(SystemColor.control); 500 textConf.setBackground(SystemColor.control); 501 } 502 } 503 504 private void jbInit() throws Exception { 505 checkStartupJava = 506 (JCheckBox) Beans.instantiate(getClass().getClassLoader(), 507 JCheckBox.class.getName()); 508 labelConf = (JLabel) Beans.instantiate(getClass().getClassLoader(), 509 JLabel.class.getName()); 510 textConf = (JTextField) Beans.instantiate(getClass().getClassLoader(), 511 JTextField.class.getName()); 512 layoutConf = 513 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 514 GridBagLayout.class.getName()); 515 labelBoot = (JLabel) Beans.instantiate(getClass().getClassLoader(), 516 JLabel.class.getName()); 517 textBoot = (JTextField) Beans.instantiate(getClass().getClassLoader(), 518 JTextField.class.getName()); 519 buttonBoot = (JButton) Beans.instantiate(getClass().getClassLoader(), 520 JButton.class.getName()); 521 layoutBoot = 522 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 523 GridBagLayout.class.getName()); 524 radioIDE = 525 (JRadioButton) Beans.instantiate(getClass().getClassLoader(), 526 JRadioButton.class.getName()); 527 labelAuto = (JLabel) Beans.instantiate(getClass().getClassLoader(), 528 JLabel.class.getName()); 529 layoutAuto = 530 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 531 GridBagLayout.class.getName()); 532 textAuto = (JTextField) Beans.instantiate(getClass().getClassLoader(), 533 JTextField.class.getName()); 534 buttonAuto = (JButton) Beans.instantiate(getClass().getClassLoader(), 535 JButton.class.getName()); 536 layoutMain = 537 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 538 GridBagLayout.class.getName()); 539 radioAuto = 540 (JRadioButton) Beans.instantiate(getClass().getClassLoader(), 541 JRadioButton.class.getName()); 542 labelAutoFile = 543 (JLabel) Beans.instantiate(getClass().getClassLoader(), 544 JLabel.class.getName()); 545 textAutoFile = 546 (JTextField) Beans.instantiate(getClass().getClassLoader(), 547 JTextField.class.getName()); 548 buttonAutoFile = 549 (JButton) Beans.instantiate(getClass().getClassLoader(), 550 JButton.class.getName()); 551 checkEnable = 552 (JCheckBox) Beans.instantiate(getClass().getClassLoader(), 553 JCheckBox.class.getName()); 554 radioAuto.setText("Auto-deploy to locally running server"); 555 radioIDE.setText("Configure project for starting server from IDE"); 556 textAuto.setEnabled(false); 557 textAuto.setEditable(false); 558 textAuto.setText("AUTODEPLOY DIRECTORY"); 559 buttonAuto.setText("..."); 560 textBoot.setEnabled(false); 561 textBoot.setEditable(false); 562 textBoot.setText("BOOT CONF"); 563 buttonBoot.setToolTipText(""); 564 buttonBoot.setText("..."); 565 textConf.setEnabled(false); 566 textConf.setEditable(false); 567 textConf.setText("TEXT CONF"); 568 labelAuto.setText("Deploy directory:"); 569 labelBoot.setText("Server configuration:"); 570 571 labelConf.setText("Configuration root:"); 573 labelAutoFile.setText("Deploy file:"); 575 textAutoFile.setEnabled(false); 576 textAutoFile.setEditable(false); 577 textAutoFile.setText("AUTODEPLOY FILE"); 578 buttonAutoFile.setText("..."); 579 checkEnable.setSelected(true); 580 checkEnable.setText("Enable run configuration"); 581 checkEnable.setActionCommand("checkEnable"); 582 this.setLayout(layoutMain); 583 this.add(labelConf, 584 new GridBagConstraints(0, 6, 1, 1, 0.1, 0.0, 585 GridBagConstraints.WEST, 586 GridBagConstraints.HORIZONTAL, 587 new Insets(3, 35, 3, 5), 0, 0)); 588 this.add(textConf, 589 new GridBagConstraints(1, 6, 2, 1, 0.6, 0.0, 590 GridBagConstraints.WEST, 591 GridBagConstraints.HORIZONTAL, 592 new Insets(3, 5, 3, 5), 0, 0)); 593 this.add(labelBoot, 594 new GridBagConstraints(0, 5, 1, 1, 0.1, 0.0, 595 GridBagConstraints.CENTER, 596 GridBagConstraints.HORIZONTAL, 597 new Insets(3, 35, 3, 5), 0, 0)); 598 this.add(textBoot, 599 new GridBagConstraints(1, 5, 1, 1, 0.6, 0.0, 600 GridBagConstraints.WEST, 601 GridBagConstraints.HORIZONTAL, 602 new Insets(3, 5, 3, 5), 0, 0)); 603 this.add(buttonBoot, 604 new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0, 605 GridBagConstraints.CENTER, 606 GridBagConstraints.NONE, 607 new Insets(3, 5, 3, 5), 0, 0)); 608 this.add(radioAuto, 609 new GridBagConstraints(0, 1, 3, 1, 0.1, 0.0, 610 GridBagConstraints.WEST, 611 GridBagConstraints.HORIZONTAL, 612 new Insets(5, 20, 0, 5), 0, 0)); 613 this.add(radioIDE, 614 new GridBagConstraints(0, 4, 3, 1, 0.1, 0.0, 615 GridBagConstraints.WEST, 616 GridBagConstraints.HORIZONTAL, 617 new Insets(10, 20, 0, 5), 0, 0)); 618 this.add(labelAuto, 619 new GridBagConstraints(0, 2, 1, 1, 0.1, 0.0, 620 GridBagConstraints.CENTER, 621 GridBagConstraints.HORIZONTAL, 622 new Insets(3, 35, 3, 5), 0, 0)); 623 this.add(textAuto, 624 new GridBagConstraints(1, 2, 1, 1, 0.6, 0.0, 625 GridBagConstraints.WEST, 626 GridBagConstraints.HORIZONTAL, 627 new Insets(3, 5, 3, 5), 0, 0)); 628 this.add(buttonAuto, 629 new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, 630 GridBagConstraints.CENTER, 631 GridBagConstraints.NONE, 632 new Insets(3, 5, 3, 5), 0, 0)); 633 this.add(labelAutoFile, 639 new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, 640 GridBagConstraints.WEST, 641 GridBagConstraints.HORIZONTAL, 642 new Insets(3, 35, 3, 0), 0, 0)); 643 this.add(textAutoFile, 644 new GridBagConstraints(1, 3, 1, 1, 0.6, 0.0, 645 GridBagConstraints.CENTER, 646 GridBagConstraints.HORIZONTAL, 647 new Insets(3, 5, 3, 5), 0, 0)); 648 this.add(buttonAutoFile, 649 new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0, 650 GridBagConstraints.CENTER, 651 GridBagConstraints.NONE, 652 new Insets(3, 5, 3, 5), 0, 0)); 653 this.add(checkEnable, 654 new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0, 655 GridBagConstraints.WEST, 656 GridBagConstraints.HORIZONTAL, 657 new Insets(0, 10, 0, 10), 0, 0)); 658 } 659 660 private class LocalRadioListener implements ItemListener { 662 public void itemStateChanged(ItemEvent e) { 663 if (e.getStateChange() == ItemEvent.SELECTED) { 664 radioRefresh(); 665 } 666 } 667 668 } 669 670 private class LocalButtonListener implements ActionListener { 672 public void actionPerformed(ActionEvent event) { 673 Object source = event.getSource(); 674 675 if (source == buttonAuto) { 676 browseForAutoDirectory(); 679 } else if (source == buttonAutoFile) { 680 browseForAutoFile(); 683 } else if (source == buttonBoot) { 684 browseForBootFile(); 687 } 688 } 689 690 } 691 692 private class LocalCheckListener implements ChangeListener { 694 public void stateChanged(ChangeEvent e) { 695 Object source = e.getSource(); 696 697 if (source == checkEnable) { 698 refreshEnable(); 699 } 700 } 701 702 } 703 704 708 private void browseForAutoDirectory() { 709 JFileChooser chooser; 710 File file; 711 String fileDir = new String (); 712 String fileName = new String (); 713 714 chooser = new JFileChooser(); 715 if (textAuto.getText().trim().length() > 0) { 716 chooser.setCurrentDirectory(new File (textAuto.getText())); 717 } else { 718 PathHandle ph = null; 719 720 chooser.setCurrentDirectory(new File ("")); 721 } 722 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 723 chooser.setFileFilter((javax.swing.filechooser.FileFilter ) new DirectoryFilter()); 724 chooser.setDialogTitle(res.getString("chooser_AutoDeployDirectory_DialogTitle")); 725 chooser.setApproveButtonText(res.getString("OK")); 726 int v = chooser.showOpenDialog(this); 727 728 this.requestFocus(); 729 buttonAuto.requestFocus(); 730 if (v == JFileChooser.APPROVE_OPTION) { 731 if (chooser.getSelectedFile() == null) { 732 textAuto.setText(new String ()); 733 } else { 734 fileDir = chooser.getCurrentDirectory().toString(); 735 fileDir = stripSlash(fileDir); 736 fileName = chooser.getSelectedFile().getName(); 737 String strDeployRoot = fileDir + File.separator + fileName; 738 textAuto.setText(strDeployRoot.replace('\\','/')); 739 } 740 } 741 chooser.removeAll(); 742 chooser = null; 743 } 744 745 749 private void browseForBootFile() { 750 JFileChooser chooser; 751 ExtensionFilter filter; 752 File file; 753 String fileDir = new String (); 754 String fileName = new String (); 755 756 filter = new ExtensionFilter(); 757 filter.addExtension(Constants.TYPE_CONF); 758 filter.setDescriptionTitle(res.getString("filter_Conf_DescriptionTitle")); 759 chooser = new JFileChooser(); 760 if (textBoot.getText().trim().length() > 0) { 761 chooser.setCurrentDirectory(new File (textBoot.getText())); 762 } else { 763 PathHandle ph = null; 764 chooser.setCurrentDirectory(new File ("")); 765 } 766 chooser.setFileFilter(filter); 767 chooser.setDialogTitle(res.getString("chooser_BootFile_DialogTitle")); 768 chooser.setApproveButtonText(res.getString("OK")); 769 int v = chooser.showOpenDialog(this); 770 771 this.requestFocus(); 772 buttonBoot.requestFocus(); 773 if (v == JFileChooser.APPROVE_OPTION) { 774 if (chooser.getSelectedFile() == null 775 || (!chooser.getSelectedFile().isFile())) { 776 textBoot.setText(new String ()); 777 } else { 778 fileDir = chooser.getCurrentDirectory().toString(); 779 fileDir = stripSlash(fileDir); 780 fileName = chooser.getSelectedFile().getName(); 781 textBoot.setText(fileDir + File.separator + fileName); 782 } 783 } 784 chooser.removeAll(); 785 chooser = null; 786 } 787 788 792 private void browseForAutoFile() { 793 JFileChooser chooser; 794 ExtensionFilter filter; 795 File file; 796 String fileDir = new String (); 797 String fileName = new String (); 798 799 filter = new ExtensionFilter(); 800 filter.addExtension(Constants.TYPE_WAR); 801 filter.setDescriptionTitle(res.getString("filter_War_DescriptionTitle")); 802 chooser = new JFileChooser(); 803 if (textAutoFile.getText().trim().length() > 0) { 804 chooser.setCurrentDirectory(new File (textAutoFile.getText())); 805 } else { 806 PathHandle ph = null; 807 chooser.setCurrentDirectory(new File ("")); 808 } 809 chooser.setFileFilter(filter); 810 chooser.setDialogTitle(res.getString("chooser_AutoDeployFile_DialogTitle")); 811 chooser.setApproveButtonText(res.getString("OK")); 812 int v = chooser.showOpenDialog(this); 813 814 this.requestFocus(); 815 buttonAutoFile.requestFocus(); 816 if (v == JFileChooser.APPROVE_OPTION) { 817 if (chooser.getSelectedFile() == null 818 || (!chooser.getSelectedFile().isFile())) { 819 textAutoFile.setText(new String ()); 820 } else { 821 fileDir = chooser.getCurrentDirectory().toString(); 822 fileDir = stripSlash(fileDir); 823 fileName = chooser.getSelectedFile().getName(); 824 textAutoFile.setText(fileDir + File.separator + fileName); 825 } 826 } 827 chooser.removeAll(); 828 chooser = null; 829 } 830 831 839 private String stripSlash(String dir) { 840 String stripped = new String (dir); 841 842 if (dir != null) { 843 if (dir.length() > 0) { 844 if (dir.endsWith(File.separator)) { 845 stripped = dir.substring(0, dir.length() - 1); 846 } 847 } 848 } 849 return stripped; 850 } 851 } 852 | Popular Tags |