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.awt.event.*;
|
---|
41 | import javax.swing.*;
|
---|
42 | import javax.swing.event.*;
|
---|
43 | import javax.swing.tree.*;
|
---|
44 | import org.greenstone.gatherer.Configuration;
|
---|
45 | import org.greenstone.gatherer.Dictionary;
|
---|
46 | import org.greenstone.gatherer.Gatherer;
|
---|
47 | import org.greenstone.gatherer.collection.CollectionTreeNode;
|
---|
48 | import org.greenstone.gatherer.gui.GLIButton;
|
---|
49 | import org.greenstone.gatherer.gui.SimpleMenuBar;
|
---|
50 | import org.greenstone.gatherer.gui.ModalDialog;
|
---|
51 |
|
---|
52 |
|
---|
53 | /** The MetaAuditFrame provides a table view of all of the metadata assigned to a selection of CollectionTreeNodes. All values for a certain file and a certain metadata element appear in the same cell. This table can be sorted by any column, and also has a MS Excel-like AutoFilter allowing you to restrict the rows visible to only those that match a certain set of criteria (applied to each column, and then 'ANDED', or cojoined, to determine the filter). Finally this dialog does not block the Gatherer tool, so the file selection can be changed and the dialog will just generate a new table dynamically.<BR>
|
---|
54 | * Much effort has gone into optimizing this table, as it quickly becomes slow and unresponsive to build/filter/sort when the number of records selected is high. However its performance is still nowhere as good as the Excel spreadsheet, and selections of 1000+ records can cause some serious waiting problems. Performance progression, shown in terms of time taken to perform action, are shown below. Note that building includes both the creation of the data model, and/or the time taken to lay out row and column sizes (due to this using multiple entry cells). Also all tables, by default, must be sorted by one column, which is initially the first column in ascending order:<BR><BR>
|
---|
55 | * <TABLE border=1 cellspacing=0 cellpadding=5>
|
---|
56 | * <TR><TD align=center colspan=5>Time Taken with 1000 records (ms)</TD></TR>
|
---|
57 | * <TR><TD>Action</TD><TD>Original</TD><TD>Revision 1</TD><TD>Revision 2</TD><TD>Revision 3</TD></TR>
|
---|
58 | * <TR><TD>Build</TD><TD align=right>113013</TD><TD align=right>1500</TD><TD align=right>1280</TD><TD align=right>665</TD></TR>
|
---|
59 | * <TR><TD>Sort</TD><TD align=right>34228</TD><TD align=right>353</TD><TD align=right>341</TD><TD align=right>338</TD></TR>
|
---|
60 | * <TR><TD>Filter</TD><TD align=right>57110</TD><TD align=right>485</TD><TD align=right>485</TD><TD align=right>485</TD></TR>
|
---|
61 | * </TABLE>
|
---|
62 | * <BR><BR>
|
---|
63 | * <TABLE border=1 cellspacing=0 cellpadding=5>
|
---|
64 | * <TR><TD align=center colspan=5>Time Taken with 10,000 records (ms) [hdlsub]</TD></TR>
|
---|
65 | * <TR><TD>Action</TD><TD>Original</TD><TD>Revision 1</TD><TD>Revision 2</TD><TD>Revision 3</TD></TR>
|
---|
66 | * <TR><TD>Build</TD><TD align=right>DNF</TD><TD align=right>8667</TD><TD align=right>6784</TD><TD align=right>3081</TD></TR>
|
---|
67 | * <TR><TD>Sort</TD><TD align=right>DNF</TD><TD align=right>236</TD><TD align=right>241</TD><TD align=right>228</TD></TR>
|
---|
68 | * <TR><TD>Filter</TD><TD align=right>DNF</TD><TD align=right>59272</TD><TD align=right>59767</TD><TD align=right>59614</TD></TR>
|
---|
69 | * </TABLE>
|
---|
70 | * <BR><BR>
|
---|
71 | * <TABLE border=1 cellspacing=0 cellpadding=5>
|
---|
72 | * <TR><TD align=center colspan=5>Time Taken with 30,000 records (ms) [hdl]</TD></TR>
|
---|
73 | * <TR><TD>Action</TD><TD>Original</TD><TD>Revision 1</TD><TD>Revision 2</TD><TD>Revision 3</TD></TR>
|
---|
74 | * <TR><TD>Build</TD><TD align=right>DNF</TD><TD align=right>19037</TD><TD align=right>16478</TD><TD align=right>8111</TD></TR>
|
---|
75 | * <TR><TD>Sort</TD><TD align=right>DNF</TD><TD align=right>314</TD><TD align=right>301</TD><TD align=right>385</TD></TR>
|
---|
76 | * <TR><TD>Filter</TD><TD align=right>DNF</TD><TD align=right>[300000]</TD><TD align=right>[300000]</TD><TD align=right>[300000]</TD></TR>
|
---|
77 | * </TABLE><BR><BR>
|
---|
78 | * It is easy to see that while building and sorting have become quite fast and reasonable, sorting is still unacceptable in terms of performance. The difficulty is this, that while sorting is easy (and fast) to implement via the Decorator pattern (making the overall table model a MDVC one) it requires the entire contents of a column to be available. Thus no matter the speed of your sort algorithm you will end up making N calls to getValueAt() in the table data model, for N records. This is not a problem for the initial model, hence the small sort times. However when you attempt to place another deocrator model (or modify the existing one) in order to filter only selected rows, even if the filtering itself takes little time, this little time quickly grows to unacceptable levels. In fact testing has shown it to grow much faster than linear time (though I'm not sure where). Doubling the number of records to filter increases the processing time by 5-7 times.<BR>
|
---|
79 | * In attempting to solve this problem, I have found many resources that mention a similar problem when trying to build visual representations of database tables, especially over networks or other temporally-non-deterministic connections. The common solution is to 'page' only those records necessary into memory on demand, thus making initial response significantly faster, while paying a small price for subsequent page seeks. There are even studies and algorithms for determining pages loads etc, I would imagine garnered from the memory management community. However none of these really help me usless I can get around the problem of having to have the entire columns population immeditaly accessable for sorting purposes.<BR>
|
---|
80 | * I believe with more time is would be possible to make a hybrid table model with properties such as you would require for the aforemenetioned database application, but which also provides fast methods for determining the highest and lowest records perhaps by building traversable heaps in the original model. Such a solution would incur a build penalty, and could consume significant memory, but would provide ordered and sequential access to the data within.<BR>
|
---|
81 | * The discussion aside, I have run out of time to do anything further on this, so will include as is, and provide a warning dialog whenever the number of records might suffer slow processing (1000+ records).
|
---|
82 | * @author John Thompson, Greenstone Digital Library, University of Waikato
|
---|
83 | * @version 2.3
|
---|
84 | */
|
---|
85 | public class MetaAuditFrame
|
---|
86 | extends ModalDialog
|
---|
87 | implements TreeSelectionListener {
|
---|
88 | public AutofilterDialog autofilter_dialog;
|
---|
89 | /** Whether the selection has changed since the last time we built the model (because it has been hidden and theres no point refreshing a model you can't see!). */
|
---|
90 | private boolean invalid = true;
|
---|
91 | /** An array holding the most recent list of paths selected (plus some nulls for those paths removed). */
|
---|
92 | private CollectionTreeNode[] records = null;
|
---|
93 | /** A reference to ourselves so that inner classes can interact with us. */
|
---|
94 | private MetaAuditFrame self;
|
---|
95 | /** The table in which the metadata is shown. */
|
---|
96 | private MetaAuditTable table;
|
---|
97 | /** The default size for the metaaudit dialog. */
|
---|
98 | static final private Dimension SIZE = new Dimension(640,505);
|
---|
99 |
|
---|
100 |
|
---|
101 | public MetaAuditFrame()
|
---|
102 | {
|
---|
103 | super(Gatherer.g_man);
|
---|
104 |
|
---|
105 | // Arguments
|
---|
106 | this.autofilter_dialog = new AutofilterDialog(this);
|
---|
107 | this.self = this;
|
---|
108 | this.table = new MetaAuditTable(this);
|
---|
109 |
|
---|
110 | // Creation
|
---|
111 | setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
|
---|
112 | setSize(SIZE);
|
---|
113 | setTitle(Dictionary.get("MetaAudit.Title"));
|
---|
114 | setJMenuBar(new SimpleMenuBar("reviewingmetadata"));
|
---|
115 |
|
---|
116 | JPanel content_pane = (JPanel) getContentPane();
|
---|
117 | JPanel button_pane = new JPanel();
|
---|
118 |
|
---|
119 | JButton close_button = new GLIButton(Dictionary.get("MetaAudit.Close"), Dictionary.get("MetaAudit.Close_Tooltip"));
|
---|
120 |
|
---|
121 | // Connection
|
---|
122 | close_button.addActionListener(new CloseListener());
|
---|
123 | Gatherer.c_man.getCollectionTree().addTreeSelectionListener(this);
|
---|
124 |
|
---|
125 | // Layout
|
---|
126 | button_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
127 | button_pane.setLayout(new BorderLayout());
|
---|
128 | button_pane.add(close_button, BorderLayout.CENTER);
|
---|
129 |
|
---|
130 | content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
131 | content_pane.setLayout(new BorderLayout());
|
---|
132 | content_pane.add(new JScrollPane(table), BorderLayout.CENTER);
|
---|
133 | content_pane.add(button_pane, BorderLayout.SOUTH);
|
---|
134 |
|
---|
135 | Dimension screen_size = Configuration.screen_size;
|
---|
136 | setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
|
---|
137 | screen_size = null;
|
---|
138 | close_button = null;
|
---|
139 | button_pane = null;
|
---|
140 | content_pane = null;
|
---|
141 | }
|
---|
142 |
|
---|
143 | /** Destructor. */
|
---|
144 | public void destroy() {
|
---|
145 | records = null;
|
---|
146 | self = null;
|
---|
147 | table = null;
|
---|
148 | }
|
---|
149 |
|
---|
150 | /** Display the dialog on screen. */
|
---|
151 | public void display() {
|
---|
152 | if(invalid) {
|
---|
153 | rebuildModel();
|
---|
154 | }
|
---|
155 | setVisible(true);
|
---|
156 | }
|
---|
157 |
|
---|
158 | public void setRecords(CollectionTreeNode[] records) {
|
---|
159 | this.records = records;
|
---|
160 | if(isVisible()) {
|
---|
161 | rebuildModel();
|
---|
162 | }
|
---|
163 | else {
|
---|
164 | invalid = true;
|
---|
165 | }
|
---|
166 | }
|
---|
167 |
|
---|
168 | /** This method is called whenever the selection within the collection tree changes. This causes the table to be rebuilt with a new model.
|
---|
169 | * @param event A <strong>TreeSelectionEvent</strong> containing information about the event.
|
---|
170 | */
|
---|
171 | public void valueChanged(TreeSelectionEvent event) {
|
---|
172 | Object source = event.getSource();
|
---|
173 | if(source instanceof JTree) {
|
---|
174 | TreePath paths[] = ((JTree)source).getSelectionPaths();
|
---|
175 | if(paths != null) {
|
---|
176 | records = new CollectionTreeNode[paths.length];
|
---|
177 | for(int i = 0; i < paths.length; i++) {
|
---|
178 | records[i] = (CollectionTreeNode) paths[i].getLastPathComponent();
|
---|
179 | }
|
---|
180 | if(isVisible()) {
|
---|
181 | rebuildModel();
|
---|
182 | }
|
---|
183 | else {
|
---|
184 | invalid = true;
|
---|
185 | }
|
---|
186 | }
|
---|
187 | }
|
---|
188 | }
|
---|
189 |
|
---|
190 | public void wait(boolean waiting) {
|
---|
191 | Component glass_pane = getGlassPane();
|
---|
192 | if(waiting) {
|
---|
193 | // Show wait cursor.
|
---|
194 | glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
---|
195 | glass_pane.setVisible(true);
|
---|
196 | }
|
---|
197 | else {
|
---|
198 | // Hide wait cursor.
|
---|
199 | glass_pane.setVisible(false);
|
---|
200 | glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
---|
201 | }
|
---|
202 | glass_pane = null;
|
---|
203 | }
|
---|
204 |
|
---|
205 | /** Rebuild the metaaudit table model using the current collection tree selection.
|
---|
206 | */
|
---|
207 | private void rebuildModel() {
|
---|
208 | // Build and set model
|
---|
209 | table.newModel(records);
|
---|
210 | // Done.
|
---|
211 | invalid = false;
|
---|
212 | }
|
---|
213 |
|
---|
214 | /** Listens for actions upon the close button, and if detected closes the dialog */
|
---|
215 | private class CloseListener
|
---|
216 | implements ActionListener {
|
---|
217 | /** Any implementation of ActionListener must include this method so that we can be informed when an action has been performed on our target control(s).
|
---|
218 | * @param event An <strong>ActionEvent</strong> containing information about the event.
|
---|
219 | */
|
---|
220 | public void actionPerformed(ActionEvent event) {
|
---|
221 | self.setVisible(false);
|
---|
222 | }
|
---|
223 | }
|
---|
224 | }
|
---|