source: trunk/gli/src/org/greenstone/gatherer/gui/OpenCollectionDialog.java@ 14063

Last change on this file since 14063 was 14063, checked in by xiao, 17 years ago

prevent legacy collections from being opened in gli

  • Property svn:keywords set to Author Date Id Revision
File size: 10.8 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.gui;
28
29import java.awt.*;
30import java.awt.event.*;
31import java.io.*;
32import java.util.*;
33import javax.swing.*;
34import javax.swing.event.*;
35import org.greenstone.gatherer.Configuration;
36import org.greenstone.gatherer.Dictionary;
37import org.greenstone.gatherer.Gatherer;
38import org.greenstone.gatherer.collection.BasicCollectionConfiguration;
39import org.greenstone.gatherer.util.StaticStrings;
40import org.greenstone.gatherer.util.Utility;
41
42/** 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. */
43public class OpenCollectionDialog
44 extends ModalDialog {
45
46 static final public int OK_OPTION = 0;
47 static final public int CANCEL_OPTION = 1;
48
49 static final private Dimension SIZE = new Dimension(640,480);
50 static final private String BLANK = "b";
51 static final private String DESCRIPTION = "d";
52
53 private CardLayout card_layout;
54 private int result;
55 private JButton cancel_button;
56 private JButton open_button;
57 private JList collection_list;
58 private JTextArea description_textarea;
59 private JPanel description_pane;
60 private String filename;
61
62 public OpenCollectionDialog() {
63 super(Gatherer.g_man, "", true);
64 setJMenuBar(new SimpleMenuBar("openingacollection"));
65 setSize(SIZE);
66 setTitle(Dictionary.get("OpenCollectionDialog.Title"));
67
68 // Creation
69 JPanel content_pane = (JPanel) getContentPane();
70
71 JPanel center_pane = new JPanel();
72
73 JPanel collection_list_pane = new JPanel();
74 JLabel collection_list_label = new JLabel(Dictionary.get("OpenCollectionDialog.Available_Collections"));
75 collection_list = new JList(new CollectionListModel());
76 description_pane = new JPanel();
77 card_layout = new CardLayout();
78
79 JPanel blank_pane = new JPanel();
80
81 JPanel description_textarea_pane = new JPanel();
82 JLabel description_textarea_label = new JLabel(Dictionary.get("OpenCollectionDialog.Description"));
83 description_textarea = new JTextArea();
84
85 JPanel button_pane = new JPanel();
86 open_button = new GLIButton(Dictionary.get("OpenCollectionDialog.Open"), Dictionary.get("OpenCollectionDialog.Open_Tooltip"));
87 open_button.setEnabled(false);
88
89 cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Pure_Cancel_Tooltip"));
90
91 // Connection
92 cancel_button.addActionListener(new CancelListener());
93 open_button.addActionListener(new OpenListener());
94 CollectionListSelectionListener clsl = new CollectionListSelectionListener();
95 collection_list.addListSelectionListener(clsl);
96 collection_list.addMouseListener(clsl);
97 clsl = null;
98
99 // Layout
100 collection_list_pane.setLayout(new BorderLayout());
101 collection_list_pane.add(collection_list_label, BorderLayout.NORTH);
102 collection_list_pane.add(new JScrollPane(collection_list), BorderLayout.CENTER);
103
104 description_textarea_pane.setLayout(new BorderLayout());
105 description_textarea_pane.add(description_textarea_label, BorderLayout.NORTH);
106 description_textarea_pane.add(new JScrollPane(description_textarea), BorderLayout.CENTER);
107
108 description_pane.setLayout(card_layout);
109 description_pane.add(description_textarea_pane, DESCRIPTION);
110 description_pane.add(blank_pane, BLANK);
111
112 center_pane.setLayout(new GridLayout(2,1,0,5));
113 center_pane.add(collection_list_pane);
114 center_pane.add(description_pane);
115
116 button_pane.setLayout(new GridLayout(1,4));
117 button_pane.add(new JPanel());
118 button_pane.add(open_button);
119 button_pane.add(cancel_button);
120
121 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
122 content_pane.setLayout(new BorderLayout());
123 content_pane.add(center_pane, BorderLayout.CENTER);
124 content_pane.add(button_pane, BorderLayout.SOUTH);
125
126 Dimension screen_size = Configuration.screen_size;
127 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
128 screen_size = null;
129 }
130
131 public void destroy() {
132 }
133
134 public int display() {
135 setVisible(true);
136 return result;
137 }
138
139 public String getFileName() {
140 return this.filename;
141 }
142
143 private class CancelListener
144 implements ActionListener {
145
146 public void actionPerformed(ActionEvent event) {
147 result = CANCEL_OPTION;
148 OpenCollectionDialog.this.dispose();
149 }
150 }
151
152 private class CollectionListSelectionListener
153 extends MouseAdapter
154 implements ListSelectionListener {
155
156 public void mouseClicked(MouseEvent event) {
157 ///ystem.err.println("Mouse clicked");
158 if(event.getClickCount() >= 2) {
159 Point location = event.getPoint();
160 int index = collection_list.locationToIndex(location);
161 collection_list.setSelectedIndex(index);
162 location = null;
163 open_button.doClick();
164 }
165 }
166
167 public void valueChanged(ListSelectionEvent event) {
168 if(collection_list.isSelectionEmpty()) {
169 card_layout.show(description_pane, BLANK);
170 open_button.setEnabled(false);
171 }
172 else {
173 BasicCollectionConfiguration collection_configuration = (BasicCollectionConfiguration) collection_list.getSelectedValue();
174 description_textarea.setText(collection_configuration.getDescription());
175 description_textarea.setCaretPosition(0);
176 card_layout.show(description_pane, DESCRIPTION);
177 open_button.setEnabled(true);
178 }
179 }
180 }
181
182 // use this if we ever go back to viewing all colls at once
183 /* private class GS3CollectionListModel
184 extends AbstractListModel {
185
186 private TreeSet data;
187
188 public GS3CollectionListModel() {
189 data = new TreeSet();
190 File sites_folder = new File(Utility.getSitesDir(Configuration.gsdl3_path));
191 File sites[] = sites_folder.listFiles();
192 for (int s=0; s<sites.length; s++) {
193 String site_name = sites[s].getName();
194 System.err.println("found site "+site_name);
195 File collect_folder = new File(Utility.getCollectDir(Configuration.gsdl3_path, site_name) );
196 if (!collect_folder.exists()) {
197 continue;
198 }
199 File[] collection_folders = collect_folder.listFiles();
200 for(int i = 0; i < collection_folders.length; i++) {
201 File collection_folder = collection_folders[i];
202 String collection_foldername = collection_folder.getName();
203 if(!collection_folder.isFile() && !collection_foldername.equals(StaticStrings.MODEL_COLLECTION_NAME)) {
204 BasicCollectionConfiguration collection_configuration = new BasicCollectionConfiguration(new File(collection_folder, Utility.CONFIG_FILE), site_name);
205 if(!collection_configuration.getName().equals(StaticStrings.ERROR_STR)) {
206 data.add(collection_configuration);
207 }
208 }
209 collection_foldername = null;
210 collection_folder = null;
211 } // for each collection
212 collection_folders = null;
213 collect_folder = null;
214 } // for each site
215 sites_folder = null;
216 sites = null;
217 }
218
219 public Object getElementAt(int index) {
220 Iterator iterator = data.iterator();
221 for(int i = 0; iterator.hasNext(); i++) {
222 Object object = iterator.next();
223 if(i == index) {
224 iterator = null;
225 return object;
226 }
227 object = null;
228 }
229 iterator = null;
230 return null;
231 }
232
233 public int getSize() {
234 return data.size();
235 }
236 }
237 */
238 private class CollectionListModel
239 extends AbstractListModel {
240
241 private TreeSet data;
242
243 public CollectionListModel() {
244 data = new TreeSet();
245 File collect_directory = new File(Gatherer.getCollectDirectoryPath());
246 if (!collect_directory.exists()) {
247 collect_directory = null;
248 return;
249 }
250 File[] collection_folders = collect_directory.listFiles();
251 for(int i = 0; i < collection_folders.length; i++) {
252 File collection_folder = collection_folders[i];
253 String collection_foldername = collection_folder.getName();
254 if(collection_folder.isDirectory() && !collection_foldername.equals(StaticStrings.MODEL_COLLECTION_NAME)) {
255 // this 'file_name' has already been prefixed by 'etc'
256 String file_name = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE;
257 File config_file = new File(collection_folder, file_name);
258 File collection_metadata_directory = new File(collection_folder, "metadata");
259 if (collection_metadata_directory.exists() && config_file.exists()) {
260 BasicCollectionConfiguration collection_configuration = new BasicCollectionConfiguration(config_file);
261 data.add(collection_configuration);
262 }
263 config_file = null;
264 }
265 collection_foldername = null;
266 collection_folder = null;
267 }
268 collection_folders = null;
269 collect_directory = null;
270 }
271
272 public Object getElementAt(int index) {
273 Iterator iterator = data.iterator();
274 for(int i = 0; iterator.hasNext(); i++) {
275 Object object = iterator.next();
276 if(i == index) {
277 iterator = null;
278 return object;
279 }
280 object = null;
281 }
282 iterator = null;
283 return null;
284 }
285
286 public int getSize() {
287 return data.size();
288 }
289 }
290
291 private class OpenListener
292 implements ActionListener {
293
294 public void actionPerformed(ActionEvent event) {
295 result = OK_OPTION;
296 Object selected_object = collection_list.getSelectedValue();
297 if (selected_object instanceof BasicCollectionConfiguration) {
298 BasicCollectionConfiguration collection_configuration = (BasicCollectionConfiguration)selected_object; //(BasicCollectionConfiguration) collection_list.getSelectedValue();
299 //*************888
300 File collect_cfg_file = collection_configuration.getFile(); // returns the collect.cfg file
301 File etc_folder = collect_cfg_file.getParentFile();
302 File collection_folder = etc_folder.getParentFile();
303 filename = collection_folder.getAbsolutePath() + File.separator + collection_folder.getName() + ".col";
304 collection_folder = null;
305 etc_folder = null;
306 collect_cfg_file = null;
307 collection_configuration = null;
308 OpenCollectionDialog.this.dispose();
309 }
310 }
311 }
312}
Note: See TracBrowser for help on using the repository browser.