/** *######################################################################### * * 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.event.*; import org.greenstone.gatherer.Configuration; import org.greenstone.gatherer.Dictionary; import org.greenstone.gatherer.Gatherer; import org.greenstone.gatherer.collection.BasicCollectionConfiguration; import org.greenstone.gatherer.util.StaticStrings; import org.greenstone.gatherer.util.Utility; import org.greenstone.gatherer.shell.GShell; import org.greenstone.gatherer.shell.GShellEvent; import org.greenstone.gatherer.shell.GShellListener; import org.greenstone.gatherer.shell.GShellProgressMonitor; /** A dialog which provides a straight-forward access to the currently installed collections. It also will contain the ability to continue through to the original OpenCollectionDialog if your source collection is located somewhere other than the gsdl collect folder. */ public class OpenCollectionDialog extends ModalDialog { static final public int OK_OPTION = 0; static final public int CANCEL_OPTION = 1; static final private Dimension SIZE = new Dimension(640,480); static final private String BLANK = "b"; static final private String DESCRIPTION = "d"; private CardLayout card_layout; private int result; private JButton cancel_button; private JButton open_button; private JList collection_list; private JTextArea description_textarea; private JPanel description_pane; private String filename; public OpenCollectionDialog() { super(Gatherer.g_man, "", true); setJMenuBar(new SimpleMenuBar("openingacollection")); this.setComponentOrientation(Dictionary.getOrientation()); setSize(SIZE); setTitle(Dictionary.get("OpenCollectionDialog.Title")); // Creation JPanel content_pane = (JPanel) getContentPane(); content_pane.setComponentOrientation(Dictionary.getOrientation()); JPanel center_pane = new JPanel(); center_pane.setComponentOrientation(Dictionary.getOrientation()); JPanel collection_list_pane = new JPanel(); collection_list_pane.setComponentOrientation(Dictionary.getOrientation()); JLabel collection_list_label = new JLabel(Dictionary.get("OpenCollectionDialog.Available_Collections")); collection_list_label.setComponentOrientation(Dictionary.getOrientation()); collection_list = new JList(new CollectionListModel()); collection_list.setComponentOrientation(Dictionary.getOrientation()); description_pane = new JPanel(); description_pane.setComponentOrientation(Dictionary.getOrientation()); card_layout = new CardLayout(); JPanel blank_pane = new JPanel(); blank_pane.setComponentOrientation(Dictionary.getOrientation()); JPanel description_textarea_pane = new JPanel(); description_textarea_pane.setComponentOrientation(Dictionary.getOrientation()); JLabel description_textarea_label = new JLabel(Dictionary.get("OpenCollectionDialog.Description")); description_textarea_label.setComponentOrientation(Dictionary.getOrientation()); description_textarea = new JTextArea(); description_textarea.setComponentOrientation(Dictionary.getOrientation()); JPanel button_pane = new JPanel(); button_pane.setComponentOrientation(Dictionary.getOrientation()); open_button = new GLIButton(Dictionary.get("OpenCollectionDialog.Open"), Dictionary.get("OpenCollectionDialog.Open_Tooltip")); open_button.setEnabled(false); cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Pure_Cancel_Tooltip")); // Connection cancel_button.addActionListener(new CancelListener()); open_button.addActionListener(new OpenListener()); CollectionListSelectionListener clsl = new CollectionListSelectionListener(); collection_list.addListSelectionListener(clsl); collection_list.addMouseListener(clsl); clsl = null; // Layout JScrollPane scrol_tmp; collection_list_pane.setLayout(new BorderLayout()); collection_list_pane.add(collection_list_label, BorderLayout.NORTH); scrol_tmp = new JScrollPane(collection_list); scrol_tmp.setComponentOrientation(Dictionary.getOrientation()); collection_list_pane.add(scrol_tmp, BorderLayout.CENTER); description_textarea_pane.setLayout(new BorderLayout()); description_textarea_pane.add(description_textarea_label, BorderLayout.NORTH); scrol_tmp =new JScrollPane(description_textarea); scrol_tmp.setComponentOrientation(Dictionary.getOrientation()); description_textarea_pane.add(scrol_tmp, BorderLayout.CENTER); description_pane.setLayout(card_layout); description_pane.add(description_textarea_pane, DESCRIPTION); description_pane.add(blank_pane, BLANK); center_pane.setLayout(new GridLayout(2,1,0,5)); center_pane.add(collection_list_pane); center_pane.add(description_pane); button_pane.setLayout(new GridLayout(1,4)); JPanel tmp =new JPanel(); tmp.setComponentOrientation(Dictionary.getOrientation()); button_pane.add(tmp); button_pane.add(open_button); button_pane.add(cancel_button); content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); content_pane.setLayout(new BorderLayout()); content_pane.add(center_pane, BorderLayout.CENTER); content_pane.add(button_pane, BorderLayout.SOUTH); Dimension screen_size = Configuration.screen_size; setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2); screen_size = null; } public void destroy() { } public int display() { setVisible(true); return result; } public String getFileName() { return this.filename; } private class CancelListener implements ActionListener { public void actionPerformed(ActionEvent event) { result = CANCEL_OPTION; OpenCollectionDialog.this.dispose(); } } private class CollectionListSelectionListener extends MouseAdapter implements ListSelectionListener { public void mouseClicked(MouseEvent event) { ///ystem.err.println("Mouse clicked"); if(event.getClickCount() >= 2) { Point location = event.getPoint(); int index = collection_list.locationToIndex(location); collection_list.setSelectedIndex(index); location = null; open_button.doClick(); } } public void valueChanged(ListSelectionEvent event) { if(collection_list.isSelectionEmpty()) { card_layout.show(description_pane, BLANK); open_button.setEnabled(false); } else { BasicCollectionConfiguration collection_configuration = (BasicCollectionConfiguration) collection_list.getSelectedValue(); description_textarea.setText(collection_configuration.getDescription()); description_textarea.setCaretPosition(0); card_layout.show(description_pane, DESCRIPTION); open_button.setEnabled(true); } } } // use this if we ever go back to viewing all colls at once /* private class GS3CollectionListModel extends AbstractListModel { private TreeSet data; public GS3CollectionListModel() { data = new TreeSet(); File sites_folder = new File(Utility.getSitesDir(Configuration.gsdl3_path)); File sites[] = sites_folder.listFiles(); for (int s=0; s if it is, don't add, but recurse to look for child collections in collect-group if (collection_configuration.getCollectGroup().equals("true")) { load_collection_configs(data, collection_folder); } else { // if we have a metadata directory, then its a valid collection if (collection_metadata_directory.exists()) { data.add(collection_configuration); } } } config_file = null; } collection_foldername = null; collection_folder = null; } collection_folders = null; collect_directory = null; } public Object getElementAt(int index) { Iterator iterator = data.iterator(); for(int i = 0; iterator.hasNext(); i++) { Object object = iterator.next(); if(i == index) { iterator = null; return object; } object = null; } iterator = null; return null; } public int getSize() { return data.size(); } public void convertToGS3Collection(File collection_folder) { File collect_cfg_file = new File(collection_folder.getAbsolutePath() + File.separator + "etc" + File.separator + "collect.cfg"); File build_cfg_file = new File(collection_folder.getAbsolutePath() + File.separator+"index" + File.separator + "build.cfg"); if (collect_cfg_file.exists() && build_cfg_file.exists()){ // Generate the convert_coll_from_gs2.pl command ArrayList command_parts_list = new ArrayList(); if (!Gatherer.isGsdlRemote) { command_parts_list.add(Configuration.perl_path); command_parts_list.add("-S"); } command_parts_list.add(Configuration.getGS3ScriptPath() + "convert_coll_from_gs2.pl"); command_parts_list.add("-collectdir"); command_parts_list.add(collection_folder.getParent()); command_parts_list.add(collection_folder.getName()); // Run the convert_coll_from_gs2.pl command String[] command_parts = (String[]) command_parts_list.toArray(new String[0]); GShell process = new GShell(command_parts, GShell.CONVERT, COLLECT, null, null, GShell.GSHELL_CONVERT); //process.addGShellListener(this); process.run(); // Don't bother threading this... yet collect_cfg_file.delete(); build_cfg_file.delete(); } } } private class OpenListener implements ActionListener { public void actionPerformed(ActionEvent event) { result = OK_OPTION; Object selected_object = collection_list.getSelectedValue(); if (selected_object instanceof BasicCollectionConfiguration) { BasicCollectionConfiguration collection_configuration = (BasicCollectionConfiguration)selected_object; //(BasicCollectionConfiguration) collection_list.getSelectedValue(); //**************** File collect_cfg_file = collection_configuration.getFile(); // returns the collect.cfg file File etc_folder = collect_cfg_file.getParentFile(); File collection_folder = etc_folder.getParentFile(); filename = collection_folder.getAbsolutePath() + File.separator + collection_folder.getName() + ".col"; collection_folder = null; etc_folder = null; collect_cfg_file = null; collection_configuration = null; OpenCollectionDialog.this.dispose(); } } } }