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

Last change on this file since 5811 was 5811, checked in by kjdon, 20 years ago

hmmm, forgot how to call constructors properly last commit

  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1package org.greenstone.gatherer.gui;
2
3import java.awt.*;
4import java.awt.event.*;
5import java.io.*;
6import java.util.*;
7import javax.swing.*;
8import javax.swing.event.*;
9import org.greenstone.gatherer.Dictionary;
10import org.greenstone.gatherer.Gatherer;
11import org.greenstone.gatherer.checklist.CheckList;
12import org.greenstone.gatherer.checklist.Entry;
13import org.greenstone.gatherer.gui.SimpleMenuBar;
14import org.greenstone.gatherer.gui.ModalDialog;
15import org.greenstone.gatherer.cdm.ElementWrapper;
16import org.greenstone.gatherer.msm.MetadataSet;
17import org.greenstone.gatherer.util.StaticStrings;
18import org.greenstone.gatherer.util.Utility;
19import org.w3c.dom.*;
20
21public class NewCollectionMetadataPrompt
22 extends ModalDialog {
23
24 private boolean cancelled = true;
25 private CheckList sets_list;
26 private JDialog self;
27 private JList elements_list;
28 static private Dimension size = new Dimension(700, 380);
29
30 public NewCollectionMetadataPrompt() {
31 this(false);
32 }
33 public NewCollectionMetadataPrompt(boolean existing_coll) {
34 super(Gatherer.g_man, true);
35 this.self = this;
36 if (existing_coll) {
37 setJMenuBar(new SimpleMenuBar("openingacollection"));
38 Dictionary.setText(this, "NewCollectionPrompt.Metadata_Title_Existing");
39 } else {
40 setJMenuBar(new SimpleMenuBar("creatingacollection"));
41 Dictionary.setText(this, "NewCollectionPrompt.Title");
42 }
43 setModal(true);
44 setSize(size);
45
46
47 // And the remaining metadata sets.
48 ArrayList sets = new ArrayList();
49 // Determine what collections are available.
50 File metadata_directory = new File(Utility.METADATA_DIR);
51 File[] possible_mdses = metadata_directory.listFiles();
52 for(int i = 0; i < possible_mdses.length; i++) {
53 String name = possible_mdses[i].getName();
54 if(name.endsWith(StaticStrings.METADATA_SET_EXTENSION) && !name.equals(Utility.EXTRACTED_METADATA_NAMESPACE + StaticStrings.METADATA_SET_EXTENSION)) {
55 sets.add(new MetadataSet(possible_mdses[i]));
56 }
57 }
58
59 // Creation
60 JPanel content_pane = (JPanel) getContentPane();
61
62 JPanel instructions_panel = new JPanel();
63 JLabel instructions_label1 = new JLabel();
64 Dictionary.setText(instructions_label1, "NewCollectionPrompt.Metadata_Instructions1");
65 JLabel instructions_label2 = new JLabel();
66 Dictionary.setText(instructions_label2, "NewCollectionPrompt.Metadata_Instructions2");
67
68 JPanel center_pane = new JPanel();
69
70 JPanel sets_list_pane = new JPanel();
71 JLabel sets_list_label = new JLabel();
72 sets_list_label.setOpaque(false);
73 Dictionary.setText(sets_list_label, "NewCollectionPrompt.Select_MDS");
74 sets_list = new CheckList(sets, true);
75
76 JPanel elements_list_pane = new JPanel();
77 JLabel elements_list_label = new JLabel();
78 Dictionary.setText(elements_list_label, "NewCollectionPrompt.Metadata_Elements");
79 elements_list = new JList();
80 elements_list.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
81 elements_list.setForeground(Gatherer.config.getColor("coloring.collection_tree_foreground", false));
82 elements_list.setSelectionBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
83 elements_list.setSelectionForeground(Gatherer.config.getColor("coloring.collection_tree_foreground", false));
84
85 JPanel button_pane = new JPanel();
86 JButton ok_button = new JButton();
87 ok_button.setMnemonic(KeyEvent.VK_O);
88 Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
89 JButton cancel_button = new JButton();
90 cancel_button.setMnemonic(KeyEvent.VK_C);
91 Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
92
93 // Connection
94 ok_button.addActionListener(new OKButtonListener());
95 cancel_button.addActionListener(new CancelButtonListener());
96 sets_list.addListSelectionListener(new MetadataListSelectionListener());
97
98 // Display
99 instructions_panel.setLayout(new GridLayout(2,1));
100 instructions_panel.add(instructions_label1);
101 instructions_panel.add(instructions_label2);
102
103 sets_list_pane.setLayout(new BorderLayout());
104 sets_list_pane.add(sets_list_label, BorderLayout.NORTH);
105 sets_list_pane.add(new JScrollPane(sets_list), BorderLayout.CENTER);
106
107 elements_list_pane.setLayout(new BorderLayout());
108 elements_list_pane.add(elements_list_label, BorderLayout.NORTH);
109 elements_list_pane.add(new JScrollPane(elements_list), BorderLayout.CENTER);
110
111 center_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
112 center_pane.setLayout(new GridLayout(2,1,0,5));
113 center_pane.add(sets_list_pane);
114 center_pane.add(elements_list_pane);
115
116 button_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
117 button_pane.setLayout(new GridLayout(1,2,5,0));
118 button_pane.add(ok_button);
119 button_pane.add(cancel_button);
120
121 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
122 content_pane.setLayout(new BorderLayout());
123 content_pane.add(instructions_panel, BorderLayout.NORTH);
124 content_pane.add(center_pane, BorderLayout.CENTER);
125 content_pane.add(button_pane, BorderLayout.SOUTH);
126
127 // Show
128 Dimension screen_size = Gatherer.config.screen_size;
129 setLocation((screen_size.width - size.width) / 2, (screen_size.height - size.height) / 2);
130 setVisible(true);
131 }
132
133 public ArrayList getSets() {
134 return sets_list.getSelected();
135 }
136
137 public boolean isCancelled() {
138 return cancelled;
139 }
140
141 private class CancelButtonListener
142 implements ActionListener {
143 public void actionPerformed(ActionEvent event) {
144 cancelled = true;
145 self.dispose();
146 }
147 }
148
149 public class MetadataListSelectionListener
150 implements ListSelectionListener {
151 public void valueChanged(ListSelectionEvent event) {
152 if(!sets_list.isSelectionEmpty()) {
153 // Retrieve the selected set.
154 Entry entry = (Entry) sets_list.getSelectedValue();
155 MetadataSet set = (MetadataSet) entry.getObject();
156 entry = null;
157 // Build a model from its elements.
158 NodeList elements = set.getElements();
159 set = null;
160 Vector elements_model = new Vector();
161 for(int i = 0; i < elements.getLength(); i++) {
162 elements_model.add(new ElementWrapper(elements.item(i)));
163 }
164 elements = null;
165 Collections.sort(elements_model);
166 elements_list.setListData(elements_model);
167 elements_model = null;
168 }
169 else {
170 elements_list.setListData(new String[0]);
171 }
172 }
173 }
174
175 public class OKButtonListener
176 implements ActionListener {
177 public void actionPerformed(ActionEvent event) {
178 // See if the user has selected no metadata sets, and if so confirm thats what they really want.
179 ArrayList selected_sets = sets_list.getSelected();
180 cancelled = false;
181 if(selected_sets.size() == 0) {
182 WarningDialog dialog = new WarningDialog("warning.NoMetadataSetsSelected", true);
183 if(dialog.display() == JOptionPane.OK_OPTION) {
184 // Otherwise we are free to go
185 self.dispose();
186 }
187 }
188 else {
189 self.dispose();
190 }
191 }
192 }
193}
Note: See TracBrowser for help on using the repository browser.