1 | /**
|
---|
2 | *#########################################################################
|
---|
3 | *
|
---|
4 | * A component of the Gatherer application, part of the Greenstone digital
|
---|
5 | * library suite from the New Zealand Digital Library Project at the
|
---|
6 | * University of Waikato, New Zealand.
|
---|
7 | *
|
---|
8 | * <BR><BR>
|
---|
9 | *
|
---|
10 | * Author: John Thompson, Greenstone Digital Library, University of Waikato
|
---|
11 | *
|
---|
12 | * <BR><BR>
|
---|
13 | *
|
---|
14 | * Copyright (C) 1999 New Zealand Digital Library Project
|
---|
15 | *
|
---|
16 | * <BR><BR>
|
---|
17 | *
|
---|
18 | * This program is free software; you can redistribute it and/or modify
|
---|
19 | * it under the terms of the GNU General Public License as published by
|
---|
20 | * the Free Software Foundation; either version 2 of the License, or
|
---|
21 | * (at your option) any later version.
|
---|
22 | *
|
---|
23 | * <BR><BR>
|
---|
24 | *
|
---|
25 | * This program is distributed in the hope that it will be useful,
|
---|
26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
28 | * GNU General Public License for more details.
|
---|
29 | *
|
---|
30 | * <BR><BR>
|
---|
31 | *
|
---|
32 | * You should have received a copy of the GNU General Public License
|
---|
33 | * along with this program; if not, write to the Free Software
|
---|
34 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
35 | *########################################################################
|
---|
36 | */
|
---|
37 | package org.greenstone.gatherer.gui.metaaudit;
|
---|
38 |
|
---|
39 | import java.awt.*;
|
---|
40 | import java.util.*;
|
---|
41 | import java.io.*;
|
---|
42 | import javax.swing.table.*;
|
---|
43 | import org.greenstone.gatherer.Dictionary;
|
---|
44 | import org.greenstone.gatherer.Gatherer;
|
---|
45 | import org.greenstone.gatherer.file.FileNode;
|
---|
46 | import org.greenstone.gatherer.msm.Metadata;
|
---|
47 | import org.greenstone.gatherer.msm.MSMUtils;
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * @author John Thompson, Greenstone Digital Library, University of Waikato
|
---|
51 | * @version 2.1
|
---|
52 | */
|
---|
53 | public class MetaAuditModel
|
---|
54 | extends AbstractTableModel {
|
---|
55 |
|
---|
56 | private ArrayList elements;
|
---|
57 | private MetadataTableCache data;
|
---|
58 |
|
---|
59 | public MetaAuditModel(FileNode records[]) {
|
---|
60 | this.elements = new ArrayList(Gatherer.c_man.getCollection().msm.getElements());
|
---|
61 | Collections.sort(this.elements, MSMUtils.METADATA_COMPARATOR);
|
---|
62 | this.data = new MetadataTableCache(elements.size() + 1);
|
---|
63 | // Work our way through the record array provided, adding files, skipping blanks and recursively searching directories.
|
---|
64 | for(int i = 0; records != null && i < records.length; i++) {
|
---|
65 | if(records[i] != null) {
|
---|
66 | addRecord(records[i]);
|
---|
67 | }
|
---|
68 | }
|
---|
69 | }
|
---|
70 | public Class getColumnClass(int column) {
|
---|
71 | return ArrayList.class;
|
---|
72 | }
|
---|
73 | public int getColumnCount() {
|
---|
74 | return elements.size() + 1;
|
---|
75 | }
|
---|
76 | public String getColumnName(int column) {
|
---|
77 | String result;
|
---|
78 | if(column == 0) {
|
---|
79 | result = Dictionary.get("AuditTable.File");
|
---|
80 | }
|
---|
81 | else {
|
---|
82 | result = elements.get(column - 1).toString();
|
---|
83 | }
|
---|
84 | return result;
|
---|
85 | }
|
---|
86 | public ArrayList getColumnValues(int column) {
|
---|
87 | ArrayList column_values = new ArrayList();
|
---|
88 | if(0 <= column && column < getColumnCount()) {
|
---|
89 | for(int i = 0; i < data.size(); i++) {
|
---|
90 | ArrayList values = (ArrayList) data.get(i, column);
|
---|
91 | for(int j = 0; j < values.size(); j++) {
|
---|
92 | column_values.add(values.get(j).toString());
|
---|
93 | }
|
---|
94 | }
|
---|
95 | }
|
---|
96 | return column_values;
|
---|
97 | }
|
---|
98 | public int getRowCount() {
|
---|
99 | return data.size();
|
---|
100 | }
|
---|
101 | public Object getValueAt(int row, int column) {
|
---|
102 | Object result = "";
|
---|
103 | if(0 <= row && row < data.size() && 0 <= column && column < elements.size() + 1) {
|
---|
104 | result = data.get(row, column);
|
---|
105 | }
|
---|
106 | return result;
|
---|
107 | }
|
---|
108 |
|
---|
109 | public void reset() {
|
---|
110 | }
|
---|
111 |
|
---|
112 | private void addRecord(FileNode record) {
|
---|
113 | if(record.isLeaf()) {
|
---|
114 | File file = record.getFile();
|
---|
115 | data.newRow();
|
---|
116 | data.put(0, file.getName());
|
---|
117 | ArrayList metadatum = Gatherer.c_man.getCollection().gdm.getAllMetadata(file);
|
---|
118 | for(int i = 0; i < metadatum.size(); i++) {
|
---|
119 | Metadata metadata = (Metadata) metadatum.get(i);
|
---|
120 | int index = elements.indexOf(metadata.getElement())+1;
|
---|
121 | if (index!=0) {
|
---|
122 | // some elements are hidden and dont appear in teh table
|
---|
123 | data.put(index, metadata.getValueNode());
|
---|
124 | }
|
---|
125 | }
|
---|
126 | }
|
---|
127 | else {
|
---|
128 | for(int i = 0; i < record.getChildCount(); i++) {
|
---|
129 | addRecord((FileNode)record.getChildAt(i));
|
---|
130 | }
|
---|
131 | }
|
---|
132 | }
|
---|
133 |
|
---|
134 | private class MetadataTableCache {
|
---|
135 | private ArrayList data;
|
---|
136 | private ArrayList current_row[];
|
---|
137 | private int columns;
|
---|
138 | private RowComparator row_comparator = new RowComparator();
|
---|
139 | public MetadataTableCache(int columns) {
|
---|
140 | this.columns = columns;
|
---|
141 | this.data = new ArrayList();
|
---|
142 | }
|
---|
143 |
|
---|
144 | public ArrayList get(int row, int column) {
|
---|
145 | ArrayList array_list[] = (ArrayList[]) data.get(row);
|
---|
146 | return array_list[column];
|
---|
147 | }
|
---|
148 |
|
---|
149 | public void newRow() {
|
---|
150 | if(current_row != null) {
|
---|
151 | for(int i = 0; i < columns; i++) {
|
---|
152 | Collections.sort(current_row[i], row_comparator);
|
---|
153 | }
|
---|
154 | }
|
---|
155 | current_row = new ArrayList[columns];
|
---|
156 | for(int i = 0; i < columns; i++) {
|
---|
157 | current_row[i] = new ArrayList();
|
---|
158 | }
|
---|
159 | data.add(current_row);
|
---|
160 | }
|
---|
161 |
|
---|
162 | public void put(int column, Object value) {
|
---|
163 | current_row[column].add(value);
|
---|
164 | }
|
---|
165 |
|
---|
166 | public int size() {
|
---|
167 | return data.size();
|
---|
168 | }
|
---|
169 | }
|
---|
170 |
|
---|
171 | private class RowComparator
|
---|
172 | implements Comparator {
|
---|
173 | public int compare(Object o1, Object o2) {
|
---|
174 | return o1.toString().compareTo(o2.toString());
|
---|
175 | }
|
---|
176 | public boolean equals(Object obj) {
|
---|
177 | return toString().equals(obj.toString());
|
---|
178 | }
|
---|
179 | }
|
---|
180 | }
|
---|