source: trunk/gli/src/org/greenstone/gatherer/cdm/GeneralManager.java@ 4932

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

Major CDM rewrite so it uses DOM.

  • Property svn:keywords set to Author Date Id Revision
File size: 21.6 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;
28import java.awt.*;
29import java.awt.event.*;
30import javax.swing.*;
31import javax.swing.event.*;
32import javax.swing.text.JTextComponent;
33import javax.swing.tree.*;
34import org.greenstone.gatherer.Configuration;
35import org.greenstone.gatherer.Dictionary;
36import org.greenstone.gatherer.Gatherer;
37import org.greenstone.gatherer.cdm.CollectionConfiguration;
38import org.greenstone.gatherer.cdm.CollectionDesignManager;
39import org.greenstone.gatherer.cdm.Control;
40import org.greenstone.gatherer.gui.EmailField;
41import org.greenstone.gatherer.msm.MSMUtils;
42import org.greenstone.gatherer.util.Utility;
43/** This class is responsible for generating the necessary GUI components. It does this by calling the getEditControls() method of the appropriate class (i.e. IndexManager for index related edits). It also is in charge of correctly adding (and removing) listeners, using phrases from the <strong>Dictionary</strong> rather than the text keys inserted in the component classes, and several other aspects of the design page, including the config file section tree.
44* @author John Thompson, Greenstone Digital Library, University of Waikato
45* @version 2.3d
46*/
47public class GeneralManager
48 extends JPanel {
49 /** The available subscreens. */
50 static final private String CONTENTS[] = {"General", "Plugins", "Indexes", "Subcollections", "Classifiers", "Formats", "SuperCollection", "Translation", "MetadataSets"};
51 /** The preferred size of the collection design module screen real-estate. */
52 static final private Dimension SIZE = new Dimension(760, 500);
53 /** The preferred size of the contents tree. */
54 static final private Dimension TREE_SIZE = new Dimension(200, 500);
55 /** The preferred size of label. */
56 static final private Dimension LABEL_SIZE = new Dimension(200,25);
57 /** The controls used to modify the general options. */
58 private Control controls;
59 /** The panel apon which is rendered the currently selected section screen. */
60 private Control view = null;
61 /** A tree to serve as a 'table of contents' for this design tool. We decided on a tree rather than a list, as it allows us to break sections into subsections if they become to complicated. */
62 private DesignTree tree;
63 /** Constructor. */
64 public GeneralManager() {
65 super();
66 Gatherer.println("GeneralManager: Main GUI components created.");
67 // Assignments
68 this.controls = new GeneralControl();
69
70 // Creation
71 JPanel tree_pane = new JPanel();
72 JLabel title = new JLabel(get("Design_Topics"));
73 tree = new DesignTree();
74 view = controls;
75
76 // Connect
77 tree.addTreeSelectionListener(new TreeListener());
78
79 // Layout
80 tree_pane.setLayout(new BorderLayout());
81 tree_pane.setPreferredSize(TREE_SIZE);
82 tree_pane.add(title, BorderLayout.NORTH);
83 tree_pane.add(new JScrollPane(tree), BorderLayout.CENTER);
84
85 setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
86 setLayout(new BorderLayout());
87 add(tree_pane, BorderLayout.WEST);
88 add((JPanel)view, BorderLayout.CENTER);
89 }
90
91 /** Destructor. */
92 public void destroy() {
93 controls.destroy();
94 controls = null;
95 tree = null;
96 view = null;
97 }
98
99 /** Force the display to show a certain pane of controls.
100 * @param type a String giving the name of the information manager or view we wish to display
101 */
102 public void setSelectedView(String type) {
103 tree.setSelectedView(type);
104 }
105
106 /** Refresh the values on our controls that could be stale due to changes in other components. */
107 public void gainFocus() {
108 if(view != null) {
109 view.gainFocus();
110 }
111 }
112
113 /** Saves the state of the controls in the current view. */
114 public void loseFocus() {
115 if(view != null) {
116 view.loseFocus();
117 }
118 }
119
120 /** Overloaded to call get with both a key and an empty argument array.
121 * @param key a String which is mapped to a key within the dictionary
122 * @return a String which has been referenced by the key and that either contains no argument fields, or has had the argument fields automatically populated with arguments provided in the get call
123 */
124 private String get(String key) {
125 return get(key, null);
126 }
127
128 /** Used to retrieve a property value from the Locale specific ResourceBundle, based upon the key and arguments supplied. If the key cannot be found or if some other part of the call fails a default (English) error message is returned. <BR>
129 * Here the get recieves a second argument which is an array of Strings used to populate argument fields, denoted {<I>n</I>}, within the value String returned. Note that argument numbers greater than or equal to 32 are automatically mapped to the formatting String named Farg<I>n</I>.
130 * @param key A <strong>String</strong> which is mapped to a initial String within the ResourceBundle.
131 * @param args A <strong>String[]</strong> used to populate argument fields within the complete String.
132 * @return A <strong>String</strong> which has been referenced by the key String and that either contains no argument fields, or has had the argument fields automatiically populated with formatting Strings of with argument String provided in the get call.
133 * @see org.greenstone.gatherer.Gatherer
134 * @see org.greenstone.gatherer.Dictionary
135 */
136 private String get(String key, String args[]) {
137 if(key.indexOf('.') == -1) {
138 key = "CDM.GUI." + key;
139 }
140 return Gatherer.dictionary.get(key, args);
141 }
142
143 /** This class is resposible for generating the controls for the editing of general options.
144 * @return the Control for editing the general options
145 */
146 private Control getControls() {
147 return controls;
148 }
149
150 /** This class represents the visual component of the general options stored in the CollectionDesignManager. */
151 private class GeneralControl
152 extends JPanel
153 implements Control {
154 private boolean ready = false;
155 private CollectionMeta beta_collectionmeta;
156 private CollectionMeta collection_extra_collectionmeta;
157 private CollectionMeta collection_name_collectionmeta;
158 private CollectionMeta creator_collectionmeta;
159 private CollectionMeta icon_collection_collectionmeta;
160 private CollectionMeta icon_collection_small_collectionmeta;
161 private CollectionMeta maintainer_collectionmeta;
162 private CollectionMeta public_collectionmeta;
163 /** The creators email. */
164 private EmailField creator_emailfield;
165 /** The maintainers email. */
166 private EmailField maintainer_emailfield;
167 /** The checkbox controlling the state of the collection. */
168 private JCheckBox beta_checkbox;
169 /** The checkbox controlling public access to the collection. */
170 private JCheckBox public_checkbox;
171 private JLabel creator_label;
172 private JLabel description_label;
173 private JLabel icon_label;
174 private JLabel maintainer_label;
175 private JLabel name_label;
176 private JLabel small_icon_label;
177 private JLabel title_label;
178 /** The text field used to edit the file name of the collections icon. */
179 private JTextField icon_textfield;
180 /** The text field used to edit the collections title. */
181 private JTextField name_textfield;
182 /** The text field used to edit the file name of the collections small icon. */
183 private JTextField small_icon_textfield;
184 /** A text area used to modify the collection description. */
185 private JTextArea description_textarea;
186 private JTextArea instructions_textarea;
187 /** Constructor. */
188 public GeneralControl() {
189 super();
190 // Retrieve some of the model elements, those we know aren't language dependant
191 beta_collectionmeta = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_BETA_STR);
192 public_collectionmeta = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_PUBLIC_STR);
193
194 // Creation
195 JPanel instruction_panel = new JPanel();
196 title_label = new JLabel("CDM.General.Title");
197 title_label.setHorizontalAlignment(JLabel.CENTER);
198 instructions_textarea = new JTextArea("CDM.General.Instructions");
199 instructions_textarea.setCaretPosition(0);
200 instructions_textarea.setEditable(false);
201 instructions_textarea.setLineWrap(true);
202 instructions_textarea.setRows(4);
203 instructions_textarea.setWrapStyleWord(true);
204
205 JPanel all_details_panel = new JPanel();
206 JPanel details_panel = new JPanel();
207 JPanel creator_panel = new JPanel();
208 creator_label = new JLabel("CDM.General.Email.Creator");
209 creator_label.setPreferredSize(LABEL_SIZE);
210 creator_emailfield = new EmailField(Gatherer.config.getColor("coloring.error_background", false));
211 JPanel maintainer_panel = new JPanel();
212 maintainer_label = new JLabel("CDM.General.Email.Maintainer");
213 maintainer_label.setPreferredSize(LABEL_SIZE);
214 maintainer_emailfield = new EmailField(Gatherer.config.getColor("coloring.error_background", false));
215 public_checkbox = new JCheckBox("CDM.General.Access", public_collectionmeta.getValue().equals(CollectionConfiguration.TRUE_STR));
216 beta_checkbox = new JCheckBox("CDM.General.Beta", beta_collectionmeta.getValue().equals(CollectionConfiguration.TRUE_STR));
217 JPanel name_panel = new JPanel();
218 name_label = new JLabel("CDM.General.Collection_Name");
219 name_label.setPreferredSize(LABEL_SIZE);
220 name_textfield = new JTextField();
221 JPanel icon_panel = new JPanel();
222 icon_label = new JLabel("CDM.General.Icon_Collection");
223 icon_label.setPreferredSize(LABEL_SIZE);
224 icon_textfield = new JTextField();
225 JPanel small_icon_panel = new JPanel();
226 small_icon_label = new JLabel("CDM.General.Icon_Collection_Small");
227 small_icon_label.setPreferredSize(LABEL_SIZE);
228 small_icon_textfield = new JTextField();
229 JPanel description_panel = new JPanel();
230 description_label = new JLabel("CDM.General.Collection_Extra");
231 description_label.setPreferredSize(LABEL_SIZE);
232 description_textarea = new JTextArea();
233 description_textarea.setBackground(Gatherer.config.getColor("coloring.editable", false));
234 // Connection
235 beta_checkbox.addActionListener(CollectionDesignManager.change_listener);
236 public_checkbox.addActionListener(CollectionDesignManager.change_listener);
237 creator_emailfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
238 description_textarea.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
239 icon_textfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
240 maintainer_emailfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
241 name_textfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
242 small_icon_textfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
243 Gatherer.dictionary.register(beta_checkbox, null, false);
244 Gatherer.dictionary.register(creator_label, null, false);
245 Gatherer.dictionary.register(description_label, null, false);
246 Gatherer.dictionary.register(icon_label, null, false);
247 Gatherer.dictionary.register(instructions_textarea, null, false);
248 Gatherer.dictionary.register(maintainer_label, null, false);
249 Gatherer.dictionary.register(name_label, null, false);
250 Gatherer.dictionary.register(public_checkbox, null, false);
251 Gatherer.dictionary.register(small_icon_label, null, false);
252 Gatherer.dictionary.register(title_label, null, false);
253 // Layout
254 instruction_panel.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
255 instruction_panel.setLayout(new BorderLayout());
256 instruction_panel.add(title_label, BorderLayout.NORTH);
257 instruction_panel.add(new JScrollPane(instructions_textarea), BorderLayout.CENTER);
258
259 creator_panel.setLayout(new BorderLayout());
260 creator_panel.add(creator_label, BorderLayout.WEST);
261 creator_panel.add(creator_emailfield, BorderLayout.CENTER);
262
263 maintainer_panel.setLayout(new BorderLayout());
264 maintainer_panel.add(maintainer_label, BorderLayout.WEST);
265 maintainer_panel.add(maintainer_emailfield, BorderLayout.CENTER);
266
267 name_panel.setLayout(new BorderLayout());
268 name_panel.add(name_label, BorderLayout.WEST);
269 name_panel.add(name_textfield, BorderLayout.CENTER);
270
271 icon_panel.setLayout(new BorderLayout());
272 icon_panel.add(icon_label, BorderLayout.WEST);
273 icon_panel.add(icon_textfield, BorderLayout.CENTER);
274
275 small_icon_panel.setLayout(new BorderLayout());
276 small_icon_panel.add(small_icon_label, BorderLayout.WEST);
277 small_icon_panel.add(small_icon_textfield, BorderLayout.CENTER);
278
279 details_panel.setLayout(new GridLayout(7,1,5,0));
280 details_panel.add(creator_panel);
281 details_panel.add(maintainer_panel);
282 details_panel.add(public_checkbox);
283 details_panel.add(beta_checkbox);
284 details_panel.add(name_panel);
285 details_panel.add(icon_panel);
286 details_panel.add(small_icon_panel);
287
288 description_panel.setLayout(new BorderLayout());
289 description_panel.add(description_label, BorderLayout.NORTH);
290 description_panel.add(new JScrollPane(description_textarea), BorderLayout.CENTER);
291
292 all_details_panel.setLayout(new BorderLayout());
293 all_details_panel.add(details_panel, BorderLayout.NORTH);
294 all_details_panel.add(description_panel, BorderLayout.CENTER);
295
296 setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
297 setLayout(new BorderLayout());
298 add(instruction_panel, BorderLayout.NORTH);
299 add(all_details_panel, BorderLayout.CENTER);
300 }
301 /** Destructor. */
302 public void destroy() {
303 Gatherer.dictionary.deregister(beta_checkbox);
304 Gatherer.dictionary.deregister(creator_label);
305 Gatherer.dictionary.deregister(description_label);
306 Gatherer.dictionary.deregister(icon_label);
307 Gatherer.dictionary.deregister(instructions_textarea);
308 Gatherer.dictionary.deregister(maintainer_label);
309 Gatherer.dictionary.deregister(name_label);
310 Gatherer.dictionary.deregister(public_checkbox);
311 Gatherer.dictionary.deregister(small_icon_label);
312 Gatherer.dictionary.deregister(title_label);
313 }
314 /** Called to refresh the components. */
315 public void gainFocus() {
316 // Retrieve all of the elements that are dependant on default language.
317 collection_extra_collectionmeta = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_COLLECTIONEXTRA_STR);
318 collection_name_collectionmeta = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_COLLECTIONNAME_STR);
319 creator_collectionmeta = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_CREATOR_STR);
320 icon_collection_collectionmeta = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_ICONCOLLECTION_STR);
321 icon_collection_small_collectionmeta = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR);
322 maintainer_collectionmeta = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_MAINTAINER_STR);
323 // Make sure the components are up to date
324 creator_emailfield.setText(creator_collectionmeta.getValue());
325 creator_emailfield.setCaretPosition(0);
326 description_textarea.setText(collection_extra_collectionmeta.getValue());
327 description_textarea.setCaretPosition(0);
328 icon_textfield.setText(icon_collection_collectionmeta.getValue());
329 icon_textfield.setCaretPosition(0);
330 maintainer_emailfield.setText(maintainer_collectionmeta.getValue());
331 maintainer_emailfield.setCaretPosition(0);
332 name_textfield.setText(collection_name_collectionmeta.getValue());
333 name_textfield.setCaretPosition(0);
334 small_icon_textfield.setText(icon_collection_small_collectionmeta.getValue());
335 small_icon_textfield.setCaretPosition(0);
336 ready = true;
337 }
338 /** Called to store the current value of the components. */
339 public void loseFocus() {
340 // String values. Have to test if this component has actually ever recieved focus anyway.
341 if(ready) {
342 // Boolean values
343 beta_collectionmeta.setValue((beta_checkbox.isSelected() ? CollectionConfiguration.TRUE_STR : CollectionConfiguration.FALSE_STR));
344 public_collectionmeta.setValue((public_checkbox.isSelected() ? CollectionConfiguration.TRUE_STR : CollectionConfiguration.FALSE_STR));
345 creator_collectionmeta.setValue(creator_emailfield.getText());
346 collection_extra_collectionmeta.setValue(description_textarea.getText());
347 icon_collection_collectionmeta.setValue(icon_textfield.getText());
348 maintainer_collectionmeta.setValue(maintainer_emailfield.getText());
349 collection_name_collectionmeta.setValue(name_textfield.getText());
350 icon_collection_small_collectionmeta.setValue(small_icon_textfield.getText());
351 ready = false;
352 }
353 }
354
355 }
356 /** This tree provides a 'table of contents' for the various components of the design process (collection configuration in more technical terms). */
357 private class DesignTree
358 extends JTree {
359 private DesignNode root = null;
360 /** Constructor. Automatically generates all of the nodes, in the order of CONTENTS. */
361 public DesignTree() {
362 super();
363 root = new DesignNode("Root");
364 this.setModel(new DefaultTreeModel(root));
365 // Now add the design categories.
366 for(int i = 0; i < CONTENTS.length; i++) {
367 root.add(new DesignNode(CONTENTS[i]));
368 }
369 expandRow(0);
370 setRootVisible(false);
371 setSelectionRow(0);
372 }
373 /** Set the current view to the one specified.
374 * @param type the name of the desired view as a String
375 */
376 public void setSelectedView(String type) {
377 type = Gatherer.dictionary.get(type);
378 for(int i = 0; i < root.getChildCount(); i++) {
379 DesignNode child = (DesignNode) root.getChildAt(i);
380 if(child.toString().equals(type)) {
381 TreePath path = new TreePath(child.getPath());
382 setSelectionPath(path);
383 }
384 }
385 }
386 }
387 /** A tree node that retains a reference to one of the possible design sub-views relating to the different sub-managers. */
388 private class DesignNode
389 extends DefaultMutableTreeNode {
390 /** Constructor.
391 * @param object The <strong>Object</strong> assigned to this node.
392 */
393 public DesignNode(String object) {
394 super(object);
395 }
396 /** Retrieve a textual representation of the object.
397 * @return a String
398 */
399 public String toString() {
400 return get((String)getUserObject());
401 }
402 }
403 /** Listens for selection changes in the 'contents' tree, and switches to the appropriate view. */
404 private class TreeListener
405 implements TreeSelectionListener {
406 /** Called whenever the selection changes, we must update the view so it matches the node selected.
407 * @param event A <strong>TreeSelectionEvent</strong> containing more information about the tree selection.
408 * @see org.greenstone.gatherer.cdm.ClassifierManager
409 * @see org.greenstone.gatherer.cdm.CollectionDesignManager
410 * @see org.greenstone.gatherer.cdm.CollectionMetaManager
411 * @see org.greenstone.gatherer.cdm.FormatManager
412 * @see org.greenstone.gatherer.cdm.LanguageManager
413 * @see org.greenstone.gatherer.cdm.MetadataSetManager
414 * @see org.greenstone.gatherer.cdm.SubcollectionManager
415 * @see org.greenstone.gatherer.cdm.PlugInManager
416 */
417 public void valueChanged(TreeSelectionEvent event) {
418 if(!tree.isSelectionEmpty()) {
419 TreePath path = tree.getSelectionPath();
420 DesignNode node = (DesignNode)path.getLastPathComponent();
421 String type = (String)node.getUserObject();
422 // Wait begins
423 Gatherer.g_man.wait(true);
424 // Save information in current view
425 view.loseFocus();
426 remove((JPanel)view);
427 // Change panes.
428 if(type.equals("General")) {
429 view = getControls();
430 }
431 else if(type.equals("Plugins")) {
432 view = CollectionDesignManager.plugin_manager.getControls();
433 }
434 else if(type.equals("Indexes")) {
435 view = CollectionDesignManager.index_manager.getControls();
436 }
437 else if(type.equals("Subcollections")) {
438 view = CollectionDesignManager.subcollection_manager.getControls();
439 }
440 else if(type.equals("SuperCollection")) {
441 view = CollectionDesignManager.supercollection_manager.getControls();
442 }
443 else if(type.equals("Classifiers")) {
444 view = CollectionDesignManager.classifier_manager.getControls();
445 }
446 else if(type.equals("Formats")) {
447 view = CollectionDesignManager.format_manager.getControls();
448 }
449 else if(type.equals("Translation")) {
450 view = CollectionDesignManager.translation_view.getControls();
451 }
452 else if(type.equals("MetadataSets")) {
453 view = CollectionDesignManager.metadataset_view.getControls();
454 }
455 add((JPanel)view, BorderLayout.CENTER);
456 // Update information on visible pane
457 view.gainFocus();
458 repaint();
459 // Wait ends
460 Gatherer.g_man.wait(false);
461 }
462 }
463 }
464}
Note: See TracBrowser for help on using the repository browser.