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