source: trunk/gli/src/org/greenstone/gatherer/gui/metaaudit/MetaAuditModel.java@ 4587

Last change on this file since 4587 was 4565, checked in by jmt12, 21 years ago

2030118, 2030119: MetaAudit view now has columns sorted by natural ordering and correctly reflects the current selection in the visible tree.

  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 KB
Line 
1package 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 */
38import java.awt.*;
39import java.util.*;
40import java.io.*;
41import javax.swing.table.*;
42import org.greenstone.gatherer.Gatherer;
43import org.greenstone.gatherer.file.FileNode;
44import org.greenstone.gatherer.msm.ElementWrapper;
45import org.greenstone.gatherer.msm.Metadata;
46import org.greenstone.gatherer.msm.MetadataSetManager;
47import org.greenstone.gatherer.msm.MSMUtils;
48import org.greenstone.gatherer.valuetree.GValueNode;
49/**
50 * @author John Thompson, Greenstone Digital Library, University of Waikato
51 * @version 2.1
52 */
53public 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 = Gatherer.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.getMetadata(file);
118 for(int i = 0; i < metadatum.size(); i++) {
119 Metadata metadata = (Metadata) metadatum.get(i);
120 data.put(elements.indexOf(metadata.getElement()) + 1, metadata.getValueNode());
121 }
122 }
123 else {
124 for(int i = 0; i < record.getChildCount(); i++) {
125 addRecord((FileNode)record.getChildAt(i));
126 }
127 }
128 }
129
130 private class MetadataTableCache {
131 private ArrayList data;
132 private ArrayList current_row[];
133 private int columns;
134 private RowComparator row_comparator = new RowComparator();
135 public MetadataTableCache(int columns) {
136 this.columns = columns;
137 this.data = new ArrayList();
138 }
139
140 public ArrayList get(int row, int column) {
141 ArrayList array_list[] = (ArrayList[]) data.get(row);
142 return array_list[column];
143 }
144
145 public void newRow() {
146 if(current_row != null) {
147 for(int i = 0; i < columns; i++) {
148 Collections.sort(current_row[i], row_comparator);
149 }
150 }
151 current_row = new ArrayList[columns];
152 for(int i = 0; i < columns; i++) {
153 current_row[i] = new ArrayList();
154 }
155 data.add(current_row);
156 }
157
158 public void put(int column, Object value) {
159 current_row[column].add(value);
160 }
161
162 public int size() {
163 return data.size();
164 }
165 }
166
167 private class RowComparator
168 implements Comparator {
169 public int compare(Object o1, Object o2) {
170 return o1.toString().compareTo(o2.toString());
171 }
172 public boolean equals(Object obj) {
173 return toString().equals(obj.toString());
174 }
175 }
176}
177
178
179
180
Note: See TracBrowser for help on using the repository browser.