1 19 package org.netbeans.modules.xsl.ui; 20 21 import java.beans.PropertyChangeEvent ; 22 import java.beans.PropertyChangeListener ; 23 import java.beans.PropertyChangeSupport ; 24 import java.io.File ; 25 import java.io.IOException ; 26 import java.net.URL ; 27 import java.net.MalformedURLException ; 28 import java.awt.*; 29 import javax.swing.*; 30 import java.util.Vector ; 31 32 import javax.xml.transform.*; 33 34 import org.openide.loaders.DataObject; 35 import org.openide.loaders.RepositoryNodeFactory; 36 import org.openide.filesystems.*; 37 import org.openide.util.Lookup; 38 import org.openide.DialogDisplayer; 39 import org.openide.NotifyDescriptor; 40 41 import org.netbeans.api.xml.cookies.TransformableCookie; 42 43 import org.netbeans.modules.xsl.settings.TransformHistory; 44 import org.netbeans.modules.xsl.utils.TransformUtil; 45 46 51 public final class TransformPanel extends javax.swing.JPanel { 52 53 private static final long serialVersionUID = -3449709794133206327L; 54 55 public static final String DATA_XML_MODIFIED="DATA_XML_MODIFIED"; 56 public static final String DATA_XSL_MODIFIED="DATA_XSL_MODIFIED"; 57 public static final String DATA_OUTPUT_MODIFIED="DATA_OUTPUT_MODIFIED"; 58 public static final String DATA_PROCESS_MODIFIED="DATA_PROCESS_MODIFIED"; 59 public static final String DATA_OVERWRITE_MODIFIED="DATA_OVERWRITE_MODIFIED"; 60 61 private URL baseURL; 62 private Data data; 63 private boolean initialized = false; 64 65 private DataObject xmlDataObject; 66 private String xml_stylesheet; private DataObject xslDataObject; 68 private TransformHistory xmlHistory; 69 private TransformHistory xslHistory; 70 71 private boolean userSetOutput = false; 72 private boolean userSetProcess = false; 73 private String lastOutputFileExt = TransformUtil.DEFAULT_OUTPUT_EXT; 74 private Object lastXSLObject = new Object (); 75 76 77 private boolean suppressXSL; 78 79 80 private static final String [] SHOW_NAMES = new String [] { 81 Util.THIS.getString("NAME_process_output_do_nothing"), Util.THIS.getString("NAME_process_output_apply_default_action"), Util.THIS.getString("NAME_process_output_open_in_browser"), }; 85 86 private static final Object JUST_PREVIEW = new Preview(); 87 88 89 public TransformPanel (DataObject xml, String xml_ss, DataObject xsl, boolean suppressXSL) throws MalformedURLException , FileStateInvalidException { 90 initComponents(); 91 92 init(xml, xml_ss, xsl, suppressXSL); 93 initAccessibility(); 94 } 95 96 97 public TransformPanel(DataObject xml, String xml_ss, DataObject xsl) throws MalformedURLException , FileStateInvalidException { 98 this(xml, xml_ss, xsl, false); 99 } 100 101 private void init(DataObject xml, String xml_ss, DataObject xsl, boolean supXSL) throws MalformedURLException , FileStateInvalidException { 102 data = new Data(); 103 xmlDataObject = xml; 104 xml_stylesheet = xml_ss; 105 xslDataObject = xsl; 106 suppressXSL = supXSL; 107 108 if ( xmlDataObject != null ) { 109 setInput(TransformUtil.getURLName(xmlDataObject.getPrimaryFile())); 110 FileObject xmlFileObject = xmlDataObject.getPrimaryFile(); 111 xmlHistory = (TransformHistory)xmlFileObject.getAttribute(TransformHistory.TRANSFORM_HISTORY_ATTRIBUTE); 112 if ( xmlHistory != null ) { 113 setXSL(xmlHistory.getLastXSL()); 114 } 115 if ( ( data.xsl == null ) && 116 ( xml_stylesheet != null ) ) { 117 setXSL(xml_stylesheet); 118 } 119 try { 120 baseURL = xmlFileObject.getParent().getURL(); 121 } catch (FileStateInvalidException exc) { 122 } 124 } 125 if ( xslDataObject != null ) { 126 setXSL(TransformUtil.getURLName(xslDataObject.getPrimaryFile())); 127 FileObject xslFileObject = xslDataObject.getPrimaryFile(); 128 xslHistory = (TransformHistory)xslFileObject.getAttribute(TransformHistory.TRANSFORM_HISTORY_ATTRIBUTE); 129 if ( ( data.xml == null ) && ( xslHistory != null ) ) { 130 setInput(xslHistory.getLastXML()); 131 } 132 if ( baseURL == null ) { 133 try { 134 baseURL = xslFileObject.getParent().getURL(); 135 } catch (FileStateInvalidException exc) { 136 } 138 } 139 } 140 141 if ( ( xmlHistory != null ) || ( xslHistory != null ) ) { 142 if ( xmlHistory != null ) { 143 setOutput(xmlHistory.getLastXSLOutput()); 144 } 145 if ( ( data.output == null || (data.output instanceof String && "".equals(data.output)) ) && 146 ( xslHistory != null ) ) { 147 setOutput(xslHistory.getLastXMLOutput()); 148 } 149 if ( data.output == null ) { 150 setOutput(JUST_PREVIEW); 151 } 152 } 153 154 if ( xmlHistory != null ) { 155 setOverwriteOutput( xmlHistory.isOverwriteOutput()); 156 setProcessOutput(new Integer (xmlHistory.getProcessOutput())); 157 } else if ( xslHistory != null ) { 158 setOverwriteOutput( xslHistory.isOverwriteOutput()); 159 setProcessOutput(new Integer (xslHistory.getProcessOutput())); 160 } 161 162 ownInitComponents(); 163 } 164 165 166 private void ownInitComponents() { 167 updateXMLComboBoxModel(null); 169 updateXSLComboBoxModel(null); 171 172 updateComponents(); 173 174 setCaretPosition(inputComboBox); 175 setCaretPosition(transformComboBox); 176 setCaretPosition(outputComboBox); 177 } 178 179 180 private void setCaretPosition(JComboBox comboBox) { 181 ComboBoxEditor cbEditor = comboBox.getEditor(); 182 final Component editorComponent = cbEditor.getEditorComponent(); 183 184 if ( Util.THIS.isLoggable() ) { 185 Util.THIS.debug("TransformPanel.setCaretPosition: " + comboBox); 186 Util.THIS.debug(" editorComponent = " + editorComponent); 187 } 188 189 if ( editorComponent instanceof JTextField ) { 190 SwingUtilities.invokeLater 191 (new Runnable () { 192 public void run() { 193 JTextField textField = (JTextField) editorComponent; 194 int length = textField.getText().length(); 195 textField.setCaretPosition(length); 196 197 if ( Util.THIS.isLoggable() ) { 198 Util.THIS.debug(" text[" + length + "]='" + textField.getText() + "' - " + textField.getCaretPosition()); 199 } 200 } 201 } 202 ); 203 } 204 } 205 206 private void updateXMLComboBoxModel(Object prefItem) { 207 Object [] history = null; 208 if ( ( xmlDataObject == null ) && 209 ( xslHistory != null ) ) { 210 history = xslHistory.getXMLs(); 211 } 212 213 Vector cbModel = new Vector (); 214 215 if ( prefItem != null ) { 217 cbModel.add(prefItem); 218 } 219 if ( history != null ) { 221 for ( int i = 0; i < history.length; i++ ) { 222 cbModel.add(history[i]); 223 } 224 } 225 226 inputComboBox.setModel(new DefaultComboBoxModel(cbModel)); 227 } 228 229 private void updateXSLComboBoxModel(Object prefItem) { 230 Object [] history = null; 231 if ( ( xslDataObject == null ) && 232 ( xmlHistory != null ) ) { 233 history = xmlHistory.getXSLs(); 234 } 235 236 Vector cbModel = new Vector (); 237 238 if ( prefItem != null ) { 240 cbModel.add(prefItem); 241 } 242 if ( xml_stylesheet != null ) { 244 cbModel.add(xml_stylesheet); 245 } 246 if ( history != null ) { 248 for ( int i = 0; i < history.length; i++ ) { 249 if ( ( history[i] != null ) && 250 ( history[i].equals(xml_stylesheet) == false ) ) { cbModel.add(history[i]); 252 } 253 } 254 } 255 256 transformComboBox.setModel(new DefaultComboBoxModel(cbModel)); 257 } 258 259 private boolean isInitialized() { 260 synchronized ( data ) { 261 return initialized; 262 } 263 } 264 265 private void setInitialized(boolean init) { 266 synchronized ( data ) { 267 initialized = init; 268 } 269 } 270 271 private static String guessFileName(String xml) { 272 String fileName = null; 273 274 int slashIndex = xml.lastIndexOf('/'); 275 if ( slashIndex != -1 ) { 276 fileName = xml.substring(slashIndex + 1); 277 } else { 278 fileName = xml; 279 } 280 281 return fileName; 282 } 283 284 private String guessOutputFileExt() { 285 String ext = lastOutputFileExt; 286 String xslObject = getXSL(); 287 288 if ( xslObject != lastXSLObject ) { 289 try { 290 Source xslSource; 291 xslSource = TransformUtil.createSource(baseURL, xslObject); 292 ext = TransformUtil.guessOutputExt(xslSource); 293 294 lastXSLObject = xslObject; 296 lastOutputFileExt = ext; 297 } catch (Exception exc) { 298 300 if ( Util.THIS.isLoggable() ) Util.THIS.debug("[TransformPanel] Cannot guess extension!", exc); 301 } 302 } 303 304 if ( Util.THIS.isLoggable() ) Util.THIS.debug("[TransformPanel] I guess output has '" + ext + "' extension."); 305 306 return ext; 307 } 308 309 private Object guessOutputFile() { 310 Object output = data.output; 311 312 if ( output == null || "".equals(output) || JUST_PREVIEW.equals(output)) { 313 String origName = guessFileName(data.xml); 314 String origExt = ""; 315 int dotIndex = origName.lastIndexOf('.'); 316 if ( dotIndex != -1 ) { 317 origExt = origName.substring(dotIndex + 1); 318 origName = origName.substring(0, dotIndex); 319 } 320 321 String ext = guessOutputFileExt(); 322 String plusName = ""; 323 if ( ext.equals(origExt) ) { 324 plusName = Util.THIS.getString("NAME_plusNameIfSameName"); 325 } 326 327 output = origName + plusName + "." + ext; } 329 330 return output; 331 } 332 333 private void initOutputComboBox(Object defaultOutput) { 334 outputComboBox.setModel(new DefaultComboBoxModel(new Object [] { defaultOutput, JUST_PREVIEW })); 335 } 336 337 338 private void updateComponents() { 339 setInitialized(false); 340 341 boolean notXML = ( xmlDataObject == null ); 343 if ( data.xml != null ) { 344 inputComboBox.setSelectedItem(data.xml); 345 inputComboBox.setEditable(data.xml instanceof String ); 346 } 347 inputComboBox.setEnabled(notXML); 348 browseInputButton.setEnabled(notXML); 349 350 if ( suppressXSL ) { 352 transformLabel.setVisible(false); 353 transformComboBox.setVisible(false); 354 browseXSLTButton.setVisible(false); 355 } else { 356 transformLabel.setVisible(true); 357 transformComboBox.setVisible(true); 358 browseXSLTButton.setVisible(true); 359 360 boolean notXSL = ( xslDataObject == null ); 361 transformComboBox.setEnabled(notXSL); 362 browseXSLTButton.setEnabled(notXSL); 363 if ( data.xsl != null ) { 364 transformComboBox.setSelectedItem(data.xsl); 365 transformComboBox.setEditable(data.xsl instanceof String ); 366 } 367 } 368 369 boolean canOutput = true; 371 if ( ( data.xml == null ) || 372 ( data.xsl == null ) || 373 ( data.xml.length() == 0 ) || 374 ( data.xsl.length() == 0 ) ) { 375 canOutput = false; 376 } 377 378 outputComboBox.setEnabled(canOutput); 380 if ( canOutput ) { 381 Object output = guessOutputFile(); 382 initOutputComboBox(output); 383 384 outputComboBox.setSelectedItem(data.output != null ? output : JUST_PREVIEW); 385 outputComboBox.setEditable(data.output != null); 386 } 387 388 if ( data.overwrite != null ) { 390 overwriteCheckBox.setSelected(data.overwrite.booleanValue()); 391 } 392 overwriteCheckBox.setEnabled(canOutput && data.output != null); 393 394 if ( data.process != null ) { 396 showComboBox.setSelectedIndex(data.process.intValue()); 397 } else { 398 String ext = guessOutputFileExt().toLowerCase(); 399 if ( ext.equals("html") || ext.equals("htm") ) { showComboBox.setSelectedIndex(TransformHistory.OPEN_IN_BROWSER); 401 } else { 402 showComboBox.setSelectedIndex(TransformHistory.APPLY_DEFAULT_ACTION); 403 } 404 } 405 showComboBox.setEnabled(canOutput && data.output != null); 406 407 setInitialized(true); 408 } 409 410 411 public Data getData() { 412 return new Data (getInput(), getXSL(), getOutput(), isOverwriteOutput(), getProcessOutput()); 413 } 414 415 public void setData(Data data) { 416 this.data = data; 417 updateComponents(); 418 } 419 420 423 private String getInput() { 424 return (String ) inputComboBox.getSelectedItem(); 425 } 426 427 430 private String getXSL() { 431 return (String ) transformComboBox.getSelectedItem(); 432 } 433 434 437 private String getOutput() { 438 Object output = outputComboBox.getSelectedItem(); 439 440 if ( JUST_PREVIEW.equals(output) ) { 441 return null; 442 } 443 return (String ) output; 444 } 445 446 449 private boolean isOverwriteOutput() { 450 return overwriteCheckBox.isSelected(); 451 } 452 453 456 private int getProcessOutput() { 457 return showComboBox.getSelectedIndex(); 458 } 459 460 464 private Dimension comboSize(int columns) { 465 JTextField template = new JTextField(); 466 template.setColumns(columns); 467 return template.getPreferredSize(); 468 } 469 470 475 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 477 478 inputLabel = new javax.swing.JLabel (); 479 inputLabel.setDisplayedMnemonic (Util.THIS.getChar ("LBL_XML_input_mnemonic")); 480 inputComboBox = new javax.swing.JComboBox (); 481 browseInputButton = new javax.swing.JButton (); 482 transformLabel = new javax.swing.JLabel (); 483 transformLabel.setDisplayedMnemonic (Util.THIS.getChar ("LBL_XSL_transform_mnemonic")); 484 transformComboBox = new javax.swing.JComboBox (); 485 browseXSLTButton = new javax.swing.JButton (); 486 outputLabel = new javax.swing.JLabel (); 487 outputLabel.setDisplayedMnemonic (Util.THIS.getChar ("LBL_trans_output_mnemonic")); 488 outputComboBox = new javax.swing.JComboBox (); 489 overwriteCheckBox = new javax.swing.JCheckBox (); 490 overwriteCheckBox.setMnemonic (Util.THIS.getChar ("LBL_over_write_mnemonic")); 491 showLabel = new javax.swing.JLabel (); 492 showLabel.setDisplayedMnemonic (Util.THIS.getChar ("LBL_show_output_mnemonic")); 493 showComboBox = new javax.swing.JComboBox (); 494 495 FormListener formListener = new FormListener(); 496 497 setLayout(new java.awt.GridBagLayout ()); 498 499 inputLabel.setLabelFor(inputComboBox); 500 inputLabel.setText(Util.THIS.getString ("LBL_XML_input")); 501 gridBagConstraints = new java.awt.GridBagConstraints (); 502 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 503 gridBagConstraints.insets = new java.awt.Insets (6, 12, 0, 0); 504 add(inputLabel, gridBagConstraints); 505 506 inputComboBox.setEditable(true); 507 inputComboBox.setPreferredSize(comboSize(40)); 508 inputComboBox.addActionListener(formListener); 509 510 gridBagConstraints = new java.awt.GridBagConstraints (); 511 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 512 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 513 gridBagConstraints.weightx = 1.0; 514 add(inputComboBox, gridBagConstraints); 515 516 browseInputButton.setMnemonic(Util.THIS.getChar ("LBL_browse_file_mnemonic")); 517 browseInputButton.setText(Util.THIS.getString ("LBL_browse_file")); 518 browseInputButton.addActionListener(formListener); 519 520 gridBagConstraints = new java.awt.GridBagConstraints (); 521 gridBagConstraints.insets = new java.awt.Insets (12, 5, 0, 11); 522 add(browseInputButton, gridBagConstraints); 523 524 transformLabel.setLabelFor(transformComboBox); 525 transformLabel.setText(Util.THIS.getString ("LBL_XSL_transform")); 526 gridBagConstraints = new java.awt.GridBagConstraints (); 527 gridBagConstraints.gridx = 0; 528 gridBagConstraints.gridy = 1; 529 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 530 gridBagConstraints.insets = new java.awt.Insets (6, 12, 0, 0); 531 add(transformLabel, gridBagConstraints); 532 533 transformComboBox.setEditable(true); 534 transformComboBox.setPreferredSize(comboSize(40)); 535 transformComboBox.addActionListener(formListener); 536 537 gridBagConstraints = new java.awt.GridBagConstraints (); 538 gridBagConstraints.gridx = 1; 539 gridBagConstraints.gridy = 1; 540 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 541 gridBagConstraints.insets = new java.awt.Insets (5, 12, 0, 0); 542 gridBagConstraints.weightx = 1.0; 543 add(transformComboBox, gridBagConstraints); 544 545 browseXSLTButton.setMnemonic(Util.THIS.getChar ("LBL_browse_xslt_mnemonic")); 546 browseXSLTButton.setText(Util.THIS.getString ("LBL_browse_xslt")); 547 browseXSLTButton.addActionListener(formListener); 548 549 gridBagConstraints = new java.awt.GridBagConstraints (); 550 gridBagConstraints.gridx = 2; 551 gridBagConstraints.gridy = 1; 552 gridBagConstraints.insets = new java.awt.Insets (5, 5, 0, 11); 553 add(browseXSLTButton, gridBagConstraints); 554 555 outputLabel.setLabelFor(outputComboBox); 556 outputLabel.setText(Util.THIS.getString ("LBL_trans_output")); 557 gridBagConstraints = new java.awt.GridBagConstraints (); 558 gridBagConstraints.gridx = 0; 559 gridBagConstraints.gridy = 2; 560 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 561 gridBagConstraints.insets = new java.awt.Insets (6, 12, 0, 0); 562 add(outputLabel, gridBagConstraints); 563 564 outputComboBox.setEditable(true); 565 outputComboBox.setPreferredSize(comboSize(40)); 566 outputComboBox.addActionListener(formListener); 567 568 gridBagConstraints = new java.awt.GridBagConstraints (); 569 gridBagConstraints.gridx = 1; 570 gridBagConstraints.gridy = 2; 571 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 572 gridBagConstraints.insets = new java.awt.Insets (5, 12, 0, 0); 573 gridBagConstraints.weightx = 1.0; 574 add(outputComboBox, gridBagConstraints); 575 576 overwriteCheckBox.setSelected(true); 577 overwriteCheckBox.setText(Util.THIS.getString ("LBL_over_write")); 578 overwriteCheckBox.addActionListener(formListener); 579 580 gridBagConstraints = new java.awt.GridBagConstraints (); 581 gridBagConstraints.gridx = 1; 582 gridBagConstraints.gridy = 4; 583 gridBagConstraints.insets = new java.awt.Insets (5, 12, 0, 0); 584 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 585 add(overwriteCheckBox, gridBagConstraints); 586 587 showLabel.setText(Util.THIS.getString ("LBL_show_output")); 588 gridBagConstraints = new java.awt.GridBagConstraints (); 589 gridBagConstraints.gridx = 0; 590 gridBagConstraints.gridy = 5; 591 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 592 gridBagConstraints.insets = new java.awt.Insets (6, 12, 6, 0); 593 add(showLabel, gridBagConstraints); 594 595 showComboBox.setModel(new javax.swing.DefaultComboBoxModel (SHOW_NAMES)); 596 showComboBox.addActionListener(formListener); 597 598 gridBagConstraints = new java.awt.GridBagConstraints (); 599 gridBagConstraints.gridx = 1; 600 gridBagConstraints.gridy = 5; 601 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 602 gridBagConstraints.insets = new java.awt.Insets (11, 12, 6, 0); 603 gridBagConstraints.weightx = 1.0; 604 add(showComboBox, gridBagConstraints); 605 606 } 607 608 610 private class FormListener implements java.awt.event.ActionListener { 611 public void actionPerformed(java.awt.event.ActionEvent evt) { 612 if (evt.getSource() == inputComboBox) { 613 TransformPanel.this.inputComboBoxActionPerformed(evt); 614 } 615 else if (evt.getSource() == browseInputButton) { 616 TransformPanel.this.browseInputButtonActionPerformed(evt); 617 } 618 else if (evt.getSource() == transformComboBox) { 619 TransformPanel.this.transformComboBoxActionPerformed(evt); 620 } 621 else if (evt.getSource() == browseXSLTButton) { 622 TransformPanel.this.browseXSLTButtonActionPerformed(evt); 623 } 624 else if (evt.getSource() == outputComboBox) { 625 TransformPanel.this.outputComboBoxActionPerformed(evt); 626 } 627 else if (evt.getSource() == overwriteCheckBox) { 628 TransformPanel.this.overwriteCheckBoxActionPerformed(evt); 629 } 630 else if (evt.getSource() == showComboBox) { 631 TransformPanel.this.showComboBoxActionPerformed(evt); 632 } 633 } 634 } 636 637 639 private void initAccessibility() { 640 this.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_TransformPanel")); 641 642 overwriteCheckBox.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_overwriteCheckBox")); 643 outputComboBox.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_outputComboBox")); 644 inputComboBox.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_inputComboBox")); 645 browseXSLTButton.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_browseXSLTButton")); 646 showComboBox.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_showComboBox")); 647 browseInputButton.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_browseInputButton")); 648 transformComboBox.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_transformComboBox")); 649 } 650 651 652 private void browseXSLTButtonActionPerformed(java.awt.event.ActionEvent evt) { 654 try { 655 File selectedFile=getFileFromChooser(getXSL()); 656 if (selectedFile==null) return; 657 FileObject fo = FileUtil.toFileObject(selectedFile); 658 DataObject dObj = DataObject.find(fo); 659 if (dObj==null || !TransformUtil.isXSLTransformation(dObj)) { 660 NotifyDescriptor desc = new NotifyDescriptor.Message( 661 Util.THIS.getString("MSG_notXslFile", selectedFile.getName()),NotifyDescriptor.ERROR_MESSAGE); 663 DialogDisplayer.getDefault().notify(desc); 664 return; 665 } 666 setXSL(TransformUtil.getURLName(fo)); 667 668 if ( ( userSetOutput == false ) && ( xmlHistory != null ) ) { 669 setOutput(xmlHistory.getXSLOutput(data.xsl)); 670 } 671 if ( userSetProcess == false ) { 672 setProcessOutput(null); 673 } 674 updateXSLComboBoxModel(data.xsl); 675 676 updateComponents(); 677 678 setCaretPosition(transformComboBox); 679 680 } catch (IOException exc) { Util.THIS.debug(exc); 683 } finally { 684 Util.icons = null; 685 } 686 } 688 private void browseInputButtonActionPerformed(java.awt.event.ActionEvent evt) { 690 try { 691 File selectedFile=getFileFromChooser(getInput()); 692 if (selectedFile==null) return; 693 FileObject fo = FileUtil.toFileObject(selectedFile); 694 DataObject dObj = DataObject.find(fo); 695 if (dObj==null || dObj.getCookie(TransformableCookie.class)==null) { 696 NotifyDescriptor desc = new NotifyDescriptor.Message( 697 Util.THIS.getString("MSG_notXmlFile", selectedFile.getName()),NotifyDescriptor.ERROR_MESSAGE); 699 DialogDisplayer.getDefault().notify(desc); 700 return; 701 } 702 setInput(TransformUtil.getURLName(fo)); 703 704 if ( ( userSetOutput == false ) && ( xslHistory != null ) ) { 705 setOutput(xslHistory.getXMLOutput(data.xml)); 706 } 707 if ( userSetProcess == false ) { 708 setProcessOutput(null); 709 } 710 updateXMLComboBoxModel(data.xml); 711 712 updateComponents(); 713 714 setCaretPosition(inputComboBox); 715 716 } catch (IOException exc) { Util.THIS.debug(exc); 719 } finally { 720 Util.icons = null; 721 } 722 } 724 public void setInput(String input) { 725 if(data==null) { 726 return; 727 } 728 String oldInput=data.getInput(); 729 data.setInput(input); 730 firePropertyChange(DATA_XML_MODIFIED,oldInput,input); 731 } 732 733 public void setXSL(String xslValue) { 734 if(data==null) { 735 return; 736 } 737 String oldXSL=data.getXSL(); 738 data.setXSL(xslValue); 739 firePropertyChange(DATA_XSL_MODIFIED,oldXSL,xslValue); 740 } 741 742 public void setOutput(Object outputValue) { 743 if(data==null) { 744 return; 745 } 746 Object oldOutput=data.getOutput(); 747 data.setOutput(outputValue); 748 firePropertyChange(DATA_OUTPUT_MODIFIED,oldOutput,outputValue); 749 } 750 751 public void setOverwriteOutput(Boolean overwriteObject) { 752 if(data==null || overwriteObject==null) { 753 return; 754 } 755 setOverwriteOutput(overwriteObject.booleanValue()); 756 } 757 758 public void setOverwriteOutput(boolean overwriteValue) { 759 if(data==null) { 760 return; 761 } 762 boolean oldOverwrite=data.isOverwriteOutput(); 763 data.setOverwriteOutput(overwriteValue); 764 firePropertyChange(DATA_OVERWRITE_MODIFIED,oldOverwrite,overwriteValue); 765 } 766 767 public void setProcessOutput(Integer processObject) { 768 if(data==null || processObject==null) { 769 return; 770 } 771 setProcessOutput(processObject.intValue()); 772 } 773 774 public void setProcessOutput(int processValue) { 775 if(data==null) { 776 return; 777 } 778 int oldProcess=data.getProcessOutput(); 779 data.setProcessOutput(processValue); 780 firePropertyChange(DATA_PROCESS_MODIFIED,oldProcess,processValue); 781 } 782 783 private void showComboBoxActionPerformed(java.awt.event.ActionEvent evt) { if ( isInitialized() ) { 786 setProcessOutput(new Integer (showComboBox.getSelectedIndex())); 787 userSetProcess = true; 788 updateComponents(); 789 } 790 } 792 private void overwriteCheckBoxActionPerformed(java.awt.event.ActionEvent evt) { if ( isInitialized() ) { 795 setOverwriteOutput( overwriteCheckBox.isSelected() ); 796 updateComponents(); 797 } 798 } 800 private void transformComboBoxActionPerformed(java.awt.event.ActionEvent evt) { if ( isInitialized() ) { 803 String item = (String ) transformComboBox.getSelectedItem(); 804 805 if ( Util.THIS.isLoggable() ) { 806 Util.THIS.debug("TransformPanel.transformComboBoxActionPerformed: getSelectedItem = " + item); 807 } 808 809 if ( item == null ) { 810 return; 811 } 812 813 setXSL(item.trim()); 814 815 if ( ( userSetOutput == false ) && ( xmlHistory != null ) ) { 816 setOutput(xmlHistory.getXSLOutput(data.xsl)); 817 } 818 if ( userSetProcess == false ) { 819 setProcessOutput(null); 820 } 821 822 updateComponents(); 823 824 } 826 } 828 private void inputComboBoxActionPerformed(java.awt.event.ActionEvent evt) { if ( isInitialized() ) { 831 String item = (String ) inputComboBox.getSelectedItem(); 832 833 if ( Util.THIS.isLoggable() ) { 834 Util.THIS.debug("TransformPanel.inputComboBoxActionPerformed: getSelectedItem = " + item); 835 } 836 837 if ( item == null ) { 838 return; 839 } 840 841 setInput(item.trim()); 842 843 if ( ( userSetOutput == false ) && ( xslHistory != null ) ) { 844 setOutput(xslHistory.getXMLOutput(data.xml)); 845 } 846 if ( userSetProcess == false ) { 847 setProcessOutput(null); 848 } 849 850 updateComponents(); 851 852 } 854 } 856 private void outputComboBoxActionPerformed(java.awt.event.ActionEvent evt) { if ( isInitialized() ) { 859 Object item = outputComboBox.getSelectedItem(); 860 if ( item instanceof String ) { 861 String str = ((String ) item).trim(); 862 if ( str.length() == 0 ) { 863 str = null; 864 } 865 item = str; 866 } 867 setOutput(item); 868 869 870 userSetOutput = true; 871 updateComponents(); 872 873 874 } 876 } 878 private javax.swing.JButton browseInputButton; 880 private javax.swing.JButton browseXSLTButton; 881 private javax.swing.JComboBox inputComboBox; 882 private javax.swing.JLabel inputLabel; 883 private javax.swing.JComboBox outputComboBox; 884 private javax.swing.JLabel outputLabel; 885 private javax.swing.JCheckBox overwriteCheckBox; 886 private javax.swing.JComboBox showComboBox; 887 private javax.swing.JLabel showLabel; 888 private javax.swing.JComboBox transformComboBox; 889 private javax.swing.JLabel transformLabel; 890 892 893 897 public static final class Data { 898 private String xml; 899 private String xsl; 900 private Object output; 901 private Boolean overwrite; 902 private Integer process; 903 904 public Data() { 905 this.xml = null; 906 this.xsl = null; 907 this.output = ""; 908 this.overwrite = null; 909 this.process = null; 910 } 911 912 public Data(String xml, String xsl, Object output, boolean overwrite, int process) { 913 this.xml = xml; 914 this.xsl = xsl; 915 this.output = output; 916 this.overwrite = overwrite ? Boolean.TRUE : Boolean.FALSE; 917 this.process = process == -1 ? null : new Integer (process); 918 } 919 920 923 public String getInput() { 924 return xml; 925 } 926 927 930 public String getXSL() { 931 return xsl; 932 } 933 934 937 public Object getOutput() { 938 return output; 939 } 940 941 944 public boolean isOverwriteOutput() { 945 if(overwrite==null) { 946 return false; 947 } 948 return overwrite.booleanValue(); 949 } 950 951 954 public int getProcessOutput() { 955 if(process==null) { 956 return 0; 957 } 958 return process.intValue(); 959 } 960 961 public void setInput(String input) { 962 xml=input; 963 } 964 965 public void setXSL(String xslValue) { 966 xsl=xslValue; 967 } 968 969 public void setOutput(Object outputValue) { 970 if (JUST_PREVIEW.equals(outputValue)) { 971 output = null; 972 } else { 973 output=outputValue; 974 } 975 } 976 977 public void setOverwriteOutput(boolean overwriteValue) { 978 overwrite = overwriteValue ? Boolean.TRUE : Boolean.FALSE; 979 } 980 981 public void setProcessOutput(Integer processObject) { 982 process=processObject; 983 } 984 985 public void setProcessOutput(int processValue) { 986 setProcessOutput(new Integer (processValue)); 987 } 988 989 public String toString() { 990 StringBuffer sb = new StringBuffer (super.toString()); 991 992 sb.append("[input='").append(xml).append("'; "); 993 sb.append("xsl='").append(xsl).append("'; "); 994 sb.append("output='").append(output).append("'; "); 995 sb.append("overwrite='").append(overwrite).append("'; "); 996 sb.append("process='").append(process).append("]"); 997 998 return sb.toString(); 999 } 1000 1001 } 1003 1004 1008 private static class Preview { 1009 public String toString() { 1010 return Util.THIS.getString("NAME_output_just_preview"); 1011 } 1012 } 1014 1015 1018 private File getFileFromChooser(String oldUrl) { 1019 javax.swing.JFileChooser chooser = new javax.swing.JFileChooser (); 1020 if (oldUrl!=null) { 1021 try { 1022 File file=null; 1023 java.net.URI url = new java.net.URI (oldUrl); 1024 if (url!=null) { 1025 file = new File (url); 1026 } 1027 if (file!=null) { 1028 File parentDir = file.getParentFile(); 1029 if (parentDir!=null && parentDir.exists() ) 1030 chooser.setCurrentDirectory(parentDir); 1031 } 1032 } catch (java.net.URISyntaxException ex) {} 1033 catch (java.lang.IllegalArgumentException x) {} 1034 } 1035 File selectedFile=null; 1036 if ( chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION ) { 1037 selectedFile = chooser.getSelectedFile(); 1038 } 1039 return selectedFile; 1040 } 1041 1042} 1043 | Popular Tags |