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

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

203B301: Changing view away from design now causes collection to release as necessary, configuration to be written, and collection to be readd if released

  • Property svn:keywords set to Author Date Id Revision
File size: 20.1 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.awt.event.*;
31import javax.swing.*;
32import javax.swing.event.*;
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.util.Utility;
42
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[] = { "CDM.GUI.General", "CDM.GUI.Plugins", "CDM.GUI.SearchTypes", "CDM.GUI.Indexes", "CDM.GUI.Subcollections", "CDM.GUI.SuperCollection", "CDM.GUI.Classifiers", "CDM.GUI.Formats", "CDM.GUI.Translation", "CDM.GUI.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();
73 Dictionary.registerText(title, "CDM.GUI.Design_Topics");
74 tree = new DesignTree();
75 view = controls;
76
77 // Connect
78 tree.addTreeSelectionListener(new TreeListener());
79
80 // Layout
81 tree_pane.setLayout(new BorderLayout());
82 tree_pane.setPreferredSize(TREE_SIZE);
83 tree_pane.add(title, BorderLayout.NORTH);
84 tree_pane.add(new JScrollPane(tree), BorderLayout.CENTER);
85
86 setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
87 setLayout(new BorderLayout());
88 add(tree_pane, BorderLayout.WEST);
89 add((JPanel)view, BorderLayout.CENTER);
90 }
91
92 /** Destructor. */
93 public void destroy() {
94 controls.destroy();
95 controls = null;
96 tree = null;
97 view = null;
98 }
99
100 /** Force the display to show a certain pane of controls.
101 * @param type a String giving the name of the information manager or view we wish to display
102 */
103 public void setSelectedView(String type) {
104 tree.setSelectedView(type);
105 }
106
107 /** Refresh the values on our controls that could be stale due to changes in other components. */
108 public void gainFocus() {
109 if (view != null) {
110 view.gainFocus();
111 }
112 }
113
114 /** Saves the state of the controls in the current view. */
115 public void loseFocus() {
116 if (view != null) {
117 view.loseFocus();
118 }
119 }
120
121 /** This class is resposible for generating the controls for the editing of general options.
122 * @return the Control for editing the general options
123 */
124 private Control getControls() {
125 return controls;
126 }
127
128 /** This class represents the visual component of the general options stored in the CollectionDesignManager. */
129 private class GeneralControl
130 extends JPanel
131 implements Control {
132 private boolean ready = false;
133 private CollectionMeta beta_collectionmeta;
134 private CollectionMeta collection_extra_collectionmeta;
135 private CollectionMeta collection_name_collectionmeta;
136 private CollectionMeta creator_collectionmeta;
137 private CollectionMeta icon_collection_collectionmeta;
138 private CollectionMeta icon_collection_small_collectionmeta;
139 private CollectionMeta maintainer_collectionmeta;
140 private CollectionMeta public_collectionmeta;
141 /** The creators email. */
142 private EmailField creator_emailfield;
143 /** The maintainers email. */
144 private EmailField maintainer_emailfield;
145 /** The checkbox controlling the state of the collection. */
146 private JCheckBox beta_checkbox;
147 /** The checkbox controlling public access to the collection. */
148 private JCheckBox public_checkbox;
149 private JLabel creator_label;
150 private JLabel description_label;
151 private JLabel icon_label;
152 private JLabel maintainer_label;
153 private JLabel name_label;
154 private JLabel small_icon_label;
155 private JLabel title_label;
156 /** The text field used to edit the file name of the collections icon. */
157 private JTextField icon_textfield;
158 /** The text field used to edit the collections title. */
159 private JTextField name_textfield;
160 /** The text field used to edit the file name of the collections small icon. */
161 private JTextField small_icon_textfield;
162 /** A text area used to modify the collection description. */
163 private JTextArea description_textarea;
164 private JTextArea instructions_textarea;
165 /** Constructor. */
166 public GeneralControl() {
167 super();
168 // Retrieve some of the model elements, those we know aren't language dependant
169 beta_collectionmeta = new CollectionMeta(CollectionDesignManager.collect_config.getBeta());
170 public_collectionmeta = new CollectionMeta(CollectionDesignManager.collect_config.getPublic());
171
172 // Creation
173 JPanel instruction_panel = new JPanel();
174 title_label = new JLabel();
175 title_label.setHorizontalAlignment(JLabel.CENTER);
176 Dictionary.registerText(title_label, "CDM.General.Title");
177
178 instructions_textarea = new JTextArea();
179 instructions_textarea.setCaretPosition(0);
180 instructions_textarea.setEditable(false);
181 instructions_textarea.setLineWrap(true);
182 instructions_textarea.setRows(6);
183 instructions_textarea.setWrapStyleWord(true);
184 Dictionary.registerText(instructions_textarea, "CDM.General.Instructions");
185
186 JPanel all_details_panel = new JPanel();
187 JPanel details_panel = new JPanel();
188 JPanel creator_panel = new JPanel();
189 creator_label = new JLabel();
190 creator_label.setPreferredSize(LABEL_SIZE);
191 Dictionary.registerText(creator_label, "CDM.General.Email.Creator");
192
193 creator_emailfield = new EmailField(Gatherer.config.getColor("coloring.error_background", false));
194 Dictionary.registerTooltip(creator_emailfield, "CDM.General.Email.Creator_Tooltip");
195
196 JPanel maintainer_panel = new JPanel();
197 maintainer_label = new JLabel();
198 maintainer_label.setPreferredSize(LABEL_SIZE);
199 Dictionary.registerText(maintainer_label, "CDM.General.Email.Maintainer");
200
201 maintainer_emailfield = new EmailField(Gatherer.config.getColor("coloring.error_background", false));
202 Dictionary.registerTooltip(maintainer_emailfield, "CDM.General.Email.Maintainer_Tooltip");
203 public_checkbox = new JCheckBox("", public_collectionmeta.getValue(CollectionMeta.TEXT).equals(CollectionConfiguration.TRUE_STR));
204 Dictionary.registerText(public_checkbox, "CDM.General.Access");
205 beta_checkbox = new JCheckBox("", beta_collectionmeta.getValue(CollectionMeta.TEXT).equals(CollectionConfiguration.TRUE_STR));
206 Dictionary.registerText(beta_checkbox, "CDM.General.Beta");
207 JPanel name_panel = new JPanel();
208 name_label = new JLabel();
209 name_label.setPreferredSize(LABEL_SIZE);
210 Dictionary.registerText(name_label, "CDM.General.Collection_Name");
211 name_textfield = new JTextField("CDM.General.Collection_Name");
212 Dictionary.registerTooltip(name_textfield, "CDM.General.Collection_Name_Tooltip");
213 JPanel icon_panel = new JPanel();
214 icon_label = new JLabel();
215 icon_label.setPreferredSize(LABEL_SIZE);
216 Dictionary.registerText(icon_label, "CDM.General.Icon_Collection");
217 icon_textfield = new JTextField("CDM.General.Icon_Collection");
218 Dictionary.registerTooltip(icon_textfield, "CDM.General.Icon_Collection_Tooltip");
219 JPanel small_icon_panel = new JPanel();
220 small_icon_label = new JLabel("CDM.General.Icon_Collection_Small");
221 small_icon_label.setPreferredSize(LABEL_SIZE);
222 Dictionary.registerText(small_icon_label, "CDM.General.Icon_Collection_Small");
223 small_icon_textfield = new JTextField("CDM.General.Icon_Collection_Small");
224 Dictionary.registerTooltip(small_icon_textfield, "CDM.General.Icon_Collection_Small_Tooltip");
225 JPanel description_panel = new JPanel();
226 description_label = new JLabel();
227 description_label.setPreferredSize(LABEL_SIZE);
228 Dictionary.registerText(description_label, "CDM.General.Collection_Extra");
229 description_textarea = new JTextArea();
230 description_textarea.setBackground(Gatherer.config.getColor("coloring.editable_background", false));
231 Dictionary.registerTooltip(description_textarea, "CDM.General.Collection_Extra_Tooltip");
232 // Connection
233 beta_checkbox.addActionListener(CollectionDesignManager.change_listener);
234 public_checkbox.addActionListener(CollectionDesignManager.change_listener);
235 creator_emailfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
236 description_textarea.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
237 icon_textfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
238 maintainer_emailfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
239 name_textfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
240 small_icon_textfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
241
242 // Layout
243 instruction_panel.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
244 instruction_panel.setLayout(new BorderLayout());
245 instruction_panel.add(title_label, BorderLayout.NORTH);
246 instruction_panel.add(new JScrollPane(instructions_textarea), BorderLayout.CENTER);
247
248 creator_panel.setLayout(new BorderLayout());
249 creator_panel.add(creator_label, BorderLayout.WEST);
250 creator_panel.add(creator_emailfield, BorderLayout.CENTER);
251
252 maintainer_panel.setLayout(new BorderLayout());
253 maintainer_panel.add(maintainer_label, BorderLayout.WEST);
254 maintainer_panel.add(maintainer_emailfield, BorderLayout.CENTER);
255
256 name_panel.setLayout(new BorderLayout());
257 name_panel.add(name_label, BorderLayout.WEST);
258 name_panel.add(name_textfield, BorderLayout.CENTER);
259
260 icon_panel.setLayout(new BorderLayout());
261 icon_panel.add(icon_label, BorderLayout.WEST);
262 icon_panel.add(icon_textfield, BorderLayout.CENTER);
263
264 small_icon_panel.setLayout(new BorderLayout());
265 small_icon_panel.add(small_icon_label, BorderLayout.WEST);
266 small_icon_panel.add(small_icon_textfield, BorderLayout.CENTER);
267
268 details_panel.setLayout(new GridLayout(7,1,5,0));
269 details_panel.add(creator_panel);
270 details_panel.add(maintainer_panel);
271 details_panel.add(public_checkbox);
272 details_panel.add(beta_checkbox);
273 details_panel.add(name_panel);
274 details_panel.add(icon_panel);
275 details_panel.add(small_icon_panel);
276
277 description_panel.setLayout(new BorderLayout());
278 description_panel.add(description_label, BorderLayout.NORTH);
279 description_panel.add(new JScrollPane(description_textarea), BorderLayout.CENTER);
280
281 all_details_panel.setLayout(new BorderLayout());
282 all_details_panel.add(details_panel, BorderLayout.NORTH);
283 all_details_panel.add(description_panel, BorderLayout.CENTER);
284
285 setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
286 setLayout(new BorderLayout());
287 add(instruction_panel, BorderLayout.NORTH);
288 add(all_details_panel, BorderLayout.CENTER);
289 }
290
291 /** Destructor. */
292 public void destroy() {
293 }
294
295 /** Called to refresh the components. */
296 public void gainFocus() {
297 // Retrieve all of the elements that are dependant on default language.
298 collection_extra_collectionmeta = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_COLLECTIONEXTRA_STR);
299 collection_name_collectionmeta = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_COLLECTIONNAME_STR);
300 creator_collectionmeta = new CollectionMeta(CollectionDesignManager.collect_config.getCreator());
301 icon_collection_collectionmeta = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_ICONCOLLECTION_STR);
302 icon_collection_small_collectionmeta = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR);
303 maintainer_collectionmeta = new CollectionMeta(CollectionDesignManager.collect_config.getMaintainer());
304 // Make sure the components are up to date
305 creator_emailfield.setText(creator_collectionmeta.getValue(CollectionMeta.TEXT));
306 creator_emailfield.setCaretPosition(0);
307 description_textarea.setText(collection_extra_collectionmeta.getValue(CollectionMeta.TEXT));
308 description_textarea.setCaretPosition(0);
309 icon_textfield.setText(icon_collection_collectionmeta.getValue(CollectionMeta.TEXT));
310 icon_textfield.setCaretPosition(0);
311 maintainer_emailfield.setText(maintainer_collectionmeta.getValue(CollectionMeta.TEXT));
312 maintainer_emailfield.setCaretPosition(0);
313 name_textfield.setText(collection_name_collectionmeta.getValue(CollectionMeta.TEXT));
314 name_textfield.setCaretPosition(0);
315 small_icon_textfield.setText(icon_collection_small_collectionmeta.getValue(CollectionMeta.TEXT));
316 small_icon_textfield.setCaretPosition(0);
317 ready = true;
318 }
319 /** Called to store the current value of the components. */
320 public void loseFocus() {
321 // String values. Have to test if this component has actually ever recieved focus anyway.
322 if(ready) {
323 // Boolean values
324 beta_collectionmeta.setValue((beta_checkbox.isSelected() ? CollectionConfiguration.TRUE_STR : CollectionConfiguration.FALSE_STR));
325 public_collectionmeta.setValue((public_checkbox.isSelected() ? CollectionConfiguration.TRUE_STR : CollectionConfiguration.FALSE_STR));
326 creator_collectionmeta.setValue(creator_emailfield.getText());
327 collection_extra_collectionmeta.setValue(description_textarea.getText());
328 icon_collection_collectionmeta.setValue(icon_textfield.getText());
329 maintainer_collectionmeta.setValue(maintainer_emailfield.getText());
330 collection_name_collectionmeta.setValue(name_textfield.getText());
331 icon_collection_small_collectionmeta.setValue(small_icon_textfield.getText());
332 ready = false;
333 }
334 }
335
336 }
337 /** This tree provides a 'table of contents' for the various components of the design process (collection configuration in more technical terms). */
338 private class DesignTree
339 extends JTree {
340 private DesignNode root = null;
341 /** Constructor. Automatically generates all of the nodes, in the order of CONTENTS. */
342 public DesignTree() {
343 super();
344 root = new DesignNode("CDM.GUI.Root");
345 this.setModel(new DefaultTreeModel(root));
346 // Now add the design categories.
347 for(int i = 0; i < CONTENTS.length; i++) {
348 root.add(new DesignNode(CONTENTS[i]));
349 }
350 expandRow(0);
351 setRootVisible(false);
352 setSelectionRow(0);
353 }
354 /** Set the current view to the one specified.
355 * @param type the name of the desired view as a String
356 */
357 public void setSelectedView(String type) {
358 type = Dictionary.get(type);
359 for(int i = 0; i < root.getChildCount(); i++) {
360 DesignNode child = (DesignNode) root.getChildAt(i);
361 if(child.toString().equals(type)) {
362 TreePath path = new TreePath(child.getPath());
363 setSelectionPath(path);
364 }
365 }
366 }
367 }
368 /** A tree node that retains a reference to one of the possible design sub-views relating to the different sub-managers. */
369 private class DesignNode
370 extends DefaultMutableTreeNode {
371 /** Constructor.
372 * @param object The <strong>Object</strong> assigned to this node.
373 */
374 public DesignNode(String object) {
375 super(object);
376 }
377 /** Retrieve a textual representation of the object.
378 * @return a String
379 */
380 public String toString() {
381 // return Dictionary.get("CDM.GUI." + (String)getUserObject());
382 return Dictionary.get((String) getUserObject());
383 }
384 }
385 /** Listens for selection changes in the 'contents' tree, and switches to the appropriate view. */
386 private class TreeListener
387 implements TreeSelectionListener {
388 /** Called whenever the selection changes, we must update the view so it matches the node selected.
389 * @param event A <strong>TreeSelectionEvent</strong> containing more information about the tree selection.
390 * @see org.greenstone.gatherer.cdm.ClassifierManager
391 * @see org.greenstone.gatherer.cdm.CollectionDesignManager
392 * @see org.greenstone.gatherer.cdm.CollectionMetaManager
393 * @see org.greenstone.gatherer.cdm.FormatManager
394 * @see org.greenstone.gatherer.cdm.LanguageManager
395 * @see org.greenstone.gatherer.cdm.MetadataSetManager
396 * @see org.greenstone.gatherer.cdm.SubcollectionManager
397 * @see org.greenstone.gatherer.cdm.PlugInManager
398 */
399 public void valueChanged(TreeSelectionEvent event) {
400 if(!tree.isSelectionEmpty()) {
401 TreePath path = tree.getSelectionPath();
402 DesignNode node = (DesignNode)path.getLastPathComponent();
403 String type = (String)node.getUserObject();
404 // Wait begins
405 Gatherer.g_man.wait(true);
406 // Save information in current view
407 view.loseFocus();
408 remove((JPanel)view);
409 // Change panes.
410 if(type == CONTENTS[0]) {
411 view = getControls();
412 }
413 else if(type == CONTENTS[1]) {
414 view = CollectionDesignManager.plugin_manager.getControls();
415 }
416 else if(type == CONTENTS[2]) {
417 view = CollectionDesignManager.searchtype_manager.getControls();
418 }
419 else if(type == CONTENTS[3]) {
420 view = CollectionDesignManager.index_manager.getControls();
421 }
422 else if(type == CONTENTS[4]) {
423 view = CollectionDesignManager.subcollection_manager.getControls();
424 }
425 else if(type == CONTENTS[5]) {
426 view = CollectionDesignManager.supercollection_manager.getControls();
427 }
428 else if(type == CONTENTS[6]) {
429 view = CollectionDesignManager.classifier_manager.getControls();
430 }
431 else if(type == CONTENTS[7]) {
432 view = CollectionDesignManager.format_manager.getControls();
433 }
434 else if(type == CONTENTS[8]) {
435 view = CollectionDesignManager.translation_view.getControls();
436 }
437 else if(type == CONTENTS[9]) {
438 view = CollectionDesignManager.metadataset_view.getControls();
439 }
440 add((JPanel)view, BorderLayout.CENTER);
441 // Update information on visible pane
442 view.gainFocus();
443 repaint();
444 // Wait ends
445 Gatherer.g_man.wait(false);
446 }
447 }
448 }
449}
Note: See TracBrowser for help on using the repository browser.