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

Last change on this file since 12065 was 11365, checked in by mdewsnip, 18 years ago

A few minor bug fixes and improvements for the new "exploded metadata set".

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