source: trunk/gli/src/org/greenstone/gatherer/cdm/MetadataSetView.java@ 6323

Last change on this file since 6323 was 6051, checked in by jmt12, 21 years ago

Here is the result of sixteen hours work over the weekend. I'm too tired to comment them all separately, but here are some of the highlights:
Rewrote how the 'base on collection' method actually retrieves and updates the collection configuration - ensuring the CDM.CollectionConfiguration class is used instead of the retarded Collection.CollectionConfiguration (which coincidently has had a name change to BasicCollectionConfiguration). Went through code search for places where the two versions had been confused. Rewrote large swathes of GDMDocument so as to differentiate between normal and extracted metadata - an attempt to prevent the snowballing extracted metadata problem. Fixed problem where GLI was correctly recieving the last few lines of an external process. The collection shortname is no longer visible, nor is the confusing double name for metadata elements. Also coloured folders in the trees are kaput. The users email is now saved as part of the GLI configuration and is used as appropriate to fill out collection fields. There are new options on the right click menus over trees to allow the expansion and collapsing of folders. 'Show Files' now shows all types (or at least 6 types) of image properly (arg, the plagues of copy and paste). 'Based On' collections are public, plugin list automatically moves to next entry if plugin removed (I guess we should do the same in every other screen?) and metadata arguments in plugins/classifiers are no longer editable. There are about a dozen other small things, but I can't remember them. Hope I remembered to set all of the files to UNIX line-endings.

  • Property svn:keywords set to Author Date Id Revision
