Changeset 6201
- Timestamp:
- 2003-12-10T16:30:33+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/msm/GDMManager.java
r6036 r6201 37 37 package org.greenstone.gatherer.msm; 38 38 39 import java.awt.*; 40 import java.awt.event.*; 39 41 import java.io.*; 40 42 import java.util.*; 43 import javax.swing.*; 44 import javax.swing.event.*; 41 45 import javax.swing.tree.*; 42 46 import org.greenstone.gatherer.Gatherer; … … 49 53 import org.greenstone.gatherer.msm.MSMEvent; 50 54 import org.greenstone.gatherer.msm.MSMListener; 55 import org.greenstone.gatherer.util.DOMTree; 51 56 import org.greenstone.gatherer.util.HashMap3D; 52 57 import org.greenstone.gatherer.util.StaticStrings; … … 62 67 /** A list of the known metadata instances, thus we only store one of each unique metadata, and reference the rest. */ 63 68 static public HashMap3D metadata_cache = null; 69 private DOMTree tree = null; 70 private JComboBox documents_in_cache_combobox = null; 64 71 /** The root file node. */ 65 72 private TreeNode root = null; … … 74 81 // Connect 75 82 Gatherer.c_man.getCollection().msm.addMSMListener(this); 83 // We also have a debug dialog 84 if(Gatherer.debug != null) { 85 display(); 86 } 76 87 } 77 88 … … 109 120 // Done! 110 121 } 122 123 /** This debug facility shows the currently loaded collect.cfg or CollectConfig.xml file as a DOM tree. */ 124 public void display() { 125 JDialog dialog = new JDialog(Gatherer.g_man, "Greenstone Metadata Document Manager", false); 126 dialog.setSize(400,400); 127 JPanel content_pane = (JPanel) dialog.getContentPane(); 128 GDMDocument metadata_xml = new GDMDocument(); 129 tree = new DOMTree(metadata_xml.getDocument()); 130 metadata_xml = null; 131 documents_in_cache_combobox = new JComboBox(); 132 documents_in_cache_combobox.addItemListener(new DOMItemListener()); 133 JButton refresh_button = new JButton("Refresh Tree"); 134 refresh_button.addActionListener(new ActionListener() { 135 public void actionPerformed(ActionEvent event) { 136 File metadata_file = (File) documents_in_cache_combobox.getSelectedItem(); 137 if(metadata_file != null) { 138 GDMDocument document = (GDMDocument) get(metadata_file); 139 tree.setDocument(document.getDocument()); 140 document = null; 141 metadata_file = null; 142 } 143 } 144 }); 145 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 146 content_pane.setLayout(new BorderLayout()); 147 content_pane.add(documents_in_cache_combobox, BorderLayout.NORTH); 148 content_pane.add(new JScrollPane(tree), BorderLayout.CENTER); 149 content_pane.add(refresh_button, BorderLayout.SOUTH); 150 dialog.show(); 151 } 152 153 private class DOMItemListener 154 implements ItemListener { 155 156 public void itemStateChanged(ItemEvent event) { 157 if(event.getStateChange() == ItemEvent.SELECTED) { 158 File metadata_file = (File) documents_in_cache_combobox.getSelectedItem(); 159 if(metadata_file != null) { 160 GDMDocument document = (GDMDocument) get(metadata_file); 161 tree.setDocument(document.getDocument()); 162 document = null; 163 metadata_file = null; 164 } 165 } 166 } 167 } 168 111 169 /** Method that is called whenever an element within a set is changed or modified. Ensure all cached GDMDocuments are marked as stale. 112 170 * @param event A <strong>MSMEvent</strong> containing details of the event that caused this message to be fired. … … 150 208 } 151 209 put(metadata_file, metadata_xml); 210 if(documents_in_cache_combobox != null) { 211 documents_in_cache_combobox.addItem(metadata_file); 212 } 152 213 //Gatherer.println("[0ms]\tCached " + metadata_file); 153 214 } … … 224 285 } 225 286 GDMDocument document = getDocument(file); 226 if( document != null) {287 if(file != null && document != null) { 227 288 metadata = document.getMetadata(filename, remove, metadata, file, append_folder_level); 228 289 document = null; … … 341 402 } 342 403 } 404 } 405 406 public void removeExtractedMetadata() { 407 try { 408 // Remove all of the extracted metadata in the collection 409 removeExtractedMetadata(new File(Gatherer.c_man.getCollectionImport())); 410 } 411 catch (Exception exception) { 412 Gatherer.println("Exception in GDMManager.removeExtractedMetadata - unexpected"); 413 Gatherer.printStackTrace(exception); 414 } 415 } 416 417 private void removeExtractedMetadata(File file) { 418 // Retrieve the gdm document for this file 419 GDMDocument metadata_xml_document = getDocument(file); 420 // Remove the extracted metadata 421 System.err.println("Removing the extracted metadata from the file: " + file); 422 metadata_xml_document.removeExtractedMetadata(); 423 metadata_xml_document = null; 424 // Then recurse down the directory structure looking for other metadata.xml files 425 File child_files[] = file.listFiles(); 426 for(int i = 0; i < child_files.length; i++) { 427 if(child_files[i].isDirectory()) { 428 removeExtractedMetadata(child_files[i]); 429 } 430 } 431 child_files = null; 343 432 } 344 433 … … 509 598 GDMDocument document = (GDMDocument) eldest.getValue(); 510 599 save(file, document); 600 601 if(documents_in_cache_combobox != null) { 602 documents_in_cache_combobox.removeItem(file); 603 } 511 604 // And then dump it 512 605 return true;
Note:
See TracChangeset
for help on using the changeset viewer.