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

Last change on this file since 19404 was 19404, checked in by oranfry, 15 years ago

incremental import and build in gli (brought over from branch)

  • Property svn:keywords set to Author Date Id Revision
File size: 11.0 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 /** A manager of configuring depositor metadata */
81 static public DepositorMetadataManager depositormetadata_manager;
82
83 /** These mark what needs to happen when building a collection where ONLY design options have been changed.
84 The build requirements of the higher numbers must include doing everything from the lower numbers. */
85 static final public int ALL = 3;
86 static final public int BUILDCOL = 2;
87 static final public int NOTHING = 0;
88 static private int rebuildTypeRequired = NOTHING; //Rebuild type required if only design options have changed
89
90 /** This indicates whether a minimal or complete build is required.
91 Minimal means do everything with the -incremental flag. Complete means do everything with -removeold */
92 static private boolean isCompleteBuild = false;
93
94
95 /** 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.
96 * @param collect_config_file the File representing a collection configuration file either in its text (G2) or xml (G3) form
97 */
98 public CollectionDesignManager(File collect_config_file) {
99 DebugStream.println("Initializaing CollectionDesignModule.");
100 change_listener = new CDMChangeListener();
101 all_change_listener = new DesignChangeListener(ALL);
102 buildcol_change_listener = new DesignChangeListener(BUILDCOL);
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 subcollection_manager = new SubcollectionManager();
135 subcollectionindex_manager = new SubcollectionIndexManager(collect_config.getSubIndexes());
136 supercollection_manager = new SuperCollectionManager(collect_config.getSuperCollection());
137 searchmetadata_manager = new SearchMetadataManager();
138 depositormetadata_manager = new DepositorMetadataManager();
139 translation_manager = new TranslationView();
140 if (Gatherer.GS3) {
141 format_manager = new Format4gs3Manager();
142 } else {
143 format_manager = new FormatManager(); // Parse formats at the very end, given that they depend upon several other managers to appear properly.
144 }
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// format_4gs3_manager.destroy();
158// format_4gs3_manager = null;
159 general_manager.destroy();
160 general_manager = null;
161 index_manager.destroy();
162 index_manager = null;
163 language_manager.destroy();
164 language_manager = 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 depositormetadata_manager.destroy();
172 depositormetadata_manager = null;
173 translation_manager.destroy();
174 translation_manager = null;
175 }
176
177 /** Called when the detail mode has changed which in turn may cause several design elements to be available/hidden
178 * @param mode the new mode as an int
179 */
180 public void modeChanged(int mode) {
181 plugin_manager.modeChanged(mode);
182 classifier_manager.modeChanged(mode);
183 subcollection_manager.modeChanged(mode);
184 supercollection_manager.modeChanged(mode);
185 //format_manager.modeChanged(mode);
186 index_manager.modeChanged(mode);
187 translation_manager.modeChanged(mode);
188 general_manager.modeChanged(mode);
189 language_manager.modeChanged(mode);
190 searchmetadata_manager.modeChanged(mode);
191 depositormetadata_manager.modeChanged(mode);
192 }
193
194 /** The cdm is considered to be ready if the collect.cfg file was found and parsed and the collection title is not error.
195 * @return true if the collection is ready, false otherwise
196 */
197 public boolean ready() {
198 return collect_config.ready();
199 }
200
201
202 /** Cause the current collection configuration to be written out to disk.
203 */
204 public void save() {
205 collect_config.saveIfNecessary();
206 }
207
208
209 public static int getRebuildTypeRequired() {
210 return rebuildTypeRequired;
211 }
212
213 public static void resetRebuildTypeRequired() {
214 setRebuildTypeRequired(NOTHING);
215 }
216 public static void setRebuildTypeRequired(int number) {
217 rebuildTypeRequired = number;
218 }
219
220 public static boolean isCompleteBuild() {
221 return isCompleteBuild;
222 }
223 public static void setCompleteBuild(boolean icb) {
224 isCompleteBuild = icb;
225 }
226
227 /**
228 * What exactly does this do?
229 */
230 private class CDMChangeListener
231 implements ActionListener, DocumentListener {
232
233 /** Gives notification that an event has happened */
234 public void actionPerformed(ActionEvent event) {
235 Gatherer.c_man.getCollection().setSaved(false);
236 }
237
238 /** Gives notification that an attribute or set of attributes changed. */
239 public void changedUpdate(DocumentEvent e) {
240 Gatherer.c_man.getCollection().setSaved(false);
241 }
242
243 /** Gives notification that there was an insert into the document. */
244 public void insertUpdate(DocumentEvent e) {
245 Gatherer.c_man.getCollection().setSaved(false);
246 }
247
248 /** Gives notification that a portion of the document has been removed. */
249 public void removeUpdate(DocumentEvent e) {
250 Gatherer.c_man.getCollection().setSaved(false);
251 }
252 }
253}
Note: See TracBrowser for help on using the repository browser.