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 |
|
---|
27 | package org.greenstone.gatherer.metadata;
|
---|
28 |
|
---|
29 |
|
---|
30 | import java.awt.*;
|
---|
31 | import java.io.*;
|
---|
32 | import java.util.*;
|
---|
33 | import javax.swing.*;
|
---|
34 | import javax.swing.table.*;
|
---|
35 | import org.greenstone.gatherer.Configuration;
|
---|
36 | import org.greenstone.gatherer.Dictionary;
|
---|
37 | import org.greenstone.gatherer.collection.CollectionTreeNode;
|
---|
38 |
|
---|
39 |
|
---|
40 | public class MetadataAuditTableModel
|
---|
41 | extends AbstractTableModel
|
---|
42 | {
|
---|
43 | /** It is not expected that this class will ever be serialized */
|
---|
44 | private static final long serialVersionUID = 0L;
|
---|
45 |
|
---|
46 | /** The CollectionTreeNodes this model is built for */
|
---|
47 | private CollectionTreeNode[] file_nodes = null;
|
---|
48 | /** The list of MetadataElements in the table (columns) */
|
---|
49 | private ArrayList metadata_elements = new ArrayList();
|
---|
50 | /** The list of MetadataAuditTableEntries in the table (rows) */
|
---|
51 | private ArrayList metadata_audit_table_entries = new ArrayList();
|
---|
52 |
|
---|
53 |
|
---|
54 | /** Returns the number of columns in this table. */
|
---|
55 | public int getColumnCount()
|
---|
56 | {
|
---|
57 | return 1 + metadata_elements.size();
|
---|
58 | }
|
---|
59 |
|
---|
60 |
|
---|
61 | /** Returns the name of the specified column. */
|
---|
62 | public String getColumnName(int col)
|
---|
63 | {
|
---|
64 | // First column: filename
|
---|
65 | if (col == 0) {
|
---|
66 | return Dictionary.get("AuditTable.File");
|
---|
67 | }
|
---|
68 |
|
---|
69 | int metadata_element_index = col - 1;
|
---|
70 | return metadata_elements.get(metadata_element_index).toString();
|
---|
71 | }
|
---|
72 |
|
---|
73 |
|
---|
74 | /** Returns the values in a particular column. */
|
---|
75 | public ArrayList getColumnValues(int col)
|
---|
76 | {
|
---|
77 | // First column: filename
|
---|
78 | if (col == 0) {
|
---|
79 | ArrayList column_values = new ArrayList();
|
---|
80 | for (int i = 0; i < metadata_audit_table_entries.size(); i++) {
|
---|
81 | MetadataAuditTableEntry metadata_audit_table_entry = (MetadataAuditTableEntry) metadata_audit_table_entries.get(i);
|
---|
82 | column_values.add(metadata_audit_table_entry.getFilename());
|
---|
83 | }
|
---|
84 |
|
---|
85 | return column_values;
|
---|
86 | }
|
---|
87 |
|
---|
88 | // Check values are reasonable
|
---|
89 | int metadata_element_index = col - 1;
|
---|
90 | if (metadata_element_index < 0 || metadata_element_index >= metadata_elements.size()) {
|
---|
91 | return null;
|
---|
92 | }
|
---|
93 |
|
---|
94 | ArrayList column_values = new ArrayList();
|
---|
95 | for (int i = 0; i < metadata_audit_table_entries.size(); i++) {
|
---|
96 | MetadataAuditTableEntry metadata_audit_table_entry = (MetadataAuditTableEntry) metadata_audit_table_entries.get(i);
|
---|
97 | MetadataValueTreeNode[] metadata_value_tree_nodes = metadata_audit_table_entry.getMetadataValueTreeNodes(metadata_element_index);
|
---|
98 | if (metadata_value_tree_nodes != null) {
|
---|
99 | for (int j = 0; j < metadata_value_tree_nodes.length; j++) {
|
---|
100 | column_values.add(metadata_value_tree_nodes[j].toString());
|
---|
101 | }
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | return column_values;
|
---|
106 | }
|
---|
107 |
|
---|
108 |
|
---|
109 | /** Returns the number of rows in this table. */
|
---|
110 | public int getRowCount()
|
---|
111 | {
|
---|
112 | return metadata_audit_table_entries.size();
|
---|
113 | }
|
---|
114 |
|
---|
115 |
|
---|
116 | /** Returns the cell value at a given row and column as an Object. */
|
---|
117 | public Object getValueAt(int row, int col)
|
---|
118 | {
|
---|
119 | // Check values are reasonable
|
---|
120 | if (row < 0 || row >= metadata_audit_table_entries.size()) {
|
---|
121 | return null;
|
---|
122 | }
|
---|
123 |
|
---|
124 | // First column: filename
|
---|
125 | if (col == 0) {
|
---|
126 | ArrayList cell_values = new ArrayList();
|
---|
127 | cell_values.add(((MetadataAuditTableEntry) metadata_audit_table_entries.get(row)).getFilename());
|
---|
128 | return cell_values;
|
---|
129 | }
|
---|
130 |
|
---|
131 | // Check values are reasonable
|
---|
132 | int metadata_element_index = col - 1;
|
---|
133 | if (metadata_element_index < 0 || metadata_element_index >= metadata_elements.size()) {
|
---|
134 | return null;
|
---|
135 | }
|
---|
136 |
|
---|
137 | ArrayList cell_values = new ArrayList();
|
---|
138 | MetadataAuditTableEntry metadata_audit_table_entry = (MetadataAuditTableEntry) metadata_audit_table_entries.get(row);
|
---|
139 | MetadataValueTreeNode[] metadata_value_tree_nodes = metadata_audit_table_entry.getMetadataValueTreeNodes(metadata_element_index);
|
---|
140 | if (metadata_value_tree_nodes != null) {
|
---|
141 | for (int j = 0; j < metadata_value_tree_nodes.length; j++) {
|
---|
142 | cell_values.add(metadata_value_tree_nodes[j].toString());
|
---|
143 | }
|
---|
144 | }
|
---|
145 |
|
---|
146 | return cell_values;
|
---|
147 | }
|
---|
148 |
|
---|
149 |
|
---|
150 | public void rebuild(CollectionTreeNode[] file_nodes)
|
---|
151 | {
|
---|
152 | metadata_elements = MetadataSetManager.getEveryMetadataSetElement();
|
---|
153 | metadata_audit_table_entries.clear();
|
---|
154 |
|
---|
155 | this.file_nodes = file_nodes;
|
---|
156 | if (file_nodes != null && file_nodes.length > 0) {
|
---|
157 | // Create model builder
|
---|
158 | MetadataAuditTableModelBuilder builder = new MetadataAuditTableModelBuilder();
|
---|
159 | builder.run();
|
---|
160 | }
|
---|
161 | }
|
---|
162 |
|
---|
163 |
|
---|
164 | private class MetadataAuditTableModelBuilder
|
---|
165 | {
|
---|
166 | // Build a list of MetadataAuditTableEntries that represent the metadata asssigned to the selected files
|
---|
167 | public void run()
|
---|
168 | {
|
---|
169 | // Process each of the selected files in turn
|
---|
170 | for (int i = 0; i < file_nodes.length; i++) {
|
---|
171 | File current_file = file_nodes[i].getFile();
|
---|
172 |
|
---|
173 | // Get the metadata assigned to this file
|
---|
174 | ArrayList current_file_metadata = MetadataXMLFileManager.getMetadataAssignedToFile(current_file);
|
---|
175 |
|
---|
176 | // Get the extracted metadata for this file, if desired
|
---|
177 | if (Configuration.get("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC) == true) {
|
---|
178 | current_file_metadata.addAll(DocXMLFileManager.getMetadataExtractedFromFile(current_file));
|
---|
179 | }
|
---|
180 |
|
---|
181 | MetadataAuditTableEntry metadata_audit_table_entry = new MetadataAuditTableEntry(current_file, current_file_metadata);
|
---|
182 | metadata_audit_table_entries.add(metadata_audit_table_entry);
|
---|
183 | }
|
---|
184 | }
|
---|
185 | }
|
---|
186 |
|
---|
187 |
|
---|
188 | /** This class represents one (file, metadata) pair */
|
---|
189 | private class MetadataAuditTableEntry
|
---|
190 | {
|
---|
191 | private File file = null;
|
---|
192 | private ArrayList[] metadata_values = null;
|
---|
193 |
|
---|
194 |
|
---|
195 | public MetadataAuditTableEntry(File file, ArrayList metadata_values_list)
|
---|
196 | {
|
---|
197 | this.file = file;
|
---|
198 |
|
---|
199 | metadata_values = new ArrayList[metadata_elements.size()];
|
---|
200 | for (int i = 0; i < metadata_values.length; i++) {
|
---|
201 | metadata_values[i] = new ArrayList();
|
---|
202 | }
|
---|
203 |
|
---|
204 | for (int i = 0; i < metadata_values_list.size(); i++) {
|
---|
205 | MetadataValue metadata_value = (MetadataValue) metadata_values_list.get(i);
|
---|
206 | MetadataElement metadata_element = metadata_value.getMetadataElement();
|
---|
207 |
|
---|
208 | // Find the right column to put the value in
|
---|
209 | for (int j = 0; j < metadata_elements.size(); j++) {
|
---|
210 | if (metadata_element.equals(metadata_elements.get(j))) {
|
---|
211 | metadata_values[j].add(metadata_value);
|
---|
212 | break;
|
---|
213 | }
|
---|
214 | }
|
---|
215 | }
|
---|
216 | }
|
---|
217 |
|
---|
218 |
|
---|
219 | public String getFilename()
|
---|
220 | {
|
---|
221 | return file.getName();
|
---|
222 | }
|
---|
223 |
|
---|
224 |
|
---|
225 | public MetadataValueTreeNode[] getMetadataValueTreeNodes(int metadata_element_index)
|
---|
226 | {
|
---|
227 | ArrayList metadata_values_list = metadata_values[metadata_element_index];
|
---|
228 | if (metadata_values_list == null) {
|
---|
229 | return null;
|
---|
230 | }
|
---|
231 |
|
---|
232 | MetadataValueTreeNode[] metadata_value_tree_nodes = new MetadataValueTreeNode[metadata_values_list.size()];
|
---|
233 | for (int i = 0; i < metadata_values_list.size(); i++) {
|
---|
234 | metadata_value_tree_nodes[i] = ((MetadataValue) metadata_values_list.get(i)).getMetadataValueTreeNode();
|
---|
235 | }
|
---|
236 |
|
---|
237 | return metadata_value_tree_nodes;
|
---|
238 | }
|
---|
239 | }
|
---|
240 | }
|
---|