source: trunk/gli/src/org/greenstone/gatherer/metadata/MetadataAuditTableModel.java@ 8168

Last change on this file since 8168 was 8168, checked in by mdewsnip, 20 years ago

Added a function needed by gui/metaaudit/HeaderListener.java.

  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 KB
Line 
1/**
2 *############################################################################
3 * A component of the Greenstone Librarian Interface, part of the Greenstone
4 * digital library suite from the New Zealand Digital Library Project at the
5 * University of Waikato, New Zealand.
6 *
7 * Author: Michael Dewsnip, NZDL Project, University of Waikato, NZ
8 *
9 * Copyright (C) 2004 New Zealand Digital Library Project
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *############################################################################
25 */
26
27package org.greenstone.gatherer.metadata;
28
29
30import java.awt.*;
31import java.io.*;
32import java.util.*;
33import javax.swing.*;
34import javax.swing.table.*;
35import org.greenstone.gatherer.Configuration;
36import org.greenstone.gatherer.Gatherer;
37import org.greenstone.gatherer.file.FileNode;
38
39
40public class MetadataAuditTableModel
41 extends AbstractTableModel
42{
43 /** The FileNodes this model is built for */
44 private FileNode[] file_nodes = null;
45 /** The list of MetadataElements in the table (columns) */
46 private ArrayList metadata_elements = new ArrayList();
47 /** The list of MetadataAuditTableEntries in the table (rows) */
48 private ArrayList metadata_audit_table_entries = new ArrayList();
49
50
51 /** Returns the number of columns in this table. */
52 public int getColumnCount()
53 {
54 return metadata_elements.size();
55 }
56
57
58 /** Returns the name of the specified column. */
59 public String getColumnName(int col)
60 {
61 return metadata_elements.get(col).toString();
62 }
63
64
65 /** Returns the values in a particular column. */
66 public ArrayList getColumnValues(int col)
67 {
68 // Check values are reasonable
69 if (col < 0 || col >= metadata_elements.size()) {
70 return null;
71 }
72
73 ArrayList column_values = new ArrayList();
74 for (int i = 0; i < metadata_audit_table_entries.size(); i++) {
75 MetadataAuditTableEntry metadata_audit_table_entry = (MetadataAuditTableEntry) metadata_audit_table_entries.get(i);
76 MetadataValueTreeNode metadata_value_tree_node = metadata_audit_table_entry.getMetadataValueTreeNode(col);
77 column_values.add(metadata_value_tree_node.toString());
78 }
79
80 return column_values;
81 }
82
83
84 /** Returns the number of rows in this table. */
85 public int getRowCount()
86 {
87 return metadata_audit_table_entries.size();
88 }
89
90
91 /** Returns the cell value at a given row and column as an Object. */
92 public Object getValueAt(int row, int col)
93 {
94 // Check values are reasonable
95 if (row < 0 || row >= metadata_audit_table_entries.size() || col < 0 || col >= metadata_elements.size()) {
96 return null;
97 }
98
99 MetadataAuditTableEntry metadata_audit_table_entry = (MetadataAuditTableEntry) metadata_audit_table_entries.get(row);
100 return metadata_audit_table_entry.getMetadataValueTreeNode(col);
101 }
102
103
104 public void rebuild(FileNode[] file_nodes)
105 {
106 metadata_elements = MetadataSetManager.getEveryMetadataSetElement();
107 metadata_audit_table_entries.clear();
108
109 this.file_nodes = file_nodes;
110 if (file_nodes != null && file_nodes.length > 0) {
111 // Create model builder
112 MetadataAuditTableModelBuilder builder = new MetadataAuditTableModelBuilder();
113 builder.run();
114 }
115 }
116
117
118 private class MetadataAuditTableModelBuilder
119 {
120 // Build a list of MetadataAuditTableEntries that represent the metadata asssigned to the selected files
121 public void run()
122 {
123 // Process each of the selected files in turn
124 for (int i = 0; i < file_nodes.length; i++) {
125 File current_file = file_nodes[i].getFile();
126
127 // Get the metadata assigned to this file
128 ArrayList current_file_metadata = MetadataXMLFileManager.getMetadataAssignedToFile(current_file);
129
130 // Get the extracted metadata for this file, if desired
131 if (Gatherer.config.get("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC) == true) {
132 current_file_metadata.addAll(DocXMLFileManager.getMetadataExtractedFromFile(current_file));
133 }
134
135 MetadataAuditTableEntry metadata_audit_table_entry = new MetadataAuditTableEntry(current_file, current_file_metadata);
136 metadata_audit_table_entries.add(metadata_audit_table_entry);
137 }
138 }
139 }
140
141
142 /** This class represents one (file, metadata) pair */
143 private class MetadataAuditTableEntry
144 {
145 private File file = null;
146 private MetadataValue[] metadata_values = null;
147
148
149 public MetadataAuditTableEntry(File file, ArrayList metadata_values_list)
150 {
151 this.file = file;
152
153 metadata_values = new MetadataValue[metadata_elements.size()];
154 for (int i = 0; i < metadata_values_list.size(); i++) {
155 MetadataValue metadata_value = (MetadataValue) metadata_values_list.get(i);
156 MetadataElement metadata_element = metadata_value.getMetadataElement();
157
158 // Find the right column to put the value in
159 for (int j = 0; j < metadata_elements.size(); j++) {
160 if (metadata_element.equals(metadata_elements.get(j))) {
161 metadata_values[j] = metadata_value;
162 break;
163 }
164 }
165 }
166 }
167
168
169 public MetadataValueTreeNode getMetadataValueTreeNode(int col)
170 {
171 if (metadata_values[col] == null) {
172 return null;
173 }
174
175 return metadata_values[col].getMetadataValueTreeNode();
176 }
177 }
178}
Note: See TracBrowser for help on using the repository browser.