- Timestamp:
- 2004-08-18T11:01:56+12:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/metadata/MetadataValueTableModel.java
r7827 r7978 15 15 16 16 public class MetadataValueTableModel 17 extends AbstractTableModel17 extends AbstractTableModel 18 18 { 19 /** The FileNodes this model is built for */20 private FileNode[] file_nodes = null;21 /** The list of MetadataValueTableEntries in the table */22 private ArrayList metadata_value_table_entries = new ArrayList();23 24 static final private String[] COLUMN_NAMES = {"", Dictionary.get("Metadata.Element"), Dictionary.get("Metadata.Value")};25 26 27 /** Returns the number of columns in this table. */28 public int getColumnCount()29 {30 31 }32 33 34 /** Retrieves the name of the specified column. */35 public String getColumnName(int col)36 {37 38 }39 40 41 /* Called to retrieve the MetadataValueTableEntry at a certain row. Usually caused by the user selecting a row in the table. It is synchronized so that the model doesn't up and change while we're trying to retrieve the indicated element. */42 public synchronized MetadataValueTableEntry getMetadataValueTableEntry(int row)43 {44 45 return (MetadataValueTableEntry) metadata_value_table_entries.get(row);46 47 48 49 }50 51 52 /** Returns the number of rows in this table. */53 public int getRowCount()54 {55 56 }57 58 59 /** Returns the cell value at a given row and column as an Object. */60 public Object getValueAt(int row, int col)61 {62 63 64 return null;65 66 67 68 69 return metadata_value_table_entry.getFolderMetadataInheritedFrom();70 71 72 73 return metadata_value_table_entry.getMetadataElement();74 75 76 77 return metadata_value_table_entry.getFullValue();78 79 80 81 }82 83 84 /** Determine if the given metadata is common to all selected file nodes given the context of the current view. */85 public boolean isCommon(MetadataValueTableEntry metadata_value_table_entry)86 {87 88 }89 90 91 /** Determine if the given metadata is common to all selected file nodes given the context of the current view. */92 public boolean isCommon(int row)93 {94 95 return isCommon((MetadataValueTableEntry) metadata_value_table_entries.get(row));96 97 98 99 }100 101 102 public void rebuild(FileNode[] file_nodes)103 {104 105 106 107 Gatherer.println("Not ready!");108 return;109 110 111 112 113 // Create model builder114 MetadataValueTableModelBuilder builder = new MetadataValueTableModelBuilder();115 builder.run();116 117 }118 119 120 private class MetadataValueTableModelBuilder121 {122 123 124 // Build a list of MetadataValueTableEntries that represent the metadata asssigned to the selected files125 boolean hid_extracted_metadata = false;126 boolean has_inherited_metadata = false;127 ArrayList metadata_elements_seen = new ArrayList();128 129 // Process each of the selected files in turn130 for (int i = 0; i < file_nodes.length; i++) {131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 }162 163 // Make sure each non-extracted metadata element appears in the table (even if blank)164 ArrayList every_metadata_set_element = MetadataSetManager.getEveryMetadataSetElement();165 for (int i = 0; i < every_metadata_set_element.size(); i++) {166 167 168 169 170 171 172 173 174 175 176 177 178 }179 180 // If extracted metadata was hidden, display the warning181 if (hid_extracted_metadata) {182 183 }184 185 // If there is inherited metadata, display the warning186 if (has_inherited_metadata) {187 188 }189 190 191 192 193 194 195 for (int i = 0; i < metadata_value_table_entries.size(); i++) {196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 }212 213 // Must go at the end of the table214 metadata_value_table_entries.add(new MetadataValueTableEntry(metadata_value));215 fireTableRowsInserted(metadata_value_table_entries.size() - 1, metadata_value_table_entries.size() - 1);216 217 218 219 220 221 Runnable task = new Runnable() {222 223 224 225 226 227 228 229 SwingUtilities.invokeLater(task);230 231 232 233 234 235 Runnable task = new Runnable() {236 237 238 239 240 241 242 243 SwingUtilities.invokeLater(task);244 245 }19 /** The FileNodes this model is built for */ 20 private FileNode[] file_nodes = null; 21 /** The list of MetadataValueTableEntries in the table */ 22 private ArrayList metadata_value_table_entries = new ArrayList(); 23 24 static final private String[] COLUMN_NAMES = {"", Dictionary.get("Metadata.Element"), Dictionary.get("Metadata.Value")}; 25 26 27 /** Returns the number of columns in this table. */ 28 public int getColumnCount() 29 { 30 return COLUMN_NAMES.length; 31 } 32 33 34 /** Retrieves the name of the specified column. */ 35 public String getColumnName(int col) 36 { 37 return COLUMN_NAMES[col]; 38 } 39 40 41 /* Called to retrieve the MetadataValueTableEntry at a certain row. Usually caused by the user selecting a row in the table. It is synchronized so that the model doesn't up and change while we're trying to retrieve the indicated element. */ 42 public synchronized MetadataValueTableEntry getMetadataValueTableEntry(int row) 43 { 44 if (row >= 0 && row < metadata_value_table_entries.size()) { 45 return (MetadataValueTableEntry) metadata_value_table_entries.get(row); 46 } 47 48 return null; 49 } 50 51 52 /** Returns the number of rows in this table. */ 53 public int getRowCount() 54 { 55 return metadata_value_table_entries.size(); 56 } 57 58 59 /** Returns the cell value at a given row and column as an Object. */ 60 public Object getValueAt(int row, int col) 61 { 62 // Check values are reasonable 63 if (row < 0 || row >= metadata_value_table_entries.size() || col < 0 || col >= COLUMN_NAMES.length) { 64 return null; 65 } 66 67 MetadataValueTableEntry metadata_value_table_entry = (MetadataValueTableEntry) metadata_value_table_entries.get(row); 68 if (col == 0 && metadata_value_table_entry.isInheritedMetadata()) { 69 return metadata_value_table_entry.getFolderMetadataInheritedFrom(); 70 } 71 72 if (col == 1) { 73 return metadata_value_table_entry.getMetadataElement(); 74 } 75 76 if (col == 2) { 77 return metadata_value_table_entry.getFullValue(); 78 } 79 80 return null; 81 } 82 83 84 /** Determine if the given metadata is common to all selected file nodes given the context of the current view. */ 85 public boolean isCommon(MetadataValueTableEntry metadata_value_table_entry) 86 { 87 return (file_nodes != null && metadata_value_table_entry.getOccurrences() == file_nodes.length); 88 } 89 90 91 /** Determine if the given metadata is common to all selected file nodes given the context of the current view. */ 92 public boolean isCommon(int row) 93 { 94 if (row >= 0 && row < metadata_value_table_entries.size()) { 95 return isCommon((MetadataValueTableEntry) metadata_value_table_entries.get(row)); 96 } 97 98 return false; 99 } 100 101 102 public void rebuild(FileNode[] file_nodes) 103 { 104 metadata_value_table_entries.clear(); 105 106 if (!Gatherer.c_man.ready()) { 107 Gatherer.println("Not ready!"); 108 return; 109 } 110 111 this.file_nodes = file_nodes; 112 if (file_nodes != null && file_nodes.length > 0) { 113 // Create model builder 114 MetadataValueTableModelBuilder builder = new MetadataValueTableModelBuilder(); 115 builder.run(); 116 } 117 } 118 119 120 private class MetadataValueTableModelBuilder 121 { 122 public void run() 123 { 124 // Build a list of MetadataValueTableEntries that represent the metadata asssigned to the selected files 125 boolean hid_extracted_metadata = false; 126 boolean has_inherited_metadata = false; 127 ArrayList metadata_elements_seen = new ArrayList(); 128 129 // Process each of the selected files in turn 130 for (int i = 0; i < file_nodes.length; i++) { 131 File current_file = file_nodes[i].getFile(); 132 133 // Get the metadata assigned to this file 134 ArrayList assigned_metadata = MetadataXMLFileManager.getMetadataAssignedToFile(current_file); 135 for (int j = 0; j < assigned_metadata.size(); j++) { 136 MetadataValue metadata_value = (MetadataValue) assigned_metadata.get(j); 137 MetadataElement metadata_element = metadata_value.getMetadataElement(); 138 139 // Note if there is inherited (folder-level) metadata in the table 140 has_inherited_metadata = has_inherited_metadata || metadata_value.isInheritedMetadata(); 141 142 // Insert this metadata value into the table, unless it already exists (in which case increment its count) 143 insertMetadataValueIntoTable(metadata_value); 144 145 // Remember we have seen this metadata element 146 if (metadata_elements_seen.contains(metadata_element) == false) { 147 metadata_elements_seen.add(metadata_element); 148 } 149 } 150 151 // Get the extracted metadata for this file, if desired 152 if (Gatherer.config.get("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC) == true) { 153 ArrayList extracted_metadata = DocXMLFileManager.getMetadataExtractedFromFile(current_file); 154 for (int k = 0; k < extracted_metadata.size(); k++) { 155 MetadataValue metadata_value = (MetadataValue) extracted_metadata.get(k); 156 157 // Insert this metadata value into the table, unless it already exists (in which case increment its count) 158 insertMetadataValueIntoTable(metadata_value); 159 } 160 } 161 } 162 163 // Make sure each non-extracted metadata element appears in the table (even if blank) 164 ArrayList every_metadata_set_element = MetadataSetManager.getEveryMetadataSetElement(); 165 for (int i = 0; i < every_metadata_set_element.size(); i++) { 166 MetadataElement metadata_element = (MetadataElement) every_metadata_set_element.get(i); 167 168 // If we haven't seen this metadata element and it isn't extracted, add it now 169 if (!metadata_elements_seen.contains(metadata_element) && !metadata_element.isExtractedMetadata()) { 170 MetadataValueTableEntry metadata_value_table_entry = new MetadataValueTableEntry(metadata_element, new MetadataValueTreeNode("")); 171 172 // Blank metadata is common to all selected files (otherwise it wouldn't be blank!) 173 metadata_value_table_entry.setOccurrences(file_nodes.length); 174 175 // Add it to the table 176 insertMetadataValueIntoTable(metadata_value_table_entry); 177 } 178 } 179 180 // If extracted metadata was hidden, display the warning 181 if (hid_extracted_metadata) { 182 showExtractedMetadataWarning(); 183 } 184 185 // If there is inherited metadata, display the warning 186 if (has_inherited_metadata) { 187 showInheritedMetadataWarning(); 188 } 189 } 190 191 192 /** Alphabetically inserts the new metadata value into the table */ 193 private void insertMetadataValueIntoTable(MetadataValue metadata_value) 194 { 195 for (int i = 0; i < metadata_value_table_entries.size(); i++) { 196 MetadataValueTableEntry current_metadata_value_table_entry = (MetadataValueTableEntry) metadata_value_table_entries.get(i); 197 int c = current_metadata_value_table_entry.compareTo(metadata_value); 198 199 // Insert value before existing entry 200 if (c > 0) { 201 metadata_value_table_entries.add(i, new MetadataValueTableEntry(metadata_value)); 202 fireTableRowsInserted(i, i); 203 return; 204 } 205 206 // Entry already exists (increment existing count) 207 if (c == 0) { 208 current_metadata_value_table_entry.anotherOccurrence(); 209 return; 210 } 211 } 212 213 // Must go at the end of the table 214 metadata_value_table_entries.add(new MetadataValueTableEntry(metadata_value)); 215 fireTableRowsInserted(metadata_value_table_entries.size() - 1, metadata_value_table_entries.size() - 1); 216 } 217 218 219 private void showExtractedMetadataWarning() 220 { 221 Runnable task = new Runnable() { 222 public void run() { 223 WarningDialog dialog = new WarningDialog("warning.ExtractedMetadata", false); 224 dialog.display(); 225 dialog.dispose(); 226 dialog = null; 227 } 228 }; 229 SwingUtilities.invokeLater(task); 230 } 231 232 233 private void showInheritedMetadataWarning() 234 { 235 Runnable task = new Runnable() { 236 public void run() { 237 WarningDialog dialog = new WarningDialog("warning.InheritedMetadata", false); 238 dialog.display(); 239 dialog.dispose(); 240 dialog = null; 241 } 242 }; 243 SwingUtilities.invokeLater(task); 244 } 245 } 246 246 }
Note:
See TracChangeset
for help on using the changeset viewer.