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

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

Removed some debug statements and made others go to the debug stream.

  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 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 /** Retrieves 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 number of rows in this table. */
66 public int getRowCount()
67 {
68 return metadata_audit_table_entries.size();
69 }
70
71
72 /** Returns the cell value at a given row and column as an Object. */
73 public Object getValueAt(int row, int col)
74 {
75 // Check values are reasonable
76 if (row < 0 || row >= metadata_audit_table_entries.size() || col < 0 || col >= metadata_elements.size()) {
77 return null;
78 }
79
80 MetadataAuditTableEntry metadata_audit_table_entry = (MetadataAuditTableEntry) metadata_audit_table_entries.get(row);
81 return metadata_audit_table_entry.getMetadataValueTreeNode(col);
82 }
83
84
85 public void rebuild(FileNode[] file_nodes)
86 {
87 metadata_elements = MetadataSetManager.getEveryMetadataSetElement();
88 metadata_audit_table_entries.clear();
89
90 this.file_nodes = file_nodes;
91 if (file_nodes != null && file_nodes.length > 0) {
92 // Create model builder
93 MetadataAuditTableModelBuilder builder = new MetadataAuditTableModelBuilder();
94 builder.run();
95 }
96 }
97
98
99 private class MetadataAuditTableModelBuilder
100 {
101 // Build a list of MetadataAuditTableEntries that represent the metadata asssigned to the selected files
102 public void run()
103 {
104 // Process each of the selected files in turn
105 for (int i = 0; i < file_nodes.length; i++) {
106 File current_file = file_nodes[i].getFile();
107
108 // Get the metadata assigned to this file
109 ArrayList current_file_metadata = MetadataXMLFileManager.getMetadataAssignedToFile(current_file);
110
111 // Get the extracted metadata for this file, if desired
112 if (Gatherer.config.get("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC) == true) {
113 current_file_metadata.addAll(DocXMLFileManager.getMetadataExtractedFromFile(current_file));
114 }
115
116 MetadataAuditTableEntry metadata_audit_table_entry = new MetadataAuditTableEntry(current_file, current_file_metadata);
117 metadata_audit_table_entries.add(metadata_audit_table_entry);
118 }
119 }
120 }
121
122
123 /** This class represents one (file, metadata) pair */
124 private class MetadataAuditTableEntry
125 {
126 private File file = null;
127 private MetadataValue[] metadata_values = null;
128
129
130 public MetadataAuditTableEntry(File file, ArrayList metadata_values_list)
131 {
132 this.file = file;
133
134 metadata_values = new MetadataValue[metadata_elements.size()];
135 for (int i = 0; i < metadata_values_list.size(); i++) {
136 MetadataValue metadata_value = (MetadataValue) metadata_values_list.get(i);
137 MetadataElement metadata_element = metadata_value.getMetadataElement();
138
139 // Find the right column to put the value in
140 for (int j = 0; j < metadata_elements.size(); j++) {
141 if (metadata_element.equals(metadata_elements.get(j))) {
142 metadata_values[j] = metadata_value;
143 break;
144 }
145 }
146 }
147 }
148
149
150 public MetadataValueTreeNode getMetadataValueTreeNode(int col)
151 {
152 if (metadata_values[col] == null) {
153 return null;
154 }
155
156 return metadata_values[col].getMetadataValueTreeNode();
157 }
158 }
159}
Note: See TracBrowser for help on using the repository browser.