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

Last change on this file since 12123 was 12123, checked in by kjdon, 18 years ago

Changed text handling to use Dictionary.get rather than Dictionary.setText or Dictionary.registerBoth etc. also removed mnemonics cos they suck for other languages.

  • 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.apache.xerces.parsers.*;
35import org.greenstone.gatherer.Configuration;
36import org.greenstone.gatherer.DebugStream;
37import org.greenstone.gatherer.Gatherer;
38import org.greenstone.gatherer.LocalLibraryServer;
39import org.greenstone.gatherer.remote.RemoteGreenstoneServer;
40import org.greenstone.gatherer.util.Utility;
41import org.greenstone.gatherer.util.ZipTools;
42import org.w3c.dom.*;
43import org.xml.sax.*;
44
45/** 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.
46 * @author John Thompson, Greenstone Digital Library, University of Waikato
47 * @version 2.3d
48 */
49public class CollectionDesignManager {
50 /** 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. */
51 static public CDMChangeListener change_listener;
52 /** These listeners listen to changes in the Design mode so as to allow incremental building */
53 static public DesignChangeListener all_change_listener;
54 static public DesignChangeListener buildcol_change_listener;
55 static public DesignChangeListener collect_cfg_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 /** A manager of general options */
65 static public GeneralManager general_manager;
66 /** List of indexes to be built, and the default index.
67 also handles build type and levels */
68 static public IndexingManager index_manager;
69 /** Contains instructions dealing with the collection language. */
70 static public LanguageManager language_manager;
71 /** Handling writing extra.dm file */
72 static public MacrosManager macros_manager;
73 /** A simple manager for the visual review of metadata sets. */
74 static public MetadataSetView metadataset_view;
75 /** A list of plugins to use at build time. */
76 static public PluginManager plugin_manager;
77 /** a manager of searching metadata such as index names*/
78 static public SearchMetadataManager searchmetadata_manager;
79 /** Contains: A list of subcollections, (defined on metadatadata), a list of which subcollection indexes to build and the default subcollection index. */
80 static public SubcollectionManager subcollection_manager;
81
82 static public SubcollectionIndexManager subcollectionindex_manager;
83 /** 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. */
84 static public SuperCollectionManager supercollection_manager; // Just cause I could ;p
85 /** The text translation manager. */
86 static public TranslationView translation_manager;
87 /** These mark what needs to happen when building a collection where ONLY design options have been changed.
88 The build requirements of the higher numbers must include doing everything from the lower numbers. */
89 static final public int ALL = 3;
90 static final public int BUILDCOL = 2;
91 static final public int UPDATE_COLLECT_CFG = 1;
92 static final public int NOTHING = 0;
93 static private int rebuildTypeRequired = NOTHING; //Rebuild type required if only design options have changed
94 static public boolean update_collect_cfg_required = false;
95
96 /** 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.
97 * @param collect_config_file the File representing a collection configuration file either in its text (G2) or xml (G3) form
98 */
99 public CollectionDesignManager(File collect_config_file) {
100 DebugStream.println("Initializaing CollectionDesignModule.");
101 change_listener = new CDMChangeListener();
102 all_change_listener = new DesignChangeListener(ALL);
103 buildcol_change_listener = new DesignChangeListener(BUILDCOL);
104 collect_cfg_change_listener = new DesignChangeListener(UPDATE_COLLECT_CFG);
105 // Parse the collection configuration
106 collect_config = new CollectionConfiguration(collect_config_file);
107 if (DebugStream.isDebuggingEnabled()) {
108 collect_config.display();
109 }
110 loadDesignDetails();
111 DebugStream.println("CollectionDesignModule loaded.");
112 }
113
114 /** Reloads the various managers to ensure they have built themselves from the latest details available in the collection configuration class
115 * @see org.greenstone.gatherer.cdm.ClassifierManager
116 * @see org.greenstone.gatherer.cdm.CollectionMetaManager
117 * @see org.greenstone.gatherer.cdm.FormatManager
118 * @see org.greenstone.gatherer.cdm.GeneralManager
119 * @see org.greenstone.gatherer.cdm.IndexManager
120 * @see org.greenstone.gatherer.cdm.LanguageManager
121 * @see org.greenstone.gatherer.cdm.MetadataSetView
122 * @see org.greenstone.gatherer.cdm.PluginManager
123 * @see org.greenstone.gatherer.cdm.SubcollectionIndexManager
124 * @see org.greenstone.gatherer.cdm.SubcollectionManager
125 * @see org.greenstone.gatherer.cdm.SuperCollectionManager
126 * @see org.greenstone.gatherer.cdm.TranslationView
127 */
128 private void loadDesignDetails() {
129 // Create the command information managers, registering the config file with each as necessary
130 language_manager = new LanguageManager(collect_config.getLanguages());
131 collectionmeta_manager = new CollectionMetaManager();
132 classifier_manager = new ClassifierManager();
133 general_manager = new GeneralManager();
134 macros_manager = new MacrosManager();
135 index_manager = new IndexingManager();
136 metadataset_view = new MetadataSetView();
137 plugin_manager = new PluginManager();
138 plugin_manager.placeSeparator();
139 subcollection_manager = new SubcollectionManager();
140 subcollectionindex_manager = new SubcollectionIndexManager(collect_config.getSubIndexes());
141 supercollection_manager = new SuperCollectionManager(collect_config.getSuperCollection());
142 searchmetadata_manager = new SearchMetadataManager();
143 translation_manager = new TranslationView();
144 format_manager = new FormatManager(); // Parse formats at the very end, given that they depend upon several other managers to appear properly.
145 }
146
147 /** This method deconstructs each of the managers, causing them to dispose of their controls.
148 */
149 public void destroy() {
150 // Remove references from persistant listeners.
151 classifier_manager.destroy();
152 classifier_manager = null;
153 searchmetadata_manager.destroy();
154 searchmetadata_manager = null;
155 format_manager.destroy();
156 format_manager = null;
157 general_manager.destroy();
158 general_manager = null;
159 index_manager.destroy();
160 index_manager = null;
161 language_manager.destroy();
162 language_manager = null;
163 metadataset_view.destroy();
164 metadataset_view = null;
165 plugin_manager.destroy();
166 plugin_manager = null;
167 subcollection_manager.destroy();
168 subcollection_manager = null;
169 supercollection_manager.destroy();
170 supercollection_manager = null;
171 translation_manager.destroy();
172 translation_manager = null;
173 }
174
175 /** Called when the detail mode has changed which in turn may cause several design elements to be available/hidden
176 * @param mode the new mode as an int
177 */
178 public void modeChanged(int mode) {
179 plugin_manager.modeChanged(mode);
180 classifier_manager.modeChanged(mode);
181 subcollection_manager.modeChanged(mode);
182 supercollection_manager.modeChanged(mode);
183 format_manager.modeChanged(mode);
184 index_manager.modeChanged(mode);
185 translation_manager.modeChanged(mode);
186 metadataset_view.modeChanged(mode);
187 general_manager.modeChanged(mode);
188 language_manager.modeChanged(mode);
189 searchmetadata_manager.modeChanged(mode);
190 }
191
192 /** The cdm is considered to be ready if the collect.cfg file was found and parsed and the collection title is not error.
193 * @return true if the collection is ready, false otherwise
194 */
195 public boolean ready() {
196 return collect_config.ready();
197 }
198
199
200 public void save() {
201 save(false);
202 }
203 /** Cause the current collection configuration to be written out to disk.
204 */
205 public void save(boolean force_save)
206 {
207 general_manager.loseFocus();
208 if (!update_collect_cfg_required && !force_save) {
209 DebugStream.println("Asked to save the config file, but don't need to");
210 return;
211 }
212
213 DebugStream.println("Saving the collection config file");
214 // Release collection as necessary
215 String collection_name = Gatherer.c_man.getCollection().getName();
216 boolean collection_released = false;
217
218 if (Gatherer.c_man.built() && LocalLibraryServer.isRunning() == true) {
219 // Release the collection
220 LocalLibraryServer.releaseCollection(collection_name);
221 collection_released = true;
222 }
223
224 collect_config.save();
225
226 // Read collection
227 if (collection_released) {
228 // Now re-add collection to server to force format commands to be processed
229 LocalLibraryServer.addCollection(collection_name);
230 }
231
232 // Unset formats changed
233 update_collect_cfg_required = false;
234
235 }
236
237
238 static public Document XMLStringToDOM(StringBuffer xml, String form)
239 {
240 Document document = null;
241
242 try {
243 // Read the xml from the piped input stream.
244 StringReader xml_sr = new StringReader(xml.toString());
245 InputSource source = new InputSource(xml_sr);
246 DOMParser parser = new DOMParser();
247 parser.parse(source);
248 document = parser.getDocument();
249 }
250 catch (Exception error) {
251 System.err.println("Failed when trying to parse XML stream ");
252 error.printStackTrace();
253 }
254
255 return document;
256 }
257
258 public static int getRebuildTypeRequired() {
259 return rebuildTypeRequired;
260 }
261 public static void resetRebuildTypeRequired() {
262 setRebuildTypeRequired(NOTHING);
263 }
264 public static void setRebuildTypeRequired(int number) {
265 rebuildTypeRequired = number;
266 }
267
268 /**
269 * What exactly does this do?
270 */
271 private class CDMChangeListener
272 implements ActionListener, DocumentListener {
273
274 /** Gives notification that an event has happened */
275 public void actionPerformed(ActionEvent event) {
276 Gatherer.c_man.getCollection().setSaved(false);
277 }
278
279 /** Gives notification that an attribute or set of attributes changed. */
280 public void changedUpdate(DocumentEvent e) {
281 Gatherer.c_man.getCollection().setSaved(false);
282 }
283
284 /** Gives notification that there was an insert into the document. */
285 public void insertUpdate(DocumentEvent e) {
286 Gatherer.c_man.getCollection().setSaved(false);
287 }
288
289 /** Gives notification that a portion of the document has been removed. */
290 public void removeUpdate(DocumentEvent e) {
291 Gatherer.c_man.getCollection().setSaved(false);
292 }
293 }
294}
Note: See TracBrowser for help on using the repository browser.