Revision 2179
Added by Duane Costa over 20 years ago
src/edu/ucsb/nceas/metacat/harvesterClient/HarvestListEditor.java | ||
---|---|---|
37 | 37 |
import java.io.PrintStream; |
38 | 38 |
import java.io.PrintWriter; |
39 | 39 |
import java.io.Reader; |
40 |
import java.util.Properties; |
|
40 | 41 |
import javax.swing.JButton; |
41 | 42 |
import javax.swing.JFileChooser; |
42 | 43 |
import javax.swing.JFrame; |
... | ... | |
51 | 52 |
import javax.swing.ListSelectionModel; |
52 | 53 |
import javax.swing.event.ListSelectionEvent; |
53 | 54 |
import javax.swing.event.ListSelectionListener; |
55 |
import javax.swing.table.AbstractTableModel; |
|
54 | 56 |
import javax.swing.table.TableColumn; |
55 | 57 |
import javax.swing.table.TableModel; |
56 | 58 |
import javax.swing.text.Document; |
... | ... | |
65 | 67 |
import org.xml.sax.helpers.DefaultHandler; |
66 | 68 |
import org.xml.sax.helpers.XMLReaderFactory; |
67 | 69 |
|
68 |
import edu.ucsb.nceas.metacat.harvesterClient.Harvester; |
|
69 |
import edu.ucsb.nceas.utilities.Options; |
|
70 |
|
|
71 |
|
|
72 | 70 |
/** |
73 | 71 |
* The Harvest List Editor reads a Harvest List XML file and displays it as a |
74 | 72 |
* JTable. Allows user to add, modify, or delete <Document> elements in the |
... | ... | |
77 | 75 |
*/ |
78 | 76 |
public class HarvestListEditor extends JFrame implements ActionListener { |
79 | 77 |
|
80 |
// Column names for the JTable |
|
81 |
String[] columnNames = { |
|
82 |
"Scope", |
|
83 |
"Identifier", |
|
84 |
"Revision", |
|
85 |
"Document Type", |
|
86 |
"Document URL" |
|
87 |
}; |
|
88 |
|
|
89 | 78 |
String clipboardDocumentType = ""; |
90 | 79 |
String clipboardDocumentURL = ""; |
91 | 80 |
String clipboardIdentifier = ""; |
... | ... | |
105 | 94 |
File harvestListFile; |
106 | 95 |
boolean harvestListHasChanged = false; |
107 | 96 |
JMenuBar menuBar; |
108 |
final int numColumns = 5;
|
|
97 |
final int numColumns = 6;
|
|
109 | 98 |
final int numRows = 300; |
110 |
Options options; |
|
111 |
boolean optionsTest = false; // true only for JUnit testing |
|
112 | 99 |
JButton pasteButton; |
113 | 100 |
JButton pasteDefaultsButton; |
114 |
Object[][] rowData = new Object[numRows][numColumns];
|
|
101 |
Properties properties;
|
|
115 | 102 |
private String schemaLocation = |
116 | 103 |
"eml://ecoinformatics.org/harvestList ../../lib/harvester/harvestList.xsd"; |
117 | 104 |
int selectedRow = -1; |
118 | 105 |
final JTable table; |
119 | 106 |
TableModel tableModel; |
107 |
File tempFile; |
|
108 |
String title = "Harvest List Editor"; |
|
120 | 109 |
|
121 | 110 |
// Menu items |
122 | 111 |
JMenuItem exitMenuItem = new JMenuItem("Exit"); |
... | ... | |
124 | 113 |
JMenuItem openMenuItem = new JMenuItem("Open..."); |
125 | 114 |
JMenuItem saveMenuItem = new JMenuItem("Save"); |
126 | 115 |
JMenuItem saveAsMenuItem = new JMenuItem("Save As..."); |
116 |
JMenuItem validateMenuItem = new JMenuItem("Validate"); |
|
127 | 117 |
|
128 | 118 |
|
129 | 119 |
/** |
... | ... | |
148 | 138 |
JMenu fileMenu = new JMenu("File"); |
149 | 139 |
char[] fileShortCuts = {'N', 'O', 'S', 'A', 'X'}; |
150 | 140 |
TableColumn tableColumn; |
151 |
|
|
152 |
// Load default values from the metacat.properties file |
|
153 |
Harvester.loadOptions(optionsTest); |
|
154 |
options = Harvester.options; |
|
155 |
defaultHarvestList = options.getOption("defaultHarvestList"); |
|
156 |
defaultDocumentType = options.getOption("defaultDocumentType"); |
|
157 |
defaultDocumentURL = options.getOption("defaultDocumentURL"); |
|
158 |
defaultIdentifier = options.getOption("defaultIdentifier"); |
|
159 |
defaultRevision = options.getOption("defaultRevision"); |
|
160 |
defaultScope = options.getOption("defaultScope"); |
|
161 |
System.out.println("defaultHarvestList: " + defaultHarvestList); |
|
162 |
System.out.println("defaultDocumentType: " + defaultDocumentType); |
|
163 |
System.out.println("defaultDocumentURL: " + defaultDocumentURL); |
|
164 |
System.out.println("defaultIdentifier: " + defaultIdentifier); |
|
165 |
System.out.println("defaultRevision: " + defaultRevision); |
|
166 |
System.out.println("defaultScope: " + defaultScope); |
|
167 |
|
|
141 |
|
|
142 |
loadProperties(); |
|
168 | 143 |
setSize(1000, 400); |
169 | 144 |
setDefaultCloseOperation(EXIT_ON_CLOSE); |
170 | 145 |
menuBar = new JMenuBar(); |
... | ... | |
197 | 172 |
saveAsMenuItem.addActionListener(this); |
198 | 173 |
fileMenu.add(saveAsMenuItem); |
199 | 174 |
|
175 |
validateMenuItem.setAccelerator(KeyStroke.getKeyStroke('V', |
|
176 |
java.awt.Event.CTRL_MASK, |
|
177 |
false)); |
|
178 |
validateMenuItem.addActionListener(this); |
|
179 |
fileMenu.add(validateMenuItem); |
|
180 |
|
|
200 | 181 |
exitMenuItem.setAccelerator(KeyStroke.getKeyStroke('X', |
201 | 182 |
java.awt.Event.CTRL_MASK, |
202 | 183 |
false)); |
... | ... | |
207 | 188 |
setJMenuBar(menuBar); // Set the frame's menu bar to this menu bar |
208 | 189 |
|
209 | 190 |
//table = new JTable(numRows, numColumns); |
210 |
table = new JTable(rowData, columnNames);
|
|
191 |
table = new JTable(new HarvestListTableModel());
|
|
211 | 192 |
table.setPreferredScrollableViewportSize(new Dimension(900, 300)); |
212 | 193 |
tableColumn = table.getColumnModel().getColumn(0); |
194 |
tableColumn.setPreferredWidth(30); |
|
195 |
tableColumn = table.getColumnModel().getColumn(1); |
|
213 | 196 |
tableColumn.setPreferredWidth(200); |
214 |
tableColumn = table.getColumnModel().getColumn(1); |
|
215 |
tableColumn.setPreferredWidth(50); |
|
216 | 197 |
tableColumn = table.getColumnModel().getColumn(2); |
217 | 198 |
tableColumn.setPreferredWidth(50); |
218 | 199 |
tableColumn = table.getColumnModel().getColumn(3); |
219 |
tableColumn.setPreferredWidth(300);
|
|
200 |
tableColumn.setPreferredWidth(50);
|
|
220 | 201 |
tableColumn = table.getColumnModel().getColumn(4); |
221 |
tableColumn.setPreferredWidth(300); |
|
202 |
tableColumn.setPreferredWidth(250); |
|
203 |
tableColumn = table.getColumnModel().getColumn(5); |
|
204 |
tableColumn.setPreferredWidth(320); |
|
222 | 205 |
|
223 | 206 |
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
224 | 207 |
tableModel = table.getModel(); |
208 |
initHarvestList(); |
|
225 | 209 |
|
226 | 210 |
//Ask to be notified of selection changes. |
227 | 211 |
ListSelectionModel rowSM = table.getSelectionModel(); |
... | ... | |
327 | 311 |
} |
328 | 312 |
} |
329 | 313 |
|
314 |
try { |
|
315 |
tempFile = File.createTempFile("harvestListTemp", ".xml"); |
|
316 |
} |
|
317 |
catch (IOException ioe) { |
|
318 |
System.out.println("Error creating temporary file: " + ioe.getMessage()); |
|
319 |
} |
|
320 |
|
|
330 | 321 |
setVisible(true); |
331 | 322 |
} |
332 | 323 |
|
... | ... | |
350 | 341 |
else if ((e.getActionCommand()).equals("Save As...")) { |
351 | 342 |
fileSaveAs(); |
352 | 343 |
} |
344 |
else if ((e.getActionCommand()).equals("Validate")) { |
|
345 |
fileValidate(); |
|
346 |
} |
|
353 | 347 |
else if ((e.getActionCommand()).equals("Exit")) { |
354 | 348 |
fileExit(); |
355 | 349 |
} |
... | ... | |
369 | 363 |
*/ |
370 | 364 |
void addRow(int rowIndex, String scope, String identifier, String revision, |
371 | 365 |
String documentType, String documentURL) { |
372 |
tableModel.setValueAt(scope, rowIndex, 0);
|
|
373 |
tableModel.setValueAt(identifier, rowIndex, 1);
|
|
374 |
tableModel.setValueAt(revision, rowIndex, 2);
|
|
375 |
tableModel.setValueAt(documentType, rowIndex, 3);
|
|
376 |
tableModel.setValueAt(documentURL, rowIndex, 4);
|
|
366 |
tableModel.setValueAt(scope, rowIndex, 1);
|
|
367 |
tableModel.setValueAt(identifier, rowIndex, 2);
|
|
368 |
tableModel.setValueAt(revision, rowIndex, 3);
|
|
369 |
tableModel.setValueAt(documentType, rowIndex, 4);
|
|
370 |
tableModel.setValueAt(documentURL, rowIndex, 5);
|
|
377 | 371 |
} |
378 | 372 |
|
379 | 373 |
|
... | ... | |
416 | 410 |
* @param rowIndex the index to the table row to be cleared |
417 | 411 |
*/ |
418 | 412 |
void clearRow(int rowIndex) { |
419 |
final String nil = null;
|
|
413 |
final String nil = "";
|
|
420 | 414 |
|
421 |
tableModel.setValueAt(nil, rowIndex, 0); |
|
422 | 415 |
tableModel.setValueAt(nil, rowIndex, 1); |
423 | 416 |
tableModel.setValueAt(nil, rowIndex, 2); |
424 | 417 |
tableModel.setValueAt(nil, rowIndex, 3); |
425 |
tableModel.setValueAt(nil, rowIndex, 4); |
|
418 |
tableModel.setValueAt(nil, rowIndex, 4); |
|
419 |
tableModel.setValueAt(nil, rowIndex, 5); |
|
426 | 420 |
} |
427 | 421 |
|
428 | 422 |
|
... | ... | |
432 | 426 |
* @param rowIndex the index of the table row to be copied |
433 | 427 |
*/ |
434 | 428 |
void copyRow(int rowIndex) { |
435 |
clipboardScope = (String) tableModel.getValueAt(rowIndex, 0);
|
|
436 |
clipboardIdentifier = (String) tableModel.getValueAt(rowIndex, 1);
|
|
437 |
clipboardRevision = (String) tableModel.getValueAt(rowIndex, 2);
|
|
438 |
clipboardDocumentType = (String) tableModel.getValueAt(rowIndex, 3);
|
|
439 |
clipboardDocumentURL = (String) tableModel.getValueAt(rowIndex, 4);
|
|
429 |
clipboardScope = (String) tableModel.getValueAt(rowIndex, 1);
|
|
430 |
clipboardIdentifier = (String) tableModel.getValueAt(rowIndex, 2);
|
|
431 |
clipboardRevision = (String) tableModel.getValueAt(rowIndex, 3);
|
|
432 |
clipboardDocumentType = (String) tableModel.getValueAt(rowIndex, 4);
|
|
433 |
clipboardDocumentURL = (String) tableModel.getValueAt(rowIndex, 5);
|
|
440 | 434 |
} |
441 | 435 |
|
442 | 436 |
|
... | ... | |
508 | 502 |
|
509 | 503 |
clearHarvestList(); |
510 | 504 |
harvestListFile = null; |
505 |
setTitle(title + ": (Untitled)"); |
|
511 | 506 |
saveMenuItem.setEnabled(false); |
512 | 507 |
harvestListHasChanged = false; |
513 | 508 |
} |
... | ... | |
578 | 573 |
if (returnVal == JFileChooser.APPROVE_OPTION) { |
579 | 574 |
harvestListFile = fileChooser.getSelectedFile(); |
580 | 575 |
writeFile(harvestListFile); |
576 |
setTitle(title + ": " + harvestListFile.getName()); |
|
581 | 577 |
saveMenuItem.setEnabled(true); |
582 | 578 |
harvestListHasChanged = false; |
583 | 579 |
} |
584 | 580 |
} |
585 | 581 |
|
582 |
|
|
583 |
/** |
|
584 |
* Validate the Harvest List that is currently stored in the table. This is |
|
585 |
* implemented by writing the Harvest List to a temporary file and then |
|
586 |
* running the SAX parser on the temporary file. |
|
587 |
*/ |
|
588 |
void fileValidate() { |
|
589 |
FileInputStream fis; |
|
590 |
HarvestListHandler harvestListHandler = new HarvestListHandler(); |
|
591 |
InputStreamReader inputStreamReader; |
|
592 |
boolean loadHarvestList = false; |
|
593 |
boolean validateHarvestList = true; |
|
594 |
|
|
595 |
writeFile(tempFile); |
|
596 |
|
|
597 |
try { |
|
598 |
fis = new FileInputStream(tempFile); |
|
599 |
inputStreamReader = new InputStreamReader(fis); |
|
600 |
harvestListHandler.runParser(this, inputStreamReader, schemaLocation, |
|
601 |
loadHarvestList, validateHarvestList); |
|
602 |
fis.close(); |
|
603 |
tempFile.delete(); |
|
604 |
harvestListMessage("Harvest List is valid"); |
|
605 |
} |
|
606 |
catch (SAXException e) { |
|
607 |
harvestListMessage("Validation error: " + e.getMessage()); |
|
608 |
} |
|
609 |
catch (ClassNotFoundException e) { |
|
610 |
System.out.println("ClassNotFoundException: " + e.getMessage()); |
|
611 |
} |
|
612 |
catch (IOException ioe) { |
|
613 |
System.out.println("Error opening file: " + ioe.getMessage()); |
|
614 |
} |
|
615 |
} |
|
616 |
|
|
586 | 617 |
|
587 | 618 |
/** |
619 |
* Displays a short message in a dialog box. |
|
620 |
* |
|
621 |
* @param message the message text |
|
622 |
*/ |
|
623 |
void harvestListMessage(String message) { |
|
624 |
JOptionPane.showMessageDialog(this, message); |
|
625 |
} |
|
626 |
|
|
627 |
|
|
628 |
/** |
|
629 |
* Initializes the Harvest List table, filling column 0 with row numbers. |
|
630 |
* This is a non-editable column, so its values should never change after |
|
631 |
* this point. |
|
632 |
*/ |
|
633 |
void initHarvestList() { |
|
634 |
for (int rowIndex = 0; rowIndex < numRows; rowIndex++) { |
|
635 |
tableModel.setValueAt(new Integer(rowIndex + 1).toString(), rowIndex, 0); |
|
636 |
} |
|
637 |
} |
|
638 |
|
|
639 |
|
|
640 |
/** |
|
588 | 641 |
* Determines whether the clipboard is currently empty. The clipboard is |
589 | 642 |
* empty if all five of the fields are empty. |
590 | 643 |
* |
... | ... | |
612 | 665 |
*/ |
613 | 666 |
boolean isEmptyRow(int rowIndex) { |
614 | 667 |
boolean isEmpty = true; |
615 |
String scope = (String) tableModel.getValueAt(rowIndex, 0);
|
|
616 |
String identifier = (String) tableModel.getValueAt(rowIndex, 1);
|
|
617 |
String revision = (String) tableModel.getValueAt(rowIndex, 2);
|
|
618 |
String documentType = (String) tableModel.getValueAt(rowIndex, 3);
|
|
619 |
String documentURL = (String) tableModel.getValueAt(rowIndex, 4);
|
|
668 |
String scope = (String) tableModel.getValueAt(rowIndex, 1);
|
|
669 |
String identifier = (String) tableModel.getValueAt(rowIndex, 2);
|
|
670 |
String revision = (String) tableModel.getValueAt(rowIndex, 3);
|
|
671 |
String documentType = (String) tableModel.getValueAt(rowIndex, 4);
|
|
672 |
String documentURL = (String) tableModel.getValueAt(rowIndex, 5);
|
|
620 | 673 |
|
621 | 674 |
isEmpty = isEmpty && ((scope == null) || (scope.equals(""))); |
622 | 675 |
isEmpty = isEmpty && ((identifier == null) || (identifier.equals(""))); |
... | ... | |
639 | 692 |
HarvestListHandler harvestListHandler = new HarvestListHandler(); |
640 | 693 |
FileInputStream fis; |
641 | 694 |
InputStreamReader inputStreamReader; |
695 |
boolean loadHarvestList = true; |
|
696 |
boolean validateHarvestList = false; |
|
642 | 697 |
|
643 | 698 |
try { |
644 | 699 |
fis = new FileInputStream(harvestList); |
645 | 700 |
inputStreamReader = new InputStreamReader(fis); |
646 |
System.out.println("Opened file successfully."); |
|
647 |
harvestListHandler.runParser(this, inputStreamReader, schemaLocation); |
|
701 |
//System.out.println("Opened file successfully."); |
|
702 |
harvestListHandler.runParser(this, inputStreamReader, schemaLocation, |
|
703 |
loadHarvestList, validateHarvestList); |
|
648 | 704 |
fis.close(); |
705 |
setTitle(title + ": " + harvestListFile.getName()); |
|
649 | 706 |
} |
650 | 707 |
catch (SAXException e) { |
651 | 708 |
System.out.println("Error parsing Harvest List: " + e.getMessage()); |
... | ... | |
660 | 717 |
|
661 | 718 |
|
662 | 719 |
/** |
720 |
* Loads properties from the .harvestListEditor file in the user's home |
|
721 |
* directory. |
|
722 |
*/ |
|
723 |
void loadProperties () { |
|
724 |
String homedir = System.getProperty("user.home"); |
|
725 |
File propertiesFile = new File(homedir, ".harvestListEditor"); |
|
726 |
|
|
727 |
properties = new Properties(); |
|
728 |
|
|
729 |
try { |
|
730 |
properties.load(new FileInputStream(propertiesFile)); |
|
731 |
defaultHarvestList = properties.getProperty("defaultHarvestList"); |
|
732 |
defaultDocumentType = properties.getProperty("defaultDocumentType"); |
|
733 |
defaultDocumentURL = properties.getProperty("defaultDocumentURL"); |
|
734 |
defaultIdentifier = properties.getProperty("defaultIdentifier"); |
|
735 |
defaultRevision = properties.getProperty("defaultRevision"); |
|
736 |
defaultScope = properties.getProperty("defaultScope"); |
|
737 |
} |
|
738 |
catch (IOException ioe) { |
|
739 |
System.out.println("Error loading properties file: " + ioe.getMessage()); |
|
740 |
} |
|
741 |
} |
|
742 |
|
|
743 |
|
|
744 |
/** |
|
663 | 745 |
* Enables or disables buttons depending on the state of the currently |
664 | 746 |
* selected row and the state of the clipboard. |
665 | 747 |
* |
... | ... | |
698 | 780 |
* @param rowIndex the index of the row that is being pasted to |
699 | 781 |
*/ |
700 | 782 |
void pasteRow(int rowIndex) { |
701 |
tableModel.setValueAt(clipboardScope, rowIndex, 0);
|
|
702 |
tableModel.setValueAt(clipboardIdentifier, rowIndex, 1);
|
|
703 |
tableModel.setValueAt(clipboardRevision, rowIndex, 2);
|
|
704 |
tableModel.setValueAt(clipboardDocumentType, rowIndex, 3);
|
|
705 |
tableModel.setValueAt(clipboardDocumentURL, rowIndex, 4);
|
|
783 |
tableModel.setValueAt(clipboardScope, rowIndex, 1);
|
|
784 |
tableModel.setValueAt(clipboardIdentifier, rowIndex, 2);
|
|
785 |
tableModel.setValueAt(clipboardRevision, rowIndex, 3);
|
|
786 |
tableModel.setValueAt(clipboardDocumentType, rowIndex, 4);
|
|
787 |
tableModel.setValueAt(clipboardDocumentURL, rowIndex, 5);
|
|
706 | 788 |
} |
707 | 789 |
|
708 | 790 |
|
... | ... | |
712 | 794 |
* @param rowIndex the index of the row that is being pasted to |
713 | 795 |
*/ |
714 | 796 |
void pasteDefaultValues(int rowIndex) { |
715 |
tableModel.setValueAt(defaultScope, rowIndex, 0);
|
|
716 |
tableModel.setValueAt(defaultIdentifier, rowIndex, 1);
|
|
717 |
tableModel.setValueAt(defaultRevision, rowIndex, 2);
|
|
718 |
tableModel.setValueAt(defaultDocumentType, rowIndex, 3);
|
|
719 |
tableModel.setValueAt(defaultDocumentURL, rowIndex, 4);
|
|
797 |
tableModel.setValueAt(defaultScope, rowIndex, 1);
|
|
798 |
tableModel.setValueAt(defaultIdentifier, rowIndex, 2);
|
|
799 |
tableModel.setValueAt(defaultRevision, rowIndex, 3);
|
|
800 |
tableModel.setValueAt(defaultDocumentType, rowIndex, 4);
|
|
801 |
tableModel.setValueAt(defaultDocumentURL, rowIndex, 5);
|
|
720 | 802 |
} |
721 | 803 |
|
722 | 804 |
|
... | ... | |
750 | 832 |
void writeFile(File harvestList) { |
751 | 833 |
try { |
752 | 834 |
PrintWriter out = new PrintWriter(new FileWriter(harvestList)); |
835 |
writeHarvestList(out); |
|
836 |
} |
|
837 |
catch (IOException ioe) { |
|
838 |
System.out.println("IOException: " + ioe.getMessage()); |
|
839 |
} |
|
840 |
} |
|
841 |
|
|
842 |
|
|
843 |
/** |
|
844 |
* Writes the contents of the table to a PrintWriter. |
|
845 |
* |
|
846 |
* @param out the PrintWriter to write the Harvest List to |
|
847 |
*/ |
|
848 |
void writeHarvestList(PrintWriter out) { |
|
753 | 849 |
out.println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); |
754 | 850 |
out.println(""); |
755 | 851 |
out.println( |
... | ... | |
764 | 860 |
out.println(""); |
765 | 861 |
out.println("</hrv:harvestList>"); |
766 | 862 |
out.close(); |
767 |
} |
|
768 |
catch (IOException ioe) { |
|
769 |
System.out.println("IOException: " + ioe.getMessage()); |
|
770 |
} |
|
771 | 863 |
} |
772 | 864 |
|
773 | 865 |
|
... | ... | |
780 | 872 |
*/ |
781 | 873 |
void writeRow(PrintWriter out, int rowIndex) { |
782 | 874 |
int indentLevel = 6; |
783 |
String scope = (String) tableModel.getValueAt(rowIndex, 0);
|
|
784 |
String identifier = (String) tableModel.getValueAt(rowIndex, 1);
|
|
785 |
String revision = (String) tableModel.getValueAt(rowIndex, 2);
|
|
786 |
String documentType = (String) tableModel.getValueAt(rowIndex, 3);
|
|
787 |
String documentURL = (String) tableModel.getValueAt(rowIndex, 4);
|
|
875 |
String scope = (String) tableModel.getValueAt(rowIndex, 1);
|
|
876 |
String identifier = (String) tableModel.getValueAt(rowIndex, 2);
|
|
877 |
String revision = (String) tableModel.getValueAt(rowIndex, 3);
|
|
878 |
String documentType = (String) tableModel.getValueAt(rowIndex, 4);
|
|
879 |
String documentURL = (String) tableModel.getValueAt(rowIndex, 5);
|
|
788 | 880 |
|
789 | 881 |
out.println(""); |
790 | 882 |
out.println(" <document>"); |
... | ... | |
799 | 891 |
out.println(" </document>"); |
800 | 892 |
} |
801 | 893 |
|
802 |
|
|
894 |
|
|
895 |
/* |
|
896 |
* Inner class: HarvestListTableModel |
|
897 |
*/ |
|
898 |
class HarvestListTableModel extends AbstractTableModel { |
|
899 |
final boolean DEBUG = false; |
|
900 |
// Column names for the JTable |
|
901 |
private String[] columnNames = { |
|
902 |
"Row #", |
|
903 |
"Scope", |
|
904 |
"Identifier", |
|
905 |
"Revision", |
|
906 |
"Document Type", |
|
907 |
"Document URL" |
|
908 |
}; |
|
909 |
|
|
910 |
private Object[][] data = new Object[numRows][numColumns]; |
|
911 |
|
|
912 |
public int getColumnCount() { |
|
913 |
return columnNames.length; |
|
914 |
} |
|
915 |
|
|
916 |
public int getRowCount() { |
|
917 |
return data.length; |
|
918 |
} |
|
919 |
|
|
920 |
public String getColumnName(int col) { |
|
921 |
return columnNames[col]; |
|
922 |
} |
|
923 |
|
|
924 |
public Object getValueAt(int row, int col) { |
|
925 |
return data[row][col]; |
|
926 |
} |
|
927 |
|
|
928 |
/* |
|
929 |
* JTable uses this method to determine the default renderer/ |
|
930 |
* editor for each cell. If we didn't implement this method, |
|
931 |
* then the last column would contain text ("true"/"false"), |
|
932 |
* rather than a check box. |
|
933 |
*/ |
|
934 |
public Class getColumnClass(int c) { |
|
935 |
return getValueAt(0, c).getClass(); |
|
936 |
} |
|
937 |
|
|
938 |
/* |
|
939 |
* Don't need to implement this method unless your table's |
|
940 |
* editable. |
|
941 |
*/ |
|
942 |
public boolean isCellEditable(int row, int col) { |
|
943 |
//Note that the data/cell address is constant, |
|
944 |
//no matter where the cell appears onscreen. |
|
945 |
if (col < 1) { |
|
946 |
return false; |
|
947 |
} else { |
|
948 |
return true; |
|
949 |
} |
|
950 |
} |
|
951 |
|
|
952 |
/* |
|
953 |
* Don't need to implement this method unless your table's |
|
954 |
* data can change. |
|
955 |
*/ |
|
956 |
public void setValueAt(Object value, int row, int col) { |
|
957 |
if (DEBUG) { |
|
958 |
System.out.println("Setting value at " + row + "," + col |
|
959 |
+ " to " + value |
|
960 |
+ " (an instance of " |
|
961 |
+ value.getClass() + ")"); |
|
962 |
} |
|
963 |
|
|
964 |
data[row][col] = value; |
|
965 |
fireTableCellUpdated(row, col); |
|
966 |
|
|
967 |
if (DEBUG) { |
|
968 |
System.out.println("New value of data:"); |
|
969 |
printDebugData(); |
|
970 |
} |
|
971 |
} |
|
972 |
|
|
973 |
private void printDebugData() { |
|
974 |
int numRows = getRowCount(); |
|
975 |
int numCols = getColumnCount(); |
|
976 |
|
|
977 |
for (int i=0; i < numRows; i++) { |
|
978 |
System.out.print(" row " + i + ":"); |
|
979 |
for (int j=0; j < numCols; j++) { |
|
980 |
System.out.print(" " + data[i][j]); |
|
981 |
} |
|
982 |
System.out.println(); |
|
983 |
} |
|
984 |
System.out.println("--------------------------"); |
|
985 |
} |
|
986 |
} |
|
987 |
|
|
803 | 988 |
/** |
804 | 989 |
* This inner class extends DefaultHandler. It parses the Harvest List file, |
805 | 990 |
* writing a new row to the table every time it encounters a </Document> |
... | ... | |
812 | 997 |
public String identifierString; |
813 | 998 |
public String documentType; |
814 | 999 |
private HarvestListEditor harvestListEditor; |
1000 |
boolean loadHarvestList; |
|
815 | 1001 |
public int revision; |
816 | 1002 |
public String revisionString; |
817 | 1003 |
private int rowIndex = 0; |
... | ... | |
820 | 1006 |
public final static String DEFAULT_PARSER = |
821 | 1007 |
"org.apache.xerces.parsers.SAXParser"; |
822 | 1008 |
private boolean schemaValidate = true; |
1009 |
private boolean validateHarvestList; |
|
823 | 1010 |
|
824 | 1011 |
|
825 | 1012 |
/** |
... | ... | |
859 | 1046 |
* Handles an end-of-document event. |
860 | 1047 |
*/ |
861 | 1048 |
public void endDocument () { |
862 |
System.out.println("Finished parsing Harvest List"); |
|
863 | 1049 |
} |
864 | 1050 |
|
865 | 1051 |
|
... | ... | |
885 | 1071 |
revision = Integer.parseInt(revisionString); |
886 | 1072 |
} |
887 | 1073 |
else if (qname.equals("document")) { |
888 |
harvestListEditor.addRow(rowIndex, scope, identifierString, |
|
889 |
revisionString, documentType, documentURL); |
|
1074 |
if (loadHarvestList) { |
|
1075 |
harvestListEditor.addRow(rowIndex, scope, identifierString, |
|
1076 |
revisionString, documentType, documentURL); |
|
1077 |
} |
|
1078 |
|
|
890 | 1079 |
rowIndex++; |
891 | 1080 |
} |
892 | 1081 |
|
... | ... | |
918 | 1107 |
*/ |
919 | 1108 |
public void runParser(HarvestListEditor harvestListEditor, |
920 | 1109 |
Reader xml, |
921 |
String schemaLocation) |
|
1110 |
String schemaLocation, |
|
1111 |
boolean loadHarvestList, |
|
1112 |
boolean validateHarvestList) |
|
922 | 1113 |
throws IOException, ClassNotFoundException, |
923 | 1114 |
SAXException, SAXParseException { |
924 | 1115 |
|
... | ... | |
926 | 1117 |
XMLReader parser; |
927 | 1118 |
|
928 | 1119 |
this.harvestListEditor = harvestListEditor; |
1120 |
this.loadHarvestList = loadHarvestList; |
|
1121 |
this.validateHarvestList = validateHarvestList; |
|
929 | 1122 |
this.rowIndex = 0; |
930 | 1123 |
|
931 | 1124 |
parser = XMLReaderFactory.createXMLReader(DEFAULT_PARSER); |
... | ... | |
953 | 1146 |
* Handles a start-of-document event. |
954 | 1147 |
*/ |
955 | 1148 |
public void startDocument () { |
956 |
System.out.println("Started parsing Harvest List"); |
|
1149 |
//System.out.println("Started parsing Harvest List");
|
|
957 | 1150 |
} |
958 | 1151 |
|
959 | 1152 |
|
Also available in: Unified diff
Add File Validate menu item
Add column to display the row number
Add name of file to the title bar
Load properties from .harvestListEditor in home directory instead
of from metacat.properties