source: trunk/gli/src/org/greenstone/gatherer/gui/SimpleOpenCollectionDialog.java@ 6160

Last change on this file since 6160 was 6051, checked in by jmt12, 21 years ago

Here is the result of sixteen hours work over the weekend. I'm too tired to comment them all separately, but here are some of the highlights:
Rewrote how the 'base on collection' method actually retrieves and updates the collection configuration - ensuring the CDM.CollectionConfiguration class is used instead of the retarded Collection.CollectionConfiguration (which coincidently has had a name change to BasicCollectionConfiguration). Went through code search for places where the two versions had been confused. Rewrote large swathes of GDMDocument so as to differentiate between normal and extracted metadata - an attempt to prevent the snowballing extracted metadata problem. Fixed problem where GLI was correctly recieving the last few lines of an external process. The collection shortname is no longer visible, nor is the confusing double name for metadata elements. Also coloured folders in the trees are kaput. The users email is now saved as part of the GLI configuration and is used as appropriate to fill out collection fields. There are new options on the right click menus over trees to allow the expansion and collapsing of folders. 'Show Files' now shows all types (or at least 6 types) of image properly (arg, the plagues of copy and paste). 'Based On' collections are public, plugin list automatically moves to next entry if plugin removed (I guess we should do the same in every other screen?) and metadata arguments in plugins/classifiers are no longer editable. There are about a dozen other small things, but I can't remember them. Hope I remembered to set all of the files to UNIX line-endings.

  • Property svn:keywords set to Author Date Id Revision
