source: trunk/gli/src/org/greenstone/gatherer/cdm/CollectionDesignManager.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: 10.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.awt.event.*;
31import java.io.*;
32import javax.swing.*;
33import javax.swing.event.*;
34import org.greenstone.gatherer.Gatherer;
35import org.greenstone.gatherer.cdm.ClassifierManager;
36import org.greenstone.gatherer.cdm.CollectionConfiguration;
37import org.greenstone.gatherer.cdm.CollectionMetaManager;
38import org.greenstone.gatherer.cdm.FormatManager;
39import org.greenstone.gatherer.cdm.GeneralManager;
40import org.greenstone.gatherer.cdm.IndexManager;
41import org.greenstone.gatherer.cdm.MetadataSetView;
42import org.greenstone.gatherer.cdm.PlugInManager;
43import org.greenstone.gatherer.cdm.SubcollectionManager;
44import org.greenstone.gatherer.cdm.TranslationView;
45import org.greenstone.gatherer.util.GSDLSiteConfig;
46
47/** This manager provides access to submanagers, which in turn provide tools for the designing of Greenstone collections via the information stored in etc/collect.cfg. This class acts as a hub for the managers that handle specific parts of the configuration such as classifiers, format strings and language settings.
48 * @author John Thompson, Greenstone Digital Library, University of Waikato
49 * @version 2.3d
50 */
51public class CollectionDesignManager {
52 /** This listener listens for any event on any of the components in any of the sub-views, and marks the collection as needing saving if any change occurs. */
53 static public CDMChangeListener change_listener;
54 /** A list of classifiers to use at build time. */
55 static public ClassifierManager classifier_manager;
56 /** The CollectionConfiguration object on which this CDM will be based. */
57 static public CollectionConfiguration collect_config;
58 /** A manager of collection level metadata. */
59 static public CollectionMetaManager collectionmeta_manager;
60 /** A list of formating strings to use at build time. */
61 static public FormatManager format_manager;
62 /** The manager in charge of displaying this manager and the controls for other managers. */
63 static public GeneralManager general_manager;
64 /** List of indexes to be built, and the default index. */
65 static public IndexManager index_manager;
66 /** Contains instructions dealing with the collection language. */
67 static public LanguageManager language_manager;
68 /** A simple manager for the visual review of metadata sets. */
69 static public MetadataSetView metadataset_view;
70 /** A list of plugins to use at build time. */
71 static public PlugInManager plugin_manager;
72 /** The manager in charge of all aspects of searchtypes. We also ask this manager whether we are MG or MGPP enabled. */
73 static public SearchTypeManager searchtype_manager;
74 /** Contains: A list of subcollections, (defined on metadatadata), a list of which subcollection indexes to build and the default subcollection index. */
75 static public SubcollectionManager subcollection_manager;
76
77 static public SubcollectionIndexManager subcollectionindex_manager;
78 /** A supercollection command allows a single search to be conducted across several collections. It is a very basic command and so avoids all the crazy model stuff that exists in most of the design managers. */
79 static public SuperCollectionManager supercollection_manager; // Just cause I could ;p
80 /** The text translation manager. */
81 static public TranslationView translation_view;
82 /** Constructor. Loads a certain collection configuration file, which is parsed into a DOM. This model is then registered with the command information managers, each of whom knows how to, and provides controls to, alter certain commands.
83 * @param collect_config_file the File representing a collection configuration file either in its text (G2) or xml (G3) form
84 */
85 public CollectionDesignManager(File collect_config_file) {
86 Gatherer.println("Initializaing CollectionDesignModule.");
87 change_listener = new CDMChangeListener();
88 // Parse the collection configuration
89 collect_config = new CollectionConfiguration(collect_config_file);
90 if(Gatherer.debug != null) {
91 collect_config.display();
92 }
93 // Create the command information managers, registering the config file with each as necessary
94 language_manager = new LanguageManager(collect_config.getLanguages());
95 collectionmeta_manager = new CollectionMetaManager();
96 classifier_manager = new ClassifierManager();
97 general_manager = new GeneralManager();
98
99 searchtype_manager = new SearchTypeManager(collect_config.getSearchType());
100 if(searchtype_manager.isMGPPEnabled()) {
101 index_manager = new IndexManager(collect_config.getMGPPIndexes());
102 }
103 else {
104 index_manager = new IndexManager(collect_config.getMGIndexes());
105 }
106
107 metadataset_view = new MetadataSetView();
108 plugin_manager = new PlugInManager();
109 plugin_manager.placeSeparator();
110 subcollection_manager = new SubcollectionManager();
111 subcollectionindex_manager = new SubcollectionIndexManager(collect_config.getSubIndexes());
112 supercollection_manager = new SuperCollectionManager(collect_config.getSuperCollection());
113 translation_view = new TranslationView();
114 format_manager = new FormatManager(); // Parse formats at the very end, given that they depend upon several other managers to appear properly.
115 Gatherer.println("CollectionDesignModule loaded.");
116 }
117 /** This method deconstructs each of the managers, causing them to dispose of their controls.
118 */
119 public void destroy() {
120 // Remove visual the component from its parent.
121 if(general_manager.getParent() != null) {
122 general_manager.getParent().remove(general_manager);
123 }
124 // Remove references from persistant listeners.
125 classifier_manager.destroy();
126 classifier_manager = null;
127 format_manager.destroy();
128 format_manager = null;
129 general_manager.destroy();
130 general_manager = null;
131 index_manager.destroy();
132 index_manager = null;
133 language_manager.destroy();
134 language_manager = null;
135 metadataset_view.destroy();
136 metadataset_view = null;
137 plugin_manager.destroy();
138 plugin_manager = null;
139 subcollection_manager.destroy();
140 subcollection_manager = null;
141 supercollection_manager.destroy();
142 supercollection_manager = null;
143 translation_view.destroy();
144 translation_view = null;
145 }
146
147 /** Display the GUI interface for the CollectionDesignManager in the centre of the indicated panel.
148 * @param target the JPanel you wish to display the gui on
149 */
150 public void display(JPanel target) {
151 target.add(general_manager, BorderLayout.CENTER);
152 }
153 /** When the tab on the JTabbedPane that contains the GUI is selected, this method is called to ensure that the controls are all up to date, in terms of references to metadata etc.
154 */
155 public void gainFocus() {
156 general_manager.gainFocus();
157 }
158
159 /** Retrieve the name of the collection configuration file which is being used as the source of the information in this object.
160 * @return The files absolute path as a <strong>String</strong>.
161 */
162 public String getFilename() {
163 return collect_config.getFile().getAbsolutePath();
164 }
165
166 /** Cause the current collection configuration to be written out to disk.
167 * @see org.greenstone.gatherer.cdm.ClassifierManager
168 * @see org.greenstone.gatherer.cdm.CollectionMetaManager
169 * @see org.greenstone.gatherer.cdm.FormatManager
170 * @see org.greenstone.gatherer.cdm.IndexManager
171 * @see org.greenstone.gatherer.cdm.LanguageManager
172 * @see org.greenstone.gatherer.cdm.MetadataSetManager
173 * @see org.greenstone.gatherer.cdm.PlugInManager
174 * @see org.greenstone.gatherer.cdm.SubcollectionManager
175 * @see org.greenstone.gatherer.util.EmailAddress
176 */
177 public void save() {
178 // Release collection as necessary
179 ///ystem.err.println("Would have released collection if necessary.");
180 boolean collection_released = false;
181 if(format_manager.formatsChanged() && Gatherer.c_man.built() && Gatherer.config.exec_file != null) {
182 // Release the collection
183 Gatherer.g_man.preview_pane.configServer(GSDLSiteConfig.RELEASE_COMMAND + Gatherer.c_man.getCollection().getName());
184 collection_released = true;
185 }
186
187 general_manager.loseFocus();
188 collect_config.save();
189
190 // Readd collection
191 ///ystem.err.println("Would have added collection if it had been released.");
192 if(collection_released) {
193 // Then re-add it to force format commands to be processed
194 Gatherer.g_man.preview_pane.configServer(GSDLSiteConfig.ADD_COMMAND + Gatherer.c_man.getCollection().getName());
195 // Unset formats changed
196 format_manager.setFormatsChanged(false);
197 }
198 }
199
200 /** Method used during a global search and replace to highlight the appropriate record within the Collection Design Managers version of the Metadata Set Manager (view only).
201 * @param element The name of the desired element as a <strong>String</strong>.
202 * @see org.greenstone.gatherer.cdm.GUI
203 * @see org.greenstone.gatherer.cdm.MetadataSetManager
204 */
205 public Rectangle setSelectedElement(String element) {
206 // First ensure that the metadata set controls are visible.
207 general_manager.setSelectedView("CDM.GUI.MetadataSets");
208 // Then tell them to select the given element.
209 return metadataset_view.setSelectedElement(element);
210 }
211
212 private class CDMChangeListener
213 implements ActionListener, DocumentListener {
214
215 public void actionPerformed(ActionEvent event) {
216 Gatherer.c_man.getCollection().setSaved(false);
217 }
218
219 /** Gives notification that an attribute or set of attributes changed. */
220 public void changedUpdate(DocumentEvent e) {
221 Gatherer.c_man.getCollection().setSaved(false);
222 }
223
224 /** Gives notification that there was an insert into the document. */
225 public void insertUpdate(DocumentEvent e) {
226 Gatherer.c_man.getCollection().setSaved(false);
227 }
228
229 /** Gives notification that a portion of the document has been removed. */
230 public void removeUpdate(DocumentEvent e) {
231 Gatherer.c_man.getCollection().setSaved(false);
232 }
233 }
234}
Note: See TracBrowser for help on using the repository browser.