source: gli/branches/rtl-gli/src/org/greenstone/gatherer/cdm/CollectionDesignManager.java@ 18368

Last change on this file since 18368 was 18368, checked in by kjdon, 15 years ago

copied a couple of files directly over from gli trunk. They should have been identical after merge as I had made no changes to them, but they weren't

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