/** *######################################################################### * * A component of the Gatherer application, part of the Greenstone digital * library suite from the New Zealand Digital Library Project at the * University of Waikato, New Zealand. * * Author: John Thompson, Greenstone Digital Library, University of Waikato * * Copyright (C) 1999 New Zealand Digital Library Project * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *######################################################################## */ package org.greenstone.gatherer.cdm; import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*; import javax.swing.event.*; import org.greenstone.gatherer.Gatherer; import org.greenstone.gatherer.cdm.ClassifierManager; import org.greenstone.gatherer.cdm.CollectionConfiguration; import org.greenstone.gatherer.cdm.CollectionMetaManager; import org.greenstone.gatherer.cdm.FormatManager; import org.greenstone.gatherer.cdm.GeneralManager; import org.greenstone.gatherer.cdm.IndexManager; import org.greenstone.gatherer.cdm.MetadataSetView; import org.greenstone.gatherer.cdm.PlugInManager; import org.greenstone.gatherer.cdm.SubcollectionManager; import org.greenstone.gatherer.cdm.TranslationView; import org.greenstone.gatherer.util.GSDLSiteConfig; /** 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. * @author John Thompson, Greenstone Digital Library, University of Waikato * @version 2.3d */ public class CollectionDesignManager { /** 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. */ static public CDMChangeListener change_listener; /** A list of classifiers to use at build time. */ static public ClassifierManager classifier_manager; /** The CollectionConfiguration object on which this CDM will be based. */ static public CollectionConfiguration collect_config; /** A manager of collection level metadata. */ static public CollectionMetaManager collectionmeta_manager; /** A list of formating strings to use at build time. */ static public FormatManager format_manager; /** The manager in charge of displaying this manager and the controls for other managers. */ static public GeneralManager general_manager; /** List of indexes to be built, and the default index. */ static public IndexManager index_manager; /** Contains instructions dealing with the collection language. */ static public LanguageManager language_manager; /** A simple manager for the visual review of metadata sets. */ static public MetadataSetView metadataset_view; /** A list of plugins to use at build time. */ static public PlugInManager plugin_manager; /** The manager in charge of all aspects of searchtypes. We also ask this manager whether we are MG or MGPP enabled. */ static public SearchTypeManager searchtype_manager; /** Contains: A list of subcollections, (defined on metadatadata), a list of which subcollection indexes to build and the default subcollection index. */ static public SubcollectionManager subcollection_manager; static public SubcollectionIndexManager subcollectionindex_manager; /** 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. */ static public SuperCollectionManager supercollection_manager; // Just cause I could ;p /** The text translation manager. */ static public TranslationView translation_view; /** 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. * @param collect_config_file the File representing a collection configuration file either in its text (G2) or xml (G3) form */ public CollectionDesignManager(File collect_config_file) { Gatherer.println("Initializaing CollectionDesignModule."); change_listener = new CDMChangeListener(); // Parse the collection configuration collect_config = new CollectionConfiguration(collect_config_file); if(Gatherer.debug != null) { collect_config.display(); } // Create the command information managers, registering the config file with each as necessary language_manager = new LanguageManager(collect_config.getLanguages()); collectionmeta_manager = new CollectionMetaManager(); classifier_manager = new ClassifierManager(); general_manager = new GeneralManager(); searchtype_manager = new SearchTypeManager(collect_config.getSearchType()); if(searchtype_manager.isMGPPEnabled()) { index_manager = new IndexManager(collect_config.getMGPPIndexes()); } else { index_manager = new IndexManager(collect_config.getMGIndexes()); } metadataset_view = new MetadataSetView(); plugin_manager = new PlugInManager(); plugin_manager.placeSeparator(); subcollection_manager = new SubcollectionManager(); subcollectionindex_manager = new SubcollectionIndexManager(collect_config.getSubIndexes()); supercollection_manager = new SuperCollectionManager(collect_config.getSuperCollection()); translation_view = new TranslationView(); format_manager = new FormatManager(); // Parse formats at the very end, given that they depend upon several other managers to appear properly. Gatherer.println("CollectionDesignModule loaded."); } /** This method deconstructs each of the managers, causing them to dispose of their controls. */ public void destroy() { // Remove visual the component from its parent. if(general_manager.getParent() != null) { general_manager.getParent().remove(general_manager); } // Remove references from persistant listeners. classifier_manager.destroy(); classifier_manager = null; format_manager.destroy(); format_manager = null; general_manager.destroy(); general_manager = null; index_manager.destroy(); index_manager = null; language_manager.destroy(); language_manager = null; metadataset_view.destroy(); metadataset_view = null; plugin_manager.destroy(); plugin_manager = null; subcollection_manager.destroy(); subcollection_manager = null; supercollection_manager.destroy(); supercollection_manager = null; translation_view.destroy(); translation_view = null; } /** Display the GUI interface for the CollectionDesignManager in the centre of the indicated panel. * @param target the JPanel you wish to display the gui on */ public void display(JPanel target) { target.add(general_manager, BorderLayout.CENTER); } /** 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. */ public void gainFocus() { general_manager.gainFocus(); } /** Retrieve the name of the collection configuration file which is being used as the source of the information in this object. * @return The files absolute path as a String. */ public String getFilename() { return collect_config.getFile().getAbsolutePath(); } /** Cause the current collection configuration to be written out to disk. * @see org.greenstone.gatherer.cdm.ClassifierManager * @see org.greenstone.gatherer.cdm.CollectionMetaManager * @see org.greenstone.gatherer.cdm.FormatManager * @see org.greenstone.gatherer.cdm.IndexManager * @see org.greenstone.gatherer.cdm.LanguageManager * @see org.greenstone.gatherer.cdm.MetadataSetManager * @see org.greenstone.gatherer.cdm.PlugInManager * @see org.greenstone.gatherer.cdm.SubcollectionManager * @see org.greenstone.gatherer.util.EmailAddress */ public void save() { // Release collection as necessary ///ystem.err.println("Would have released collection if necessary."); boolean collection_released = false; if(format_manager.formatsChanged() && Gatherer.c_man.built() && Gatherer.config.exec_file != null) { // Release the collection Gatherer.g_man.preview_pane.configServer(GSDLSiteConfig.RELEASE_COMMAND + Gatherer.c_man.getCollection().getName()); collection_released = true; } general_manager.loseFocus(); collect_config.save(); // Readd collection ///ystem.err.println("Would have added collection if it had been released."); if(collection_released) { // Then re-add it to force format commands to be processed Gatherer.g_man.preview_pane.configServer(GSDLSiteConfig.ADD_COMMAND + Gatherer.c_man.getCollection().getName()); // Unset formats changed format_manager.setFormatsChanged(false); } } /** 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). * @param element The name of the desired element as a String. * @see org.greenstone.gatherer.cdm.GUI * @see org.greenstone.gatherer.cdm.MetadataSetManager */ public Rectangle setSelectedElement(String element) { // First ensure that the metadata set controls are visible. general_manager.setSelectedView("CDM.GUI.MetadataSets"); // Then tell them to select the given element. return metadataset_view.setSelectedElement(element); } private class CDMChangeListener implements ActionListener, DocumentListener { public void actionPerformed(ActionEvent event) { Gatherer.c_man.getCollection().setSaved(false); } /** Gives notification that an attribute or set of attributes changed. */ public void changedUpdate(DocumentEvent e) { Gatherer.c_man.getCollection().setSaved(false); } /** Gives notification that there was an insert into the document. */ public void insertUpdate(DocumentEvent e) { Gatherer.c_man.getCollection().setSaved(false); } /** Gives notification that a portion of the document has been removed. */ public void removeUpdate(DocumentEvent e) { Gatherer.c_man.getCollection().setSaved(false); } } }