File size: 9.1 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.Dictionary;
36import org.greenstone.gatherer.Gatherer;
37import org.greenstone.gatherer.collection.BasicCollectionConfiguration;
38import org.greenstone.gatherer.gui.ModalDialog;
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 SimpleOpenCollectionDialog
44 extends ModalDialog {
45
46 static final public int OK_OPTION = 0;
47 static final public int CANCEL_OPTION = 1;
48 static final public int BROWSE_OPTION = 2;
49
50 static final private Dimension SIZE = new Dimension(640,480);
51 static final private String BLANK = "b";
52 static final private String DESCRIPTION = "d";
53
54 private CardLayout card_layout;
55 private int result;
56 private JButton advanced_button;
57 private JButton cancel_button;
58 private JButton open_button;
59 private JList collection_list;
60 private JTextArea description_textarea;
61 private JPanel description_pane;
62 private String filename;
63
64 public SimpleOpenCollectionDialog() {
65 super(Gatherer.g_man, "", true);
66 setSize(SIZE);
67 Dictionary.setText(this, "OpenCollectionDialog.Title");
68
69 // Creation
70 JPanel content_pane = (JPanel) getContentPane();
71
72 JPanel center_pane = new JPanel();
73
74 JPanel collection_list_pane = new JPanel();
75 JLabel collection_list_label = new JLabel();
76 Dictionary.setText(collection_list_label, "OpenCollectionDialog.Available_Collections");
77 collection_list = new JList(new CollectionListModel());
78
79 description_pane = new JPanel();
80 card_layout = new CardLayout();
81
82 JPanel blank_pane = new JPanel();
83
84 JPanel description_textarea_pane = new JPanel();
85 JLabel description_textarea_label = new JLabel();
86 Dictionary.setText(description_textarea_label, "OpenCollectionDialog.Description");
87 description_textarea = new JTextArea();
88
89 JPanel button_pane = new JPanel();
90 open_button = new JButton();
91 open_button.setEnabled(false);
92 open_button.setMnemonic(KeyEvent.VK_O);
93 Dictionary.setBoth(open_button, "OpenCollectionDialog.Open", "OpenCollectionDialog.Open_Tooltip");
94 advanced_button = new JButton();
95 advanced_button.setMnemonic(KeyEvent.VK_B);
96 Dictionary.setBoth(advanced_button, "OpenCollectionDialog.Browse", "OpenCollectionDialog.Browse_Tooltip");
97 cancel_button = new JButton();
98 cancel_button.setMnemonic(KeyEvent.VK_C);
99 Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
100
101 // Connection
102 advanced_button.addActionListener(new AdvancedListener());
103 cancel_button.addActionListener(new CancelListener());
104 open_button.addActionListener(new OpenListener());
105 CollectionListSelectionListener clsl = new CollectionListSelectionListener();
106 collection_list.addListSelectionListener(clsl);
107 collection_list.addMouseListener(clsl);
108 clsl = null;
109
110 // Layout
111 collection_list_pane.setLayout(new BorderLayout());
112 collection_list_pane.add(collection_list_label, BorderLayout.NORTH);
113 collection_list_pane.add(new JScrollPane(collection_list), BorderLayout.CENTER);
114
115 description_textarea_pane.setLayout(new BorderLayout());
116 description_textarea_pane.add(description_textarea_label, BorderLayout.NORTH);
117 description_textarea_pane.add(new JScrollPane(description_textarea), BorderLayout.CENTER);
118
119 description_pane.setLayout(card_layout);
120 description_pane.add(description_textarea_pane, DESCRIPTION);
121 description_pane.add(blank_pane, BLANK);
122
123 center_pane.setLayout(new GridLayout(2,1,0,5));
124 center_pane.add(collection_list_pane);
125 center_pane.add(description_pane);
126
127 button_pane.setLayout(new GridLayout(1,4));
128 button_pane.add(new JPanel());
129 button_pane.add(open_button);
130 button_pane.add(advanced_button);
131 button_pane.add(cancel_button);
132
133 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
134 content_pane.setLayout(new BorderLayout());
135 content_pane.add(center_pane, BorderLayout.CENTER);
136 content_pane.add(button_pane, BorderLayout.SOUTH);
137
138 Dimension screen_size = Gatherer.config.screen_size;
139 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
140 screen_size = null;
141 }
142
143 public void destroy() {
144 }
145
146 public int display() {
147 setVisible(true);
148 return result;
149 }
150
151 public String getFileName() {
152 return filename;
153 }
154
155 private class AdvancedListener
156 implements ActionListener {
157
158 public void actionPerformed(ActionEvent event) {
159 result = BROWSE_OPTION;
160 SimpleOpenCollectionDialog.this.dispose();
161 }
162 }
163
164 private class CancelListener
165 implements ActionListener {
166
167 public void actionPerformed(ActionEvent event) {
168 result = CANCEL_OPTION;
169 SimpleOpenCollectionDialog.this.dispose();
170 }
171 }
172
173 private class CollectionListSelectionListener
174 extends MouseAdapter
175 implements ListSelectionListener {
176
177 public void mouseClicked(MouseEvent event) {
178 ///ystem.err.println("Mouse clicked");
179 if(event.getClickCount() >= 2) {
180 Point location = event.getPoint();
181 int index = collection_list.locationToIndex(location);
182 collection_list.setSelectedIndex(index);
183 location = null;
184 open_button.doClick();
185 }
186 }
187
188 public void valueChanged(ListSelectionEvent event) {
189 if(collection_list.isSelectionEmpty()) {
190 card_layout.show(description_pane, BLANK);
191 open_button.setEnabled(false);
192 }
193 else {
194 BasicCollectionConfiguration collection_configuration = (BasicCollectionConfiguration) collection_list.getSelectedValue();
195 description_textarea.setText(collection_configuration.getDescription());
196 description_textarea.setCaretPosition(0);
197 card_layout.show(description_pane, DESCRIPTION);
198 open_button.setEnabled(true);
199 }
200 }
201 }
202
203 private class CollectionListModel
204 extends AbstractListModel {
205
206 private TreeSet data;
207
208 public CollectionListModel() {
209 data = new TreeSet();
210 File collect_folder = new File(Gatherer.config.gsdl_path + Utility.COL_DIR);
211 File[] collection_folders = collect_folder.listFiles();
212 for(int i = 0; i < collection_folders.length; i++) {
213 File collection_folder = collection_folders[i];
214 String collection_foldername = collection_folder.getName();
215 if(!collection_folder.isFile() && !collection_foldername.equals(StaticStrings.MODEL_COLLECTION_NAME)) {
216 BasicCollectionConfiguration collection_configuration = new BasicCollectionConfiguration(new File(collection_folder, Utility.CONFIG_DIR));
217 if(!collection_configuration.getName().equals(StaticStrings.ERROR_STR)) {
218 data.add(collection_configuration);
219 }
220 }
221 collection_foldername = null;
222 collection_folder = null;
223 }
224 collection_folders = null;
225 collect_folder = null;
226 }
227
228 public Object getElementAt(int index) {
229 Iterator iterator = data.iterator();
230 for(int i = 0; iterator.hasNext(); i++) {
231 Object object = iterator.next();
232 if(i == index) {
233 iterator = null;
234 return object;
235 }
236 object = null;
237 }
238 iterator = null;
239 return null;
240 }
241
242 public int getSize() {
243 return data.size();
244 }
245 }
246
247 private class OpenListener
248 implements ActionListener {
249
250 public void actionPerformed(ActionEvent event) {
251 result = OK_OPTION;
252 BasicCollectionConfiguration collection_configuration = (BasicCollectionConfiguration) collection_list.getSelectedValue();
253 File collect_cfg_file = collection_configuration.getFile();
254 File etc_folder = collect_cfg_file.getParentFile();
255 File collection_folder = etc_folder.getParentFile();
256 filename = collection_folder.getAbsolutePath() + File.separator + collection_folder.getName() + Utility.GLI_EXTENSION;
257 collection_folder = null;
258 etc_folder = null;
259 collect_cfg_file = null;
260 collection_configuration = null;
261 SimpleOpenCollectionDialog.this.dispose();
262 }
263 }
264}
Note: See TracBrowser for help on using the repository browser.