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