source: trunk/gli/src/org/greenstone/gatherer/gui/NewCollectionMetadataPrompt.java@ 10396

Last change on this file since 10396 was 10345, checked in by mdewsnip, 19 years ago

Removed some more crap out of the Utility class.

  • Property svn:keywords set to Author Date Id Revision
File size: 8.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.border.*;
35import javax.swing.event.*;
36import org.greenstone.gatherer.Configuration;
37import org.greenstone.gatherer.Dictionary;
38import org.greenstone.gatherer.Gatherer;
39import org.greenstone.gatherer.metadata.MetadataSet;
40import org.greenstone.gatherer.metadata.MetadataSetManager;
41import org.greenstone.gatherer.util.CheckList;
42import org.greenstone.gatherer.util.CheckListEntry;
43
44
45public class NewCollectionMetadataPrompt
46 extends ModalDialog
47{
48 private boolean cancelled = true;
49 private JDialog self;
50 private JList elements_list;
51 private CheckList metadata_sets_list;
52 static private Dimension size = new Dimension(700, 380);
53
54 public NewCollectionMetadataPrompt() {
55 this(false);
56 }
57 public NewCollectionMetadataPrompt(boolean existing_coll) {
58 super(Gatherer.g_man, true);
59 this.self = this;
60 if (existing_coll) {
61 setJMenuBar(new SimpleMenuBar("openingacollection"));
62 Dictionary.setText(this, "NewCollectionPrompt.Metadata_Title_Existing");
63 } else {
64 setJMenuBar(new SimpleMenuBar("creatingacollection"));
65 Dictionary.setText(this, "NewCollectionPrompt.Title");
66 }
67 setModal(true);
68 setSize(size);
69
70 // Show the metadata sets (except extracted!) available in the GLI "metadata" folder
71 ArrayList metadata_sets = MetadataSetManager.listMetadataSets(new File(Gatherer.getGLIMetadataDirectoryPath()));
72 ArrayList metadata_set_list_entries = new ArrayList();
73 for (int i = 0; i < metadata_sets.size(); i++) {
74 MetadataSet metadata_set = (MetadataSet) metadata_sets.get(i);
75
76 // Don't show the extracted metadata set
77 if (metadata_set.getNamespace().equals(MetadataSetManager.EXTRACTED_METADATA_NAMESPACE)) {
78 continue;
79 }
80
81 metadata_set_list_entries.add(metadata_set);
82 }
83
84 // Creation
85 JPanel content_pane = (JPanel) getContentPane();
86
87 JPanel instructions_panel = new JPanel();
88 JLabel instructions_label1 = new JLabel();
89 Dictionary.setText(instructions_label1, "NewCollectionPrompt.Metadata_Instructions1");
90 JLabel instructions_label2 = new JLabel();
91 Dictionary.setText(instructions_label2, "NewCollectionPrompt.Metadata_Instructions2");
92
93 JPanel center_pane = new JPanel();
94
95 JPanel sets_list_pane = new JPanel();
96 JLabel sets_list_label = new JLabel();
97 sets_list_label.setOpaque(false);
98 Dictionary.setText(sets_list_label, "NewCollectionPrompt.Select_MDS");
99 metadata_sets_list = new CheckList(true);
100 metadata_sets_list.addListSelectionListener(new MetadataSetListSelectionListener());
101 metadata_sets_list.setListData(metadata_set_list_entries);
102 metadata_sets_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
103
104 JPanel elements_list_pane = new JPanel();
105 JLabel elements_list_label = new JLabel();
106 Dictionary.setText(elements_list_label, "NewCollectionPrompt.Metadata_Elements");
107 elements_list = new JList();
108 elements_list.setCellRenderer(new MetadataElementListCellRenderer());
109 elements_list.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
110 elements_list.setForeground(Configuration.getColor("coloring.collection_tree_foreground", false));
111 elements_list.setSelectionBackground(Configuration.getColor("coloring.collection_tree_background", false));
112 elements_list.setSelectionForeground(Configuration.getColor("coloring.collection_tree_foreground", false));
113
114 // Set Dublin Core to be ticked initially, at Ian's request
115 for (int i = 0; i < metadata_set_list_entries.size(); i++) {
116 MetadataSet metadata_set = (MetadataSet) metadata_set_list_entries.get(i);
117 if (metadata_set.getMetadataSetFile().getName().equals("dublin.mds")) {
118 metadata_sets_list.setTickedObjects(new Object[] { metadata_set });
119 }
120 }
121
122 JPanel button_pane = new JPanel();
123 JButton ok_button = new GLIButton();
124 ok_button.setMnemonic(KeyEvent.VK_O);
125 Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
126 JButton cancel_button = new GLIButton();
127 cancel_button.setMnemonic(KeyEvent.VK_C);
128 Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
129
130 // Connection
131 ok_button.addActionListener(new OKButtonListener());
132 cancel_button.addActionListener(new CancelButtonListener());
133
134 // Display
135 instructions_panel.setLayout(new GridLayout(2,1));
136 instructions_panel.add(instructions_label1);
137 instructions_panel.add(instructions_label2);
138
139 sets_list_pane.setLayout(new BorderLayout());
140 sets_list_pane.add(sets_list_label, BorderLayout.NORTH);
141 sets_list_pane.add(new JScrollPane(metadata_sets_list), BorderLayout.CENTER);
142
143 elements_list_pane.setLayout(new BorderLayout());
144 elements_list_pane.add(elements_list_label, BorderLayout.NORTH);
145 elements_list_pane.add(new JScrollPane(elements_list), BorderLayout.CENTER);
146
147 center_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
148 center_pane.setLayout(new GridLayout(2,1,0,5));
149 center_pane.add(sets_list_pane);
150 center_pane.add(elements_list_pane);
151
152 button_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
153 button_pane.setLayout(new GridLayout(1,2,5,0));
154 button_pane.add(ok_button);
155 button_pane.add(cancel_button);
156
157 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
158 content_pane.setLayout(new BorderLayout());
159 content_pane.add(instructions_panel, BorderLayout.NORTH);
160 content_pane.add(center_pane, BorderLayout.CENTER);
161 content_pane.add(button_pane, BorderLayout.SOUTH);
162
163 // Show
164 Dimension screen_size = Configuration.screen_size;
165 setLocation((screen_size.width - size.width) / 2, (screen_size.height - size.height) / 2);
166 setVisible(true);
167 }
168
169 public ArrayList getSets() {
170 return metadata_sets_list.getTicked();
171 }
172
173 public boolean isCancelled() {
174 return cancelled;
175 }
176
177
178 private class CancelButtonListener
179 implements ActionListener {
180 public void actionPerformed(ActionEvent event) {
181 cancelled = true;
182 self.dispose();
183 }
184 }
185
186
187 private class MetadataSetListSelectionListener
188 implements ListSelectionListener
189 {
190 public void valueChanged(ListSelectionEvent event)
191 {
192 if (!metadata_sets_list.isSelectionEmpty()) {
193 // Retrieve the selected set
194 MetadataSet metadata_set = (MetadataSet) ((CheckListEntry) metadata_sets_list.getSelectedValue()).getObject();
195 elements_list.setListData(new Vector(metadata_set.getMetadataSetElements()));
196 }
197 else {
198 elements_list.setListData(new String[0]);
199 }
200 }
201 }
202
203
204 private class OKButtonListener
205 implements ActionListener
206 {
207 public void actionPerformed(ActionEvent event)
208 {
209 // See if the user has selected no metadata sets, and if so confirm thats what they really want.
210 cancelled = false;
211 if (metadata_sets_list.isNothingTicked()) {
212 WarningDialog dialog = new WarningDialog("warning.NoMetadataSetsSelected", "NoMetadataSetsSelected.Title", Dictionary.get("NoMetadataSetsSelected.Message"), null, true);
213 if (dialog.display() == JOptionPane.OK_OPTION) {
214 // Otherwise we are free to go
215 self.dispose();
216 }
217 dialog.dispose();
218 dialog = null;
219 }
220 else {
221 self.dispose();
222 }
223 }
224 }
225}
Note: See TracBrowser for help on using the repository browser.