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 | */
|
---|
27 | package org.greenstone.gatherer.cdm;
|
---|
28 |
|
---|
29 | import java.awt.event.*;
|
---|
30 | import java.io.*;
|
---|
31 | import javax.swing.event.*;
|
---|
32 | import org.greenstone.gatherer.DebugStream;
|
---|
33 | import org.greenstone.gatherer.Gatherer;
|
---|
34 | import org.greenstone.gatherer.collection.CollectionManager;
|
---|
35 | import org.w3c.dom.*;
|
---|
36 |
|
---|
37 | //save()
|
---|
38 | import org.greenstone.gatherer.util.XMLTools;
|
---|
39 | import 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 | */
|
---|
45 | public 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 | static public DesignChangeListener databasecol_change_listener;
|
---|
52 | /** A list of classifiers to use at build time. */
|
---|
53 | static public ClassifierManager classifier_manager;
|
---|
54 | /** The CollectionConfiguration object on which this CDM will be based. */
|
---|
55 | static public CollectionConfiguration collect_config;
|
---|
56 | /** A manager of collection level metadata. */
|
---|
57 | static public CollectionMetaManager collectionmeta_manager;
|
---|
58 | /** A list of formating strings to use at build time. */
|
---|
59 | static public SharedByTwoFormatManager format_manager;
|
---|
60 | /** A manager of general options */
|
---|
61 | static public GeneralManager general_manager;
|
---|
62 | /** List of indexes to be built, and the default index.
|
---|
63 | also handles build type and levels */
|
---|
64 | static public IndexingManager index_manager;
|
---|
65 | /** Contains instructions dealing with the collection language. */
|
---|
66 | static public LanguageManager language_manager;
|
---|
67 | /** Handling writing extra.dm file */
|
---|
68 | static public MacrosManager macros_manager;
|
---|
69 | /** A list of plugins to use at build time. */
|
---|
70 | static public PluginManager plugin_manager;
|
---|
71 | /** a manager of searching metadata such as index names*/
|
---|
72 | static public SearchMetadataManager searchmetadata_manager;
|
---|
73 | /** Contains: A list of subcollections, (defined on metadatadata), a list of which subcollection indexes to build and the default subcollection index. */
|
---|
74 | static public SubcollectionManager subcollection_manager;
|
---|
75 |
|
---|
76 | static public SubcollectionIndexManager subcollectionindex_manager;
|
---|
77 | /** 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. */
|
---|
78 | static public SuperCollectionManager supercollection_manager; // Just cause I could ;p
|
---|
79 | /** The text translation manager. */
|
---|
80 | static public TranslationView translation_manager;
|
---|
81 | /** A manager of configuring depositor metadata */
|
---|
82 | static public DepositorMetadataManager depositormetadata_manager;
|
---|
83 |
|
---|
84 | /** These mark what needs to happen when building a collection where ONLY design options have been changed.
|
---|
85 | The build requirements of the higher numbers must include doing everything from the lower numbers. */
|
---|
86 | static final public int ALL = 3;
|
---|
87 | static final public int BUILDCOL = 2;
|
---|
88 | static final public int NOTHING = 0;
|
---|
89 | static private int rebuildTypeRequired = NOTHING; //Rebuild type required if only design options have changed
|
---|
90 |
|
---|
91 | /** This indicates whether a minimal or complete build is required.
|
---|
92 | Minimal means do an incremental rebuild. Complete means do a full rebuild
|
---|
93 | Note: This stores preceisely whether the user selected the minimal or full build radio button.
|
---|
94 | Its value does not indicate anything about what gli eventually chose as a result of that "suggestion" */
|
---|
95 | static private boolean isCompleteBuild = false;
|
---|
96 |
|
---|
97 | /** These remember which scripts were run for the last build.
|
---|
98 | true indicated 'full-' prefix, false indicates 'incremental-' prefix to the given perl script (import.pl or buildcol.pl)
|
---|
99 | Note: This stores what gli did, regardless of whether minimal or full was requested by the user */
|
---|
100 | static private boolean importWasFull = false;
|
---|
101 | static private boolean buildcolWasFull = false;
|
---|
102 |
|
---|
103 | /** 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.
|
---|
104 | * @param collect_config_file the File representing a collection configuration file either in its text (G2) or xml (G3) form
|
---|
105 | */
|
---|
106 | public CollectionDesignManager(File collect_config_file) {
|
---|
107 | DebugStream.println("Initializaing CollectionDesignModule.");
|
---|
108 | change_listener = new CDMChangeListener();
|
---|
109 | all_change_listener = new DesignChangeListener(ALL);
|
---|
110 | buildcol_change_listener = new DesignChangeListener(BUILDCOL);
|
---|
111 | databasecol_change_listener = new DesignChangeListener(BUILDCOL);
|
---|
112 |
|
---|
113 | // Parse the collection configuration
|
---|
114 | collect_config = new CollectionConfiguration(collect_config_file);
|
---|
115 | if (DebugStream.isDebuggingEnabled()) {
|
---|
116 | collect_config.display();
|
---|
117 | }
|
---|
118 | loadDesignDetails();
|
---|
119 | DebugStream.println("CollectionDesignModule loaded.");
|
---|
120 | }
|
---|
121 |
|
---|
122 |
|
---|
123 | public void reloadConfig() {
|
---|
124 | // Parse and load the current collection configuration again
|
---|
125 | // Used after GLI > Edit > collectionConfig.xml > Save to get these edits into GLI.
|
---|
126 |
|
---|
127 | collect_config.reload();
|
---|
128 | if (DebugStream.isDebuggingEnabled()) {
|
---|
129 | collect_config.display();
|
---|
130 | }
|
---|
131 | loadDesignDetails();
|
---|
132 | DebugStream.println("CollectionDesignModule loaded.");
|
---|
133 | }
|
---|
134 |
|
---|
135 | /** Reloads the various managers to ensure they have built themselves from the latest details available in the collection configuration class
|
---|
136 | * @see org.greenstone.gatherer.cdm.ClassifierManager
|
---|
137 | * @see org.greenstone.gatherer.cdm.CollectionMetaManager
|
---|
138 | * @see org.greenstone.gatherer.cdm.FormatManager
|
---|
139 | * @see org.greenstone.gatherer.cdm.GeneralManager
|
---|
140 | * @see org.greenstone.gatherer.cdm.IndexManager
|
---|
141 | * @see org.greenstone.gatherer.cdm.LanguageManager
|
---|
142 | * @see org.greenstone.gatherer.cdm.PluginManager
|
---|
143 | * @see org.greenstone.gatherer.cdm.SubcollectionIndexManager
|
---|
144 | * @see org.greenstone.gatherer.cdm.SubcollectionManager
|
---|
145 | * @see org.greenstone.gatherer.cdm.SuperCollectionManager
|
---|
146 | * @see org.greenstone.gatherer.cdm.TranslationView
|
---|
147 | */
|
---|
148 | private void loadDesignDetails() {
|
---|
149 | // Create the command information managers, registering the config file with each as necessary
|
---|
150 | language_manager = new LanguageManager(collect_config.getLanguages());
|
---|
151 | collectionmeta_manager = new CollectionMetaManager();
|
---|
152 | classifier_manager = new ClassifierManager();
|
---|
153 | general_manager = new GeneralManager();
|
---|
154 | macros_manager = new MacrosManager();
|
---|
155 | index_manager = new IndexingManager();
|
---|
156 | plugin_manager = new PluginManager();
|
---|
157 | subcollection_manager = new SubcollectionManager();
|
---|
158 | subcollectionindex_manager = new SubcollectionIndexManager(collect_config.getSubIndexes());
|
---|
159 | supercollection_manager = new SuperCollectionManager(collect_config.getSuperCollection());
|
---|
160 | searchmetadata_manager = new SearchMetadataManager();
|
---|
161 | depositormetadata_manager = new DepositorMetadataManager();
|
---|
162 | translation_manager = new TranslationView();
|
---|
163 | if (Gatherer.GS3) {
|
---|
164 | format_manager = new Format4gs3Manager();
|
---|
165 | } else {
|
---|
166 | format_manager = new FormatManager(); // Parse formats at the very end, given that they depend upon several other managers to appear properly.
|
---|
167 | }
|
---|
168 | }
|
---|
169 |
|
---|
170 | /** This method deconstructs each of the managers, causing them to dispose of their controls.
|
---|
171 | */
|
---|
172 | public void destroy() {
|
---|
173 | // Remove references from persistant listeners.
|
---|
174 | classifier_manager.destroy();
|
---|
175 | classifier_manager = null;
|
---|
176 | searchmetadata_manager.destroy();
|
---|
177 | searchmetadata_manager = null;
|
---|
178 | format_manager.destroy();
|
---|
179 | format_manager = null;
|
---|
180 | // format_4gs3_manager.destroy();
|
---|
181 | // format_4gs3_manager = null;
|
---|
182 | general_manager.destroy();
|
---|
183 | general_manager = null;
|
---|
184 | index_manager.destroy();
|
---|
185 | index_manager = null;
|
---|
186 | language_manager.destroy();
|
---|
187 | language_manager = null;
|
---|
188 | plugin_manager.destroy();
|
---|
189 | plugin_manager = null;
|
---|
190 | subcollection_manager.destroy();
|
---|
191 | subcollection_manager = null;
|
---|
192 | supercollection_manager.destroy();
|
---|
193 | supercollection_manager = null;
|
---|
194 | depositormetadata_manager.destroy();
|
---|
195 | depositormetadata_manager = null;
|
---|
196 | translation_manager.destroy();
|
---|
197 | translation_manager = null;
|
---|
198 | }
|
---|
199 |
|
---|
200 | /** Called when the detail mode has changed which in turn may cause several design elements to be available/hidden
|
---|
201 | * @param mode the new mode as an int
|
---|
202 | */
|
---|
203 | public void modeChanged(int mode) {
|
---|
204 | if (plugin_manager != null) plugin_manager.modeChanged(mode);
|
---|
205 | if(classifier_manager != null) classifier_manager.modeChanged(mode);
|
---|
206 | if(subcollection_manager != null) subcollection_manager.modeChanged(mode);
|
---|
207 | if(supercollection_manager != null) supercollection_manager.modeChanged(mode);
|
---|
208 | //if(format_manager != null) format_manager.modeChanged(mode);
|
---|
209 | if(index_manager != null) index_manager.modeChanged(mode);
|
---|
210 | if(translation_manager != null) translation_manager.modeChanged(mode);
|
---|
211 | if(general_manager != null) general_manager.modeChanged(mode);
|
---|
212 | if(language_manager != null) language_manager.modeChanged(mode);
|
---|
213 | if(searchmetadata_manager != null) searchmetadata_manager.modeChanged(mode);
|
---|
214 | if(depositormetadata_manager != null) depositormetadata_manager.modeChanged(mode);
|
---|
215 | }
|
---|
216 |
|
---|
217 | /** The cdm is considered to be ready if the collect.cfg file was found and parsed and the collection title is not error.
|
---|
218 | * @return true if the collection is ready, false otherwise
|
---|
219 | */
|
---|
220 | public boolean ready() {
|
---|
221 | return collect_config.ready();
|
---|
222 | }
|
---|
223 |
|
---|
224 |
|
---|
225 | /** Cause the current collection configuration to be written out to disk.
|
---|
226 | */
|
---|
227 | public void save() {
|
---|
228 | collect_config.saveIfNecessary();
|
---|
229 | }
|
---|
230 |
|
---|
231 |
|
---|
232 | public static int getRebuildTypeRequired() {
|
---|
233 | return rebuildTypeRequired;
|
---|
234 | }
|
---|
235 |
|
---|
236 | public static void resetRebuildTypeRequired() {
|
---|
237 | setRebuildTypeRequired(NOTHING);
|
---|
238 | }
|
---|
239 | public static void setRebuildTypeRequired(int number) {
|
---|
240 | rebuildTypeRequired = number;
|
---|
241 | }
|
---|
242 |
|
---|
243 | public static boolean isCompleteBuild() {
|
---|
244 | return isCompleteBuild;
|
---|
245 | }
|
---|
246 | public static void setCompleteBuild(boolean icb) {
|
---|
247 | isCompleteBuild = icb;
|
---|
248 | }
|
---|
249 |
|
---|
250 | public static void setImportWasFull( boolean wasFull ) {
|
---|
251 | importWasFull = wasFull;
|
---|
252 | }
|
---|
253 | public static boolean importWasFull() {
|
---|
254 | return importWasFull;
|
---|
255 | }
|
---|
256 | public static void setBuildcolWasFull( boolean wasFull ) {
|
---|
257 | buildcolWasFull = wasFull;
|
---|
258 | }
|
---|
259 | public static boolean buildcolWasFull() {
|
---|
260 | return buildcolWasFull;
|
---|
261 | }
|
---|
262 |
|
---|
263 | /**
|
---|
264 | * What exactly does this do?
|
---|
265 | */
|
---|
266 | private class CDMChangeListener
|
---|
267 | implements ActionListener, DocumentListener {
|
---|
268 |
|
---|
269 | /** Gives notification that an event has happened */
|
---|
270 | public void actionPerformed(ActionEvent event) {
|
---|
271 | Gatherer.c_man.getCollection().setSaved(false);
|
---|
272 | }
|
---|
273 |
|
---|
274 | /** Gives notification that an attribute or set of attributes changed. */
|
---|
275 | public void changedUpdate(DocumentEvent e) {
|
---|
276 | Gatherer.c_man.getCollection().setSaved(false);
|
---|
277 | }
|
---|
278 |
|
---|
279 | /** Gives notification that there was an insert into the document. */
|
---|
280 | public void insertUpdate(DocumentEvent e) {
|
---|
281 | Gatherer.c_man.getCollection().setSaved(false);
|
---|
282 | }
|
---|
283 |
|
---|
284 | /** Gives notification that a portion of the document has been removed. */
|
---|
285 | public void removeUpdate(DocumentEvent e) {
|
---|
286 | Gatherer.c_man.getCollection().setSaved(false);
|
---|
287 | }
|
---|
288 | }
|
---|
289 | }
|
---|