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

Last change on this file since 14038 was 14038, checked in by xiao, 17 years ago

Changes made to detect whether it is in gs2 mode - should FormatManager.java be used; or gs3 mode - should Format4gs3Manager.java be used.

  • Property svn:keywords set to Author Date Id Revision
File size: 10.8 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.event.*;
30import java.io.*;
31import javax.swing.event.*;
32import org.greenstone.gatherer.DebugStream;
33import org.greenstone.gatherer.Gatherer;
34import org.greenstone.gatherer.collection.CollectionManager;
35import org.w3c.dom.*;
36
37//save()
38import org.greenstone.gatherer.util.XMLTools;
39import javax.swing.*;
40
41/** 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.
42 * @author John Thompson, Greenstone Digital Library, University of Waikato
43 * @version 2.3d
44 */
45public class CollectionDesignManager {
46 /** 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. */
47 static public CDMChangeListener change_listener;
48 /** These listeners listen to changes in the Design mode so as to allow minimal rebuilding */
49 static public DesignChangeListener all_change_listener;
50 static public DesignChangeListener buildcol_change_listener;
51 /** A list of classifiers to use at build time. */
52 static public ClassifierManager classifier_manager;
53 /** The CollectionConfiguration object on which this CDM will be based. */
54 static public CollectionConfiguration collect_config;
55 /** A manager of collection level metadata. */
56 static public CollectionMetaManager collectionmeta_manager;
57 /** A list of formating strings to use at build time. */
58 static public SharedByTwoFormatManager format_manager;
59 /** A manager of general options */
60 static public GeneralManager general_manager;
61 /** List of indexes to be built, and the default index.
62 also handles build type and levels */
63 static public IndexingManager index_manager;
64 /** Contains instructions dealing with the collection language. */
65 static public LanguageManager language_manager;
66 /** Handling writing extra.dm file */
67 static public MacrosManager macros_manager;
68 /** A list of plugins to use at build time. */
69 static public PluginManager plugin_manager;
70 /** a manager of searching metadata such as index names*/
71 static public SearchMetadataManager searchmetadata_manager;
72 /** Contains: A list of subcollections, (defined on metadatadata), a list of which subcollection indexes to build and the default subcollection index. */
73 static public SubcollectionManager subcollection_manager;
74
75 static public SubcollectionIndexManager subcollectionindex_manager;
76 /** 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. */
77 static public SuperCollectionManager supercollection_manager; // Just cause I could ;p
78 /** The text translation manager. */
79 static public TranslationView translation_manager;
80 /** These mark what needs to happen when building a collection where ONLY design options have been changed.
81 The build requirements of the higher numbers must include doing everything from the lower numbers. */
82 static final public int ALL = 3;
83 static final public int BUILDCOL = 2;
84 static final public int NOTHING = 0;
85 static private int rebuildTypeRequired = NOTHING; //Rebuild type required if only design options have changed
86
87 /** 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.
88 * @param collect_config_file the File representing a collection configuration file either in its text (G2) or xml (G3) form
89 */
90 public CollectionDesignManager(File collect_config_file) {
91 DebugStream.println("Initializaing CollectionDesignModule.");
92 change_listener = new CDMChangeListener();
93 all_change_listener = new DesignChangeListener(ALL);
94 buildcol_change_listener = new DesignChangeListener(BUILDCOL);
95 // Parse the collection configuration
96 collect_config = new CollectionConfiguration(collect_config_file);
97 if (DebugStream.isDebuggingEnabled()) {
98 collect_config.display();
99 }
100 loadDesignDetails();
101 DebugStream.println("CollectionDesignModule loaded.");
102 }
103
104 /** Reloads the various managers to ensure they have built themselves from the latest details available in the collection configuration class
105 * @see org.greenstone.gatherer.cdm.ClassifierManager
106 * @see org.greenstone.gatherer.cdm.CollectionMetaManager
107 * @see org.greenstone.gatherer.cdm.FormatManager
108 * @see org.greenstone.gatherer.cdm.GeneralManager
109 * @see org.greenstone.gatherer.cdm.IndexManager
110 * @see org.greenstone.gatherer.cdm.LanguageManager
111 * @see org.greenstone.gatherer.cdm.PluginManager
112 * @see org.greenstone.gatherer.cdm.SubcollectionIndexManager
113 * @see org.greenstone.gatherer.cdm.SubcollectionManager
114 * @see org.greenstone.gatherer.cdm.SuperCollectionManager
115 * @see org.greenstone.gatherer.cdm.TranslationView
116 */
117 private void loadDesignDetails() {
118 // Create the command information managers, registering the config file with each as necessary
119 language_manager = new LanguageManager(collect_config.getLanguages());
120 collectionmeta_manager = new CollectionMetaManager();
121 classifier_manager = new ClassifierManager();
122 general_manager = new GeneralManager();
123 macros_manager = new MacrosManager();
124 index_manager = new IndexingManager();
125 plugin_manager = new PluginManager();
126 subcollection_manager = new SubcollectionManager();
127 subcollectionindex_manager = new SubcollectionIndexManager(collect_config.getSubIndexes());
128 supercollection_manager = new SuperCollectionManager(collect_config.getSuperCollection());
129 searchmetadata_manager = new SearchMetadataManager();
130 translation_manager = new TranslationView();
131 if (Gatherer.GS3) {
132 format_manager = new Format4gs3Manager();
133 } else {
134 format_manager = new FormatManager(); // Parse formats at the very end, given that they depend upon several other managers to appear properly.
135 }
136 }
137
138 /** This method deconstructs each of the managers, causing them to dispose of their controls.
139 */
140 public void destroy() {
141 // Remove references from persistant listeners.
142 classifier_manager.destroy();
143 classifier_manager = null;
144 searchmetadata_manager.destroy();
145 searchmetadata_manager = null;
146 format_manager.destroy();
147 format_manager = null;
148// format_4gs3_manager.destroy();
149// format_4gs3_manager = null;
150 general_manager.destroy();
151 general_manager = null;
152 index_manager.destroy();
153 index_manager = null;
154 language_manager.destroy();
155 language_manager = null;
156 plugin_manager.destroy();
157 plugin_manager = null;
158 subcollection_manager.destroy();
159 subcollection_manager = null;
160 supercollection_manager.destroy();
161 supercollection_manager = null;
162 translation_manager.destroy();
163 translation_manager = null;
164 }
165
166 /** Called when the detail mode has changed which in turn may cause several design elements to be available/hidden
167 * @param mode the new mode as an int
168 */
169 public void modeChanged(int mode) {
170 plugin_manager.modeChanged(mode);
171 classifier_manager.modeChanged(mode);
172 subcollection_manager.modeChanged(mode);
173 supercollection_manager.modeChanged(mode);
174 //format_manager.modeChanged(mode);
175 index_manager.modeChanged(mode);
176 translation_manager.modeChanged(mode);
177 general_manager.modeChanged(mode);
178 language_manager.modeChanged(mode);
179 searchmetadata_manager.modeChanged(mode);
180 }
181
182 /** The cdm is considered to be ready if the collect.cfg file was found and parsed and the collection title is not error.
183 * @return true if the collection is ready, false otherwise
184 */
185 public boolean ready() {
186 return collect_config.ready();
187 }
188
189
190 /** Cause the current collection configuration to be written out to disk.
191 */
192 public void save()
193 {
194// String msg = XMLParser.parseDOM(CollectionManager.getLoadedCollectionCfgFilePath());
195 Element root = this.collect_config.getDocumentElement ();
196 String msg = XMLTools.parseDOM(XMLTools.xmlNodeToString(root));
197 if(msg.startsWith(XMLTools.NOTWELLFORMED)) {
198 String str = new String("The collection configuration file is not wellformed, and cannot be saved to disk.");
199 JOptionPane.showMessageDialog(null, str, XMLTools.NOTWELLFORMED, JOptionPane.ERROR_MESSAGE);
200 } else {
201
202 collect_config.saveIfNecessary();
203 }
204 }
205
206
207 public static int getRebuildTypeRequired() {
208 return rebuildTypeRequired;
209 }
210 public static void resetRebuildTypeRequired() {
211 setRebuildTypeRequired(NOTHING);
212 }
213 public static void setRebuildTypeRequired(int number) {
214 rebuildTypeRequired = number;
215 }
216
217 /**
218 * What exactly does this do?
219 */
220 private class CDMChangeListener
221 implements ActionListener, DocumentListener {
222
223 /** Gives notification that an event has happened */
224 public void actionPerformed(ActionEvent event) {
225 Gatherer.c_man.getCollection().setSaved(false);
226 }
227
228 /** Gives notification that an attribute or set of attributes changed. */
229 public void changedUpdate(DocumentEvent e) {
230 Gatherer.c_man.getCollection().setSaved(false);
231 }
232
233 /** Gives notification that there was an insert into the document. */
234 public void insertUpdate(DocumentEvent e) {
235 Gatherer.c_man.getCollection().setSaved(false);
236 }
237
238 /** Gives notification that a portion of the document has been removed. */
239 public void removeUpdate(DocumentEvent e) {
240 Gatherer.c_man.getCollection().setSaved(false);
241 }
242 }
243}
Note: See TracBrowser for help on using the repository browser.