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

Last change on this file since 7454 was 7271, checked in by kjdon, 20 years ago

undid previous change

  • Property svn:keywords set to Author Date Id Revision
File size: 13.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.*;
30import java.awt.event.*;
31import java.io.*;
32import javax.swing.*;
33import javax.swing.event.*;
34import org.greenstone.gatherer.Gatherer;
35import org.greenstone.gatherer.cdm.ClassifierManager;
36import org.greenstone.gatherer.cdm.CollectionConfiguration;
37import org.greenstone.gatherer.cdm.CollectionMetaManager;
38import org.greenstone.gatherer.cdm.FormatManager;
39import org.greenstone.gatherer.cdm.GeneralManager;
40import org.greenstone.gatherer.cdm.IndexManager;
41import org.greenstone.gatherer.cdm.MetadataSetView;
42import org.greenstone.gatherer.cdm.PlugInManager;
43import org.greenstone.gatherer.cdm.SubcollectionManager;
44import org.greenstone.gatherer.cdm.TranslationView;
45import org.greenstone.gatherer.util.GSDLSiteConfig;
46
47/** 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.
48 * @author John Thompson, Greenstone Digital Library, University of Waikato
49 * @version 2.3d
50 */
51public class CollectionDesignManager {
52 /** 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. */
53 static public CDMChangeListener change_listener;
54 /** A list of classifiers to use at build time. */
55 static public ClassifierManager classifier_manager;
56 /** The CollectionConfiguration object on which this CDM will be based. */
57 static public CollectionConfiguration collect_config;
58 /** A manager of collection level metadata. */
59 static public CollectionMetaManager collectionmeta_manager;
60 /** A list of formating strings to use at build time. */
61 static public FormatManager format_manager;
62 /** The manager in charge of displaying this manager and the controls for other managers. */
63 static public GeneralManager general_manager;
64 /** List of indexes to be built, and the default index. */
65 static public IndexManager index_manager;
66 /** Contains instructions dealing with the collection language. */
67 static public LanguageManager language_manager;
68 /** A simple manager for the visual review of metadata sets. */
69 static public MetadataSetView metadataset_view;
70 /** A list of plugins to use at build time. */
71 static public PlugInManager plugin_manager;
72 /** The manager in charge of all aspects of searchtypes. We also ask this manager whether we are MG or MGPP enabled. */
73 static public SearchTypeManager searchtype_manager;
74 /** Contains: A list of subcollections, (defined on metadatadata), a list of which subcollection indexes to build and the default subcollection index. */
75 static public SubcollectionManager subcollection_manager;
76
77 static public SubcollectionIndexManager subcollectionindex_manager;
78 /** 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. */
79 static public SuperCollectionManager supercollection_manager; // Just cause I could ;p
80 /** The text translation manager. */
81 static public TranslationView translation_view;
82 /** 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.
83 * @param collect_config_file the File representing a collection configuration file either in its text (G2) or xml (G3) form
84 */
85 public CollectionDesignManager(File collect_config_file) {
86 Gatherer.println("Initializaing CollectionDesignModule.");
87 change_listener = new CDMChangeListener();
88 // Parse the collection configuration
89 collect_config = new CollectionConfiguration(collect_config_file);
90 if(Gatherer.debug != null) {
91 collect_config.display();
92 }
93 loadDesignDetails();
94 Gatherer.println("CollectionDesignModule loaded.");
95 }
96
97 /** Reloads the various managers to ensure they have built themselves from the latest details available in the collection configuration class
98 * @see org.greenstone.gatherer.cdm.ClassifierManager
99 * @see org.greenstone.gatherer.cdm.CollectionMetaManager
100 * @see org.greenstone.gatherer.cdm.FormatManager
101 * @see org.greenstone.gatherer.cdm.GeneralManager
102 * @see org.greenstone.gatherer.cdm.IndexManager
103 * @see org.greenstone.gatherer.cdm.LanguageManager
104 * @see org.greenstone.gatherer.cdm.MetadataSetView
105 * @see org.greenstone.gatherer.cdm.PlugInManager
106 * @see org.greenstone.gatherer.cdm.SearchTypeManager
107 * @see org.greenstone.gatherer.cdm.SubcollectionIndexManager
108 * @see org.greenstone.gatherer.cdm.SubcollectionManager
109 * @see org.greenstone.gatherer.cdm.SuperCollectionManager
110 * @see org.greenstone.gatherer.cdm.TranslationView
111 */
112 public void loadDesignDetails() {
113 // Create the command information managers, registering the config file with each as necessary
114 language_manager = new LanguageManager(collect_config.getLanguages());
115 collectionmeta_manager = new CollectionMetaManager();
116 classifier_manager = new ClassifierManager();
117 general_manager = new GeneralManager();
118
119 searchtype_manager = new SearchTypeManager(collect_config.getSearchType());
120 if(searchtype_manager.isMGPPEnabled()) {
121 index_manager = new IndexManager(collect_config.getMGPPIndexes());
122 }
123 else {
124 index_manager = new IndexManager(collect_config.getMGIndexes());
125 }
126
127 metadataset_view = new MetadataSetView();
128 plugin_manager = new PlugInManager();
129 plugin_manager.placeSeparator();
130 subcollection_manager = new SubcollectionManager();
131 subcollectionindex_manager = new SubcollectionIndexManager(collect_config.getSubIndexes());
132 supercollection_manager = new SuperCollectionManager(collect_config.getSuperCollection());
133 translation_view = new TranslationView();
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 /** This method deconstructs each of the managers, causing them to dispose of their controls.
138 */
139 public void destroy() {
140 // Remove visual the component from its parent.
141 if(general_manager.getParent() != null) {
142 general_manager.getParent().remove(general_manager);
143 }
144 // Remove references from persistant listeners.
145 classifier_manager.destroy();
146 classifier_manager = null;
147 format_manager.destroy();
148 format_manager = null;
149 general_manager.destroy();
150 general_manager = null;
151 index_manager.destroy();
152 index_manager = null;
153 language_manager.destroy();
154 language_manager = null;
155 metadataset_view.destroy();
156 metadataset_view = null;
157 plugin_manager.destroy();
158 plugin_manager = null;
159 subcollection_manager.destroy();
160 subcollection_manager = null;
161 supercollection_manager.destroy();
162 supercollection_manager = null;
163 translation_view.destroy();
164 translation_view = null;
165 }
166
167 /** Display the GUI interface for the CollectionDesignManager in the centre of the indicated panel.
168 * @param target the JPanel you wish to display the gui on
169 */
170 public void display(JPanel target) {
171 target.add(general_manager, BorderLayout.CENTER);
172 }
173 /** When the tab on the JTabbedPane that contains the GUI is selected, this method is called to ensure that the controls are all up to date, in terms of references to metadata etc.
174 */
175 public void gainFocus() {
176 general_manager.gainFocus();
177 }
178
179 /** Called when the detail mode has changed which in turn may cause several design elements to be available/hidden
180 * @param mode the new mode as an int
181 */
182 public void modeChanged(int mode) {
183 plugin_manager.modeChanged(mode);
184 subcollection_manager.modeChanged(mode);
185 }
186
187 /** The cdm is considered to be ready if the collect.cfg file was found and parsed and the collection title is not error.
188 * @return true if the collection is ready, false otherwise
189 */
190 public boolean ready() {
191 return collect_config.ready();
192 }
193
194 /** Ensure that saving will actually work. This can return false if there is a collection filename clash for instance. */
195 public boolean canSave() {
196 return (general_manager == null || general_manager.canSave());
197 }
198
199 /** Cause the current collection configuration to be written out to disk.
200 * @see org.greenstone.gatherer.cdm.ClassifierManager
201 * @see org.greenstone.gatherer.cdm.CollectionMetaManager
202 * @see org.greenstone.gatherer.cdm.FormatManager
203 * @see org.greenstone.gatherer.cdm.IndexManager
204 * @see org.greenstone.gatherer.cdm.LanguageManager
205 * @see org.greenstone.gatherer.cdm.MetadataSetView
206 * @see org.greenstone.gatherer.cdm.PlugInManager
207 * @see org.greenstone.gatherer.cdm.SubcollectionManager
208 */
209 public void save() {
210 // Release collection as necessary
211 ///ystem.err.println("Would have released collection if necessary.");
212 boolean collection_released = false;
213 if(format_manager.formatsChanged() && Gatherer.c_man.built() && Gatherer.config.exec_file != null) {
214 // Release the collection
215 //Gatherer.g_man.preview_pane.configServer(GSDLSiteConfig.RELEASE_COMMAND + Gatherer.c_man.getCollection().getName());
216 Gatherer.self.configServer(GSDLSiteConfig.RELEASE_COMMAND + Gatherer.c_man.getCollection().getName());
217 collection_released = true;
218 }
219
220 general_manager.loseFocus();
221 collect_config.save();
222
223 // Readd collection
224 ///ystem.err.println("Would have added collection if it had been released.");
225 if(collection_released) {
226 // Then re-add it to force format commands to be processed
227 //Gatherer.g_man.preview_pane.configServer(GSDLSiteConfig.ADD_COMMAND + Gatherer.c_man.getCollection().getName());
228 Gatherer.self.configServer(GSDLSiteConfig.ADD_COMMAND + Gatherer.c_man.getCollection().getName());
229 // Unset formats changed
230 format_manager.setFormatsChanged(false);
231 }
232 }
233
234// /** Ensures that the collection is now public. Useful for collections that are based on another, or that are about to be exported */
235// public void setCollectionAsPublic() {
236// CollectionMeta public_collectionmeta = new CollectionMeta(CollectionDesignManager.collect_config.getPublic());
237// if(public_collectionmeta != null) {
238// public_collectionmeta.setValue(CollectionConfiguration.TRUE_STR);
239// public_collectionmeta = null;
240// }
241// }
242
243 /** Method used during a global search and replace to highlight the appropriate record within the Collection Design Managers version of the Metadata Set Manager (view only).
244 * @param element The name of the desired element as a <strong>String</strong>.
245 * @see org.greenstone.gatherer.cdm.GeneralManager
246 * @see org.greenstone.gatherer.cdm.MetadataSetView
247 */
248 public Rectangle setSelectedElement(String element) {
249 // First ensure that the metadata set controls are visible.
250 general_manager.setSelectedView("CDM.GUI.MetadataSets");
251 // Then tell them to select the given element.
252 return metadataset_view.setSelectedElement(element);
253 }
254
255 private class CDMChangeListener
256 implements ActionListener, DocumentListener {
257
258 public void actionPerformed(ActionEvent event) {
259 Gatherer.c_man.getCollection().setSaved(false);
260 }
261
262 /** Gives notification that an attribute or set of attributes changed. */
263 public void changedUpdate(DocumentEvent e) {
264 Gatherer.c_man.getCollection().setSaved(false);
265 }
266
267 /** Gives notification that there was an insert into the document. */
268 public void insertUpdate(DocumentEvent e) {
269 Gatherer.c_man.getCollection().setSaved(false);
270 }
271
272 /** Gives notification that a portion of the document has been removed. */
273 public void removeUpdate(DocumentEvent e) {
274 Gatherer.c_man.getCollection().setSaved(false);
275 }
276 }
277}
Note: See TracBrowser for help on using the repository browser.