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

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

Changed WarningDialog to take the direct message text, rather than the message text key. This makes it more flexible, allowing arguments in the message text (eg. used by PluginManager).

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