source: trunk/gli/src/org/greenstone/gatherer/cdm/CollectionDesignManager.java@ 8231

Last change on this file since 8231 was 8231, checked in by mdewsnip, 20 years ago

Replaced all "Gatherer.config" with "Configuration".

  • Property svn:keywords set to Author Date Id Revision
File size: 12.3 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.Configuration;
35import org.greenstone.gatherer.Gatherer;
36import org.greenstone.gatherer.cdm.ClassifierManager;
37import org.greenstone.gatherer.cdm.CollectionConfiguration;
38import org.greenstone.gatherer.cdm.CollectionMetaManager;
39import org.greenstone.gatherer.cdm.FormatManager;
40import org.greenstone.gatherer.cdm.GeneralManager;
41import org.greenstone.gatherer.cdm.IndexManager;
42import org.greenstone.gatherer.cdm.MetadataSetView;
43import org.greenstone.gatherer.cdm.PlugInManager;
44import org.greenstone.gatherer.cdm.SubcollectionManager;
45import org.greenstone.gatherer.cdm.TranslationView;
46import org.greenstone.gatherer.util.GSDLSiteConfig;
47import org.greenstone.gatherer.util.Utility;
48
49/** 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.
50 * @author John Thompson, Greenstone Digital Library, University of Waikato
51 * @version 2.3d
52 */
53public class CollectionDesignManager {
54 /** 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. */
55 static public CDMChangeListener change_listener;
56 /** A list of classifiers to use at build time. */
57 static public ClassifierManager classifier_manager;
58 /** The CollectionConfiguration object on which this CDM will be based. */
59 static public CollectionConfiguration collect_config;
60 /** A manager of collection level metadata. */
61 static public CollectionMetaManager collectionmeta_manager;
62 /** A list of formating strings to use at build time. */
63 static public FormatManager format_manager;
64 /** The manager in charge of displaying this manager and the controls for other managers. */
65 static public GeneralManager general_manager;
66 /** List of indexes to be built, and the default index. */
67 static public IndexManager index_manager;
68 /** Contains instructions dealing with the collection language. */
69 static public LanguageManager language_manager;
70 /** A simple manager for the visual review of metadata sets. */
71 static public MetadataSetView metadataset_view;
72 /** A list of plugins to use at build time. */
73 static public PlugInManager plugin_manager;
74 /** The manager in charge of all aspects of searchtypes. We also ask this manager whether we are MG or MGPP enabled. */
75 static public SearchTypeManager searchtype_manager;
76 /** Contains: A list of subcollections, (defined on metadatadata), a list of which subcollection indexes to build and the default subcollection index. */
77 static public SubcollectionManager subcollection_manager;
78
79 static public SubcollectionIndexManager subcollectionindex_manager;
80 /** 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. */
81 static public SuperCollectionManager supercollection_manager; // Just cause I could ;p
82 /** The text translation manager. */
83 static public TranslationView translation_view;
84 /** 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.
85 * @param collect_config_file the File representing a collection configuration file either in its text (G2) or xml (G3) form
86 */
87 public CollectionDesignManager(File collect_config_file) {
88 Gatherer.println("Initializaing CollectionDesignModule.");
89 change_listener = new CDMChangeListener();
90 // Parse the collection configuration
91 collect_config = new CollectionConfiguration(collect_config_file);
92 if(Gatherer.debug != null) {
93 collect_config.display();
94 }
95 loadDesignDetails();
96 Gatherer.println("CollectionDesignModule loaded.");
97 }
98
99 /** Reloads the various managers to ensure they have built themselves from the latest details available in the collection configuration class
100 * @see org.greenstone.gatherer.cdm.ClassifierManager
101 * @see org.greenstone.gatherer.cdm.CollectionMetaManager
102 * @see org.greenstone.gatherer.cdm.FormatManager
103 * @see org.greenstone.gatherer.cdm.GeneralManager
104 * @see org.greenstone.gatherer.cdm.IndexManager
105 * @see org.greenstone.gatherer.cdm.LanguageManager
106 * @see org.greenstone.gatherer.cdm.MetadataSetView
107 * @see org.greenstone.gatherer.cdm.PlugInManager
108 * @see org.greenstone.gatherer.cdm.SearchTypeManager
109 * @see org.greenstone.gatherer.cdm.SubcollectionIndexManager
110 * @see org.greenstone.gatherer.cdm.SubcollectionManager
111 * @see org.greenstone.gatherer.cdm.SuperCollectionManager
112 * @see org.greenstone.gatherer.cdm.TranslationView
113 */
114 private void loadDesignDetails() {
115 // Create the command information managers, registering the config file with each as necessary
116 language_manager = new LanguageManager(collect_config.getLanguages());
117 collectionmeta_manager = new CollectionMetaManager();
118 classifier_manager = new ClassifierManager();
119 general_manager = new GeneralManager();
120
121 searchtype_manager = new SearchTypeManager(collect_config.getSearchType());
122 if(searchtype_manager.isMGPPEnabled()) {
123 index_manager = new IndexManager(collect_config.getMGPPIndexes());
124 }
125 else {
126 index_manager = new IndexManager(collect_config.getMGIndexes());
127 }
128
129 metadataset_view = new MetadataSetView();
130 plugin_manager = new PlugInManager();
131 plugin_manager.placeSeparator();
132 subcollection_manager = new SubcollectionManager();
133 subcollectionindex_manager = new SubcollectionIndexManager(collect_config.getSubIndexes());
134 supercollection_manager = new SuperCollectionManager(collect_config.getSuperCollection());
135 translation_view = new TranslationView();
136 format_manager = new FormatManager(); // Parse formats at the very end, given that they depend upon several other managers to appear properly.
137 }
138
139 /** This method deconstructs each of the managers, causing them to dispose of their controls.
140 */
141 public void destroy() {
142 // Remove visual the component from its parent.
143 if(general_manager.getParent() != null) {
144 general_manager.getParent().remove(general_manager);
145 }
146 // Remove references from persistant listeners.
147 classifier_manager.destroy();
148 classifier_manager = null;
149 format_manager.destroy();
150 format_manager = null;
151 general_manager.destroy();
152 general_manager = null;
153 index_manager.destroy();
154 index_manager = null;
155 language_manager.destroy();
156 language_manager = null;
157 metadataset_view.destroy();
158 metadataset_view = null;
159 plugin_manager.destroy();
160 plugin_manager = null;
161 subcollection_manager.destroy();
162 subcollection_manager = null;
163 supercollection_manager.destroy();
164 supercollection_manager = null;
165 translation_view.destroy();
166 translation_view = null;
167 }
168
169 /** Display the GUI interface for the CollectionDesignManager in the centre of the indicated panel.
170 * @param target the JPanel you wish to display the gui on
171 */
172 public void display(JPanel target) {
173 target.add(general_manager, BorderLayout.CENTER);
174 }
175 /** 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.
176 */
177 public void gainFocus() {
178 general_manager.gainFocus();
179 }
180
181 /** Called when the detail mode has changed which in turn may cause several design elements to be available/hidden
182 * @param mode the new mode as an int
183 */
184 public void modeChanged(int mode) {
185 plugin_manager.modeChanged(mode);
186 subcollection_manager.modeChanged(mode);
187 }
188
189 /** The cdm is considered to be ready if the collect.cfg file was found and parsed and the collection title is not error.
190 * @return true if the collection is ready, false otherwise
191 */
192 public boolean ready() {
193 return collect_config.ready();
194 }
195
196 /** Ensure that saving will actually work. This can return false if there is a collection filename clash for instance. */
197 public boolean canSave() {
198 return (general_manager == null || general_manager.canSave());
199 }
200
201 /** Cause the current collection configuration to be written out to disk.
202 * @see org.greenstone.gatherer.cdm.ClassifierManager
203 * @see org.greenstone.gatherer.cdm.CollectionMetaManager
204 * @see org.greenstone.gatherer.cdm.FormatManager
205 * @see org.greenstone.gatherer.cdm.IndexManager
206 * @see org.greenstone.gatherer.cdm.LanguageManager
207 * @see org.greenstone.gatherer.cdm.MetadataSetView
208 * @see org.greenstone.gatherer.cdm.PlugInManager
209 * @see org.greenstone.gatherer.cdm.SubcollectionManager
210 */
211 public void save() {
212 // Release collection as necessary
213 ///ystem.err.println("Would have released collection if necessary.");
214 boolean collection_released = false;
215 String col_name = Gatherer.c_man.getCollection().getName();
216 boolean formats_changed = format_manager.formatsChanged();
217
218 if(formats_changed && Gatherer.c_man.built() && Configuration.exec_file != null) {
219 // Release the collection
220 Gatherer.self.configServer(GSDLSiteConfig.RELEASE_COMMAND + col_name);
221 // This is very important -- it ensures that the above command has finished
222 Gatherer.self.configServer("");
223 collection_released = true;
224 }
225
226 general_manager.loseFocus();
227 collect_config.save();
228
229 if (Gatherer.isGsdlRemote) {
230 if(formats_changed && Gatherer.c_man.built()) {
231 // upload etc/collect.cfg to server to reflect changes
232 Utility.zipup(col_name,Utility.CONFIG_FILE);
233 Utility.upload_url_zip(col_name,"etc");
234 }
235 }
236
237 // Readd collection
238 ///ystem.err.println("Would have added collection if it had been released.");
239 if(collection_released) {
240 // Now re-add collection to server to force format commands to be processed
241 Gatherer.self.configServer(GSDLSiteConfig.ADD_COMMAND + col_name);
242 // This is very important -- it ensures that the above command has finished
243 Gatherer.self.configServer("");
244 }
245
246 if (formats_changed) {
247 // Unset formats changed
248 format_manager.setFormatsChanged(false);
249 }
250 }
251
252
253 private class CDMChangeListener
254 implements ActionListener, DocumentListener {
255
256 public void actionPerformed(ActionEvent event) {
257 Gatherer.c_man.getCollection().setSaved(false);
258 }
259
260 /** Gives notification that an attribute or set of attributes changed. */
261 public void changedUpdate(DocumentEvent e) {
262 Gatherer.c_man.getCollection().setSaved(false);
263 }
264
265 /** Gives notification that there was an insert into the document. */
266 public void insertUpdate(DocumentEvent e) {
267 Gatherer.c_man.getCollection().setSaved(false);
268 }
269
270 /** Gives notification that a portion of the document has been removed. */
271 public void removeUpdate(DocumentEvent e) {
272 Gatherer.c_man.getCollection().setSaved(false);
273 }
274 }
275}
Note: See TracBrowser for help on using the repository browser.