source: trunk/gli/src/org/greenstone/gatherer/gui/MetadataImportMappingPrompt.java@ 12119

Last change on this file since 12119 was 12119, checked in by kjdon, 18 years ago

Changed text handling to use Dictionary.get rather than Dictionary.setText or Dictionary.registerBoth etc. also removed mnemonics cos they suck for other languages

  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
Line 
1package org.greenstone.gatherer.gui;
2
3
4import java.awt.*;
5import java.awt.event.*;
6import java.util.*;
7import javax.swing.*;
8import org.greenstone.gatherer.Configuration;
9import org.greenstone.gatherer.Dictionary;
10import org.greenstone.gatherer.Gatherer;
11import org.greenstone.gatherer.metadata.MetadataElement;
12import org.greenstone.gatherer.metadata.MetadataSet;
13import org.greenstone.gatherer.metadata.MetadataSetManager;
14import org.greenstone.gatherer.metadata.MetadataTools;
15
16
17public class MetadataImportMappingPrompt
18 implements ActionListener
19{
20 final static public int ADD_BUTTON_PRESSED = 0;
21 final static public int MERGE_BUTTON_PRESSED = 1;
22 final static public int IGNORE_BUTTON_PRESSED = 2;
23 final static private Dimension DIALOG_SIZE = new Dimension(640, 180);
24
25 private int result;
26 private String metadata_element_name_full = null;
27 private GComboBox metadata_sets_combobox = null;
28 private GComboBox metadata_elements_combobox = null;
29 private JButton add_button = null;
30 private JButton merge_button = null;
31 private JButton ignore_button = null;
32 private JDialog on_screen = null;
33
34
35 public MetadataImportMappingPrompt(String metadata_element_name_full)
36 {
37 this.metadata_element_name_full = metadata_element_name_full;
38
39 // Construction and configuration
40 JDialog dialog = new ModalDialog(Gatherer.g_man);
41 dialog.setModal(true);
42 dialog.setSize(DIALOG_SIZE);
43 dialog.setJMenuBar(new SimpleMenuBar("importingpreviouslyassignedmetadata"));
44 dialog.setTitle(Dictionary.get("MIMP.Title"));
45
46 // All the loaded metadata sets except the extracted metadata set are applicable
47 ArrayList metadata_sets = MetadataSetManager.getMetadataSets();
48 for (int i = metadata_sets.size() - 1; i >= 0; i--) {
49 if (((MetadataSet) metadata_sets.get(i)).getNamespace().equals(MetadataSetManager.EXTRACTED_METADATA_NAMESPACE)) {
50 metadata_sets.remove(i);
51 }
52 }
53
54 add_button = new GLIButton(Dictionary.get("MIMP.Add"), Dictionary.get("MIMP.Add_Tooltip"));
55 add_button.addActionListener(this);
56
57 merge_button = new GLIButton(Dictionary.get("MIMP.Merge"), Dictionary.get("MIMP.Merge_Tooltip"));
58 merge_button.addActionListener(this);
59 merge_button.setEnabled(true);
60
61 ignore_button = new GLIButton(Dictionary.get("MIMP.Ignore"), Dictionary.get("MIMP.Ignore_Tooltip"));
62 ignore_button.addActionListener(this);
63 ignore_button.setEnabled(true);
64
65 // !! Need to add instructions: "MIMP.Instructions", args: source elem
66 metadata_elements_combobox = new GComboBox();
67
68 metadata_sets_combobox = new GComboBox(metadata_sets);
69 metadata_sets_combobox.addActionListener(new MetadataSetListSelectionListener());
70 metadata_sets_combobox.setSelectedIndex(0);
71
72 // Layout
73 JPanel left_pane = new JPanel();
74 left_pane.setLayout(new GridLayout(3,1));
75 left_pane.add(new JLabel(Dictionary.get("MIMP.Source_Element")));
76 left_pane.add(new JLabel(Dictionary.get("MIMP.Target_Set")));
77 left_pane.add(new JLabel(Dictionary.get("MIMP.Target_Element")));
78
79 JPanel right_pane = new JPanel();
80 right_pane.setLayout(new GridLayout(3,1));
81 right_pane.add(new JLabel(metadata_element_name_full));
82 right_pane.add(metadata_sets_combobox);
83 right_pane.add(metadata_elements_combobox);
84
85 JPanel button_pane = new JPanel();
86 button_pane.setBorder(BorderFactory.createEmptyBorder(0,5,5,5));
87 button_pane.setLayout(new GridLayout(1,3));
88 button_pane.add(add_button);
89 button_pane.add(merge_button);
90 button_pane.add(ignore_button);
91
92 JPanel content_pane = (JPanel) dialog.getContentPane();
93 content_pane.setLayout(new BorderLayout());
94 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
95 content_pane.add(left_pane, BorderLayout.WEST);
96 content_pane.add(right_pane, BorderLayout.CENTER);
97 content_pane.add(button_pane, BorderLayout.SOUTH);
98
99 // Display
100 Dimension screen_size = Configuration.screen_size;
101 dialog.setLocation((screen_size.width - DIALOG_SIZE.width) / 2, (screen_size.height - DIALOG_SIZE.height) / 2);
102 on_screen = dialog;
103 on_screen.setVisible(true); // Blocks until hidden.
104 on_screen.dispose();
105 on_screen = null;
106 }
107
108
109 /** Any implementation of <i>ActionListener</i> must include this method so that we can be informed when an action has occured.
110 * @param event An <strong>ActionEvent</strong> containing information gatherer when this event occured.
111 */
112 public void actionPerformed(ActionEvent event)
113 {
114 Object esrc = event.getSource();
115
116 if (esrc == add_button) {
117 result = ADD_BUTTON_PRESSED;
118 }
119 if (esrc == merge_button) {
120 result = MERGE_BUTTON_PRESSED;
121 }
122 if (esrc == ignore_button) {
123 result = IGNORE_BUTTON_PRESSED;
124 }
125
126 on_screen.setVisible(false);
127 }
128
129
130 public MetadataElement getSelectedMetadataElement()
131 {
132 return (MetadataElement) metadata_elements_combobox.getSelectedItem();
133 }
134
135
136 public MetadataSet getSelectedMetadataSet()
137 {
138 return (MetadataSet) metadata_sets_combobox.getSelectedItem();
139 }
140
141
142 public int getResult()
143 {
144 return result;
145 }
146
147
148 private class MetadataSetListSelectionListener
149 implements ActionListener
150 {
151 public void actionPerformed(ActionEvent event)
152 {
153 boolean enable_add_button = true;
154 String metadata_element_name = MetadataTools.getMetadataElementName(metadata_element_name_full);
155
156 MetadataSet metadata_set = (MetadataSet) metadata_sets_combobox.getSelectedItem();
157 ArrayList metadata_elements = metadata_set.getMetadataSetElements();
158
159 metadata_elements_combobox.removeAllItems();
160 for (int i = 0; i < metadata_elements.size(); i++) {
161 MetadataElement metadata_element = (MetadataElement) metadata_elements.get(i);
162 metadata_elements_combobox.addItem(metadata_element);
163 if (metadata_element.getName().equals(metadata_element_name)) {
164 metadata_elements_combobox.setSelectedIndex(i);
165 enable_add_button = false;
166 }
167 }
168
169 add_button.setEnabled(enable_add_button);
170
171 // are there any elements in the set? if not (e.g. with exp set),
172 // disable merge
173 if (metadata_elements.size()==0) {
174 merge_button.setEnabled(false);
175 }
176 }
177 }
178}
Note: See TracBrowser for help on using the repository browser.