1 | package org.greenstone.gatherer.msm;
|
---|
2 | /**
|
---|
3 | *#########################################################################
|
---|
4 | *
|
---|
5 | * A component of the Gatherer application, part of the Greenstone digital
|
---|
6 | * library suite from the New Zealand Digital Library Project at the
|
---|
7 | * University of Waikato, New Zealand.
|
---|
8 | *
|
---|
9 | * <BR><BR>
|
---|
10 | *
|
---|
11 | * Author: John Thompson, Greenstone Digital Library, University of Waikato
|
---|
12 | *
|
---|
13 | * <BR><BR>
|
---|
14 | *
|
---|
15 | * Copyright (C) 1999 New Zealand Digital Library Project
|
---|
16 | *
|
---|
17 | * <BR><BR>
|
---|
18 | *
|
---|
19 | * This program is free software; you can redistribute it and/or modify
|
---|
20 | * it under the terms of the GNU General Public License as published by
|
---|
21 | * the Free Software Foundation; either version 2 of the License, or
|
---|
22 | * (at your option) any later version.
|
---|
23 | *
|
---|
24 | * <BR><BR>
|
---|
25 | *
|
---|
26 | * This program is distributed in the hope that it will be useful,
|
---|
27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
29 | * GNU General Public License for more details.
|
---|
30 | *
|
---|
31 | * <BR><BR>
|
---|
32 | *
|
---|
33 | * You should have received a copy of the GNU General Public License
|
---|
34 | * along with this program; if not, write to the Free Software
|
---|
35 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
36 | *########################################################################
|
---|
37 | */
|
---|
38 | import java.awt.*;
|
---|
39 | import java.awt.event.*;
|
---|
40 | import java.io.*;
|
---|
41 | import java.util.*;
|
---|
42 | import javax.swing.*;
|
---|
43 | import javax.swing.event.*;
|
---|
44 | import org.greenstone.gatherer.Gatherer;
|
---|
45 | import org.greenstone.gatherer.gui.ModalDialog;
|
---|
46 | import org.greenstone.gatherer.gui.SimpleMenuBar;
|
---|
47 | import org.greenstone.gatherer.msm.Declarations;
|
---|
48 | import org.greenstone.gatherer.msm.MetadataSet;
|
---|
49 | import org.greenstone.gatherer.msm.MetadataSetManager;
|
---|
50 | import org.greenstone.gatherer.util.ArrayTools;
|
---|
51 | import org.greenstone.gatherer.util.MED;
|
---|
52 | import org.w3c.dom.*;
|
---|
53 | /** A class dedicated to producing the visual components used by the MSM package.
|
---|
54 | * @author John Thompson, Greenstone Digital Library, University of Waikato
|
---|
55 | * @version 1.2
|
---|
56 | */
|
---|
57 | public class MSMPrompt
|
---|
58 | implements ActionListener {
|
---|
59 |
|
---|
60 | private boolean dialog_cancelled = false;
|
---|
61 | private Dimension screen_size = null;
|
---|
62 | private int action = Declarations.NO_ACTION;
|
---|
63 | private JButton add = null;
|
---|
64 | private JButton cancel = null;
|
---|
65 | private JButton merge = null;
|
---|
66 | private JButton rename = null;
|
---|
67 | private JButton replace = null;
|
---|
68 | private JButton skip = null;
|
---|
69 | private JDialog off_screen = null;
|
---|
70 | private JDialog on_screen = null;
|
---|
71 | private JDialog dialog = null;
|
---|
72 | private JLabel current_details_label = null;
|
---|
73 | private JLabel new_details_label = null;
|
---|
74 | private JLabel progress_label = null;
|
---|
75 | private JProgressBar progress = null;
|
---|
76 | private JTextArea current_details = null;
|
---|
77 | private JTextArea new_details = null;
|
---|
78 | private MetadataSetManager manager = null;
|
---|
79 | private Object result = null;
|
---|
80 |
|
---|
81 | final static private Dimension MDE_SIZE = new Dimension(500,225);
|
---|
82 | final static private Dimension MDS_SIZE = new Dimension(800,425);
|
---|
83 | final static private Dimension PROGRESS_SIZE = new Dimension(500,105);
|
---|
84 | final static private Dimension RENAME_LABEL_SIZE = new Dimension(100,25);
|
---|
85 | final static private Dimension RENAME_SIZE = new Dimension(300,145);
|
---|
86 | final static private Dimension SELECT_ELEMENT_SIZE = new Dimension(500,305);
|
---|
87 | final static private Dimension SELECT_LABEL_SIZE = new Dimension(175, 25);
|
---|
88 | final static private Dimension SELECT_SET_SIZE = new Dimension(600,210);
|
---|
89 | final static private Dimension SELECT_SIZE = new Dimension(200,225);
|
---|
90 | final static private int SELECT_LINE_COUNT = 8;
|
---|
91 |
|
---|
92 | public MSMPrompt(MetadataSetManager manager) {
|
---|
93 | this.manager = manager;
|
---|
94 | // Create components
|
---|
95 |
|
---|
96 | add = new JButton(get("Add"));
|
---|
97 | add.addActionListener(this);
|
---|
98 | add.setEnabled(false);
|
---|
99 | add.setMnemonic(KeyEvent.VK_A);
|
---|
100 |
|
---|
101 |
|
---|
102 | cancel = new JButton(get("Cancel"));
|
---|
103 | cancel.addActionListener(this);
|
---|
104 | cancel.setEnabled(true);
|
---|
105 | cancel.setMnemonic(KeyEvent.VK_C);
|
---|
106 |
|
---|
107 | current_details = new JTextArea(get("No_Details"));
|
---|
108 |
|
---|
109 | current_details_label = new JLabel(get("Current_Details"));
|
---|
110 |
|
---|
111 | merge = new JButton(get("Merge"));
|
---|
112 | merge.addActionListener(this);
|
---|
113 | merge.setEnabled(true);
|
---|
114 | merge.setMnemonic(KeyEvent.VK_M);
|
---|
115 |
|
---|
116 | new_details = new JTextArea(get("No_Details"));
|
---|
117 |
|
---|
118 | new_details_label = new JLabel(get("New_Details"));
|
---|
119 |
|
---|
120 | progress = new JProgressBar();
|
---|
121 | progress.setStringPainted(true);
|
---|
122 |
|
---|
123 | progress_label = new JLabel(get("Progress"));
|
---|
124 |
|
---|
125 | rename = new JButton(get("Rename"));
|
---|
126 | rename.addActionListener(this);
|
---|
127 | rename.setEnabled(false);
|
---|
128 | rename.setMnemonic(KeyEvent.VK_N);
|
---|
129 |
|
---|
130 | replace = new JButton(get("Replace"));
|
---|
131 | replace.addActionListener(this);
|
---|
132 | replace.setEnabled(false);
|
---|
133 | replace.setMnemonic(KeyEvent.VK_R);
|
---|
134 |
|
---|
135 | skip = new JButton(get("Skip"));
|
---|
136 | skip.addActionListener(this);
|
---|
137 | skip.setEnabled(true);
|
---|
138 | skip.setMnemonic(KeyEvent.VK_S);
|
---|
139 |
|
---|
140 | screen_size = Gatherer.config.screen_size;
|
---|
141 | }
|
---|
142 |
|
---|
143 | /** When called this method produces a nice error message on the screen, advising the user that the add action has failed.
|
---|
144 | * @param mde_new The <strong>Element</strong> that we were attempting to add.
|
---|
145 | * @param reason The phrase key for the reason the add failed, as a <strong>String</strong>.
|
---|
146 | */
|
---|
147 | public void addFailed(Element mde_new, String reason) {
|
---|
148 | String args[] = new String[2];
|
---|
149 | args[0] = mde_new.getAttribute("name");
|
---|
150 | args[1] = get(reason, null);
|
---|
151 | JOptionPane.showMessageDialog(off_screen, get("Add_Failed", args), get("Add_Failed_Title", null), JOptionPane.ERROR_MESSAGE);
|
---|
152 | }
|
---|
153 |
|
---|
154 | /** Any implementation of <i>ActionListener</i> must include this method so that we can be informed when an action has occured.
|
---|
155 | * @param event An <strong>ActionEvent</strong> containing information gatherer when this event occured.
|
---|
156 | */
|
---|
157 | public void actionPerformed(ActionEvent event) {
|
---|
158 | Object source = event.getSource();
|
---|
159 | action = Declarations.NO_ACTION;
|
---|
160 | if(source == add) {
|
---|
161 | action = Declarations.ADD;
|
---|
162 | }
|
---|
163 | else if(source == cancel) {
|
---|
164 | action = Declarations.CANCEL;
|
---|
165 | }
|
---|
166 | else if(source == merge) {
|
---|
167 | action = Declarations.MERGE;
|
---|
168 | }
|
---|
169 | else if(source == rename) {
|
---|
170 | action = Declarations.RENAME;
|
---|
171 | }
|
---|
172 | else if(source == replace) {
|
---|
173 | action = Declarations.REPLACE;
|
---|
174 | }
|
---|
175 | else if(source == skip) {
|
---|
176 | action = Declarations.SKIP;
|
---|
177 | }
|
---|
178 | on_screen.setVisible(false);
|
---|
179 | }
|
---|
180 | /** Method called when the merging process is complete and the progress bar is no longer needed.
|
---|
181 | */
|
---|
182 | public void endMerge() {
|
---|
183 | off_screen.dispose();
|
---|
184 | off_screen = null;
|
---|
185 | }
|
---|
186 | /** Method to indicate that yet another element has been succesfully merged, so that progress bar should reflect this.
|
---|
187 | */
|
---|
188 | public void incrementMerge() {
|
---|
189 | progress.setValue(progress.getValue() + 1);
|
---|
190 | String percent = ((100 * progress.getValue()) / progress.getMaximum()) + "%";
|
---|
191 | progress.setString(percent);
|
---|
192 | }
|
---|
193 | /** Method to display the metadata element merging prompt, wherein the user determines how the attributes within an element should be merged.
|
---|
194 | * @param mde_cur The current <strong>Element</strong> we are merging against.
|
---|
195 | * @param att_cur The attribute <strong>Element</strong> of the current element in question.
|
---|
196 | * @param mde_new The <strong>Element</strong> which we have choosen to merge in, and whose attributes are being examined.
|
---|
197 | * @param att_new And the new elements attribute <strong>Element</strong>.
|
---|
198 | * @return An <i>int</i> specifying what further action should be undertaken, if any.
|
---|
199 | */
|
---|
200 | public int mDEPrompt(Element mde_cur, Element att_cur, Element mde_new, Element att_new) {
|
---|
201 | action = Declarations.NO_ACTION;
|
---|
202 | // Construction and configuration
|
---|
203 | JDialog dialog = new ModalDialog(Gatherer.g_man);
|
---|
204 | dialog.setModal(true);
|
---|
205 | dialog.setSize(MDE_SIZE);
|
---|
206 | dialog.setTitle(get("Merge_MDE"));
|
---|
207 | dialog.setJMenuBar(new SimpleMenuBar("6.8"));
|
---|
208 | JPanel content_pane = (JPanel)dialog.getContentPane();
|
---|
209 |
|
---|
210 | JLabel cur_name_label = new JLabel(get("Element_Name"));
|
---|
211 |
|
---|
212 | JLabel cur_name = new JLabel(MSMUtils.getFullName(mde_cur));
|
---|
213 | cur_name.setBackground(Color.white);
|
---|
214 | cur_name.setOpaque(true);
|
---|
215 |
|
---|
216 | JLabel cur_att_label = new JLabel(get("Attribute"));
|
---|
217 |
|
---|
218 | JLabel cur_att = new JLabel(att_cur.getAttribute("name") +" = " + MSMUtils.getValue(att_cur));
|
---|
219 | cur_att.setBackground(Color.white);
|
---|
220 | cur_att.setOpaque(true);
|
---|
221 |
|
---|
222 | JLabel new_name_label = new JLabel(cur_name_label.getText());
|
---|
223 |
|
---|
224 | JLabel new_name = new JLabel(MSMUtils.getFullName(mde_new));
|
---|
225 | new_name.setBackground(Color.white);
|
---|
226 | new_name.setOpaque(true);
|
---|
227 |
|
---|
228 | JLabel new_att_label = new JLabel(cur_att_label.getText());
|
---|
229 |
|
---|
230 | JLabel new_att = new JLabel(att_new.getAttribute("name") +" = " + MSMUtils.getValue(att_new));
|
---|
231 | new_att.setBackground(Color.white);
|
---|
232 | new_att.setOpaque(true);
|
---|
233 |
|
---|
234 | replace.setEnabled(true);
|
---|
235 | skip.setEnabled(true);
|
---|
236 |
|
---|
237 | // Layout
|
---|
238 | JPanel current_pane = new JPanel();
|
---|
239 | current_pane.setBorder(BorderFactory.createTitledBorder(get("Current_Element")));
|
---|
240 | current_pane.setLayout(new GridLayout(2,2));
|
---|
241 | current_pane.add(cur_name_label);
|
---|
242 | current_pane.add(cur_name);
|
---|
243 | current_pane.add(cur_att_label);
|
---|
244 | current_pane.add(cur_att);
|
---|
245 |
|
---|
246 | JPanel new_pane = new JPanel();
|
---|
247 | new_pane.setBorder(BorderFactory.createTitledBorder(get("New_Element")));
|
---|
248 | new_pane.setLayout(new GridLayout(2,2));
|
---|
249 | new_pane.add(new_name_label);
|
---|
250 | new_pane.add(new_name);
|
---|
251 | new_pane.add(new_att_label);
|
---|
252 | new_pane.add(new_att);
|
---|
253 |
|
---|
254 | JPanel central_pane = new JPanel();
|
---|
255 | central_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
256 | central_pane.setLayout(new GridLayout(2,1));
|
---|
257 | central_pane.add(current_pane);
|
---|
258 | central_pane.add(new_pane);
|
---|
259 |
|
---|
260 | JPanel button_pane = new JPanel();
|
---|
261 | button_pane.setBorder(BorderFactory.createEmptyBorder(0,5,5,5));
|
---|
262 | button_pane.setLayout(new GridLayout(1,3));
|
---|
263 | button_pane.add(replace);
|
---|
264 | button_pane.add(skip);
|
---|
265 | button_pane.add(cancel);
|
---|
266 |
|
---|
267 | content_pane.setLayout(new BorderLayout());
|
---|
268 | content_pane.add(central_pane, BorderLayout.CENTER);
|
---|
269 | content_pane.add(button_pane, BorderLayout.SOUTH);
|
---|
270 |
|
---|
271 | // Display
|
---|
272 | dialog.setLocation((screen_size.width - MDE_SIZE.width) / 2, (screen_size.height - MDE_SIZE.height) / 2);
|
---|
273 | on_screen = dialog;
|
---|
274 | off_screen.setVisible(false);
|
---|
275 | on_screen.setVisible(true);
|
---|
276 | off_screen.setVisible(true);
|
---|
277 | on_screen.dispose();
|
---|
278 |
|
---|
279 | content_pane = null;
|
---|
280 | cur_name_label = null;
|
---|
281 | cur_name = null;
|
---|
282 | cur_att_label = null;
|
---|
283 | cur_att = null;
|
---|
284 | new_name_label = null;
|
---|
285 | new_name = null;
|
---|
286 | new_att_label = null;
|
---|
287 | new_att = null;
|
---|
288 | current_pane = null;
|
---|
289 | new_pane = null;
|
---|
290 | central_pane = null;
|
---|
291 | button_pane = null;
|
---|
292 | screen_size = null;
|
---|
293 | on_screen = null;
|
---|
294 | dialog = null;
|
---|
295 |
|
---|
296 | return action;
|
---|
297 | }
|
---|
298 | /** This method displays the metadata data set merging prompt, wherein the user determines how the elements within a set should be merged.
|
---|
299 | * @param mds_cur The current <strong>MetadataSet</strong> containing our document.
|
---|
300 | * @param mde_cur The current <strong>Element</strong> we are merging against.
|
---|
301 | * @param mds_new The <strong>MetadataSet</strong> we are merging in.
|
---|
302 | * @param mde_new The <strong>Element</strong> which we have choosen to merge in.
|
---|
303 | * @return An <i>int</i> specifying what further action should be undertaken, if any.
|
---|
304 | */
|
---|
305 | public int mDSPrompt(MetadataSet mds_cur, Element mde_cur, MetadataSet mds_new, Element mde_new) {
|
---|
306 | action = Declarations.NO_ACTION;
|
---|
307 | // Construction and configuration
|
---|
308 | JDialog dialog = new ModalDialog(Gatherer.g_man);
|
---|
309 | dialog.setModal(true);
|
---|
310 | dialog.setSize(MDS_SIZE);
|
---|
311 | dialog.setTitle(get("Merge_MDS"));
|
---|
312 | dialog.setJMenuBar(new SimpleMenuBar("6.8"));
|
---|
313 | JPanel content_pane = (JPanel)dialog.getContentPane();
|
---|
314 | if(mde_cur != null) {
|
---|
315 | add.setEnabled(false);
|
---|
316 | cancel.setEnabled(true);
|
---|
317 | merge.setEnabled(true);
|
---|
318 | rename.setEnabled(true);
|
---|
319 | replace.setEnabled(true);
|
---|
320 | skip.setEnabled(true);
|
---|
321 | // Current details.
|
---|
322 | String str_cur[] = MSMUtils.getStructuralDetails(mde_cur);
|
---|
323 | String opt_cur[] = MSMUtils.getOptionListDetails(mde_cur);
|
---|
324 | String ass_cur[] = MSMUtils.getAssignedValuesDetails(mds_cur, mde_cur);
|
---|
325 | String details_cur = get("Structural");
|
---|
326 | if(opt_cur != null) {
|
---|
327 | details_cur = details_cur + "\n" + get("OptionList", opt_cur);
|
---|
328 | }
|
---|
329 | if(ass_cur != null) {
|
---|
330 | details_cur = details_cur + "\n" + get("AssignedValues", ass_cur);
|
---|
331 | }
|
---|
332 | current_details.setText(details_cur);
|
---|
333 | str_cur = null;
|
---|
334 | opt_cur = null;
|
---|
335 | ass_cur = null;
|
---|
336 | details_cur = null;
|
---|
337 | }
|
---|
338 | else {
|
---|
339 | add.setEnabled(true);
|
---|
340 | cancel.setEnabled(true);
|
---|
341 | merge.setEnabled(true);
|
---|
342 | rename.setEnabled(false);
|
---|
343 | replace.setEnabled(false);
|
---|
344 | skip.setEnabled(true);
|
---|
345 | current_details.setText(get("No_Element"));
|
---|
346 | }
|
---|
347 | // New details.
|
---|
348 | String str_new[] = MSMUtils.getStructuralDetails(mde_new);
|
---|
349 | String opt_new[] = MSMUtils.getOptionListDetails(mde_new);
|
---|
350 | String ass_new[] = MSMUtils.getAssignedValuesDetails(mds_new, mde_new);
|
---|
351 | String details_new = get("Structural", str_new);
|
---|
352 | if(opt_new != null) {
|
---|
353 | details_new = details_new + "\n" + get("OptionList", opt_new);
|
---|
354 | }
|
---|
355 | if(ass_new != null) {
|
---|
356 | details_new = details_new + "\n" + get("AssignedValues", ass_new);
|
---|
357 | }
|
---|
358 | new_details.setText(details_new);
|
---|
359 | // Layout
|
---|
360 | JPanel current_details_pane = new JPanel();
|
---|
361 | current_details_pane.setLayout(new BorderLayout());
|
---|
362 | current_details_pane.add(current_details_label, BorderLayout.NORTH);
|
---|
363 | current_details_pane.add(new JScrollPane(current_details), BorderLayout.CENTER);
|
---|
364 |
|
---|
365 | JPanel new_details_pane = new JPanel();
|
---|
366 | new_details_pane.setLayout(new BorderLayout());
|
---|
367 | new_details_pane.add(new_details_label, BorderLayout.NORTH);
|
---|
368 | new_details_pane.add(new JScrollPane(new_details), BorderLayout.CENTER);
|
---|
369 |
|
---|
370 | JPanel details_pane = new JPanel();
|
---|
371 | details_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
372 | details_pane.setLayout(new GridLayout(1,2));
|
---|
373 | details_pane.add(current_details_pane);
|
---|
374 | details_pane.add(new_details_pane);
|
---|
375 |
|
---|
376 | JPanel button_pane = new JPanel();
|
---|
377 | button_pane.setBorder(BorderFactory.createEmptyBorder(0,5,5,5));
|
---|
378 | button_pane.setLayout(new GridLayout(1,6));
|
---|
379 | button_pane.add(add);
|
---|
380 | button_pane.add(merge);
|
---|
381 | button_pane.add(rename);
|
---|
382 | button_pane.add(replace);
|
---|
383 | button_pane.add(skip);
|
---|
384 | button_pane.add(cancel);
|
---|
385 |
|
---|
386 | JPanel control_pane = new JPanel();
|
---|
387 | control_pane.setLayout(new BorderLayout());
|
---|
388 | control_pane.add(details_pane, BorderLayout.CENTER);
|
---|
389 | control_pane.add(button_pane, BorderLayout.SOUTH);
|
---|
390 |
|
---|
391 | JPanel progress_pane = new JPanel();
|
---|
392 | progress_pane.setBorder(BorderFactory.createEmptyBorder(5,5,0,5));
|
---|
393 | progress_pane.setLayout(new BorderLayout());
|
---|
394 | progress_pane.add(progress_label, BorderLayout.NORTH);
|
---|
395 | progress_pane.add(progress, BorderLayout.CENTER);
|
---|
396 |
|
---|
397 | content_pane.setLayout(new BorderLayout());
|
---|
398 | content_pane.add(progress_pane, BorderLayout.NORTH);
|
---|
399 | content_pane.add(control_pane, BorderLayout.CENTER);
|
---|
400 |
|
---|
401 | // Display
|
---|
402 | dialog.setLocation((screen_size.width - MDS_SIZE.width) / 2, (screen_size.height - MDS_SIZE.height) / 2);
|
---|
403 | on_screen = dialog;
|
---|
404 | off_screen.setVisible(false);
|
---|
405 | on_screen.setVisible(true); // Blocks until hidden.
|
---|
406 | off_screen.setVisible(true);
|
---|
407 | on_screen.dispose();
|
---|
408 | on_screen = null;
|
---|
409 |
|
---|
410 | content_pane = null;
|
---|
411 | str_new = null;
|
---|
412 | opt_new = null;
|
---|
413 | ass_new = null;
|
---|
414 | details_new = null;
|
---|
415 | current_details_pane = null;
|
---|
416 | new_details_pane = null;
|
---|
417 | details_pane = null;
|
---|
418 | button_pane = null;
|
---|
419 | control_pane = null;
|
---|
420 | progress_pane = null;
|
---|
421 | dialog = null;
|
---|
422 |
|
---|
423 | if(mde_cur == null && action == Declarations.MERGE) {
|
---|
424 | action = Declarations.FORCE_MERGE;
|
---|
425 | }
|
---|
426 | return action;
|
---|
427 | }
|
---|
428 | /** This method creates an initial JDialog which simply shows the MSMs progress towards merging the metadata sets.
|
---|
429 | * @param element_count An <i>int</i> specifying the total number of elements to be merged.
|
---|
430 | */
|
---|
431 | public void startMerge(int element_count) {
|
---|
432 | action = Declarations.NO_ACTION;
|
---|
433 | JDialog dialog = new ModalDialog(Gatherer.g_man);
|
---|
434 | dialog.setModal(false);
|
---|
435 | dialog.setSize(PROGRESS_SIZE);
|
---|
436 | dialog.setTitle(get("Merge_Progress"));
|
---|
437 | //dialog.setJMenuBar(new SimpleMenuBar("0")); ?? do we want help here??
|
---|
438 |
|
---|
439 | JPanel content_pane = (JPanel)dialog.getContentPane();
|
---|
440 | progress.setMaximum(element_count);
|
---|
441 | progress.setMinimum(0);
|
---|
442 | progress.setString("0%");
|
---|
443 | progress.setValue(0);
|
---|
444 | // Layout.
|
---|
445 | content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
446 | content_pane.setLayout(new BorderLayout());
|
---|
447 | content_pane.add(progress_label, BorderLayout.NORTH);
|
---|
448 | content_pane.add(progress, BorderLayout.CENTER);
|
---|
449 | // Display.
|
---|
450 | dialog.setLocation((screen_size.width - PROGRESS_SIZE.width) / 2, (screen_size.height - PROGRESS_SIZE.height) / 2);
|
---|
451 | off_screen = dialog;
|
---|
452 | dialog.setVisible(true);
|
---|
453 | content_pane = null;
|
---|
454 | dialog = null;
|
---|
455 | }
|
---|
456 | /** This method creates a prompt for renaming an Element.
|
---|
457 | * @param mde_new The <strong>Element</strong> we wish to rename.
|
---|
458 | * @return The new name as a <strong>String</strong>, <i>null</i> if cancelled.
|
---|
459 | */
|
---|
460 | public String rename(Element mde_new) {
|
---|
461 | action = Declarations.NO_ACTION;
|
---|
462 | // Create
|
---|
463 | JDialog dialog = new ModalDialog(Gatherer.g_man);
|
---|
464 | dialog.setModal(true);
|
---|
465 | dialog.setSize(RENAME_SIZE);
|
---|
466 | dialog.setTitle(get("Rename"));
|
---|
467 | dialog.setJMenuBar(new SimpleMenuBar("6.8"));
|
---|
468 | JLabel old_name_label = new JLabel(get("Old_Name"));
|
---|
469 | old_name_label.setPreferredSize(RENAME_LABEL_SIZE);
|
---|
470 |
|
---|
471 | JLabel old_name = new JLabel(mde_new.getAttribute("name"));
|
---|
472 | old_name.setBackground(Color.white);
|
---|
473 | old_name.setOpaque(true);
|
---|
474 |
|
---|
475 | JLabel new_name_label = new JLabel(get("New_Name"));
|
---|
476 | new_name_label.setPreferredSize(RENAME_LABEL_SIZE);
|
---|
477 |
|
---|
478 | JTextField new_name = new JTextField("");
|
---|
479 | new_name.grabFocus();
|
---|
480 |
|
---|
481 | JButton ok = new JButton(get("General.OK"));
|
---|
482 | ok.addActionListener(this);
|
---|
483 | ok.setMnemonic(KeyEvent.VK_O);
|
---|
484 |
|
---|
485 | JPanel content_pane = (JPanel) dialog.getContentPane();
|
---|
486 |
|
---|
487 | // Layout
|
---|
488 | JPanel old_name_pane = new JPanel();
|
---|
489 | old_name_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
490 | old_name_pane.setLayout(new BorderLayout());
|
---|
491 | old_name_pane.add(old_name_label, BorderLayout.WEST);
|
---|
492 | old_name_pane.add(old_name, BorderLayout.CENTER);
|
---|
493 |
|
---|
494 | JPanel new_name_pane = new JPanel();
|
---|
495 | new_name_pane.setBorder(BorderFactory.createEmptyBorder(0,5,5,5));
|
---|
496 | new_name_pane.setLayout(new BorderLayout());
|
---|
497 | new_name_pane.add(new_name_label, BorderLayout.WEST);
|
---|
498 | new_name_pane.add(new_name, BorderLayout.CENTER);
|
---|
499 |
|
---|
500 | JPanel control_pane = new JPanel();
|
---|
501 | control_pane.setLayout(new GridLayout(2,1));
|
---|
502 | control_pane.add(old_name_pane);
|
---|
503 | control_pane.add(new_name_pane);
|
---|
504 |
|
---|
505 | JPanel button_pane = new JPanel();
|
---|
506 | button_pane.setBorder(BorderFactory.createEmptyBorder(0,5,5,5));
|
---|
507 | button_pane.setLayout(new GridLayout(1,2));
|
---|
508 | button_pane.add(ok);
|
---|
509 | button_pane.add(cancel);
|
---|
510 |
|
---|
511 | content_pane.setLayout(new BorderLayout());
|
---|
512 | content_pane.add(control_pane, BorderLayout.CENTER);
|
---|
513 | content_pane.add(button_pane, BorderLayout.SOUTH);
|
---|
514 | // Display
|
---|
515 | dialog.setLocation((screen_size.width - RENAME_SIZE.width) / 2, (screen_size.height - RENAME_SIZE.height) / 2);
|
---|
516 | on_screen = dialog;
|
---|
517 | off_screen.setVisible(false);
|
---|
518 | on_screen.setVisible(true);
|
---|
519 | off_screen.setVisible(true);
|
---|
520 | on_screen.dispose();
|
---|
521 | on_screen = null;
|
---|
522 |
|
---|
523 | button_pane = null;
|
---|
524 | control_pane = null;
|
---|
525 | new_name_pane = null;
|
---|
526 | old_name_pane = null;
|
---|
527 | content_pane = null;
|
---|
528 | ok.removeActionListener(this);
|
---|
529 | ok = null;
|
---|
530 | new_name = null;
|
---|
531 | new_name_label = null;
|
---|
532 | old_name = null;
|
---|
533 | old_name_label = null;
|
---|
534 | dialog = null;
|
---|
535 |
|
---|
536 | if(action == Declarations.CANCEL) {
|
---|
537 | return null;
|
---|
538 | }
|
---|
539 | action = Declarations.NO_ACTION;
|
---|
540 | dialog = null;
|
---|
541 | return new_name.getText();
|
---|
542 | }
|
---|
543 |
|
---|
544 | /** When called this method produces a nice error message on the screen, advising the user that the remove action has failed.
|
---|
545 | * @param mde_cur The <strong>Element</strong> that we are attempting to remove.
|
---|
546 | * @param reason The phrase key for the reason the rename failed, also as a <strong>String</strong>.
|
---|
547 | */
|
---|
548 | public void removeFailed(Element mde_cur, String reason) {
|
---|
549 | String args[] = new String[2];
|
---|
550 | args[0] = mde_cur.getAttribute("name");
|
---|
551 | args[1] = get(reason, null);
|
---|
552 | JOptionPane.showMessageDialog(off_screen, get("Remove_Failed", args), get("Remove_Failed_Title", null), JOptionPane.ERROR_MESSAGE);
|
---|
553 | }
|
---|
554 |
|
---|
555 | /** When called this method produces a nice error message on the screen, advising the user that the rename action has failed.
|
---|
556 | * @param mde_new The <strong>Element</strong> that we are attempting to add.
|
---|
557 | * @param new_name The name that we attempted to add it under, as a <strong>String</strong>.
|
---|
558 | * @param reason The phrase key for the reason the rename failed, also as a <strong>String</strong>.
|
---|
559 | */
|
---|
560 | public void renameFailed(Element mde_new, String new_name, String reason) {
|
---|
561 | String args[] = new String[3];
|
---|
562 | args[0] = mde_new.getAttribute("name");
|
---|
563 | args[1] = new_name;
|
---|
564 | args[2] = get(reason, null);
|
---|
565 | JOptionPane.showMessageDialog(off_screen, get("Rename_Failed", args), get("Rename_Failed_Title", null), JOptionPane.ERROR_MESSAGE);
|
---|
566 | }
|
---|
567 |
|
---|
568 | /** Method to display a prompt asking the user to select a specific element to merge with.
|
---|
569 | * @param mds_cur The current <strong>MetadataSet</strong>.
|
---|
570 | * @return The selected <strong>Element</strong> or <i>null</i> if the user cancels the action.
|
---|
571 | */
|
---|
572 | public Element selectElement(MetadataSet mds_cur) {
|
---|
573 | action = Declarations.NO_ACTION;
|
---|
574 | // Create
|
---|
575 | JDialog dialog = new ModalDialog(Gatherer.g_man);
|
---|
576 | dialog.setModal(true);
|
---|
577 | dialog.setSize(SELECT_SIZE);
|
---|
578 | dialog.setTitle(get("Select"));
|
---|
579 | dialog.setJMenuBar(new SimpleMenuBar("6.8"));
|
---|
580 |
|
---|
581 | JButton ok = new JButton(get("General.OK"));
|
---|
582 | ok.addActionListener(this);
|
---|
583 | ok.setMnemonic(KeyEvent.VK_O);
|
---|
584 | ok.setEnabled(false);
|
---|
585 |
|
---|
586 | Node elements_raw[] = ArrayTools.nodeListToNodeArray(mds_cur.getElements());
|
---|
587 | ElementWrapper elements[] = new ElementWrapper[elements_raw.length];
|
---|
588 | for(int i = 0; i < elements_raw.length; i++) {
|
---|
589 | elements[i] = new ElementWrapper((Element)elements_raw[i]);
|
---|
590 | }
|
---|
591 | JList list = new JList(elements);
|
---|
592 | ElementListListener element_list_listener = new ElementListListener(list, ok);
|
---|
593 | list.addListSelectionListener(element_list_listener);
|
---|
594 | JPanel content_pane = (JPanel) dialog.getContentPane();
|
---|
595 | // Layout
|
---|
596 | JPanel list_pane = new JPanel();
|
---|
597 | list_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
598 | list_pane.setLayout(new BorderLayout());
|
---|
599 | list_pane.add(new JScrollPane(list), BorderLayout.CENTER);
|
---|
600 |
|
---|
601 | JPanel button_pane = new JPanel();
|
---|
602 | button_pane.setBorder(BorderFactory.createEmptyBorder(0,5,5,5));
|
---|
603 | button_pane.setLayout(new GridLayout(1,2));
|
---|
604 | button_pane.add(ok);
|
---|
605 | button_pane.add(cancel);
|
---|
606 |
|
---|
607 | content_pane.setLayout(new BorderLayout());
|
---|
608 | content_pane.add(list_pane, BorderLayout.CENTER);
|
---|
609 | content_pane.add(button_pane, BorderLayout.SOUTH);
|
---|
610 | // Display
|
---|
611 | dialog.setLocation((screen_size.width - SELECT_SIZE.width) / 2, (screen_size.height - SELECT_SIZE.height) / 2);
|
---|
612 | on_screen = dialog;
|
---|
613 | off_screen.setVisible(false);
|
---|
614 | on_screen.setVisible(true);
|
---|
615 | off_screen.setVisible(true);
|
---|
616 | on_screen.dispose();
|
---|
617 | on_screen = null;
|
---|
618 | // Deallocate stuff since JDK1.4 won't.
|
---|
619 | ok.removeActionListener(this);
|
---|
620 | ok = null;
|
---|
621 | elements_raw = null;
|
---|
622 | elements = null;
|
---|
623 | list.removeListSelectionListener(element_list_listener);
|
---|
624 | list = null;
|
---|
625 | element_list_listener = null;
|
---|
626 | content_pane = null;
|
---|
627 | list_pane = null;
|
---|
628 | button_pane = null;
|
---|
629 | dialog = null;
|
---|
630 | // Return selected element.
|
---|
631 | if(action == Declarations.CANCEL) {
|
---|
632 | return null;
|
---|
633 | }
|
---|
634 | return ((ElementWrapper)list.getSelectedValue()).getElement();
|
---|
635 | }
|
---|
636 |
|
---|
637 | /** Prompts the user to choose how to import a metadata element. Gives the option of renaming the element to a certain value of a certain set, or adding to a selected set.
|
---|
638 | * @param name The name of the original metadata as a String.
|
---|
639 | * @param set The set previously choosen as the default set for this metadata (which it doesn't match somehow).
|
---|
640 | * @return An ElementWrapper around the element that it has been matched to.
|
---|
641 | * @see org.greenstone.gatherer.msm.MSMPrompt.MSMDialog
|
---|
642 | * @see org.greenstone.gatherer.util.MED
|
---|
643 | */
|
---|
644 | public ElementWrapper selectElement(String name) {
|
---|
645 | dialog_cancelled = false;
|
---|
646 | result = null;
|
---|
647 | String args[] = new String[1];
|
---|
648 | args[0] = name;
|
---|
649 | // Create
|
---|
650 | MSMDialog dialog = new MSMDialog();
|
---|
651 | dialog.setModal(true);
|
---|
652 | dialog.setSize(SELECT_ELEMENT_SIZE);
|
---|
653 | dialog.setTitle(get("Select_Element_Title"));
|
---|
654 | dialog.setJMenuBar(new SimpleMenuBar("6.8"));
|
---|
655 | JPanel content_pane = (JPanel) dialog.getContentPane();
|
---|
656 | JPanel control_pane = new JPanel();
|
---|
657 | JTextArea instructions = new JTextArea(get("Select_Element_Instructions", args));
|
---|
658 | instructions.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
|
---|
659 | instructions.setEditable(false);
|
---|
660 | instructions.setLineWrap(true);
|
---|
661 | instructions.setRows(SELECT_LINE_COUNT);
|
---|
662 | instructions.setWrapStyleWord(true);
|
---|
663 | JPanel original_pane = new JPanel();
|
---|
664 | JLabel original_label = new JLabel(get("Select_Element_Original"));
|
---|
665 | original_label.setPreferredSize(SELECT_LABEL_SIZE);
|
---|
666 | JTextField original = new JTextField(name);
|
---|
667 | original.setEditable(false);
|
---|
668 | JPanel element_pane = new JPanel();
|
---|
669 | JLabel element_label = new JLabel(get("Select_Element_Element"));
|
---|
670 | element_label.setPreferredSize(SELECT_LABEL_SIZE);
|
---|
671 | JComboBox element = new JComboBox();
|
---|
672 | element.setBackground(Color.white);
|
---|
673 | JButton add_button = new JButton(get("Select_Element_Add"));
|
---|
674 | add_button.setEnabled(false);
|
---|
675 | add_button.setMnemonic(KeyEvent.VK_A);
|
---|
676 | JButton cancel_button = new JButton(get("General.Cancel"));
|
---|
677 | cancel_button.setMnemonic(KeyEvent.VK_C);
|
---|
678 | JButton merge_button = new JButton(get("Select_Element_Merge"));
|
---|
679 | merge_button.setEnabled(false);
|
---|
680 | merge_button.setMnemonic(KeyEvent.VK_M);
|
---|
681 | JButton ignore_button = new JButton(get("Select_Element_Ignore"));
|
---|
682 | ignore_button.setMnemonic(KeyEvent.VK_I);
|
---|
683 | JPanel set_pane = new JPanel();
|
---|
684 | JLabel set_label = new JLabel(get("Select_Element_Set"));
|
---|
685 | set_label.setPreferredSize(SELECT_LABEL_SIZE);
|
---|
686 | JComboBox set = new JComboBox(manager.getSets(false)); // Don't include the greenstone metadata set.
|
---|
687 | set.setBackground(Color.white);
|
---|
688 | JPanel button_pane = new JPanel();
|
---|
689 | // Connect
|
---|
690 | AddListener add_listener = new AddListener(dialog, name, set);
|
---|
691 | CancelListener cancel_listener = new CancelListener(dialog);
|
---|
692 | IgnoreListener ignore_listener = new IgnoreListener(dialog);
|
---|
693 | MergeListener merge_listener = new MergeListener(dialog, element);
|
---|
694 | SetListener set_listener = new SetListener(set, element, name, add_button, merge_button);
|
---|
695 |
|
---|
696 | add_button.addActionListener(add_listener);
|
---|
697 | cancel_button.addActionListener(cancel_listener);
|
---|
698 | merge_button.addActionListener(merge_listener);
|
---|
699 | ignore_button.addActionListener(ignore_listener);
|
---|
700 | set.addActionListener(set_listener);
|
---|
701 |
|
---|
702 | // Init controls
|
---|
703 | if(set.getItemCount() > 0) {
|
---|
704 | // We now try to determine the existing metadata element that is the closest match to the one we are trying to merge.
|
---|
705 | MetadataSet closest_set = null;
|
---|
706 | ElementWrapper closest_element = null;
|
---|
707 | int med = -1;
|
---|
708 | for(int i = 0; i < set.getItemCount(); i++) {
|
---|
709 | MetadataSet mds = (MetadataSet) set.getItemAt(i);
|
---|
710 | for(int j = 0; j < mds.size(); j++) {
|
---|
711 | ElementWrapper mde = new ElementWrapper(mds.getElement(j));
|
---|
712 | int new_med = MED.LD(name, mde.toString());
|
---|
713 | if(med == -1 || new_med < med) {
|
---|
714 | med = new_med;
|
---|
715 | closest_element = mde;
|
---|
716 | closest_set = mds;
|
---|
717 | }
|
---|
718 | mde = null;
|
---|
719 | }
|
---|
720 | mds = null;
|
---|
721 | }
|
---|
722 | if(closest_set != null && closest_element != null) {
|
---|
723 | set.setSelectedItem(closest_set);
|
---|
724 | element.setSelectedItem(closest_element);
|
---|
725 | set_listener.actionPerformed();
|
---|
726 | }
|
---|
727 | else {
|
---|
728 | set_listener.actionPerformed();
|
---|
729 | }
|
---|
730 | closest_set = null;
|
---|
731 | closest_element = null;
|
---|
732 | }
|
---|
733 | merge_button.setEnabled(element.getItemCount() > 0);
|
---|
734 | // Layout
|
---|
735 | original_label.setBorder(BorderFactory.createEmptyBorder(0,0,0,5));
|
---|
736 | original_pane.setLayout(new BorderLayout());
|
---|
737 | original_pane.add(original_label, BorderLayout.WEST);
|
---|
738 | original_pane.add(original, BorderLayout.CENTER);
|
---|
739 | set_label.setBorder(BorderFactory.createEmptyBorder(0,0,0,5));
|
---|
740 | set_pane.setLayout(new BorderLayout());
|
---|
741 | set_pane.add(set_label, BorderLayout.WEST);
|
---|
742 | set_pane.add(set, BorderLayout.CENTER);
|
---|
743 | element_label.setBorder(BorderFactory.createEmptyBorder(0,0,0,5));
|
---|
744 | element_pane.setLayout(new BorderLayout());
|
---|
745 | element_pane.add(element_label, BorderLayout.WEST);
|
---|
746 | element_pane.add(element, BorderLayout.CENTER);
|
---|
747 | control_pane.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
|
---|
748 | control_pane.setLayout(new GridLayout(3,1));
|
---|
749 | control_pane.add(original_pane);
|
---|
750 | control_pane.add(set_pane);
|
---|
751 | control_pane.add(element_pane);
|
---|
752 | button_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
|
---|
753 | button_pane.setLayout(new GridLayout(1,4));
|
---|
754 | button_pane.add(add_button);
|
---|
755 | button_pane.add(merge_button);
|
---|
756 | button_pane.add(ignore_button);
|
---|
757 | button_pane.add(cancel_button);
|
---|
758 | content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
759 | content_pane.setLayout(new BorderLayout());
|
---|
760 | content_pane.add(new JScrollPane(instructions), BorderLayout.NORTH);
|
---|
761 | content_pane.add(control_pane, BorderLayout.CENTER);
|
---|
762 | content_pane.add(button_pane, BorderLayout.SOUTH);
|
---|
763 | // Display
|
---|
764 | dialog.setLocation((screen_size.width - SELECT_ELEMENT_SIZE.width) / 2, (screen_size.height - SELECT_ELEMENT_SIZE.height) / 2);
|
---|
765 | dialog.setVisible(true);
|
---|
766 | // Deallocate everything because JDK1.4 won't.
|
---|
767 | // Why, oh why did I do this?
|
---|
768 | add_button.removeActionListener(add_listener);
|
---|
769 | merge_button.removeActionListener(merge_listener);
|
---|
770 | ignore_button.removeActionListener(ignore_listener);
|
---|
771 | add_button = null;
|
---|
772 | merge_button = null;
|
---|
773 | ignore_button = null;
|
---|
774 | add_listener = null;
|
---|
775 | merge_listener = null;
|
---|
776 | ignore_listener = null;
|
---|
777 | // References
|
---|
778 | args = null;
|
---|
779 | content_pane = null;
|
---|
780 | control_pane = null;
|
---|
781 | instructions = null;
|
---|
782 | original_pane = null;
|
---|
783 | original_pane = null;
|
---|
784 | original = null;
|
---|
785 | element_pane = null;
|
---|
786 | element_label = null;
|
---|
787 | element = null;
|
---|
788 | set_pane = null;
|
---|
789 | set_label = null;
|
---|
790 | set.removeActionListener(set_listener);
|
---|
791 | set_listener = null;
|
---|
792 | set = null;
|
---|
793 | button_pane = null;
|
---|
794 | dialog.dispose();
|
---|
795 | dialog.destroy();
|
---|
796 | dialog = null;
|
---|
797 | // Dondage.
|
---|
798 | return (ElementWrapper)result;
|
---|
799 | }
|
---|
800 |
|
---|
801 | public boolean wasDialogCancelled() {
|
---|
802 | return dialog_cancelled;
|
---|
803 | }
|
---|
804 |
|
---|
805 | private String get(String key) {
|
---|
806 | return get(key, null);
|
---|
807 | }
|
---|
808 |
|
---|
809 | private String get(String key, String args[]) {
|
---|
810 | if(key.indexOf(".") == -1) {
|
---|
811 | key = "MSMPrompt." + key;
|
---|
812 | }
|
---|
813 | return Gatherer.dictionary.get(key, args);
|
---|
814 | }
|
---|
815 |
|
---|
816 | /** Prompts the user to select a metadata set from the given list. Uses the name parameter to attempt to automatically select the correct collection (ie the only collection that has an element with the same name).
|
---|
817 | * @param name The name of the metadata element whose set name is unknown.
|
---|
818 | * @return The metadata set the user has selected or null if no set selected.
|
---|
819 | */
|
---|
820 | final public MetadataSet selectSet(String name) {
|
---|
821 | String args[] = new String[1];
|
---|
822 | args[0] = name;
|
---|
823 | // Creation
|
---|
824 | MSMDialog dialog = new MSMDialog();
|
---|
825 | dialog.setModal(true);
|
---|
826 | dialog.setSize(SELECT_SET_SIZE);
|
---|
827 | dialog.setTitle(get("Select_Set_Title"));
|
---|
828 | dialog.setJMenuBar(new SimpleMenuBar("6.8"));
|
---|
829 | JPanel content_pane = (JPanel) dialog.getContentPane();
|
---|
830 | JPanel control_pane = new JPanel();
|
---|
831 | JTextArea instructions = new JTextArea(get("Select_Set_Instructions", args));
|
---|
832 | instructions.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
|
---|
833 | instructions.setEditable(false);
|
---|
834 | instructions.setLineWrap(true);
|
---|
835 | instructions.setRows(SELECT_LINE_COUNT);
|
---|
836 | instructions.setWrapStyleWord(true);
|
---|
837 | JComboBox set = new JComboBox();
|
---|
838 | set.setBackground(Color.white);
|
---|
839 | set.addItem(get("Select_Set_None"));
|
---|
840 | Vector sets = manager.getSets();
|
---|
841 | for(int i = sets.size() - 1; i >= 0; i--) {
|
---|
842 | set.addItem(sets.get(i));
|
---|
843 | }
|
---|
844 | JButton ok = new JButton(get("General.OK"));
|
---|
845 | ActionListener ok_listener = new IgnoreListener(dialog);
|
---|
846 | ok.addActionListener(ok_listener); // Doesn't really ignore. Just disposes()
|
---|
847 | // Select most likely set.
|
---|
848 | if(name.indexOf(".") != -1) {
|
---|
849 | String set_name = name.substring(0, name.indexOf("."));
|
---|
850 | MetadataSet metadata_set = manager.getSet(set_name);
|
---|
851 | if(metadata_set != null) {
|
---|
852 | set.setSelectedItem(metadata_set);
|
---|
853 | }
|
---|
854 | metadata_set = null;
|
---|
855 | set_name = null;
|
---|
856 | }
|
---|
857 | else {
|
---|
858 | Vector matches = manager.setsThatContain(name);
|
---|
859 | if(matches.size() == 1) {
|
---|
860 | set.setSelectedItem(matches.get(0));
|
---|
861 | }
|
---|
862 | matches = null;
|
---|
863 | }
|
---|
864 | // Layout
|
---|
865 | control_pane.setLayout(new GridLayout(2,1));
|
---|
866 | control_pane.add(set);
|
---|
867 | control_pane.add(ok);
|
---|
868 | content_pane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
|
---|
869 | content_pane.setLayout(new BorderLayout());
|
---|
870 | content_pane.add(new JScrollPane(instructions), BorderLayout.CENTER);
|
---|
871 | content_pane.add(control_pane, BorderLayout.SOUTH);
|
---|
872 | // Display
|
---|
873 | dialog.setLocation((screen_size.width - SELECT_SET_SIZE.width) / 2, (screen_size.height - SELECT_SET_SIZE.height) / 2);
|
---|
874 | dialog.setVisible(true);
|
---|
875 | Object value = set.getSelectedItem();
|
---|
876 | if(value instanceof MetadataSet) {
|
---|
877 | return (MetadataSet) value;
|
---|
878 | }
|
---|
879 | value = null;
|
---|
880 | ok.removeActionListener(ok_listener);
|
---|
881 | ok_listener = null;
|
---|
882 | ok = null;
|
---|
883 | content_pane = null;
|
---|
884 | control_pane = null;
|
---|
885 | instructions = null;
|
---|
886 | set = null;
|
---|
887 | dialog.destroy();
|
---|
888 | dialog = null;
|
---|
889 | return null;
|
---|
890 | }
|
---|
891 |
|
---|
892 | private class AddListener
|
---|
893 | implements ActionListener {
|
---|
894 | private JComboBox set = null;
|
---|
895 | private JDialog dialog = null;
|
---|
896 | private String name = null;
|
---|
897 | public AddListener(JDialog dialog, String name, JComboBox set) {
|
---|
898 | this.dialog = dialog;
|
---|
899 | this.name = name;
|
---|
900 | this.set = set;
|
---|
901 | }
|
---|
902 | public void actionPerformed(ActionEvent event) {
|
---|
903 | // Get the currently selected metadata set.
|
---|
904 | MetadataSet mds = (MetadataSet) set.getSelectedItem();
|
---|
905 | String n = name;
|
---|
906 | // If we've been forced to go this far then any given namespace is complete bollocks.
|
---|
907 | while(n.indexOf(".") != -1 && !n.equals(".")) {
|
---|
908 | n = n.substring(n.indexOf(".") + 1);
|
---|
909 | }
|
---|
910 | // However, before we attempt to add a new element to the set, we should check that none already exists.
|
---|
911 | Element element = mds.getElement(name);
|
---|
912 | if(element == null) {
|
---|
913 | result = mds.addElement(n);
|
---|
914 | }
|
---|
915 | else {
|
---|
916 | result = (ElementWrapper) element;
|
---|
917 | }
|
---|
918 | mds = null;
|
---|
919 | n = null;
|
---|
920 | element = null;
|
---|
921 | dialog.dispose();
|
---|
922 | }
|
---|
923 | }
|
---|
924 | /** This listener listens for selections within the select element to merge prompt, and once one has been made enables the ok button.*/
|
---|
925 | private class ElementListListener
|
---|
926 | implements ListSelectionListener {
|
---|
927 | /** The button we either enable or disable depending on user selection. */
|
---|
928 | private JButton ok = null;
|
---|
929 | /** The list from whom we are listening for selection events. */
|
---|
930 | private JList list = null;
|
---|
931 | /** Constructor.
|
---|
932 | * @param list The <strong>JList</Strong> from whom we are listening for selection events.
|
---|
933 | * @param ok The <Strong>JButton</strong> we either enable or disable depending on user selection.
|
---|
934 | */
|
---|
935 | public ElementListListener(JList list, JButton ok) {
|
---|
936 | this.list = list;
|
---|
937 | this.ok = ok;
|
---|
938 | }
|
---|
939 | /** Any implementation of <i>ListSelectionListener</i> must include this method so we can be informed when a list selection event has occured.
|
---|
940 | * @param event A <strong>ListSelectionEvent</strong> generated by the event.
|
---|
941 | */
|
---|
942 | public void valueChanged(ListSelectionEvent event) {
|
---|
943 | if(list.getSelectedValue() != null) {
|
---|
944 | ok.setEnabled(true);
|
---|
945 | }
|
---|
946 | else {
|
---|
947 | ok.setEnabled(false);
|
---|
948 | }
|
---|
949 | }
|
---|
950 | }
|
---|
951 |
|
---|
952 | private class CancelListener
|
---|
953 | implements ActionListener {
|
---|
954 | private JDialog dialog = null;
|
---|
955 | public CancelListener(JDialog dialog) {
|
---|
956 | this.dialog = dialog;
|
---|
957 | }
|
---|
958 | public void actionPerformed(ActionEvent event) {
|
---|
959 | dialog_cancelled = true;
|
---|
960 | dialog.dispose();
|
---|
961 | }
|
---|
962 | }
|
---|
963 |
|
---|
964 | private class IgnoreListener
|
---|
965 | implements ActionListener {
|
---|
966 | private JDialog dialog = null;
|
---|
967 | public IgnoreListener(JDialog dialog) {
|
---|
968 | this.dialog = dialog;
|
---|
969 | }
|
---|
970 | public void actionPerformed(ActionEvent event) {
|
---|
971 | dialog.dispose();
|
---|
972 | }
|
---|
973 | }
|
---|
974 |
|
---|
975 | private class MergeListener
|
---|
976 | implements ActionListener {
|
---|
977 | private JComboBox element = null;
|
---|
978 | private JDialog dialog = null;
|
---|
979 | public MergeListener(JDialog dialog, JComboBox element) {
|
---|
980 | this.dialog = dialog;
|
---|
981 | this.element = element;
|
---|
982 | }
|
---|
983 | public void actionPerformed(ActionEvent event) {
|
---|
984 | // Return the currently selected element
|
---|
985 | result = (ElementWrapper)element.getSelectedItem();
|
---|
986 | dialog.dispose();
|
---|
987 | }
|
---|
988 | }
|
---|
989 |
|
---|
990 | private class MSMDialog
|
---|
991 | extends ModalDialog {
|
---|
992 |
|
---|
993 | public MSMDialog() {
|
---|
994 | super(Gatherer.g_man);
|
---|
995 | }
|
---|
996 | public void destroy() {
|
---|
997 | rootPane = null;
|
---|
998 | }
|
---|
999 | }
|
---|
1000 |
|
---|
1001 | private class SetListener
|
---|
1002 | implements ActionListener {
|
---|
1003 | private JButton add_button = null;
|
---|
1004 | private JButton merge_button = null;
|
---|
1005 | private JComboBox element = null;
|
---|
1006 | private JComboBox set = null;
|
---|
1007 | private String name = null;
|
---|
1008 | public SetListener(JComboBox set, JComboBox element, String name, JButton add_button, JButton merge_button) {
|
---|
1009 | this.add_button = add_button;
|
---|
1010 | this.element = element;
|
---|
1011 | this.merge_button = merge_button;
|
---|
1012 | this.name = name.toLowerCase();
|
---|
1013 | this.set = set;
|
---|
1014 | }
|
---|
1015 | public void actionPerformed() {
|
---|
1016 | element.removeAllItems();
|
---|
1017 | MetadataSet mds = (MetadataSet) set.getSelectedItem();
|
---|
1018 | System.err.println("Set selected: " + mds);
|
---|
1019 | if(mds != null) {
|
---|
1020 | NodeList elements = mds.getElements();
|
---|
1021 | Vector temp = new Vector();
|
---|
1022 | for(int i = elements.getLength() - 1; i >= 0; i--) {
|
---|
1023 | temp.add(new ElementWrapper((Element)elements.item(i)));
|
---|
1024 | }
|
---|
1025 |
|
---|
1026 | // The add button is only enabled if an element with the same name doesn't already exist in the destination set.
|
---|
1027 | boolean add_button_enabled = true;
|
---|
1028 | ///ystem.err.println("Checking for " + name);
|
---|
1029 | for(int j = 0; j < temp.size(); j++) {
|
---|
1030 | ElementWrapper an_element = (ElementWrapper)temp.get(j);
|
---|
1031 | // Can only add if no file with the same name exists.
|
---|
1032 | String check = an_element.toString().toLowerCase();
|
---|
1033 | int position = -1;
|
---|
1034 | if((position = check.indexOf(".")) != -1) {
|
---|
1035 | check = check.substring(position + 1);
|
---|
1036 | }
|
---|
1037 | ///ystem.err.println("does it match " + check + "? " + name.equals(check));
|
---|
1038 | add_button_enabled = add_button_enabled && !name.equals(check);
|
---|
1039 | check = null;
|
---|
1040 | element.addItem(an_element);
|
---|
1041 | an_element = null;
|
---|
1042 | }
|
---|
1043 | add_button.setEnabled(add_button_enabled);
|
---|
1044 |
|
---|
1045 | // The merge button is only enabled if there is more than one element in the destination set.
|
---|
1046 | if(temp.size() > 0) {
|
---|
1047 | merge_button.setEnabled(true);
|
---|
1048 | }
|
---|
1049 | else {
|
---|
1050 | merge_button.setEnabled(false);
|
---|
1051 | }
|
---|
1052 | temp = null;
|
---|
1053 | elements = null;
|
---|
1054 | }
|
---|
1055 | else {
|
---|
1056 | add_button.setEnabled(false);
|
---|
1057 | merge_button.setEnabled(false);
|
---|
1058 | }
|
---|
1059 | mds = null;
|
---|
1060 | }
|
---|
1061 | public void actionPerformed(ActionEvent item) {
|
---|
1062 | actionPerformed();
|
---|
1063 | }
|
---|
1064 | }
|
---|
1065 | }
|
---|