File size: 12.9 KB
Line 
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 * Author: John Thompson, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 1999 New Zealand Digital Library Project
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *########################################################################
26 */
27package org.greenstone.gatherer.cdm;
28
29import java.awt.*;
30import java.util.*;
31import javax.swing.*;
32import javax.swing.event.*;
33import org.greenstone.gatherer.Dictionary;
34import org.greenstone.gatherer.Gatherer;
35import org.greenstone.gatherer.cdm.CollectionDesignManager;
36import org.greenstone.gatherer.cdm.Control;
37import org.greenstone.gatherer.cdm.ElementWrapper;
38import org.greenstone.gatherer.msm.MetadataSet;
39import org.greenstone.gatherer.msm.MSMEvent;
40import org.greenstone.gatherer.msm.MSMUtils;
41import org.greenstone.gatherer.msm.MSMListener;
42import org.w3c.dom.*;
43
44/** Unlike its namesake in the msm package, this class really only knows how to produce a simple visual representation of the currently imported metadata sets. It is also read-only, so should be fairly straight forward. (It has no namesake any longer as my co-programmers found this far too confusing - however I have now added a CollectionConfiguration to the cdm package just to keep them on their toes!)
45 * @author John Thompson, Greenstone Digital Library, University of Waikato
46 * @version 2.3d
47 * @see org.greenstone.gatherer.msm.MetadataSetManager
48 */
49public class MetadataSetView
50 extends DynamicListModel
51 implements MSMListener {
52 /** The visual contols used to review the metadata sets. */
53 private Control controls = null;
54 /** A reference to ourselves so our inner classes can refer to us. */
55 private DynamicListModel model = null;
56
57 /** Constructor.
58 */
59 public MetadataSetView() {
60 Gatherer.println("MetadataSetView: Initialized.");
61 model = this;
62 Gatherer.c_man.getCollection().msm.addMSMListener(this);
63 loadMetadataSets();
64 // Build the controls
65 controls = new MetadataSetControl();
66 }
67
68 /** Destructor. Remove any references of this class from persistant objects.
69 * @see org.greenstone.gatherer.Gatherer
70 * @see org.greenstone.gatherer.collection.CollectionManager
71 * @see org.greenstone.gatherer.msm.MetadataSetManager
72 */
73 public void destroy() {
74 controls.destroy();
75 controls = null;
76 Gatherer.c_man.msm.removeMSMListener(this);
77 model = null;
78 }
79
80 /** Called when an element is changed within a set in the MSM, prompting us to refresh our list of elements being shown.
81 * @param event A <strong>MSMEvent</strong> which encapsulates relevant data about the change.
82 * @see org.greenstone.gatherer.cdm.MetadataSetManager.Control
83 */
84 public void elementChanged(MSMEvent event) {
85 // Get the controls to refresh element list.
86 ((MetadataSetControl)controls).refreshElementList();
87 }
88
89 /** A method for retrieve the controls for this manager.
90 * @see org.greenstone.gatherer.Dictionary
91 * @see org.greenstone.gatherer.gui.Coloring
92 * @see org.greenstone.gatherer.msm.MetadataSetManager
93 */
94 public Control getControls() {
95 return controls;
96 }
97
98 /** Called when a metadata value has undergone significant change.
99 * @param event A <strong>MSMEvent</strong> which encapsulates relevant data about the change.
100 */
101 public void metadataChanged(MSMEvent event) {
102 // Couldn't care less.
103 }
104
105 /** Called when a set is added or removed from the MSM.
106 * @param event A <strong>MSMEvent</strong> which encapsulates relevant data about the change.
107 */
108 public void setChanged(MSMEvent event) {
109 // Reload model.
110 clear();
111 loadMetadataSets();
112 }
113
114 /** Select the selected element, given its name, and return the bounds of the selection. Used during search and replace.
115 * @param element The elements fully qualified name as a <strong>String</strong>.
116 * @return The bounds of the selection as a <strong>Rectangle</strong>.
117 * @see org.greenstone.gatherer.cdm.MetadataSetManager.Control
118 */
119 public Rectangle setSelectedElement(String element) {
120 return ((MetadataSetControl)controls).setSelectedElement(element);
121 }
122
123 /** Prints out the contents of this manager, as they would appear in the collection configuration file.
124 * @return A <strong>String</strong> containing a block of commands.
125 * @see org.greenstone.gatherer.cdm.MetadataSetManager.SetWrapper
126 */
127 public String toString() {
128 String text = "";
129 for(int i = 0; i < size(); i++) {
130 SetWrapper set = (SetWrapper)get(i);
131 text = text + set.toString() + "\n";
132 }
133 text = text + "\n";
134 return text;
135 }
136
137 /** Called when a significant change has occured to a value tree for a certain element, however we take no further action.
138 * @param event A <strong>MSMEvent</strong> containing information relevant to the event.
139 */
140 public void valueChanged(MSMEvent event) {
141 }
142
143 /** Retrieves the current list of loaded metadata sets, and builds a list model around them.
144 * @see org.greenstone.gatherer.Gatherer
145 * @see org.greenstone.gatherer.cdm.MetadataSetManager.SetWrapper
146 * @see org.greenstone.gatherer.collection.CollectionManager
147 * @see org.greenstone.gatherer.msm.MetadataSet
148 * @see org.greenstone.gatherer.msm.MetadataSetManager
149 */
150 private void loadMetadataSets() {
151 // We initialize the set_model with wrapped metadata sets. Note that when we call getSets() we also end up adding ourselves as a listener to the metadata set manager.
152 Vector sets = Gatherer.c_man.getCollection().msm.getSets();
153 for(int i = 0; i < sets.size(); i++) {
154 addElement(new SetWrapper((MetadataSet)sets.get(i)));
155 }
156 }
157
158 /** This class creates and lays-out the various controls for reviewing the metadata sets, and their commands as they would appear in the collection configuration file. */
159 private class MetadataSetControl
160 extends JPanel
161 implements Control {
162 /** The label denoting the element list. */
163 private JLabel element_label = null;
164 /** The label denoting the set list. */
165 private JLabel set_label = null;
166 /** The title of these controls. */
167 private JLabel title = null;
168 /** The list of elements for the choosen set. */
169 private JList element_list = null;
170 /** The list of sets in this collection. */
171 private JList set_list = null;
172 /** The panel onto which all other panels will be placed. */
173 private JPanel central_pane = null;
174 /** The panel onto which the element list will be placed. */
175 private JPanel element_pane = null;
176 /** The panel containing the title and instructions. */
177 private JPanel header_pane = null;
178 /** The panel containing the set list. */
179 private JPanel set_pane = null;
180 /** The text area of inline instructions. */
181 private JTextArea instructions = null;
182 /** The element model for the currently selected set. */
183 private Vector element_model = null;
184
185 /* Constructor.
186 * @see org.greenstone.gatherer.Coloring;
187 * @see org.greenstone.gatherer.Dictionary
188 * @see org.greenstone.gatherer.cdm.MetadataSetManager.ListListener
189 * @see org.greenstone.gatherer.msm.MetadataSetManager
190 */
191 public MetadataSetControl() {
192 // Create visual components
193 central_pane = new JPanel();
194 element_label = new JLabel();
195 element_label.setHorizontalAlignment(JLabel.CENTER);
196 element_label.setOpaque(true);
197 Dictionary.registerText(element_label, "CDM.MetadataSetManager.Elements");
198 element_list = new JList();
199 element_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
200 element_pane = new JPanel();
201 header_pane = new JPanel();
202 instructions = new JTextArea();
203 instructions.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
204 instructions.setEditable(false);
205 instructions.setLineWrap(true);
206 instructions.setRows(6);
207 instructions.setWrapStyleWord(true);
208 Dictionary.registerText(instructions, "CDM.MetadataSetManager.Instructions");
209 set_label = new JLabel();
210 set_label.setHorizontalAlignment(JLabel.CENTER);
211 set_label.setOpaque(true);
212 Dictionary.registerText(set_label, "CDM.MetadataSetManager.Sets");
213 set_list = new JList(model);
214 set_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
215 set_pane = new JPanel();
216 title = new JLabel();
217 title.setHorizontalAlignment(JLabel.CENTER);
218 title.setOpaque(true);
219 Dictionary.registerText(title, "CDM.MetadataSetManager.Title");
220
221 // Add listeners
222 set_list.addListSelectionListener(new ListListener());
223
224 // Layout
225 instructions.setBorder(BorderFactory.createEmptyBorder(2,5,2,5));
226
227 header_pane.setLayout(new BorderLayout());
228 header_pane.add(title, BorderLayout.NORTH);
229 header_pane.add(new JScrollPane(instructions), BorderLayout.CENTER);
230
231 set_pane.setLayout(new BorderLayout());
232 set_pane.add(set_label, BorderLayout.NORTH);
233 set_pane.add(new JScrollPane(set_list), BorderLayout.CENTER);
234
235 element_pane.setLayout(new BorderLayout());
236 element_pane.add(element_label, BorderLayout.NORTH);
237 element_pane.add(new JScrollPane(element_list), BorderLayout.CENTER);
238
239 central_pane.setLayout(new GridLayout(2,1));
240 central_pane.add(set_pane);
241 central_pane.add(element_pane);
242
243 setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
244 setLayout(new BorderLayout());
245 add(header_pane, BorderLayout.NORTH);
246 add(central_pane, BorderLayout.CENTER);
247 }
248 /** Destructor. */
249 public void destroy() {
250 }
251 /** Update the element list. */
252 public void refreshElementList() {
253 element_list.updateUI();
254 }
255 /** Select the selected element, given its name, and return the bounds of the selection. Used during search and replace.
256 * @param element The elements fully qualified name as a <strong>String</strong>.
257 * @return The bounds of the selection as a <strong>Rectangle</strong>.
258 * @see org.greenstone.gatherer.cdm.MetadataSetManager.Control
259 * @see org.greenstone.gatherer.cdm.MetadataSetManager.Control.ElementWrapper
260 */
261 public Rectangle setSelectedElement(String element) {
262 Rectangle bounds = null;
263 // Parse off namespace
264 String namespace = element.substring(0, element.indexOf("."));
265 // Force the set list to show the correct entry.
266 ListModel s_model = set_list.getModel();
267 for(int i = 0; i < s_model.getSize(); i++) {
268 SetWrapper sw = (SetWrapper) s_model.getElementAt(i);
269 if(sw.getSet().getNamespace().equals(namespace)) {
270 set_list.setSelectedValue(sw, true);
271 }
272 }
273 // Force the element list to show that name.
274 ListModel e_model = element_list.getModel();
275 for(int i = 0; i < e_model.getSize(); i++) {
276 ElementWrapper ew = (ElementWrapper) e_model.getElementAt(i);
277 if(ew.name().equals(element)) {
278 element_list.setSelectedValue(ew, true);
279 bounds = element_list.getCellBounds(i, i);
280 }
281 }
282 // Return the bounds of the selected row.
283 return bounds;
284 }
285
286 /** Overriden to ensure the instruction area is scrolled to top.
287 */
288 public void gainFocus() {
289 if(instructions != null) {
290 instructions.setCaretPosition(0);
291 }
292 }
293
294 public void loseFocus() {
295 }
296
297 private class ListListener
298 implements ListSelectionListener {
299 public void valueChanged(ListSelectionEvent event) {
300 if(!set_list.isSelectionEmpty()) {
301 MetadataSet set = ((SetWrapper)set_list.getSelectedValue()).getSet();
302 NodeList elements = set.getElements();
303 element_model = new Vector();
304 for(int i = 0; i < elements.getLength(); i++) {
305 element_model.add(new ElementWrapper(elements.item(i)));
306 }
307 Collections.sort(element_model);
308 element_list.setListData(element_model);
309 }
310 }
311 }
312 }
313
314 /** Provides a convience wrapper around a metadata set, that allows it to appear in the <strong>JList</strong> the same way it would in the collection configuration file. */
315 private class SetWrapper {
316 private MetadataSet set = null;
317 public SetWrapper(MetadataSet set) {
318 this.set = set;
319 }
320 public MetadataSet getSet() {
321 return set;
322 }
323 public String toString() {
324 String namespace = set.getNamespace();
325 // Watch out for the greenstone set, with its namespace of ""
326 return "metadataset " + namespace + " \"" + set.getName() + "\"";
327 }
328 }
329}
Note: See TracBrowser for help on using the repository browser.