/** *######################################################################### * * 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.gui; import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; import org.greenstone.gatherer.Configuration; import org.greenstone.gatherer.Dictionary; import org.greenstone.gatherer.Gatherer; import org.greenstone.gatherer.metadata.MetadataSet; import org.greenstone.gatherer.metadata.MetadataSetManager; import org.greenstone.gatherer.util.CheckList; import org.greenstone.gatherer.util.CheckListEntry; public class NewCollectionMetadataPrompt extends ModalDialog { private boolean cancelled = true; private JDialog self; private JList elements_list; private CheckList metadata_sets_list; static private Dimension size = new Dimension(700, 380); public NewCollectionMetadataPrompt() { this(false); } public NewCollectionMetadataPrompt(boolean existing_coll) { super(Gatherer.g_man, true); this.self = this; if (existing_coll) { setJMenuBar(new SimpleMenuBar("openingacollection")); Dictionary.setText(this, "NewCollectionPrompt.Metadata_Title_Existing"); } else { setJMenuBar(new SimpleMenuBar("creatingacollection")); Dictionary.setText(this, "NewCollectionPrompt.Title"); } setModal(true); setSize(size); // Show the metadata sets (except extracted and exploded) available in the GLI "metadata" folder ArrayList metadata_sets = MetadataSetManager.listMetadataSets(new File(Gatherer.getGLIMetadataDirectoryPath())); ArrayList metadata_set_list_entries = new ArrayList(); for (int i = 0; i < metadata_sets.size(); i++) { MetadataSet metadata_set = (MetadataSet) metadata_sets.get(i); // Don't show the extracted metadata set if (metadata_set.getNamespace().equals(MetadataSetManager.EXTRACTED_METADATA_NAMESPACE)) { continue; } // Don't show the exploded metadata set if (metadata_set.getNamespace().equals("exp")) { continue; } metadata_set_list_entries.add(metadata_set); } // Creation JPanel content_pane = (JPanel) getContentPane(); JPanel instructions_panel = new JPanel(); JLabel instructions_label1 = new JLabel(); Dictionary.setText(instructions_label1, "NewCollectionPrompt.Metadata_Instructions1"); JLabel instructions_label2 = new JLabel(); Dictionary.setText(instructions_label2, "NewCollectionPrompt.Metadata_Instructions2"); JPanel center_pane = new JPanel(); JPanel sets_list_pane = new JPanel(); JLabel sets_list_label = new JLabel(); sets_list_label.setOpaque(false); Dictionary.setText(sets_list_label, "NewCollectionPrompt.Select_MDS"); metadata_sets_list = new CheckList(true); metadata_sets_list.addListSelectionListener(new MetadataSetListSelectionListener()); metadata_sets_list.setListData(metadata_set_list_entries); metadata_sets_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JPanel elements_list_pane = new JPanel(); JLabel elements_list_label = new JLabel(); Dictionary.setText(elements_list_label, "NewCollectionPrompt.Metadata_Elements"); elements_list = new JList(); elements_list.setCellRenderer(new MetadataElementListCellRenderer()); elements_list.setBackground(Configuration.getColor("coloring.collection_tree_background", false)); elements_list.setForeground(Configuration.getColor("coloring.collection_tree_foreground", false)); elements_list.setSelectionBackground(Configuration.getColor("coloring.collection_tree_background", false)); elements_list.setSelectionForeground(Configuration.getColor("coloring.collection_tree_foreground", false)); // Set Dublin Core to be ticked initially, at Ian's request for (int i = 0; i < metadata_set_list_entries.size(); i++) { MetadataSet metadata_set = (MetadataSet) metadata_set_list_entries.get(i); if (metadata_set.getMetadataSetFile().getName().equals("dublin.mds")) { metadata_sets_list.setTickedObjects(new Object[] { metadata_set }); } } JPanel button_pane = new JPanel(); JButton ok_button = new GLIButton(); ok_button.setMnemonic(KeyEvent.VK_O); Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip"); JButton cancel_button = new GLIButton(); cancel_button.setMnemonic(KeyEvent.VK_C); Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip"); // Connection ok_button.addActionListener(new OKButtonListener()); cancel_button.addActionListener(new CancelButtonListener()); // Display instructions_panel.setLayout(new GridLayout(2,1)); instructions_panel.add(instructions_label1); instructions_panel.add(instructions_label2); sets_list_pane.setLayout(new BorderLayout()); sets_list_pane.add(sets_list_label, BorderLayout.NORTH); sets_list_pane.add(new JScrollPane(metadata_sets_list), BorderLayout.CENTER); elements_list_pane.setLayout(new BorderLayout()); elements_list_pane.add(elements_list_label, BorderLayout.NORTH); elements_list_pane.add(new JScrollPane(elements_list), BorderLayout.CENTER); center_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0)); center_pane.setLayout(new GridLayout(2,1,0,5)); center_pane.add(sets_list_pane); center_pane.add(elements_list_pane); button_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0)); button_pane.setLayout(new GridLayout(1,2,5,0)); button_pane.add(ok_button); button_pane.add(cancel_button); content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); content_pane.setLayout(new BorderLayout()); content_pane.add(instructions_panel, BorderLayout.NORTH); content_pane.add(center_pane, BorderLayout.CENTER); content_pane.add(button_pane, BorderLayout.SOUTH); // Show Dimension screen_size = Configuration.screen_size; setLocation((screen_size.width - size.width) / 2, (screen_size.height - size.height) / 2); setVisible(true); } public ArrayList getSets() { return metadata_sets_list.getTicked(); } public boolean isCancelled() { return cancelled; } private class CancelButtonListener implements ActionListener { public void actionPerformed(ActionEvent event) { cancelled = true; self.dispose(); } } private class MetadataSetListSelectionListener implements ListSelectionListener { public void valueChanged(ListSelectionEvent event) { if (!metadata_sets_list.isSelectionEmpty()) { // Retrieve the selected set MetadataSet metadata_set = (MetadataSet) ((CheckListEntry) metadata_sets_list.getSelectedValue()).getObject(); elements_list.setListData(new Vector(metadata_set.getMetadataSetElements())); } else { elements_list.setListData(new String[0]); } } } private class OKButtonListener implements ActionListener { public void actionPerformed(ActionEvent event) { // See if the user has selected no metadata sets, and if so confirm thats what they really want. cancelled = false; if (metadata_sets_list.isNothingTicked()) { WarningDialog dialog = new WarningDialog("warning.NoMetadataSetsSelected", "NoMetadataSetsSelected.Title", Dictionary.get("NoMetadataSetsSelected.Message"), null, true); if (dialog.display() == JOptionPane.OK_OPTION) { // Otherwise we are free to go self.dispose(); } dialog.dispose(); dialog = null; } else { self.dispose(); } } } }