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

Last change on this file since 8243 was 8243, checked in by mdewsnip, 20 years ago

Removed all occurrences of classes explicitly importing other classes in the same package.

  • Property svn:keywords set to Author Date Id Revision
File size: 7.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.checklist.CheckList;
39import org.greenstone.gatherer.checklist.Entry;
40import org.greenstone.gatherer.cdm.ElementWrapper;
41import org.greenstone.gatherer.msm.MetadataSet;
42import org.greenstone.gatherer.util.StaticStrings;
43import org.greenstone.gatherer.util.Utility;
44import org.w3c.dom.*;
45
46public class NewCollectionMetadataPrompt
47 extends ModalDialog {
48
49 private boolean cancelled = true;
50 private CheckList sets_list;
51 private JDialog self;
52 private JList elements_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
72 // And the remaining metadata sets.
73 ArrayList sets = new ArrayList();
74 // Determine what collections are available.
75 File metadata_directory = new File(Utility.METADATA_DIR);
76 File[] possible_mdses = metadata_directory.listFiles();
77 for(int i = 0; i < possible_mdses.length; i++) {
78 String name = possible_mdses[i].getName();
79 if(name.endsWith(StaticStrings.METADATA_SET_EXTENSION) && !name.equals(Utility.EXTRACTED_METADATA_NAMESPACE + StaticStrings.METADATA_SET_EXTENSION)) {
80 sets.add(new MetadataSet(possible_mdses[i]));
81 }
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 sets_list = new CheckList(sets, true);
100
101 JPanel elements_list_pane = new JPanel();
102 JLabel elements_list_label = new JLabel();
103 Dictionary.setText(elements_list_label, "NewCollectionPrompt.Metadata_Elements");
104 elements_list = new JList();
105 elements_list.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
106 elements_list.setForeground(Configuration.getColor("coloring.collection_tree_foreground", false));
107 elements_list.setSelectionBackground(Configuration.getColor("coloring.collection_tree_background", false));
108 elements_list.setSelectionForeground(Configuration.getColor("coloring.collection_tree_foreground", false));
109
110 JPanel button_pane = new JPanel();
111 JButton ok_button = new GLIButton();
112 ok_button.setMnemonic(KeyEvent.VK_O);
113 Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
114 JButton cancel_button = new GLIButton();
115 cancel_button.setMnemonic(KeyEvent.VK_C);
116 Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
117
118 // Connection
119 ok_button.addActionListener(new OKButtonListener());
120 cancel_button.addActionListener(new CancelButtonListener());
121 sets_list.addListSelectionListener(new MetadataListSelectionListener());
122
123 // Display
124 instructions_panel.setLayout(new GridLayout(2,1));
125 instructions_panel.add(instructions_label1);
126 instructions_panel.add(instructions_label2);
127
128 sets_list_pane.setLayout(new BorderLayout());
129 sets_list_pane.add(sets_list_label, BorderLayout.NORTH);
130 sets_list_pane.add(new JScrollPane(sets_list), BorderLayout.CENTER);
131
132 elements_list_pane.setLayout(new BorderLayout());
133 elements_list_pane.add(elements_list_label, BorderLayout.NORTH);
134 elements_list_pane.add(new JScrollPane(elements_list), BorderLayout.CENTER);
135
136 center_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
137 center_pane.setLayout(new GridLayout(2,1,0,5));
138 center_pane.add(sets_list_pane);
139 center_pane.add(elements_list_pane);
140
141 button_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
142 button_pane.setLayout(new GridLayout(1,2,5,0));
143 button_pane.add(ok_button);
144 button_pane.add(cancel_button);
145
146 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
147 content_pane.setLayout(new BorderLayout());
148 content_pane.add(instructions_panel, BorderLayout.NORTH);
149 content_pane.add(center_pane, BorderLayout.CENTER);
150 content_pane.add(button_pane, BorderLayout.SOUTH);
151
152 // Show
153 Dimension screen_size = Configuration.screen_size;
154 setLocation((screen_size.width - size.width) / 2, (screen_size.height - size.height) / 2);
155 setVisible(true);
156 }
157
158 public ArrayList getSets() {
159 return sets_list.getSelected();
160 }
161
162 public boolean isCancelled() {
163 return cancelled;
164 }
165
166 private class CancelButtonListener
167 implements ActionListener {
168 public void actionPerformed(ActionEvent event) {
169 cancelled = true;
170 self.dispose();
171 }
172 }
173
174 public class MetadataListSelectionListener
175 implements ListSelectionListener {
176 public void valueChanged(ListSelectionEvent event) {
177 if(!sets_list.isSelectionEmpty()) {
178 // Retrieve the selected set.
179 Entry entry = (Entry) sets_list.getSelectedValue();
180 MetadataSet set = (MetadataSet) entry.getObject();
181 entry = null;
182 // Build a model from its elements.
183 NodeList elements = set.getElements();
184 set = null;
185 Vector elements_model = new Vector();
186 for(int i = 0; i < elements.getLength(); i++) {
187 elements_model.add(new ElementWrapper(elements.item(i)));
188 }
189 elements = null;
190 Collections.sort(elements_model);
191 elements_list.setListData(elements_model);
192 elements_model = null;
193 }
194 else {
195 elements_list.setListData(new String[0]);
196 }
197 }
198 }
199
200 public class OKButtonListener
201 implements ActionListener {
202 public void actionPerformed(ActionEvent event) {
203 // See if the user has selected no metadata sets, and if so confirm thats what they really want.
204 ArrayList selected_sets = sets_list.getSelected();
205 cancelled = false;
206 if(selected_sets.size() == 0) {
207 WarningDialog dialog = new WarningDialog("warning.NoMetadataSetsSelected", true);
208 if(dialog.display() == JOptionPane.OK_OPTION) {
209 // Otherwise we are free to go
210 self.dispose();
211 }
212 dialog.dispose();
213 dialog = null;
214 }
215 else {
216 self.dispose();
217 }
218 }
219 }
220}
Note: See TracBrowser for help on using the repository browser.