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

Last change on this file since 12803 was 12803, checked in by mdewsnip, 18 years ago

Moved dealing with the Local Library out of CollectionDesignManager and into CollectionConfiguration, as part of tidying up the saving of the collect.cfg file.

  • 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.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 list of plugins to use at build time. */
74 static public PluginManager plugin_manager;
75 /** a manager of searching metadata such as index names*/
76 static public SearchMetadataManager searchmetadata_manager;
77 /** Contains: A list of subcollections, (defined on metadatadata), a list of which subcollection indexes to build and the default subcollection index. */
78 static public SubcollectionManager subcollection_manager;
79
80 static public SubcollectionIndexManager subcollectionindex_manager;
81 /** 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. */
82 static public SuperCollectionManager supercollection_manager; // Just cause I could ;p
83 /** The text translation manager. */
84 static public TranslationView translation_manager;
85 /** These mark what needs to happen when building a collection where ONLY design options have been changed.
86 The build requirements of the higher numbers must include doing everything from the lower numbers. */
87 static final public int ALL = 3;
88 static final public int BUILDCOL = 2;
89 static final public int UPDATE_COLLECT_CFG = 1;
90 static final public int NOTHING = 0;
91 static private int rebuildTypeRequired = NOTHING; //Rebuild type required if only design options have changed
92 static public boolean update_collect_cfg_required = false;
93
94 /** 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.
95 * @param collect_config_file the File representing a collection configuration file either in its text (G2) or xml (G3) form
96 */
97 public CollectionDesignManager(File collect_config_file) {
98 DebugStream.println("Initializaing CollectionDesignModule.");
99 change_listener = new CDMChangeListener();
100 all_change_listener = new DesignChangeListener(ALL);
101 buildcol_change_listener = new DesignChangeListener(BUILDCOL);
102 collect_cfg_change_listener = new DesignChangeListener(UPDATE_COLLECT_CFG);
103 // Parse the collection configuration
104 collect_config = new CollectionConfiguration(collect_config_file);
105 if (DebugStream.isDebuggingEnabled()) {
106 collect_config.display();
107 }
108 loadDesignDetails();
109 DebugStream.println("CollectionDesignModule loaded.");
110 }
111
112 /** Reloads the various managers to ensure they have built themselves from the latest details available in the collection configuration class
113 * @see org.greenstone.gatherer.cdm.ClassifierManager
114 * @see org.greenstone.gatherer.cdm.CollectionMetaManager
115 * @see org.greenstone.gatherer.cdm.FormatManager
116 * @see org.greenstone.gatherer.cdm.GeneralManager
117 * @see org.greenstone.gatherer.cdm.IndexManager
118 * @see org.greenstone.gatherer.cdm.LanguageManager
119 * @see org.greenstone.gatherer.cdm.PluginManager
120 * @see org.greenstone.gatherer.cdm.SubcollectionIndexManager
121 * @see org.greenstone.gatherer.cdm.SubcollectionManager
122 * @see org.greenstone.gatherer.cdm.SuperCollectionManager
123 * @see org.greenstone.gatherer.cdm.TranslationView
124 */
125 private void loadDesignDetails() {
126 // Create the command information managers, registering the config file with each as necessary
127 language_manager = new LanguageManager(collect_config.getLanguages());
128 collectionmeta_manager = new CollectionMetaManager();
129 classifier_manager = new ClassifierManager();
130 general_manager = new GeneralManager();
131 macros_manager = new MacrosManager();
132 index_manager = new IndexingManager();
133 plugin_manager = new PluginManager();
134 plugin_manager.placeSeparator();
135 subcollection_manager = new SubcollectionManager();
136 subcollectionindex_manager = new SubcollectionIndexManager(collect_config.getSubIndexes());
137 supercollection_manager = new SuperCollectionManager(collect_config.getSuperCollection());
138 searchmetadata_manager = new SearchMetadataManager();
139 translation_manager = new TranslationView();
140 format_manager = new FormatManager(); // Parse formats at the very end, given that they depend upon several other managers to appear properly.
141 }
142
143 /** This method deconstructs each of the managers, causing them to dispose of their controls.
144 */
145 public void destroy() {
146 // Remove references from persistant listeners.
147 classifier_manager.destroy();
148 classifier_manager = null;
149 searchmetadata_manager.destroy();
150 searchmetadata_manager = null;
151 format_manager.destroy();
152 format_manager = null;
153 general_manager.destroy();
154 general_manager = null;
155 index_manager.destroy();
156 index_manager = null;
157 language_manager.destroy();
158 language_manager = 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_manager.destroy();
166 translation_manager = null;
167 }
168
169 /** Called when the detail mode has changed which in turn may cause several design elements to be available/hidden
170 * @param mode the new mode as an int
171 */
172 public void modeChanged(int mode) {
173 plugin_manager.modeChanged(mode);
174 classifier_manager.modeChanged(mode);
175 subcollection_manager.modeChanged(mode);
176 supercollection_manager.modeChanged(mode);
177 format_manager.modeChanged(mode);
178 index_manager.modeChanged(mode);
179 translation_manager.modeChanged(mode);
180 general_manager.modeChanged(mode);
181 language_manager.modeChanged(mode);
182 searchmetadata_manager.modeChanged(mode);
183 }
184
185 /** The cdm is considered to be ready if the collect.cfg file was found and parsed and the collection title is not error.
186 * @return true if the collection is ready, false otherwise
187 */
188 public boolean ready() {
189 return collect_config.ready();
190 }
191
192 public void save() {
193 save(false);
194 }
195
196 /** Cause the current collection configuration to be written out to disk.
197 */
198 public void save(boolean force_save)
199 {
200 general_manager.loseFocus();
201 if (!update_collect_cfg_required && !force_save) {
202 DebugStream.println("Asked to save the config file, but don't need to");
203 return;
204 }
205
206 DebugStream.println("Saving the collection config file");
207
208 collect_config.save();
209
210 // Unset formats changed
211 update_collect_cfg_required = false;
212 }
213
214
215 public static int getRebuildTypeRequired() {
216 return rebuildTypeRequired;
217 }
218 public static void resetRebuildTypeRequired() {
219 setRebuildTypeRequired(NOTHING);
220 }
221 public static void setRebuildTypeRequired(int number) {
222 rebuildTypeRequired = number;
223 }
224
225 /**
226 * What exactly does this do?
227 */
228 private class CDMChangeListener
229 implements ActionListener, DocumentListener {
230
231 /** Gives notification that an event has happened */
232 public void actionPerformed(ActionEvent event) {
233 Gatherer.c_man.getCollection().setSaved(false);
234 }
235
236 /** Gives notification that an attribute or set of attributes changed. */
237 public void changedUpdate(DocumentEvent e) {
238 Gatherer.c_man.getCollection().setSaved(false);
239 }
240
241 /** Gives notification that there was an insert into the document. */
242 public void insertUpdate(DocumentEvent e) {
243 Gatherer.c_man.getCollection().setSaved(false);
244 }
245
246 /** Gives notification that a portion of the document has been removed. */
247 public void removeUpdate(DocumentEvent e) {
248 Gatherer.c_man.getCollection().setSaved(false);
249 }
250 }
251}
Note: See TracBrowser for help on using the repository browser.