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 | * <BR><BR>
|
---|
9 | *
|
---|
10 | * Author: Shaoqun Wu, Greenstone Digital Library, University of Waikato
|
---|
11 | *
|
---|
12 | * <BR><BR>
|
---|
13 | *
|
---|
14 | * Copyright (C) 2006 New Zealand Digital Library Project
|
---|
15 | *
|
---|
16 | * <BR><BR>
|
---|
17 | *
|
---|
18 | * This program is free software; you can redistribute it and/or modify
|
---|
19 | * it under the terms of the GNU General Public License as published by
|
---|
20 | * the Free Software Foundation; either version 2 of the License, or
|
---|
21 | * (at your option) any later version.
|
---|
22 | *
|
---|
23 | * <BR><BR>
|
---|
24 | *
|
---|
25 | * This program is distributed in the hope that it will be useful,
|
---|
26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
28 | * GNU General Public License for more details.
|
---|
29 | *
|
---|
30 | * <BR><BR>
|
---|
31 | *
|
---|
32 | * You should have received a copy of the GNU General Public License
|
---|
33 | * along with this program; if not, write to the Free Software
|
---|
34 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
35 | *########################################################################
|
---|
36 | */
|
---|
37 | package org.greenstone.gatherer.gems;
|
---|
38 |
|
---|
39 | import java.awt.*;
|
---|
40 | import java.awt.event.*;
|
---|
41 | import javax.swing.*;
|
---|
42 | import javax.swing.event.*;
|
---|
43 | import java.util.ArrayList;
|
---|
44 | import java.util.Collection;
|
---|
45 | import java.util.Vector;
|
---|
46 | import java.util.HashMap;
|
---|
47 |
|
---|
48 |
|
---|
49 | import org.greenstone.gatherer.Configuration;
|
---|
50 | import org.greenstone.gatherer.Dictionary;
|
---|
51 | import org.greenstone.gatherer.gui.ModalDialog;
|
---|
52 | import org.greenstone.gatherer.gui.GLIButton;
|
---|
53 |
|
---|
54 | public class DeleteMetadataSetPrompt
|
---|
55 | extends ModalDialog {
|
---|
56 |
|
---|
57 | static private Dimension SIZE = new Dimension(500, 500);
|
---|
58 |
|
---|
59 | private ArrayList available_metadata_sets;
|
---|
60 | private ArrayList listeners;
|
---|
61 |
|
---|
62 | private JCheckBox confirmation = null;
|
---|
63 | private JButton delete_button = null;
|
---|
64 | private JButton close_button = null;
|
---|
65 | private JList available_set_list = null;
|
---|
66 | /** The model behind the list. */
|
---|
67 | private DefaultListModel list_model = null;
|
---|
68 | private JTextArea description_textarea = null;
|
---|
69 | private DeleteMetadataSetPrompt self;
|
---|
70 | private MetadataSetManager meta_manager;
|
---|
71 |
|
---|
72 | public DeleteMetadataSetPrompt(Frame parent,MetadataSetManager msm) {
|
---|
73 | super(parent, true);
|
---|
74 | self = this;
|
---|
75 | meta_manager = msm;
|
---|
76 | listeners = new ArrayList();
|
---|
77 |
|
---|
78 | setSize(SIZE);
|
---|
79 | setTitle(Dictionary.get("GEMS.DeleteMetadataSetPrompt.Title"));
|
---|
80 |
|
---|
81 | JPanel content_pane = (JPanel) getContentPane();
|
---|
82 | content_pane.setOpaque(true);
|
---|
83 | content_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
84 |
|
---|
85 | JLabel available_metadata_sets_label = new JLabel(Dictionary.get("GEMS.DeleteMetadataSetPrompt.Available_Sets"));
|
---|
86 | available_metadata_sets_label.setOpaque(true);
|
---|
87 | available_metadata_sets_label.setComponentOrientation(Dictionary.getOrientation());
|
---|
88 |
|
---|
89 | list_model = new DefaultListModel();
|
---|
90 |
|
---|
91 | available_set_list = new JList();
|
---|
92 | available_set_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
---|
93 | available_set_list.setModel(list_model);
|
---|
94 | available_set_list.setCellRenderer(new MetadatSetListCellRenderer());
|
---|
95 | available_set_list.setFixedCellHeight(20);
|
---|
96 | available_set_list.addListSelectionListener(new MetadataSetListSelectionListener());
|
---|
97 | available_set_list.setComponentOrientation(Dictionary.getOrientation());
|
---|
98 |
|
---|
99 | JPanel set_pane = new JPanel();
|
---|
100 | set_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
101 | set_pane.setLayout(new BorderLayout());
|
---|
102 | set_pane.add(available_metadata_sets_label,BorderLayout.NORTH);
|
---|
103 | set_pane.add(new JScrollPane(available_set_list),BorderLayout.CENTER);
|
---|
104 |
|
---|
105 |
|
---|
106 | JLabel metadata_set_des_label = new JLabel(Dictionary.get("GEMS.Set_Description"));
|
---|
107 | metadata_set_des_label.setOpaque(true);
|
---|
108 |
|
---|
109 | description_textarea = new JTextArea();
|
---|
110 | description_textarea.setOpaque(true);
|
---|
111 | description_textarea.setEditable(false);
|
---|
112 | description_textarea.setLineWrap(true);
|
---|
113 | description_textarea.setWrapStyleWord(true);
|
---|
114 | description_textarea.setComponentOrientation(Dictionary.getOrientation());
|
---|
115 |
|
---|
116 | JPanel des_pane = new JPanel();
|
---|
117 | des_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
118 | des_pane.setLayout(new BorderLayout());
|
---|
119 | des_pane.add(metadata_set_des_label,BorderLayout.NORTH);
|
---|
120 | des_pane.add(new JScrollPane(description_textarea),BorderLayout.CENTER);
|
---|
121 |
|
---|
122 | JPanel button_pane = new JPanel();
|
---|
123 | button_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
124 | delete_button = new GLIButton(Dictionary.get("GEMS.DeleteMetadataSetPrompt.Delete"), Dictionary.get("GEMS.DeleteMetadataSetPrompt.Delete_Tooltip"));
|
---|
125 | delete_button.setEnabled(false);
|
---|
126 |
|
---|
127 |
|
---|
128 | confirmation = new JCheckBox(Dictionary.get("GEMS.DeleteMetadataSetPrompt.Confirm_Delete"));
|
---|
129 | confirmation.setEnabled(false);
|
---|
130 | confirmation.setSelected(false);
|
---|
131 | confirmation.setComponentOrientation(Dictionary.getOrientation());
|
---|
132 |
|
---|
133 | close_button = new GLIButton(Dictionary.get("General.Close"), Dictionary.get("General.Close_Tooltip"));
|
---|
134 | close_button.setEnabled(true);
|
---|
135 |
|
---|
136 | confirmation.addActionListener(new ActionListener() {
|
---|
137 | public void actionPerformed(ActionEvent event) {
|
---|
138 | delete_button.setEnabled(confirmation.isSelected());
|
---|
139 | //confirmation.setEnabled(false);
|
---|
140 | //confirmation.setSelected(false);
|
---|
141 | }
|
---|
142 | });
|
---|
143 |
|
---|
144 | // Add listeners
|
---|
145 | delete_button.addActionListener(new DeleteButtonListener());
|
---|
146 |
|
---|
147 | close_button.addActionListener(new ActionListener() {
|
---|
148 | public void actionPerformed(ActionEvent event) {
|
---|
149 | self.dispose();
|
---|
150 | }
|
---|
151 | });
|
---|
152 |
|
---|
153 |
|
---|
154 | button_pane.setLayout(new GridLayout(1,2));
|
---|
155 | button_pane.add(delete_button);
|
---|
156 | button_pane.add(close_button);
|
---|
157 |
|
---|
158 | JPanel bottom_pane = new JPanel();
|
---|
159 | bottom_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
160 | bottom_pane.setLayout(new BorderLayout());
|
---|
161 | bottom_pane.add(confirmation,BorderLayout.NORTH);
|
---|
162 | bottom_pane.add(button_pane, BorderLayout.CENTER);
|
---|
163 |
|
---|
164 |
|
---|
165 | content_pane.setLayout(new BorderLayout());
|
---|
166 | content_pane.add(set_pane, BorderLayout.NORTH);
|
---|
167 | content_pane.add(des_pane, BorderLayout.CENTER);
|
---|
168 | content_pane.add(bottom_pane, BorderLayout.SOUTH);
|
---|
169 |
|
---|
170 | // Show
|
---|
171 | Dimension screen_size = Configuration.screen_size;
|
---|
172 | setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
|
---|
173 | setVisible(false);
|
---|
174 | }
|
---|
175 |
|
---|
176 |
|
---|
177 | public void display() {
|
---|
178 | available_metadata_sets = meta_manager.getAvailableMetadataSets();
|
---|
179 | for (int i=0; i<available_metadata_sets.size(); i++) {
|
---|
180 | list_model.addElement(available_metadata_sets.get(i));
|
---|
181 | }
|
---|
182 | //available_set_list.setListData(new Vector((Collection)available_metadata_sets));
|
---|
183 | delete_button.setEnabled(false);
|
---|
184 | confirmation.setEnabled(false);
|
---|
185 | confirmation.setSelected(false);
|
---|
186 | setVisible(true);
|
---|
187 |
|
---|
188 | }
|
---|
189 |
|
---|
190 |
|
---|
191 | /** The Delete button listener implementation. */
|
---|
192 | private class DeleteButtonListener
|
---|
193 | implements ActionListener {
|
---|
194 | /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
|
---|
195 | * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
|
---|
196 | * @see org.greenstone.gatherer.Configuration
|
---|
197 | * @see org.greenstone.gatherer.Gatherer
|
---|
198 | * @see org.greenstone.gatherer.util.Utility
|
---|
199 | */
|
---|
200 | public void actionPerformed(ActionEvent event) {
|
---|
201 | // Delete the selected MetadataSet.
|
---|
202 | Object selectedValue = available_set_list.getSelectedValue();
|
---|
203 |
|
---|
204 | if (selectedValue !=null && (selectedValue instanceof MetadataSetInfo)){
|
---|
205 | ((MetadataSetInfo)selectedValue).deleteMetadataSet();
|
---|
206 | list_model.removeElement(selectedValue);
|
---|
207 | }
|
---|
208 | delete_button.setEnabled(false);
|
---|
209 | confirmation.setEnabled(false);
|
---|
210 | confirmation.setSelected(false);
|
---|
211 | description_textarea.setText(Dictionary.get("GEMS.DeleteMetadataSetPrompt.No_Set"));
|
---|
212 | //self.dispose();
|
---|
213 | }
|
---|
214 |
|
---|
215 | }
|
---|
216 |
|
---|
217 |
|
---|
218 | private class MetadatSetListCellRenderer extends JLabel implements ListCellRenderer {
|
---|
219 | public MetadatSetListCellRenderer() {
|
---|
220 | setOpaque(true);
|
---|
221 | this.setComponentOrientation(Dictionary.getOrientation());
|
---|
222 | }
|
---|
223 |
|
---|
224 | public Component getListCellRendererComponent(JList list,
|
---|
225 | Object value,
|
---|
226 | int index,
|
---|
227 | boolean isSelected,
|
---|
228 | boolean cellHasFocus)
|
---|
229 | {
|
---|
230 | String name= "unknown";
|
---|
231 |
|
---|
232 | if (value instanceof MetadataSetInfo){
|
---|
233 | MetadataSetInfo meta_info = (MetadataSetInfo) value;
|
---|
234 | name = meta_info.getMetadataSetName();
|
---|
235 | }
|
---|
236 |
|
---|
237 | setText(name);
|
---|
238 | if (isSelected) {
|
---|
239 | setBackground(list.getSelectionBackground());
|
---|
240 | setForeground(list.getSelectionForeground());
|
---|
241 | }
|
---|
242 | else {
|
---|
243 | setBackground(list.getBackground());
|
---|
244 | setForeground(list.getForeground());
|
---|
245 | }
|
---|
246 |
|
---|
247 | return this;
|
---|
248 | }
|
---|
249 | }
|
---|
250 |
|
---|
251 |
|
---|
252 | private class MetadataSetListSelectionListener implements ListSelectionListener {
|
---|
253 | public void valueChanged(ListSelectionEvent lse){
|
---|
254 | if (lse.getValueIsAdjusting()) return;
|
---|
255 |
|
---|
256 | delete_button.setEnabled(false);
|
---|
257 |
|
---|
258 | Object selectedValue = available_set_list.getSelectedValue();
|
---|
259 |
|
---|
260 | if (selectedValue !=null && (selectedValue instanceof MetadataSetInfo)){
|
---|
261 | MetadataSetInfo meta_info = (MetadataSetInfo)selectedValue;
|
---|
262 | description_textarea.setText(meta_info.getMetadataSetDescription());
|
---|
263 | confirmation.setEnabled(true);
|
---|
264 | confirmation.setSelected(false);
|
---|
265 | }
|
---|
266 | else {
|
---|
267 | confirmation.setEnabled(false);
|
---|
268 | description_textarea.setText(Dictionary.get("GEMS.DeleteMetadataSetPrompt.No_Set"));
|
---|
269 | }
|
---|
270 |
|
---|
271 | }
|
---|
272 | }
|
---|
273 |
|
---|
274 |
|
---|
275 |
|
---|
276 | public void addMetadataSetListener(MetadataSetListener msl){
|
---|
277 | listeners.add(msl);
|
---|
278 | }
|
---|
279 |
|
---|
280 |
|
---|
281 | }
|
---|