source: trunk/gli/src/org/greenstone/gatherer/gems/GEMS.java@ 8793

Last change on this file since 8793 was 8793, checked in by mdewsnip, 19 years ago

More improvements to the GEMS, by Attila Aros.

  • Property svn:keywords set to Author Date Id Revision
File size: 125.3 KB
Line 
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 th * University of Waikato, New Zealand.
6 *
7 * <BR><BR>
8 *
9 * Author: John Thompson, Greenstone Digital Library, University of Waikato
10 *
11 * <BR><BR>
12 *
13 * Copyright (C) 1999 New Zealand Digital Library Project
14 *
15 * <BR><BR>
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * <BR><BR>
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * <BR><BR>
30 *
31 * You should have received a copy of the GNU General Public License
32 * along with this program; if not, write to the Free Software
33 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
34 *############################################## ##########################
35 */
36package org.greenstone.gatherer.gems;
37
38
39
40import java.awt.*;
41import java.awt.event.*;
42import java.io.File;
43import java.io.PrintStream;
44import java.io.FileInputStream;
45import java.io.FileOutputStream;
46import java.io.DataInputStream;
47import java.io.IOException;
48import java.util.*;
49import javax.swing.*;
50import java.lang.String;
51import javax.swing.event.*;
52import javax.swing.filechooser.*;
53import javax.swing.text.*;
54import javax.swing.tree.*;
55import org.greenstone.gatherer.Configuration;
56import org.greenstone.gatherer.DebugStream;
57import org.greenstone.gatherer.Dictionary;
58import org.greenstone.gatherer.GetOpt;
59import org.greenstone.gatherer.cdm.*;
60import org.greenstone.gatherer.gui.GComboBox;
61import org.greenstone.gatherer.gui.GLIButton;
62import org.greenstone.gatherer.gui.HelpFrame;
63import org.greenstone.gatherer.gui.ModalDialog;
64import org.greenstone.gatherer.gui.NonWhitespaceField;
65import org.greenstone.gatherer.gui.TransformCharacterTextField;
66import org.greenstone.gatherer.util.Codec;
67import org.greenstone.gatherer.util.Utility;
68import org.w3c.dom.*;
69
70
71
72/** Provides a GUI and relevant suite of tools for the editing of the metadata set associated with this collection. Again I have tried to capture a file manager type feel, with a tree showing the various set-element relations to the left of the dialog, and the right side showing details on the current tree selection. When a set is selected these details include a list of attributes, while when an element is selected this list is joined by another showing assigned values. In order for the editor to be stable and consistant with the rest of the tool, care must be taken for fire appropriate events whenever the sets are changed. There is also the addded complexity of determining what actions have to occur in order for a users edit of an assigned value to be completed, i.e. if the user chooses to remove a value then a call must be made to record_set.root.removeMetadata() to ensure all such values are actually removed, so it is not enough just to remove the value from the value model.
73 * @author John Thompson, Greenstone Digital Library, University of Waikato
74 * @version 2.3b
75 */
76public class GEMS
77 extends JFrame
78{
79 static final public int ADD_SET = 0;
80 static final public int NORMAL = 1;
81 static final public int REMOVE_SET = 2;
82 /** The default size of the editor dialog. */
83 static final private Dimension ADD_ELEMENT_SIZE = new Dimension(400,125);
84 static final private Dimension ADD_FILE_SIZE = new Dimension(400,125);
85 static final private Dimension ADD_SET_SIZE = new Dimension(400,150);
86 static final private Dimension OPEN_SETS_SIZE = new Dimension(400,135);
87 static final private Dimension ADD_OR_EDIT_ATTRIBUTE_SIZE = new Dimension(600,325);
88 static final private Dimension ADD_OR_EDIT_VALUE_SIZE = new Dimension(600,440);
89
90 static final private Dimension COMPONENT_SIZE = new Dimension(300,30);
91 static final private Dimension SIZE = new Dimension(800,480);
92 static final private String BLANK = "blank";
93 static final private String ELEMENT = "element";
94 static final private String PROFILE = "profile";
95 static final private String SET = "set";
96 static final private String VALUES = "values";
97 // static final public String MAX_LOADED_SETS = 64;
98 static public Configuration config = null;
99 private MetadataSetManager msm = new MetadataSetManager(this);
100
101 public AddElementActionListener add_element_action_listener = null;
102 private AddFileActionListener add_file_action_listener = null;
103 public AddSetActionListener add_set_action_listener = null;
104 /** The class used to handle add or edit attribute actions has to be globally available so that we can dispose of its dialog properly. */
105 public AddOrEditAttributeActionListener add_or_edit_attribute_action_listener = null;
106 /** The class used to handle add or edit value actions has to be globally available so that we can dispose of its dialog properly. */
107 public AddOrEditValueActionListener add_or_edit_value_action_listener = null;
108 private boolean ignore = false;
109 /** A card layout is used to switch between the two differing detail views. */
110 private CardLayout card_layout = null;
111 /** A card layout is used to switch between a value tree or an empty placeholder (if no value tree available). */
112 private CardLayout element_values_layout = null;
113 /** Um, the size of the screen I'd guess. */
114 private Dimension screen_size = null;
115 private ElementWrapper current_element = null;
116 private GValueNode current_value_node = null;
117 /** A reference to ourselves so our inner classes can dispose of us. */
118 private GEMS self = null;
119 private String gsdl_path = null;
120 private int current_attribute = -1;
121 private int current_attribute_type = -1;
122 private JButton add_attribute = null;
123 private JButton add_element = null;
124 private JButton add_file = null;
125 private JButton add_set = null;
126 private JButton add_value = null;
127 private JButton edit_attribute = null;
128 private JButton edit_value = null;
129 private JButton remove_attribute = null;
130 private JButton remove_element = null;
131 private JButton remove_file = null;
132 private JButton remove_set = null;
133 private JButton remove_value = null;
134 private JLabel element_name = null;
135 private JLabel profile_name = null;
136 private JLabel set_name = null;
137 private JScrollPane element_attributes_scroll = null;
138 private JScrollPane profile_attributes_scroll = null;
139 private JScrollPane set_attributes_scroll = null;
140 private JPanel details_pane = null;
141 private JPanel element_values_pane = null;
142 private KeepTreeRootExpandedListener keep_root_expanded_listener = null;
143 private GEMSModel model = null;
144 private GEMSNode current_node = null;
145 private MetadataSet current_set = null;
146 private Object target = null;
147 public RemoveSetActionListener remove_set_action_listener;
148 private SmarterTable element_attributes = null;
149 private SmarterTable profile_attributes = null;
150 private SmarterTable set_attributes = null;
151 private SmarterTree element_values = null;
152 public org.w3c.dom.Element rootelement;
153
154 // public LanguageManager languageManager = new LanguageManager(rootelement);
155 //PopupListener provides right-click functionality to any component that needs it
156 //It is a centralized manager for all popups, then we use evt.Source() and determine where the
157 //event was performed
158 private PopupListener popupListener = new PopupListener(this);
159 /** A tree that represents the current metadata sets associated with this collection. */
160 private SmarterTree mds_tree = null;
161 private String current_collection_file = null;
162 private String dialog_options[] = null;
163 private boolean atLeastOneSetChanged = false;
164
165 static public void main(String[] args)
166 {
167 // Parse arguments
168 GetOpt go = new GetOpt(args);
169 //org.w3c.dom.Document attiladoc = Utility.parse(new String("xml/languages.xml"),false);
170
171 // attiladoc.getAttributes();
172 // attiladoc.getAttributes();
173 //System.out.println(attiladoc.getLocalName());
174 //for(int k = 0; k < nnm.getLength(); k++) {
175 // System.out.println("My lang: " + nnm.item(k).toString());
176
177 // }
178 // Debugging control
179 // Configuration.setLocale("general.locale", true, new Locale("ar"));
180
181 if (go.debug) {
182 DebugStream.enableDebugging();
183
184 Calendar now = Calendar.getInstance();
185 String debug_file_path = "debug" + now.get(Calendar.DATE) + "-" + now.get(Calendar.MONTH) + "-" + now.get(Calendar.YEAR) + ".txt";
186
187 // Debug file is created in the GLI directory
188 DebugStream.println("Debug file path: " + debug_file_path);
189 DebugStream.setDebugFile(debug_file_path);
190 }
191
192 // Load configuration file
193 try {
194
195 config = new Configuration(go.gsdl_path, null, null);
196
197
198 }
199 catch (Exception exception) {
200 DebugStream.printStackTrace(exception);
201 }
202 GEMS GEMS;
203 GEMS = new GEMS(go.gsdl_path);
204 }
205
206
207 /** Constructor.
208 * @param set a MetadataSet that should be initially selected
209 * @param action a systematic action that should be performed
210 */
211 public GEMS(String gsdl_path)
212 {
213 this.dialog_options = new String[2];
214 this.screen_size = config.screen_size;
215 this.self = this;
216 this.gsdl_path = gsdl_path;
217
218 // Initialise some common images
219 Utility.initImages(this);
220
221 // Load help
222 HelpFrame help = new HelpFrame();
223
224 dialog_options[0] = Dictionary.get("General.OK");
225 dialog_options[1] = Dictionary.get("General.Cancel");
226
227 // Creation
228 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
229 setSize(SIZE);
230 setJMenuBar(new GEMSMenuBar());
231 Dictionary.setText(this, "GEMS.Title");
232
233 JPanel content_pane = (JPanel) getContentPane();
234 content_pane.setBackground(config.getColor("coloring.collection_heading_background", false));
235
236 JPanel upper_pane = new JPanel();
237 upper_pane.setOpaque(false);
238
239 // Load all the core metadata sets (in the GLI "metadata" directory)
240 model = new GEMSModel();
241 File metadata_directory = new File(Utility.METADATA_DIR);
242 if (metadata_directory.exists()) {
243 // Load just those .mds files in this directory, and return them
244 File[] directory_files = metadata_directory.listFiles();
245 for (int i = 0; i < directory_files.length; i++) {
246 File child_file = directory_files[i];
247 if (!child_file.isDirectory() && child_file.getName().endsWith(".mds")) {
248 System.err.println("Found mds file: " + child_file);
249 MetadataSet metadata_set = msm.loadMetadataSet(child_file);
250 model.add(null, metadata_set, GEMSNode.SET);
251 }
252 }
253 }
254
255 JPanel mds_tree_pane = new JPanel();
256 mds_tree_pane.setOpaque(false);
257 mds_tree_pane.setPreferredSize(new Dimension(300,500));
258 mds_tree = new SmarterTree(model);
259 mds_tree.setCellRenderer(new GEMSTreeCellRenderer());
260 mds_tree.setRootVisible(false);
261 mds_tree.setBackground(config.getColor("coloring.collection_tree_background", false));
262 mds_tree.setForeground(config.getColor("coloring.collection_tree_foreground", false));
263 mds_tree.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
264 mds_tree.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
265
266 //add popupevent handler for tree items
267
268 mds_tree.addMouseListener(popupListener);
269 details_pane = new JPanel();
270 details_pane.setOpaque(false);
271 card_layout = new CardLayout();
272
273 JPanel set_details_pane = new JPanel();
274 set_details_pane.setOpaque(false);
275
276 JPanel set_name_pane = new JPanel();
277 set_name_pane.setOpaque(false);
278 JLabel set_name_label = new JLabel();
279 set_name_label.setOpaque(false);
280 //Dictionary.setText(set_name_label, "GEMS.Name");
281 set_name = new JLabel();
282 //set_name.setBorder(BorderFactory.createLoweredBevelBorder());
283 //set_name.setOpaque(false);
284
285 JPanel set_attributes_pane = new JPanel();
286 set_attributes_pane.setOpaque(false);
287 set_attributes_scroll = new JScrollPane();
288 set_attributes_scroll.getViewport().setBackground(config.getColor("coloring.collection_tree_background", false));
289 set_attributes_scroll.setOpaque(true);
290 set_attributes = new SmarterTable();
291 set_attributes.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
292 set_attributes.setBackground(config.getColor("coloring.collection_tree_background", false));
293 set_attributes.setForeground(config.getColor("coloring.collection_tree_foreground", false));
294 set_attributes.setHeadingBackground(config.getColor("coloring.collection_heading_background", false));
295 set_attributes.setHeadingForeground(config.getColor("coloring.collection_heading_foreground", false));
296 set_attributes.setOpaque(false);
297 set_attributes.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
298 set_attributes.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
299 set_attributes.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
300 set_attributes.addMouseListener(popupListener);
301 JPanel element_details_pane = new JPanel();
302 element_details_pane.setOpaque(false);
303
304 JPanel element_name_pane = new JPanel();
305 element_name_pane.setOpaque(false);
306 JLabel element_name_label = new JLabel();
307 element_name_label.setOpaque(false);
308 //Dictionary.setText(element_name_label, "GEMS.Name");
309 //element_name = new JLabel();
310 //element_name.setBorder(BorderFactory.createLoweredBevelBorder());
311 //element_name.setOpaque(false);
312
313 JPanel element_inner_pane = new JPanel();
314 element_inner_pane.setOpaque(false);
315
316 JPanel element_attributes_pane = new JPanel();
317 element_attributes_pane.setOpaque(false);
318 element_attributes_scroll = new JScrollPane();
319 element_attributes_scroll.getViewport().setBackground(config.getColor("coloring.collection_tree_background", false));
320 element_attributes_scroll.setOpaque(true);
321 element_attributes = new SmarterTable();
322 element_attributes.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
323 element_attributes.setBackground(config.getColor("coloring.collection_tree_background", false));
324 element_attributes.setForeground(config.getColor("coloring.collection_tree_foreground", false));
325 element_attributes.setHeadingBackground(config.getColor("coloring.collection_heading_background", false));
326 element_attributes.setHeadingForeground(config.getColor("coloring.collection_heading_foreground", false));
327 element_attributes.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
328 element_attributes.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
329 element_attributes.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
330 element_attributes.addMouseListener(popupListener);
331
332 element_values_layout = new CardLayout();
333 element_values_pane = new JPanel();
334 element_values_pane.setOpaque(false);
335 element_values = new SmarterTree();
336 element_values.setBackground(config.getColor("coloring.collection_tree_background", false));
337 element_values.setForeground(config.getColor("coloring.collection_tree_foreground", false));
338 element_values.setRootVisible(false);
339 element_values.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
340 element_values.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
341
342 JPanel element_novalues_pane = new JPanel();
343
344 keep_root_expanded_listener = new KeepTreeRootExpandedListener();
345
346 JPanel profile_details_pane = new JPanel();
347 profile_details_pane.setOpaque(false);
348 JPanel profile_name_pane = new JPanel();
349 profile_name_pane.setOpaque(false);
350 JLabel profile_name_label = new JLabel();
351 profile_name_label.setOpaque(false);
352 //Dictionary.setText(profile_name_label, "GEMS.Name");
353 profile_name = new JLabel();
354 profile_name.setBorder(BorderFactory.createLoweredBevelBorder());
355 profile_name.setOpaque(false);
356
357 JPanel profile_attributes_pane = new JPanel();
358 profile_attributes_pane.setOpaque(false);
359 profile_attributes_scroll = new JScrollPane();
360 profile_attributes_scroll.getViewport().setBackground(config.getColor("coloring.collection_tree_background", false));
361 profile_attributes_scroll.setOpaque(true);
362 profile_attributes = new SmarterTable();
363 profile_attributes.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
364 profile_attributes.setBackground(config.getColor("coloring.collection_tree_background", false));
365 profile_attributes.setForeground(config.getColor("coloring.collection_tree_foreground", false));
366 profile_attributes.setHeadingBackground(config.getColor("coloring.collection_heading_background", false));
367 profile_attributes.setHeadingForeground(config.getColor("coloring.collection_heading_foreground", false));
368 profile_attributes.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
369 profile_attributes.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
370 profile_attributes.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
371
372 JPanel button_pane = new JPanel();
373 button_pane.setOpaque(false);
374
375 JPanel button_label_pane = new JPanel();
376 button_label_pane.setOpaque(false);
377
378 JLabel attribute_label = new JLabel();
379 attribute_label.setOpaque(false);
380 Dictionary.setText(attribute_label, "GEMS.Attribute");
381
382 JLabel element_label = new JLabel();
383 element_label.setOpaque(false);
384 Dictionary.setText(element_label, "GEMS.Element");
385
386 JLabel file_label = new JLabel();
387 file_label.setOpaque(false);
388 Dictionary.setText(file_label, "GEMS.File");
389
390 JLabel set_label = new JLabel();
391 set_label.setOpaque(false);
392 Dictionary.setText(set_label, "GEMS.Set");
393
394 JLabel value_label = new JLabel();
395 value_label.setOpaque(false);
396 Dictionary.setText(value_label, "GEMS.Value");
397
398 JPanel inner_button_pane = new JPanel();
399 inner_button_pane.setOpaque(false);
400 add_attribute = new GLIButton();
401 add_attribute.setMnemonic(KeyEvent.VK_4);
402 Dictionary.setBoth(add_attribute, "GEMS.Add", "GEMS.Add_Attribute_Tooltip");
403 add_element = new GLIButton();
404 add_element.setMnemonic(KeyEvent.VK_3);
405 Dictionary.setBoth(add_element, "GEMS.Add", "GEMS.Add_Element_Tooltip");
406 add_file = new GLIButton();
407 add_file.setMnemonic(KeyEvent.VK_2);
408 Dictionary.setBoth(add_file, "GEMS.Add", "GEMS.Add_File_Tooltip");
409 add_set = new GLIButton();
410 add_set.setMnemonic(KeyEvent.VK_1);
411 Dictionary.setBoth(add_set, "GEMS.Add", "GEMS.Add_Set_Tooltip");
412 add_value = new GLIButton();
413 add_value.setMnemonic(KeyEvent.VK_5);
414 Dictionary.setBoth(add_value, "GEMS.Add", "GEMS.Add_Value_Tooltip");
415
416 edit_attribute = new GLIButton();
417 edit_attribute.setMnemonic(KeyEvent.VK_6);
418 Dictionary.setBoth(edit_attribute, "GEMS.Edit", "GEMS.Edit_Attribute_Tooltip");
419 edit_value = new GLIButton();
420 edit_value.setMnemonic(KeyEvent.VK_7);
421 Dictionary.setBoth(edit_value, "GEMS.Edit", "GEMS.Edit_Value_Tooltip");
422
423 remove_attribute = new GLIButton();
424 remove_attribute.setMnemonic(KeyEvent.VK_MINUS);
425 Dictionary.setBoth(remove_attribute, "GEMS.Remove", "GEMS.Remove_Attribute_Tooltip");
426 remove_element = new GLIButton();
427 remove_element.setMnemonic(KeyEvent.VK_0);
428 Dictionary.setBoth(remove_element, "GEMS.Remove", "GEMS.Remove_Element_Tooltip");
429 remove_file = new GLIButton();
430 remove_file.setMnemonic(KeyEvent.VK_9);
431 Dictionary.setBoth(remove_file, "GEMS.Remove", "GEMS.Remove_File_Tooltip");
432 remove_set = new GLIButton();
433 remove_set.setMnemonic(KeyEvent.VK_8);
434 Dictionary.setBoth(remove_set, "GEMS.Remove", "GEMS.Remove_Set_Tooltip");
435 remove_value = new GLIButton();
436 remove_value.setMnemonic(KeyEvent.VK_EQUALS);
437 Dictionary.setBoth(remove_value, "GEMS.Remove", "GEMS.Remove_Value_Tooltip");
438 //setControls(false, false, false, false, false, false, false, false, false, false, false, false);
439
440 add_element_action_listener = new AddElementActionListener();
441 add_file_action_listener = new AddFileActionListener();
442 add_set_action_listener = new AddSetActionListener();
443
444
445
446 add_or_edit_attribute_action_listener = new AddOrEditAttributeActionListener();
447 add_or_edit_value_action_listener = new AddOrEditValueActionListener();
448 remove_set_action_listener = new RemoveSetActionListener();
449
450 // Some blank panel
451 JPanel blank_pane = new JPanel();
452 blank_pane.setOpaque(false);
453 JPanel edit_file_pane = new JPanel();
454 edit_file_pane.setOpaque(false);
455 JPanel edit_element_pane = new JPanel();
456 edit_element_pane.setOpaque(false);
457 JPanel edit_set_pane = new JPanel();
458 edit_set_pane.setOpaque(false);
459
460 // Connection
461 add_attribute.addActionListener(add_or_edit_attribute_action_listener);
462 add_element.addActionListener(add_element_action_listener);
463 add_file.addActionListener(add_file_action_listener);
464 add_set.addActionListener(add_set_action_listener);
465 add_value.addActionListener(add_or_edit_value_action_listener);
466 edit_attribute.addActionListener(add_or_edit_attribute_action_listener);
467 edit_value.addActionListener(add_or_edit_value_action_listener);
468 remove_attribute.addActionListener(new RemoveAttributeActionListener());
469 remove_element.addActionListener(new RemoveElementActionListener());
470 remove_file.addActionListener(new RemoveFileActionListener());
471 remove_set.addActionListener(remove_set_action_listener);
472 remove_value.addActionListener(new RemoveValueActionListener());
473 element_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(element_attributes));
474 profile_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(profile_attributes));
475 set_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(set_attributes));
476 //element_values.addTreeSelectionListener(new ElementValuesTreeSelectionListener());
477 mds_tree.addTreeSelectionListener(new MDSTreeSelectionListener());
478 // Layout
479 mds_tree_pane.setLayout(new BorderLayout());
480 mds_tree_pane.add(new JScrollPane(mds_tree), BorderLayout.CENTER);
481
482 set_name_pane.setLayout(new BorderLayout());
483 set_name_pane.add(set_name_label, BorderLayout.WEST);
484 set_name_pane.add(set_name, BorderLayout.CENTER);
485
486 set_attributes_scroll.setViewportView(set_attributes);
487
488 set_attributes_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Attributes")), BorderFactory.createEmptyBorder(2,2,2,2)));
489 set_attributes_pane.setLayout(new BorderLayout());
490 set_attributes_pane.add(set_attributes_scroll, BorderLayout.CENTER);
491
492 set_details_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Set_Details")), BorderFactory.createEmptyBorder(2,2,2,2)));
493 set_details_pane.setLayout(new BorderLayout());
494 set_details_pane.add(set_name_pane, BorderLayout.NORTH);
495 set_details_pane.add(set_attributes_pane, BorderLayout.CENTER);
496
497 element_name_pane.setLayout(new BorderLayout());
498 //element_name_pane.add(element_name_label, BorderLayout.WEST);
499 //element_name_pane.add(element_name, BorderLayout.CENTER);
500
501 element_attributes_scroll.setViewportView(element_attributes);
502
503 element_attributes_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Attributes")), BorderFactory.createEmptyBorder(2,2,2,2)));
504 element_attributes_pane.setLayout(new BorderLayout());
505 element_attributes_pane.add(element_attributes_scroll, BorderLayout.CENTER);
506
507 element_values_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Values")), BorderFactory.createEmptyBorder(2,2,2,2)));
508 element_values_pane.setLayout(new BorderLayout());
509 element_values_pane.add(new JScrollPane(element_values), BorderLayout.CENTER);
510 element_values_pane.setLayout(element_values_layout);
511 //element_values_pane.add(element_novalues_pane, BLANK);
512 //element_values_pane.add(new JScrollPane(element_values), VALUES);
513
514 element_inner_pane.setLayout(new BorderLayout());
515 element_inner_pane.add(element_attributes_pane);
516 //element_inner_pane.add(element_values_pane);
517
518 element_details_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Element_Details")), BorderFactory.createEmptyBorder(2,2,2,2)));
519 element_details_pane.setLayout(new BorderLayout());
520 //element_details_pane.add(element_name_pane, BorderLayout.NORTH);
521 element_details_pane.add(element_inner_pane, BorderLayout.CENTER);
522
523 profile_name_pane.setLayout(new BorderLayout());
524 profile_name_pane.add(profile_name_label, BorderLayout.WEST);
525 profile_name_pane.add(profile_name, BorderLayout.CENTER);
526
527 profile_attributes_scroll.setViewportView(profile_attributes);
528
529 profile_attributes_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Profiles")), BorderFactory.createEmptyBorder(2,2,2,2)));
530 profile_attributes_pane.setLayout(new BorderLayout());
531 profile_attributes_pane.add(profile_attributes_scroll, BorderLayout.CENTER);
532
533 profile_details_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Profile_Details")), BorderFactory.createEmptyBorder(2,2,2,2)));
534 profile_details_pane.setLayout(new BorderLayout());
535 //profile_details_pane.add(profile_name_pane, BorderLayout.NORTH);
536 profile_details_pane.add(profile_attributes_pane, BorderLayout.CENTER);
537
538 details_pane.setBorder(BorderFactory.createEmptyBorder(0,5,0,0));
539 details_pane.setLayout(card_layout);
540 details_pane.add(blank_pane, BLANK);
541 details_pane.add(set_details_pane, SET);
542 details_pane.add(element_details_pane, ELEMENT);
543 details_pane.add(profile_details_pane, PROFILE);
544
545 upper_pane.setLayout(new BorderLayout());
546 upper_pane.add(mds_tree_pane, BorderLayout.WEST);
547 upper_pane.add(details_pane, BorderLayout.CENTER);
548
549 button_label_pane.setLayout(new GridLayout(4,1,0,2));
550 button_label_pane.setBorder(BorderFactory.createEmptyBorder(0,0,0,2));
551 //button_label_pane.add(set_label);
552 // button_label_pane.add(file_label);
553 //button_label_pane.add(element_label);
554 //button_label_pane.add(attribute_label);
555 //button_label_pane.add(value_label);
556
557 inner_button_pane.setLayout(new GridLayout(4,3,0,2));
558 //inner_button_pane.add(add_set);
559 //inner_button_pane.add(edit_set_pane);
560 //inner_button_pane.add(remove_set);
561
562 //inner_button_pane.add(add_file);
563 //inner_button_pane.add(edit_file_pane);
564 // inner_button_pane.add(remove_file);
565
566 //inner_button_pane.add(add_element);
567 //inner_button_pane.add(edit_element_pane);
568 //inner_button_pane.add(remove_element);
569 //inner_button_pane.add(add_attribute);
570 //inner_button_pane.add(edit_attribute);
571 //inner_button_pane.add(remove_attribute);
572 //inner_button_pane.add(add_value);
573 //inner_button_pane.add(edit_value);
574 //inner_button_pane.add(remove_value);
575
576 button_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
577 button_pane.setLayout(new BorderLayout());
578 //button_pane.add(button_label_pane, BorderLayout.WEST);
579 //button_pane.add(inner_button_pane, BorderLayout.CENTER);
580
581 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
582 content_pane.setLayout(new BorderLayout());
583 content_pane.add(upper_pane, BorderLayout.CENTER);
584 content_pane.add(button_pane, BorderLayout.SOUTH);
585
586 // initialise the selection
587 mds_tree.setSelectionRow(0);
588 // Display
589 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
590 setVisible(true);
591 }
592
593
594 private void exit()
595 {
596 // Flush debug
597 //System.out.println("Final exit func");
598 DebugStream.closeDebugStream();
599 if(atLeastOneSetChanged == true) {
600
601 int result = JOptionPane.showOptionDialog(self, Dictionary.get("GEMS.Menu.Confirm_Exit_Save", Dictionary.get("GEMS.Element")), Dictionary.get("GEMS.Menu.Confirm_Exit_Save_Title"), JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, dialog_options, dialog_options[0]);
602
603 // System.out.println("Exit: "+result);
604 if(result == 0) {
605 msm.save();
606 }
607
608 }
609
610 System.exit(0);
611 }
612
613
614 private class GEMSMenuBar
615 extends JMenuBar
616 implements ActionListener
617 {
618 private JMenu file = null;
619 private JMenu edit = null;
620 private JMenu help = null;
621
622 public JMenuItem file_exit = null;
623 public JMenuItem file_new = null;
624 public JMenuItem file_open = null;
625 public JMenuItem file_save = null;
626 public JMenuItem edit_copy = null;
627 public JMenuItem edit_cut = null;
628 public JMenuItem edit_paste = null;
629 public JMenuItem help_help = null;
630 public JMenuItem file_delete = null;
631 public JMenuItem file_preferences = null;
632 public GEMSMenuBar()
633 {
634 file = new JMenu();
635 file.setMnemonic(KeyEvent.VK_F);
636 Dictionary.registerText(file, "Menu.File");
637
638 file_exit = new JMenuItem();
639 file_exit.addActionListener(this);
640 file_exit.setMnemonic(KeyEvent.VK_X);
641 Dictionary.registerText(file_exit, "Menu.File_Exit");
642
643 file_new = new JMenuItem();
644 file_new.addActionListener(this);
645 file_new.setMnemonic(KeyEvent.VK_N);
646 Dictionary.registerText(file_new, "Menu.File_New");
647
648 file_open = new JMenuItem();
649 file_open.addActionListener(this);
650 file_open.setMnemonic(KeyEvent.VK_O);
651 Dictionary.registerText(file_open, "Menu.File_Open");
652
653 file_save = new JMenuItem();
654 file_save.addActionListener(this);
655 file_save.setMnemonic(KeyEvent.VK_S);
656 // Dictionary.registerText(file_save, "GEMS.Menu.File_Save");
657 Dictionary.registerText(file_save, "Menu.File_Save");
658
659 file_delete = new JMenuItem();
660 file_delete.addActionListener(new RemoveSetActionListener());
661 file_delete.setMnemonic(KeyEvent.VK_S);
662 // Dictionary.registerText(file_delete, "GEMS.Menu.File_Delete");
663 Dictionary.registerText(file_delete, "Menu.File_Delete");
664
665 file_preferences = new JMenuItem();
666 file_preferences.addActionListener(this);
667 file_preferences.setMnemonic(KeyEvent.VK_S);
668 //Dictionary.registerText(file_preferences, "GEMS.Menu.File_Preferences");
669 Dictionary.registerText(file_preferences, "Menu.File_Options");
670
671 // Layout (file menu)
672 file.add(file_new);
673 file.add(file_open);
674 file.add(file_save);
675 file.add(file_delete);
676 file.add(new JSeparator());
677 file.add(file_preferences);
678 file.add(new JSeparator());
679 file.add(file_exit);
680
681 // Edit menu
682 edit = new JMenu();
683 edit.setMnemonic(KeyEvent.VK_E);
684 Dictionary.registerText(edit, "Menu.Edit");
685
686 edit_cut = new JMenuItem();
687 edit_cut.addActionListener(this);
688 edit_cut.setMnemonic(KeyEvent.VK_X);
689 Dictionary.registerText(edit_cut, "Menu.Edit_Cut");
690
691 edit_copy = new JMenuItem();
692 edit_copy.addActionListener(this);
693 edit_copy.setMnemonic(KeyEvent.VK_C);
694 Dictionary.registerText(edit_copy, "Menu.Edit_Copy");
695
696 edit_paste = new JMenuItem();
697 edit_paste.addActionListener(this);
698 edit_paste.setMnemonic(KeyEvent.VK_V);
699 Dictionary.registerText(edit_paste, "Menu.Edit_Paste");
700
701 // Layout (edit menu)
702 edit.add(edit_cut);
703 edit.add(edit_copy);
704 edit.add(edit_paste);
705
706 // Help menu
707 help = new JMenu();
708 help.setIcon(Utility.HELP_ICON);
709 Dictionary.setText(help, "GEMS.Menu.Help");
710
711 help_help = new JMenuItem();
712 help_help.addActionListener(this);
713 Dictionary.registerText(help_help, "GEMS.Menu.Help");
714
715 // Layout (help menu)
716 help.add(help_help);
717
718 // Layout (menu bar)
719 this.add(file);
720 this.add(Box.createHorizontalStrut(15));
721 this.add(edit);
722 this.add(Box.createHorizontalGlue());
723 //this.add(help);
724 }
725
726
727 public void actionPerformed(ActionEvent event)
728 {
729 Object event_source = event.getSource();
730
731 // File -> New
732 if (event_source == file_new) {
733 add_set.doClick();
734 // set_changed = true;
735 return;
736 }
737
738 // File -> Open
739 if (event_source == file_open) {
740
741 //we first launch the dialog to determine where the jfilechooser should be opened
742 //ie: for collection specific sets - attila dec10-04
743 String set_directory = Utility.METADATA_DIR;
744
745 SetSelectionDialog m = new SetSelectionDialog();
746 m.show();
747
748 //once we have clicked 'ok' on the jdialog above, then we should have
749 //the directory pointer in string set_directory...and pass it to the jfilechoose constru
750
751
752 return;
753 }
754
755 // File -> Save
756 if (event_source == file_save) {
757 msm.save();
758 atLeastOneSetChanged = false;
759 return;
760 }
761
762 // File -> Exit
763 if (event_source == file_exit) {
764 exit();
765 /*
766 if(set_changed == true) {
767 int result = JOptionPane.showOptionDialog(self, Dictionary.get("GEMS.Menu.Confirm_Exit_Save", Dictionary.get("GEMS.Element")), Dictionary.get("GEMS.Menu.Confirm_Exit_Save_Title"), JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, dialog_options, dialog_options[0]);
768
769 // System.out.println("Exit: "+result);
770 if(result == 0) {
771 msm.save();
772 exit();
773 }
774 else{
775 exit();
776 }
777
778 }
779 else{
780
781 exit();
782 }*/
783 }
784
785 // Edit -> Cut
786 if(event_source == file_preferences){
787 GEMSPreferences GemsPreferences = new GEMSPreferences();
788
789
790 }
791 if (event_source == edit_cut) {
792 try {
793 KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
794 // Get the component with selected text as a JTextComponent
795 JTextComponent text = (JTextComponent) kfm.getPermanentFocusOwner();
796 // Cut the text to the clipboard
797 text.cut();
798 }
799 catch (ClassCastException cce) {
800 // If the component is not a text component ignore the cut command
801 DebugStream.println(cce.toString());
802 }
803 return;
804 }
805
806 // Edit -> Copy
807 if (event_source == edit_copy) {
808 try {
809 KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
810 // Get the component with selected text as a JTextComponent
811 JTextComponent text = (JTextComponent) kfm.getPermanentFocusOwner();//getFocusOwner();
812 text.copy();
813 }
814 catch (Exception cce) {
815 // If the component is not a text component ignore the copy command
816 DebugStream.println(cce.toString());
817 }
818 return;
819 }
820
821 // Edit -> Paste
822 if (event_source == edit_paste) {
823 try {
824 KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
825 // Get the component with selected text as a JTextComponent
826 JTextComponent text = (JTextComponent) kfm.getPermanentFocusOwner();
827 // Cut the text to the clipboard
828 text.paste();
829 }
830 catch (ClassCastException cce) {
831 // If the component is not a text component ignore the paste command
832 DebugStream.println(cce.toString());
833 }
834 return;
835 }
836
837 // Help -> Help
838 if (event_source == help_help) {
839 HelpFrame.setView("editingmetadatasets");
840 return;
841 }
842 }
843 }
844
845
846 private class MetadataSetFileFilter
847 extends FileFilter
848 {
849 public boolean accept(File file)
850 {
851 String file_name = file.getName().toLowerCase();
852 if (file_name.endsWith(".mds") || file_name.indexOf(".") == -1) {
853 return true;
854 }
855
856 return false;
857 }
858
859
860 public String getDescription()
861 {
862 return Dictionary.get("MetadataSet.Files");
863 }
864 }
865
866
867 private class ActionTask
868 extends Thread {
869 private int action;
870 public ActionTask(int action) {
871 this.action = action;
872 }
873 public void run() {
874 boolean complete = false;
875 while(!complete) {
876 if(self.isVisible()) {
877 switch(action) {
878 case ADD_SET:
879 add_set_action_listener.actionPerformed(new ActionEvent(this, 0, "Blarg!"));
880 break;
881 case REMOVE_SET:
882 if(!mds_tree.isSelectionEmpty()) {
883 remove_set_action_listener.actionPerformed(new ActionEvent(this, 0, "Blarg!"));
884 }
885 break;
886 }
887 complete = true;
888 }
889 else {
890 try {
891 synchronized(this) {
892 wait(100);
893 }
894 }
895 catch(Exception exception) {
896 }
897 }
898 }
899 }
900 }
901 //callback method
902 protected void processWindowEvent(WindowEvent evt){
903
904 if(evt.getID() == WindowEvent.WINDOW_CLOSING){
905
906 exit();
907 }
908
909
910 }
911 //called from MetadataSetManager...I don't think it should be here anymore, but for now it's ok
912
913 public void warn_cant_load_set(){
914 JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Already_Loaded_Set_Error"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
915 }
916 public void dispose() {
917
918
919 //if anything has changed, warn user that they should save
920 if(atLeastOneSetChanged == true) {
921
922 int result = JOptionPane.showOptionDialog(self, Dictionary.get("GEMS.Menu.Confirm_Exit_Save", Dictionary.get("GEMS.Element")), Dictionary.get("GEMS.Menu.Confirm_Exit_Save_Title"), JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, dialog_options, dialog_options[0]);
923 // System.out.println("Exit: "+result);
924 if(result == 0) {
925 msm.save();
926
927 }
928 }
929 atLeastOneSetChanged = false;
930 // Destructor
931 card_layout = null;
932 screen_size = null;
933 self = null;
934 add_attribute = null;
935 add_element = null;
936 add_file = null;
937 add_set = null;
938 add_value = null;
939 edit_attribute = null;
940 edit_value = null;
941 remove_attribute = null;
942 remove_element = null;
943 remove_file = null;
944 remove_set = null;
945 remove_value = null;
946 details_pane = null;
947 element_attributes = null;
948 set_attributes = null;
949 element_name = null;
950 set_name = null;
951 element_values = null;
952 mds_tree = null;
953 target = null;
954
955 popupListener = null;
956 // Dispose of inner dialogs
957 if (add_element_action_listener != null) {
958 add_element_action_listener.dispose();
959 add_element_action_listener = null;
960 }
961 if (add_or_edit_attribute_action_listener != null) {
962 add_or_edit_attribute_action_listener.dispose();
963 add_or_edit_attribute_action_listener = null;
964 }
965 if (add_or_edit_value_action_listener != null) {
966 add_or_edit_value_action_listener.dispose();
967 add_or_edit_value_action_listener = null;
968 }
969 remove_set_action_listener = null;
970
971 //close
972 super.dispose();
973 }
974
975
976 private void setControls(boolean a_s, boolean r_s, boolean a_f, boolean r_f, boolean a_e, boolean r_e, boolean a_a, boolean e_a, boolean r_a, boolean a_v, boolean e_v, boolean r_v) {
977 add_attribute.setEnabled(a_a);
978 add_element.setEnabled(a_e);
979 add_file.setEnabled(true); // Always true
980 add_set.setEnabled(true); // Always true
981 add_value.setEnabled(a_v);
982 edit_attribute.setEnabled(e_a);
983 edit_value.setEnabled(e_v);
984 remove_attribute.setEnabled(r_a);
985 remove_element.setEnabled(r_e);
986 remove_file.setEnabled(r_f);
987 remove_set.setEnabled(r_s);
988 remove_value.setEnabled(r_v);
989 }
990
991 private class AddOrEditAttributeActionListener
992 extends ModalDialog
993 implements ActionListener {
994 private boolean add_type = true;
995 private ComboArea value = null;
996 private JButton cancel_button = null;
997 private JButton ok_button = null;
998 private JComboBox language_box = null;
999 private GComboBox name = null;
1000 private HashMap name_to_values = null;
1001 private JLabel target = null;
1002 private Vector attributeLists = null;
1003
1004
1005 //org.w3c.dom.Document lang = Utility.parse("/home/arosmain/gsdl/gli/classes/xml/languages.xml", false);
1006 org.w3c.dom.Document lang = Utility.parse(Configuration.gsdl_path + "/gli/classes/xml/languages.xml", false);
1007
1008 /** Constructor. */
1009 public AddOrEditAttributeActionListener() {
1010 super(self);
1011 setModal(true);
1012 attributeLists = new Vector();
1013 //
1014 attributeLists.add("identifier");
1015 attributeLists.add("comment");
1016 attributeLists.add("definition");
1017 attributeLists.add("name");
1018
1019 attributeLists.add("creator");
1020 attributeLists.add("date");
1021 attributeLists.add("contact");
1022 attributeLists.add("family");
1023
1024 attributeLists.add("lastchanged");
1025 attributeLists.add("language_dependant");
1026 attributeLists.add("version");
1027 attributeLists.add("datatype");
1028
1029 attributeLists.add("obligation");
1030 attributeLists.add("maximum_occurence");
1031 attributeLists.add("registration_authority");
1032
1033
1034 //
1035 setSize(ADD_OR_EDIT_ATTRIBUTE_SIZE);
1036 name_to_values = new HashMap();
1037
1038 // Creation
1039 JPanel content_pane = (JPanel) getContentPane();
1040 content_pane.setBackground(config.getColor("coloring.collection_heading_background", false));
1041 JPanel upper_pane = new JPanel();
1042 upper_pane.setOpaque(false);
1043
1044 JPanel labels_pane = new JPanel();
1045 JPanel boxes_pane = new JPanel();
1046
1047 JLabel target_label = new JLabel();
1048 target_label.setOpaque(false);
1049 Dictionary.setText(target_label, "GEMS.Target");
1050 target = new JLabel();
1051 target.setOpaque(false);
1052
1053 JLabel name_label = new JLabel();
1054 name_label.setOpaque(false);
1055 Dictionary.setText(name_label, "GEMS.Name");
1056 name = new GComboBox();
1057 name.setEditable(true);
1058 Dictionary.setTooltip(name, "GEMS.Attribute_Name_Tooltip");
1059
1060 JLabel language_label = new JLabel();
1061 language_label.setOpaque(false);
1062 Dictionary.setText(language_label, "GEMS.Language");
1063 language_box = new JComboBox(); // !!! Gatherer.g_man.design_pane.getLanguageCodes().toArray());
1064
1065
1066 for(int n = 0; n < attributeLists.size(); n++){
1067
1068 name.add(attributeLists.get(n));
1069
1070 }
1071 // org.w3c.dom.Element myelem = new org.w3c.dom.Element();
1072
1073 // LanguageManager languageManager = new LanguageManager(myelem);
1074
1075
1076 // !!! language_box.setRenderer(new LanguageListCellRenderer());
1077 Dictionary.setTooltip(language_box, "GEMS.Attribute_Language_Tooltip");
1078
1079 JPanel center_pane = new JPanel();
1080 center_pane.setOpaque(false);
1081 value = new ComboArea(Dictionary.get("GEMS.Values"), COMPONENT_SIZE);
1082 value.setOpaque(false);
1083
1084 JTextArea v_text_area = (JTextArea) value.getTextComponent();
1085 v_text_area.setBackground(config.getColor("coloring.collection_tree_background", false));
1086 v_text_area.setForeground(config.getColor("coloring.collection_tree_foreground", false));
1087 v_text_area.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
1088 v_text_area.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
1089 Dictionary.setTooltip(v_text_area, "GEMS.Attribute_Value_Tooltip");
1090
1091 JPanel button_pane = new JPanel();
1092 button_pane.setOpaque(false);
1093 ok_button = new GLIButton();
1094 ok_button.setMnemonic(KeyEvent.VK_O);
1095 Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
1096 cancel_button = new GLIButton();
1097 cancel_button.setMnemonic(KeyEvent.VK_C);
1098 Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
1099
1100 // Connection
1101 TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button);
1102 cancel_button.addActionListener(this);
1103 name.addActionListener(this);
1104 ok_button.addActionListener(this);
1105 ok_button_enabler.add((JTextComponent)name.getEditor()); // Assuming the default editor is a JTextField!
1106
1107 // Layout
1108 labels_pane.setLayout(new GridLayout(3,1,0,5));
1109 labels_pane.add(target_label);
1110 labels_pane.add(name_label);
1111 labels_pane.add(language_label);
1112
1113 boxes_pane.setLayout(new GridLayout(3,1,0,5));
1114 boxes_pane.add(target);
1115 boxes_pane.add(name);
1116 boxes_pane.add(language_box);
1117
1118 upper_pane.setLayout(new BorderLayout(5,0));
1119 upper_pane.add(labels_pane, BorderLayout.WEST);
1120 upper_pane.add(boxes_pane, BorderLayout.CENTER);
1121
1122 value.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
1123
1124 button_pane.setLayout(new GridLayout(1,2,5,0));
1125 button_pane.add(ok_button);
1126 button_pane.add(cancel_button);
1127
1128 center_pane.setLayout(new BorderLayout());
1129 center_pane.add(value, BorderLayout.CENTER);
1130 center_pane.add(button_pane, BorderLayout.SOUTH);
1131
1132 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
1133 content_pane.setLayout(new BorderLayout());
1134 content_pane.add(upper_pane, BorderLayout.NORTH);
1135 content_pane.add(center_pane, BorderLayout.CENTER);
1136
1137 setLocation((config.screen_size.width - ADD_OR_EDIT_ATTRIBUTE_SIZE.width) / 2, (config.screen_size.height - ADD_OR_EDIT_ATTRIBUTE_SIZE.height) / 2);
1138
1139
1140 // create dom object for language_Box
1141 //GEMSLanguageManager GemsLangManager = new GEMSLanguageManager("/home/arosmain/gsdl/gli/classes/xml/languages.xml");
1142 GEMSLanguageManager GemsLangManager = new GEMSLanguageManager(Configuration.gsdl_path + "/gli/classes/xml/languages.xml");
1143
1144 Vector languagecodes = GemsLangManager.getLanguageCodes();
1145
1146 for(int p = 0; p < languagecodes.size(); p++){
1147
1148 language_box.addItem(languagecodes.get(p).toString());
1149 }
1150
1151 String code = Configuration.getLanguage();
1152 language_box.setSelectedItem(code);
1153 //System.out.println(code);
1154 }
1155 /** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to add a new attribute to the selected set or element.
1156 * @param event An <strong>ActionEvent</strong> containing information about the event.
1157 */
1158
1159
1160 public void actionPerformed(ActionEvent event) {
1161 Object source = event.getSource();
1162 AttributeTableModel tablemodel;
1163 String prevLang = new String("");
1164 String prevValue = new String("");
1165
1166 //allow user to choose language when they create attr
1167
1168
1169
1170
1171 if(source == popupListener.menuAddAttributeAttribute) {
1172 add_type = true;
1173 language_box.setEnabled(true);
1174 }//end if source== menuaddattributeattribute
1175 else if (source == popupListener.menuEditValue){
1176 add_type = false;
1177 //grab the table model based on what is currently selected
1178 switch(current_attribute_type) {
1179 case GEMSNode.COLLECTION:
1180 tablemodel = (AttributeTableModel) profile_attributes.getModel();
1181 //String prevLang = tablemodel.getValueAt(current_attribute,0).toString();
1182 //String prevValue = tablemodel.getValueAt(current_attribute,1).toString();
1183
1184 break;
1185 case GEMSNode.SET:
1186 tablemodel = (AttributeTableModel) set_attributes.getModel();
1187 //grab value in table(
1188 prevLang = tablemodel.getValueAt(current_attribute,0).toString();
1189 prevValue = tablemodel.getValueAt(current_attribute,1).toString();
1190
1191 break;
1192 case GEMSNode.ELEMENT:
1193 tablemodel = (AttributeTableModel) element_attributes.getModel();
1194 //grab values in table( lang and value)
1195 prevLang = tablemodel.getValueAt(current_attribute,1).toString();
1196 prevValue = tablemodel.getValueAt(current_attribute,2).toString();
1197
1198 break;
1199 default:
1200 //by default grab element_attr's
1201 tablemodel = (AttributeTableModel) element_attributes.getModel();
1202 prevLang = tablemodel.getValueAt(current_attribute,1).toString();
1203 prevValue = tablemodel.getValueAt(current_attribute,2).toString();
1204
1205 break;
1206 }
1207 language_box.setEnabled(false);
1208
1209 //if a set attr is selected, then do not do any lang operations, other than setting index to -1
1210 if(current_attribute_type != GEMSNode.SET) {
1211
1212 //set the current language to show up in language_box(no lang if no lang specified)
1213 if(prevLang == null || prevLang.compareTo(" ")==0 || prevLang.compareTo("") == 0 || prevLang.compareTo(" ")==0) {
1214 language_box.setSelectedIndex(-1);
1215
1216 }
1217 else {
1218 language_box.setSelectedItem(prevLang.toLowerCase());
1219 }
1220 }// end currattr != GEMSnode.set
1221 else {
1222
1223 language_box.setSelectedIndex(-1);
1224
1225 }// end currattr == GEMSnode.set
1226
1227 value.setText(prevValue);
1228
1229 }//end if source == popupListener.menuEditValue)
1230 ///////////////////////////////////////////////
1231 if(source == ok_button) {
1232 boolean success = true;
1233 AttributeTableModel model;
1234
1235 // Add or edit a collect/set/element attribute
1236 switch(current_attribute_type) {
1237 case GEMSNode.COLLECTION:
1238 model = (AttributeTableModel) profile_attributes.getModel();
1239 success = addOrEditCollectionAttribute(model);
1240 break;
1241 case GEMSNode.SET:
1242 model = (AttributeTableModel) set_attributes.getModel();
1243 success = addOrEditSetAttribute(model);
1244
1245 break;
1246 case GEMSNode.ELEMENT:
1247 model = (AttributeTableModel) element_attributes.getModel();
1248 success = addOrEditElementAttribute(model);
1249 break;
1250 }
1251
1252 if (success) {
1253 // Hide dialog
1254
1255 setVisible(false);
1256 return;
1257 }
1258 }
1259 else if(source == cancel_button) {
1260 // Hide dialog
1261 setVisible(false);
1262 return;
1263 }
1264 else if(source == name) {
1265 Object object = name.getSelectedItem();
1266 if(object != null) {
1267 java.util.List values = (java.util.List) name_to_values.get(object.toString());
1268 if(values == null && current_attribute_type==GEMSNode.COLLECTION) {
1269 values = msm.getElements();
1270 }
1271
1272 if(value != null && values != null){
1273 value.clear();
1274 for(int i = 0; i < values.size(); i++) {
1275 value.add(values.get(i));
1276 }
1277 }
1278 }
1279 }
1280 else if (source == popupListener.menuAddAttributeAttribute){
1281
1282 for(int i = 0; i < attributeLists.size(); i++) {
1283 name.add(attributeLists.get(i).toString());
1284
1285 }
1286 name.setEnabled(true);
1287 }
1288 /* else if (source == popupListener.menuAddAttributeAttribute){
1289 System.out.println("add attr\n");
1290
1291 name.setEnabled(true);
1292
1293 }*/
1294 /* else{
1295 // Name combo box is enabled except when attributes are edited
1296 //name.setEnabled((source != popupListener.menuEditValue));
1297 //System.out.println("elsed");
1298 name_to_values.clear();
1299 name.clear();
1300 value.clear();
1301 value.setText("");
1302 // Build the correct name_to_values mapping
1303 // Attributes are slightly tricky as they can come from several sources. Has a collection file been selected...
1304 if(current_collection_file != null) {
1305 target.setText(current_collection_file);
1306 // Name is empty in this one, however values must be the current elements in the collection.
1307 language_box.setEnabled(false);
1308 }
1309 // or has an element been selected
1310 else if(current_element != null) {
1311 target.setText(current_element.toString());
1312 // Develop a model for name based on known attributes from all other elements.
1313 java.util.List elements = msm.getElements();
1314 for(int i = 0; i < elements.size(); i++) {
1315 ElementWrapper element = (ElementWrapper) elements.get(i);
1316 TreeSet attributes = element.getAttributes();
1317 for(Iterator attribute_iterator = attributes.iterator(); attribute_iterator.hasNext(); ) {
1318 Attribute attribute = (Attribute) attribute_iterator.next();
1319 java.util.List values = (java.util.List) name_to_values.get(attribute.name);
1320 if(values == null) {
1321 values = new ArrayList();
1322 name_to_values.put(attribute.name, values);
1323 }
1324 if(!values.contains(attribute.value)) {
1325 values.add(attribute.value);
1326 }
1327 values = null;
1328 attribute = null;
1329 }
1330 attributes = null;
1331 element = null;
1332 }
1333 elements = null;
1334 language_box.setEnabled(true);
1335 }
1336 else if(current_set != null) {
1337 target.setText(current_set.toString());
1338 // Develop a model for name based on known attributes from all other metadata sets. At the same time build a hashmap mapping attribute name to lists of values.
1339 java.util.List sets = msm.getSets();
1340 for(int i = 0; i < sets.size(); i++) {
1341 MetadataSet set = (MetadataSet) sets.get(i);
1342 NamedNodeMap attributes = set.getAttributes();
1343 for(int j = 0; j < attributes.getLength(); j++) {
1344 Attr attribute = (Attr) attributes.item(j);
1345 String name_str = attribute.getName();
1346 String value_str = attribute.getValue();
1347 java.util.List values = (java.util.List) name_to_values.get(name_str);
1348 if(values == null) {
1349 values = new ArrayList();
1350 name_to_values.put(name_str, values);
1351 }
1352 if(!values.contains(value_str)) {
1353 values.add(value_str);
1354 }
1355 values = null;
1356 value_str = null;
1357 name_str = null;
1358 attribute = null;
1359 }
1360 attributes = null;
1361 set = null;
1362 language_box.setEnabled(false);
1363 }
1364 sets = null;
1365 // If this is an add remove all the attributes already present in the current set.
1366 if(source == add_attribute) {
1367 name.setEnabled(true);
1368 NamedNodeMap attributes = current_set.getAttributes();
1369 for(int i = 0; i < attributes.getLength(); i++) {
1370 Attr attribute = (Attr) attributes.item(i);
1371 String name_str = attribute.getName();
1372 name_to_values.remove(name_str);
1373 name_str = null;
1374 attribute = null;
1375 }
1376 attributes = null;
1377 }
1378 }
1379 // Otherwise we actually disable the name combobox
1380 else {
1381 name.setEnabled(false);
1382 }
1383 // Now name_to_values should contain a list of unique attribute names each mapping to a list of attribute values.
1384 for(Iterator name_iterator = name_to_values.keySet().iterator(); name_iterator.hasNext(); ) {
1385 name.add(name_iterator.next());
1386 }
1387 // Now pritty up the dialog depending on the action type
1388 if(source == add_attribute || source == popupListener.menuAddAttributeSet || source == popupListener.menuAddAttributeElement || source == popupListener.menuAddAttributeAttribute) {
1389 add_type = true;
1390 Dictionary.setText(this, "GEMS.AddAttribute");
1391 if(current_collection_file != null) {
1392 // Name is empty in this one, however values must be the current elements in the collection.
1393 java.util.List values = msm.getElements();
1394 for(int i = 0; i < values.size(); i++) {
1395 value.add(new NameElementWrapperEntry(values.get(i)));
1396 }
1397 values = null;
1398 }
1399 setVisible(true);
1400 }*/
1401 // else if(source == popupListener.menuAddAttributeAttribute){
1402
1403 // System.out.println("fromattrib table");
1404 // }
1405 // else if(source == popupListener.menuAddAttributeElement){
1406
1407 // System.out.println("from elements");
1408 // }*/
1409 else if(current_attribute != -1) {
1410
1411 //System.out.println(source.toString()+"\n");
1412 AttributeTableModel model = null;
1413 switch(current_attribute_type) {
1414 case GEMSNode.COLLECTION:
1415 model = (AttributeTableModel) profile_attributes.getModel();
1416 break;
1417 case GEMSNode.ELEMENT:
1418 model = (AttributeTableModel) element_attributes.getModel();
1419 break;
1420 case GEMSNode.SET:
1421 model = (AttributeTableModel) set_attributes.getModel();
1422 break;
1423 }
1424 add_type = false;
1425 Dictionary.setText(this, "GEMS.EditAttribute");
1426 String name_str = (String) model.getValueAt(current_attribute, 0);
1427 String value_str = (String) model.getValueAt(current_attribute, model.getColumnCount() - 1);
1428 model = null;
1429 // Retrieve the appropriate value model
1430 java.util.List values = (java.util.List) name_to_values.get(name_str);
1431 // Only possible for collection file selections.
1432 if(values == null) {
1433 values = msm.getElements();
1434 }
1435 name.setSelectedItem(name_str);
1436 name_str = null;
1437 for(int i = 0; i < values.size(); i++) {
1438 Object temp_value = values.get(i);
1439 if(temp_value instanceof ElementWrapper) {
1440 value.add(new NameElementWrapperEntry(temp_value));
1441 }
1442 else {
1443 value.add(temp_value);
1444 }
1445 }
1446 values = null;
1447 value.setSelectedItem(value_str);
1448 value_str = null;
1449
1450 }
1451 // }
1452 setVisible(true);
1453 source = null;
1454 }
1455
1456 private boolean addOrEditCollectionAttribute(AttributeTableModel model)
1457 {
1458 String name_str = name.getSelectedItem().toString();
1459 String value_str = Codec.transform(Codec.transformUnicode(value.getText()), Codec.TEXT_TO_DOM);
1460
1461 // Remove the existing attribute if this is an edit
1462 if(!add_type && current_attribute != -1) {
1463 String old_source = (String) model.getValueAt(current_attribute, 0);
1464 // !!! msm.profiler.removeAction(current_collection_file, old_source);
1465 old_source = null;
1466 model.removeRow(current_attribute);
1467 }
1468
1469 boolean cont = true;
1470 // Check that there isn't already an entry for this attribute
1471 if (!model.contains(name_str, 0)) {
1472 // Add profile
1473 // !!! msm.profiler.addAction(current_collection_file, name_str, value_str);
1474 // Update attribute table
1475 model.add(new Attribute(name_str, value_str));
1476 }
1477 // Otherwise show an error message and do not proceed
1478 else {
1479 cont = false;
1480 JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Attribute_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
1481 }
1482
1483 value_str = null;
1484 name_str = null;
1485 return cont;
1486 }
1487
1488
1489 private boolean addOrEditSetAttribute(AttributeTableModel model)
1490 {
1491 String name_str = name.getSelectedItem().toString();
1492 String value_str = Codec.transform(Codec.transformUnicode(value.getText()), Codec.TEXT_TO_DOM);
1493
1494 // Remove the existing attribute if this is an edit
1495
1496 if(!add_type && current_attribute != -1) {
1497
1498 current_set.removeAttribute(name_str);
1499 // Update attribute table
1500 model.removeRow(current_attribute);
1501 }
1502 current_set.addAttribute(name_str, value_str);
1503 // Update the attribute table
1504 model.add(new Attribute(name_str, value_str));
1505 boolean cont = true;
1506
1507 /* // Check that there isn't already an entry for this attribute
1508 *
1509
1510 if (!model.contains(name_str, 0)) {
1511 // Add the new attribute
1512 current_set.addAttribute(name_str, value_str);
1513 // Update the attribute table
1514 model.add(new Attribute(name_str, value_str));
1515 }
1516 // Otherwise show an error message and do not proceed
1517 else {
1518 cont = false;
1519 JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Attribute_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
1520 }*/
1521
1522 value_str = null;
1523 name_str = null;
1524 return cont;
1525 }
1526
1527
1528 private boolean addOrEditElementAttribute(AttributeTableModel model)
1529 {
1530 // Add the attribute, even if one of the same name already exists. Maybe one day someone would like to enforce the occurance rules but not me and not today.
1531 String name_str = name.getSelectedItem().toString();
1532 String language_code = (String) language_box.getSelectedItem();
1533
1534 String value_str = Codec.transform(Codec.transformUnicode(value.getText()), Codec.TEXT_TO_DOM);
1535
1536 // Remove the existing attribute if this is an edit
1537 if(!add_type && current_attribute != -1) {
1538 Attribute old_attribute = model.getAttribute(current_attribute);
1539 String old_value_str = old_attribute.value;
1540 String old_lang_code = old_attribute.language;
1541 current_element.removeAttribute(name_str, old_lang_code, old_value_str);
1542 // Update the attribute table
1543 model.removeRow(current_attribute);
1544 }
1545
1546 // Add the new attribute
1547 current_element.addAttribute(name_str, language_code, value_str);
1548 // Update the attribute table
1549 int row = model.add(new Attribute(name_str, language_code, value_str));
1550 element_attributes.setRowSelectionInterval(row, row);
1551
1552 value_str = null;
1553 language_code = null;
1554 name_str = null;
1555 return true;
1556 }
1557
1558
1559 public void dispose() {
1560 cancel_button = null;
1561 name = null;
1562 name_to_values = null;
1563 ok_button = null;
1564 target = null;
1565 value = null;
1566 ///ystem.err.println("Dispose AddOrEditAttributeActionListener");
1567 super.dispose();
1568 }
1569 }
1570
1571 private class AddElementActionListener
1572 extends ModalDialog
1573 implements ActionListener {
1574 private JButton cancel_button = null;
1575 private JButton ok_button = null;
1576 private JLabel set_field = null;
1577 private NonWhitespaceField name_field = null;
1578 public AddElementActionListener() {
1579 super(self);
1580 setModal(true);
1581 setSize(ADD_ELEMENT_SIZE);
1582 // Creation
1583 JPanel content_pane = (JPanel) getContentPane();
1584 content_pane.setBackground(config.getColor("coloring.collection_heading_background", false));
1585 JPanel center_pane = new JPanel();
1586 center_pane.setOpaque(false);
1587
1588 JPanel labels_pane = new JPanel();
1589 labels_pane.setOpaque(false);
1590 JLabel set_label = new JLabel();
1591 set_label.setOpaque(false);
1592 Dictionary.setText(set_label, "GEMS.Set");
1593 set_field = new JLabel();
1594 set_field.setOpaque(false);
1595
1596 JPanel values_pane = new JPanel();
1597 values_pane.setOpaque(false);
1598 JLabel name_label = new JLabel();
1599 name_label.setOpaque(false);
1600 Dictionary.setText(name_label, "GEMS.Name");
1601 name_field = new NonWhitespaceField();
1602 name_field.setBackground(config.getColor("coloring.collection_tree_background", false));
1603 name_field.setForeground(config.getColor("coloring.collection_tree_foreground", false));
1604 name_field.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
1605 name_field.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
1606 Dictionary.setTooltip(name_field, "GEMS.Element_Name_Tooltip");
1607
1608 JPanel button_pane = new JPanel();
1609 button_pane.setOpaque(false);
1610
1611 ok_button = new GLIButton();
1612 ok_button.setMnemonic(KeyEvent.VK_O);
1613 Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
1614 cancel_button = new GLIButton();
1615 cancel_button.setMnemonic(KeyEvent.VK_C);
1616 Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
1617
1618 TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button);
1619
1620 // Connection
1621 cancel_button.addActionListener(this);
1622 ok_button.addActionListener(this);
1623 ok_button_enabler.add(name_field);
1624
1625 // Layout
1626 labels_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
1627 labels_pane.setLayout(new GridLayout(2,1));
1628 labels_pane.add(set_label);
1629 labels_pane.add(name_label);
1630
1631 values_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
1632 values_pane.setLayout(new GridLayout(2,1));
1633 values_pane.add(set_field);
1634 values_pane.add(name_field);
1635
1636 center_pane.setLayout(new BorderLayout(5,5));
1637 center_pane.add(labels_pane, BorderLayout.WEST);
1638 center_pane.add(values_pane, BorderLayout.CENTER);
1639
1640 button_pane.setLayout(new GridLayout(1,2,0,5));
1641 button_pane.add(ok_button);
1642 button_pane.add(cancel_button);
1643
1644 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
1645 content_pane.setLayout(new BorderLayout());
1646 content_pane.add(center_pane, BorderLayout.CENTER);
1647 content_pane.add(button_pane, BorderLayout.SOUTH);
1648
1649 setLocation((config.screen_size.width - ADD_ELEMENT_SIZE.width) / 2, (config.screen_size.height - ADD_ELEMENT_SIZE.height) / 2);
1650 }
1651
1652 /** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to
1653 * @param event An <strong>ActionEvent</strong> containing information about the event.
1654 */
1655 public void actionPerformed(ActionEvent event) {
1656 Object source = event.getSource();
1657 if(source == ok_button) {
1658 // Add then dispose
1659 String name_str = Codec.transform(Codec.transformUnicode(name_field.getText()), Codec.TEXT_TO_DOM);
1660 // If this element doesn't already exist.
1661 if(!current_set.containsElement(name_str)) {
1662 // Add it,
1663 String language_code = config.getLanguage();
1664 ElementWrapper element = current_set.addElement(name_str, language_code);
1665 // Then update the tree
1666 model.add(current_node, element, GEMSNode.ELEMENT);
1667 // Signal that the metadata set has changed
1668 // msm.fireSetChanged(current_set);
1669
1670 // Done
1671 element = null;
1672 setVisible(false);
1673
1674 //mark as changed
1675 atLeastOneSetChanged = true;
1676 current_set.setSetChanged(true);
1677
1678 }
1679 // Otherwise show an error message and do not proceed.
1680 else {
1681 JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Element_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
1682 }
1683 name_str = null;
1684 }
1685 else if(source == cancel_button) {
1686 // Dispose
1687 setVisible(false);
1688 }
1689 else {
1690 if(current_set != null) {
1691 // You can't manually add elements to the Greenstone metadata set.
1692 if(!current_set.getNamespace().equals("")) {
1693 set_field.setText(current_set.toString());
1694 name_field.setText("");
1695 // Display
1696 setVisible(true);
1697 }
1698 // Warn the user that they can't do that dave.
1699 else {
1700
1701 JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Cannot_Add_Elements_To_Greenstone_MDS"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
1702 }
1703 }
1704 }
1705 source = null;
1706 }
1707
1708 public void dispose() {
1709 cancel_button = null;
1710 ok_button = null;
1711 name_field = null;
1712 set_field = null;
1713 ///ystem.err.println("Dispose AddElementActionListener");
1714 super.dispose();
1715 }
1716 }
1717
1718 private class AddFileActionListener
1719 extends ModalDialog
1720 implements ActionListener {
1721 private JButton cancel_button = null;
1722 private JButton ok_button = null;
1723 private JTextField name_field = null;
1724 public AddFileActionListener() {
1725 super(self);
1726 setModal(true);
1727 setSize(ADD_FILE_SIZE);
1728 // Creation
1729 JPanel content_pane = (JPanel) getContentPane();
1730 content_pane.setBackground(config.getColor("coloring.collection_heading_background", false));
1731 JPanel center_pane = new JPanel();
1732 center_pane.setOpaque(false);
1733 JPanel profile_pane = new JPanel();
1734 profile_pane.setOpaque(false);
1735 JLabel profile_label = new JLabel();
1736 profile_label.setOpaque(false);
1737 Dictionary.setText(profile_label, "GEMS.Profile");
1738
1739 JPanel name_pane = new JPanel();
1740 name_pane.setOpaque(false);
1741 JLabel name_label = new JLabel();
1742 name_label.setOpaque(false);
1743 Dictionary.setText(name_label, "GEMS.Name");
1744 name_field = new JTextField();
1745 name_field.setBackground(config.getColor("coloring.collection_tree_background", false));
1746 name_field.setForeground(config.getColor("coloring.collection_tree_foreground", false));
1747 name_field.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
1748 name_field.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
1749 Dictionary.setTooltip(name_field, "GEMS.Profile_Name_Tooltip");
1750
1751 JPanel button_pane = new JPanel();
1752 button_pane.setOpaque(false);
1753
1754 ok_button = new GLIButton();
1755 ok_button.setMnemonic(KeyEvent.VK_O);
1756 Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
1757 cancel_button = new GLIButton();
1758 cancel_button.setMnemonic(KeyEvent.VK_C);
1759 Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
1760
1761 TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button);
1762
1763 // Connection
1764 cancel_button.addActionListener(this);
1765 ok_button.addActionListener(this);
1766 ok_button_enabler.add(name_field);
1767
1768 // Layout
1769 profile_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
1770 profile_pane.setLayout(new BorderLayout());
1771 profile_pane.add(profile_label, BorderLayout.CENTER);
1772
1773 name_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,5));
1774 name_pane.setLayout(new BorderLayout(5,0));
1775 name_pane.add(name_label, BorderLayout.WEST);
1776 name_pane.add(name_field, BorderLayout.CENTER);
1777
1778 center_pane.setLayout(new GridLayout(2,1,0,0));
1779 center_pane.add(profile_pane);
1780 center_pane.add(name_pane);
1781
1782 button_pane.setLayout(new GridLayout(1,2,0,5));
1783 button_pane.add(ok_button);
1784 button_pane.add(cancel_button);
1785
1786 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
1787 content_pane.setLayout(new BorderLayout());
1788 content_pane.add(center_pane, BorderLayout.CENTER);
1789 content_pane.add(button_pane, BorderLayout.SOUTH);
1790
1791 setLocation((config.screen_size.width - ADD_FILE_SIZE.width) / 2, (config.screen_size.height - ADD_FILE_SIZE.height) / 2);
1792 }
1793 /** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to
1794 * @param event An <strong>ActionEvent</strong> containing information about the event.
1795 */
1796 public void actionPerformed(ActionEvent event) {
1797 Object source = event.getSource();
1798 if(source == ok_button) {
1799 String name_str = Codec.transform(Codec.transformUnicode(name_field.getText()), Codec.TEXT_TO_DOM);
1800 // Ensure that this source doesn't already exist.
1801// if(!msm.profiler.containsSource(name_str)) {
1802// // Add source with empty hashmap of actions.
1803// msm.profiler.addSource(name_str);
1804// // Add to tree
1805// model.add(model.getProfileNode(), name_str, GEMSNode.COLLECTION);
1806// setVisible(false);
1807// }
1808 // Otherwise warn the user and don't hide the prompt.
1809 // else {
1810 JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.File_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
1811 // }
1812 name_str = null;
1813 }
1814 else if(source == cancel_button) {
1815 setVisible(false);
1816 }
1817 else {
1818 name_field.setText("");
1819 setVisible(true);
1820 }
1821 source = null;
1822 }
1823
1824 public void dispose() {
1825 cancel_button = null;
1826 ok_button = null;
1827 name_field = null;
1828 ///ystem.err.println("Dispose AddFileActionListener");
1829 super.dispose();
1830 }
1831 }
1832
1833 private class AddSetActionListener
1834 extends ModalDialog
1835 implements ActionListener {
1836 private JButton cancel_button = null;
1837 private JButton ok_button = null;
1838 private JTextField name_field = null;
1839 private JTextField namespace_field = null;
1840 private JComboBox existingSetJComboBox = new JComboBox();
1841
1842 public AddSetActionListener() {
1843 super(self);
1844 setModal(true);
1845 setSize(ADD_SET_SIZE);
1846 Dictionary.setText(this, "GEMS.AddSet");
1847
1848 // Creation
1849 JPanel content_pane = (JPanel) getContentPane();
1850 content_pane.setBackground(config.getColor("coloring.collection_heading_background", false));
1851 JPanel center_pane = new JPanel();
1852 center_pane.setOpaque(false);
1853
1854 JPanel label_pane = new JPanel();
1855 JPanel boxes_pane = new JPanel();
1856
1857 JLabel namespace_label = new JLabel();
1858 namespace_label.setOpaque(false);
1859 Dictionary.setText(namespace_label, "GEMS.Namespace");
1860 namespace_field = TransformCharacterTextField.createNamespaceTextField();
1861 namespace_field.setBackground(config.getColor("coloring.collection_tree_background", false));
1862 namespace_field.setForeground(config.getColor("coloring.collection_tree_foreground", false));
1863 namespace_field.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
1864 namespace_field.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
1865 Dictionary.setTooltip(namespace_field, "GEMS.Set_Namespace_Tooltip");
1866
1867 JLabel name_label = new JLabel();
1868 name_label.setOpaque(false);
1869 Dictionary.setText(name_label, "GEMS.Name");
1870 name_field = new JTextField();
1871 name_field.setBackground(config.getColor("coloring.collection_tree_background", false));
1872 name_field.setForeground(config.getColor("coloring.collection_tree_foreground", false));
1873 name_field.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
1874 name_field.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
1875 Dictionary.setTooltip(name_field, "GEMS.Set_Name_Tooltip");
1876
1877 JPanel button_pane = new JPanel();
1878 button_pane.setOpaque(false);
1879
1880 ok_button = new GLIButton();
1881 ok_button.setMnemonic(KeyEvent.VK_O);
1882 Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
1883 cancel_button = new GLIButton();
1884 cancel_button.setMnemonic(KeyEvent.VK_C);
1885 Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
1886 TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button);
1887
1888 // Connection
1889 cancel_button.addActionListener(this);
1890 ok_button.addActionListener(this);
1891 ok_button_enabler.add(name_field);
1892 ok_button_enabler.add(namespace_field);
1893
1894 // Layout
1895 label_pane.setLayout(new GridLayout(3,1));
1896 label_pane.add(name_label);
1897 label_pane.add(namespace_label);
1898 // label_pane.add
1899 // boxes_pane.setLayout(new GridLayout(2,1,0,5));
1900 boxes_pane.setLayout(new GridLayout(3,1));
1901 boxes_pane.add(name_field);
1902 boxes_pane.add(namespace_field);
1903
1904 JLabel inheritJLabel = new JLabel();
1905 Dictionary.setText(inheritJLabel, "GEMS.inheritMetadataSet");
1906
1907 label_pane.add(inheritJLabel);
1908
1909
1910 //add inherit metadata set functionality
1911 // String[] s = msm.getSets().toArray();
1912
1913 //JComboBox existingSetJComboBox = new JComboBox(new String(msm.getSetsForInherit().toArray()));
1914
1915 int getSetsLen = msm.getSets().toArray().length;
1916 Vector theSets = msm.getSets();
1917
1918 for(int k = 0; k < theSets.size(); k++){
1919 MetadataSet ms = (MetadataSet)theSets.elementAt(k);
1920
1921 existingSetJComboBox.addItem(new String(ms.getName() + " #% " + ms.getFile().toString()));
1922
1923 }
1924 //add sets to existingSetJComboBox
1925
1926
1927 //String tempstr = new String();
1928 JLabel dummyl = new JLabel();
1929 Dictionary.setText(dummyl, "GEMS.Add_Set.No_Inherit");
1930
1931
1932
1933 existingSetJComboBox.addItem("Do not inherit");
1934 existingSetJComboBox.setSelectedIndex(getSetsLen);
1935 boxes_pane.add(existingSetJComboBox);
1936
1937 center_pane.setLayout(new BorderLayout(5,0));
1938 center_pane.add(label_pane, BorderLayout.WEST);
1939 center_pane.add(boxes_pane, BorderLayout.CENTER);
1940
1941 button_pane.setLayout(new GridLayout(1,2,0,5));
1942 button_pane.add(ok_button);
1943 button_pane.add(cancel_button);
1944
1945 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
1946 content_pane.setLayout(new BorderLayout());
1947 content_pane.add(center_pane, BorderLayout.CENTER);
1948 content_pane.add(button_pane, BorderLayout.SOUTH);
1949
1950 setLocation((config.screen_size.width - ADD_SET_SIZE.width) / 2, (config.screen_size.height - ADD_SET_SIZE.height) / 2);
1951 }
1952 /** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to
1953 * @param event An <strong>ActionEvent</strong> containing information about the event.
1954 */
1955 private boolean a_set_exists_with_this_namespace(String namespace){
1956 Vector p = msm.getSets();
1957 boolean flag = false;
1958 for(int k = 0; k < p.size(); k++){
1959 MetadataSet s = (MetadataSet)p.get(k);
1960
1961 if(s.getNamespace().compareTo(namespace) == 0){
1962 flag = true;
1963 }
1964
1965 }
1966
1967 return flag;
1968 }
1969 public void actionPerformed(ActionEvent event) {
1970 Object source = event.getSource();
1971
1972
1973 // if(a_set_exists_with_this_namespace(namespace_field.getText()) == false){
1974 if(source == ok_button) {
1975 //this code below handles whether we inherit from an existing set or not
1976
1977 String namespace_str = namespace_field.getText();
1978 String name_str = Codec.transform(Codec.transformUnicode(name_field.getText()), Codec.TEXT_TO_DOM);
1979
1980
1981
1982 if (existingSetJComboBox.getSelectedItem().toString().trim().compareTo("Do not inherit") == 0){
1983
1984 // Ensure the set doesn't already exist
1985 //if(msm.getSet(namespace_str) == null) {
1986 if(a_set_exists_with_this_namespace(namespace_str) == false){
1987
1988
1989
1990 MetadataSet set = msm.addSet(namespace_str, name_str);
1991
1992 //mark as set changed = true
1993 set.setSetChanged(true);
1994 atLeastOneSetChanged = true;
1995
1996 // Update tree.
1997 model.add(null, set, GEMSNode.SET);
1998 // Done
1999 set = null;
2000 setVisible(false);
2001
2002 }
2003 else{
2004
2005 JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Set_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
2006
2007 }
2008 //do not inherit == 0
2009 // Otherwise show a warning.
2010 //else {
2011 // JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Set_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
2012 //}
2013
2014
2015 name_str = null;
2016 namespace_str = null;
2017 }//end do not inherit
2018 else {
2019 //lets grab the metadata we want to inherit from...
2020 String anitem = existingSetJComboBox.getSelectedItem().toString();
2021
2022 // if(msm.getSet(namespace_str) == null) {
2023 if(a_set_exists_with_this_namespace(namespace_field.getText()) == false){
2024
2025 //setup to read the filename from mds file
2026 String [] items = anitem.split("#%");
2027 try {
2028
2029 FileInputStream fstream = new FileInputStream(items[1].trim());
2030 DataInputStream in = new DataInputStream(fstream);
2031 ///////////////
2032
2033 FileOutputStream out;
2034 PrintStream p;
2035 //setup to write to filename from existing file
2036 try {
2037 out = new FileOutputStream(Utility.METADATA_DIR + "/"+ namespace_str + ".mds");
2038 p = new PrintStream(out);
2039
2040 //cycle through all lines in IN and print to OUT
2041 while(in.available() != 0){
2042
2043 //System.out.println(in.readLine()+ "\n"
2044 String nextline = in.readLine();
2045
2046 if(nextline.matches(".+namespace=\".+\".*") == true){
2047
2048 nextline = nextline.replaceFirst("namespace=\".+\"","namespace=\"" + namespace_str+ "\"");
2049 }
2050 else{
2051 nextline = nextline.replaceFirst(">.+</Name>",">" + name_str + "</Name>");
2052
2053 }
2054
2055
2056
2057
2058 p.print(nextline + "\n");
2059 }
2060
2061
2062 //
2063 p.close();
2064
2065 MetadataSet loadedset = msm.loadMetadataSet(new File(Utility.METADATA_DIR + "/" + namespace_str + ".mds"));
2066 model.add(null, loadedset, GEMSNode.SET);
2067 }
2068 catch(Exception e){
2069 System.out.println("Print file error");
2070
2071 }
2072
2073
2074
2075 ///////////////
2076
2077
2078 }
2079 catch(Exception e){
2080
2081 System.out.println("File Input error");
2082
2083 }
2084
2085 }//msm.getset(namespacE) == null
2086 else{
2087
2088 JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Set_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
2089
2090
2091 }
2092 }
2093 //}//if a_set_exists_with_this_namespace
2094 //set = null;
2095 setVisible(false);
2096 }
2097 else if(source == cancel_button) {
2098 setVisible(false);
2099 }
2100 else {
2101 name_field.setText("");
2102 setVisible(true);
2103 }
2104 }
2105
2106 public void dispose() {
2107 cancel_button = null;
2108 ok_button = null;
2109 name_field = null;
2110 ///ystem.err.println("Dispose AddSetActionListener");
2111 super.dispose();
2112 }
2113 }
2114 ////
2115 private class SetSelectionDialog
2116 extends ModalDialog
2117 implements ActionListener {
2118 private JButton cancel_button = null;
2119 private JButton ok_button = null;
2120 //private JTextField name_field = null;
2121 //private JTextField namespace_field = null;
2122 private JComboBox existingSetJComboBox = new JComboBox();
2123
2124 public SetSelectionDialog() {
2125 super(self);
2126 setModal(true);
2127 setSize(OPEN_SETS_SIZE);
2128 Dictionary.setText(this, "Open Sets");
2129
2130 // Creation
2131 JPanel content_pane = (JPanel) getContentPane();
2132 content_pane.setBackground(config.getColor("coloring.collection_heading_background", false));
2133 JPanel center_pane = new JPanel();
2134 center_pane.setOpaque(false);
2135
2136
2137 JPanel boxes_pane = new JPanel();
2138
2139 JPanel button_pane = new JPanel();
2140 button_pane.setOpaque(false);
2141
2142 ok_button = new GLIButton();
2143 ok_button.setMnemonic(KeyEvent.VK_O);
2144 Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
2145 cancel_button = new GLIButton();
2146 cancel_button.setMnemonic(KeyEvent.VK_C);
2147 Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
2148 TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button);
2149
2150 // Connection
2151 cancel_button.addActionListener(this);
2152 ok_button.addActionListener(this);
2153 // ok_button_enabler.add(name_field);
2154 // ok_button_enabler.add(namespace_field);
2155
2156 // Layout
2157
2158 // label_pane.add
2159 // boxes_pane.setLayout(new GridLayout(2,1,0,5));
2160 boxes_pane.setLayout(new GridLayout(4,1));
2161 // boxes_pane.add(name_field);
2162 // boxes_pane.add(namespace_field);
2163
2164 JLabel inheritJLabel = new JLabel();
2165 Dictionary.setText(inheritJLabel, "GEMS.inheritMetadataSet");
2166
2167 //label_pane.add(inheritJLabel);
2168
2169
2170 //add inherit metadata set functionality
2171 // String[] s = msm.getSets().toArray();
2172
2173 //JComboBox existingSetJComboBox = new JComboBox(new String(msm.getSetsForInherit().toArray()));
2174
2175 int getSetsLen = msm.getSets().toArray().length;
2176 Vector theSets = msm.getSets();
2177 // System.out.println(Configuration.gsdl_path);
2178 File[] col_dir = new File(Configuration.gsdl_path + "/collect").listFiles();
2179
2180 existingSetJComboBox.addItem("Default Metadata Sets #% " + Configuration.gsdl_path + "gli/metadata");
2181
2182 for(int k = 0; k < col_dir.length; k++){
2183 //MetadataSet ms = (MetadataSet)theSets.elementAt(k);
2184
2185 if(col_dir[k].isDirectory() && col_dir[k].getName().compareTo("CVS") != 0) {
2186
2187 File metadir = new File(col_dir[k].toString() + "/metadata");
2188 if(metadir.exists())
2189 existingSetJComboBox.addItem(new String(col_dir[k].getName() + " Collection Sets #% " + col_dir[k].toString() + "/metadata"));
2190
2191 }
2192
2193 // existingSetJComboBox.addItem(new String(ms.getName() + " #% " + ms.getFile().toString()));
2194
2195 }
2196 //add sets to existingSetJComboBox
2197
2198 existingSetJComboBox.setSelectedIndex(0);
2199 //String tempstr = new String();
2200 JLabel dummyl = new JLabel();
2201 Dictionary.setText(dummyl, "GEMS.Add_Set.No_Inherit");
2202
2203
2204
2205 //existingSetJComboBox.addItem("Do not inherit");
2206 // existingSetJComboBox.setSelectedIndex(getSetsLen);
2207 boxes_pane.add(new JLabel("Select which group of metadata sets you wish to edit:\n\n\n\n"));
2208 boxes_pane.add(new JLabel("\n"));
2209 boxes_pane.add(existingSetJComboBox);
2210 boxes_pane.add(new JLabel("\n"));
2211 // center_pane.setLayout(new BorderLayout(5,0));
2212 // center_pane.add(label_pane, BorderLayout.WEST);
2213 // center_pane.add(boxes_pane, BorderLayout.CENTER);
2214
2215 // button_pane.setLayout(new GridLayout(1,3,0,5));
2216 button_pane.setLayout(new GridLayout(1,3,0,5));
2217 button_pane.add(ok_button);
2218 button_pane.add(cancel_button);
2219
2220
2221 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
2222 content_pane.setLayout(new BorderLayout());
2223 content_pane.add(boxes_pane, BorderLayout.CENTER);
2224 content_pane.add(button_pane, BorderLayout.SOUTH);
2225
2226 setLocation((config.screen_size.width - ADD_SET_SIZE.width) / 2, (config.screen_size.height - ADD_SET_SIZE.height) / 2);
2227 }
2228 /** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to
2229 * @param event An <strong>ActionEvent</strong> containing information about the event.
2230 */
2231
2232 public void actionPerformed(ActionEvent event) {
2233 Object source = event.getSource();
2234
2235
2236 // if(a_set_exists_with_this_namespace(namespace_field.getText()) == false){
2237 if(source == ok_button) {
2238 //this code below handles whether we inherit from an existing set or not
2239
2240 // String namespace_str = namespace_field.getText();
2241 //String name_str = Codec.transform(Codec.transformUnicode(name_field.getText()), Codec.TEXT_TO_DOM);
2242 String loc = (String) existingSetJComboBox.getSelectedItem();
2243
2244 String [] whereto = loc.split("#%");
2245 String set_directory = whereto[1].trim();
2246
2247 //load the jfilechooser:
2248
2249 JFileChooser metadata_set_file_chooser = new JFileChooser(new File(set_directory));
2250 metadata_set_file_chooser.setFileFilter(new MetadataSetFileFilter());
2251 if (metadata_set_file_chooser.showDialog(this, Dictionary.get("General.Open")) == JFileChooser.APPROVE_OPTION) {
2252 MetadataSet metadata_set = msm.loadMetadataSet(metadata_set_file_chooser.getSelectedFile());
2253 // Update tree
2254 //only update tree if the metadata_set return is not null(it will be null if set is already
2255 //opened-Attila - oct 19 0 4
2256 if(metadata_set != null) {
2257 model.add(null, metadata_set, GEMSNode.SET);
2258 }
2259 }
2260
2261
2262 setVisible(false);
2263 }
2264 else if(source == cancel_button) {
2265 setVisible(false);
2266 }
2267 else {
2268 //name_field.setText("");
2269 setVisible(true);
2270 }
2271 }
2272
2273 public void dispose() {
2274 cancel_button = null;
2275 ok_button = null;
2276 super.dispose();
2277 }
2278 }
2279
2280 ////
2281 private class AddOrEditValueActionListener
2282 extends ModalDialog
2283 implements ActionListener, TreeSelectionListener {
2284 private boolean add_type = true;
2285 private boolean ignore = false;
2286 private GValueNode subject_node = null;
2287 private JButton cancel_button = null;
2288 private JButton ok_button = null;
2289 private JTextArea value = null;
2290 private SmarterTree subject_tree = null;
2291
2292 /** Constructor. */
2293 public AddOrEditValueActionListener() {
2294 super(self);
2295 this.setModal(true);
2296 this.setSize(ADD_OR_EDIT_VALUE_SIZE);
2297
2298 // Create
2299 JPanel content_pane = (JPanel) getContentPane();
2300 content_pane.setBackground(config.getColor("coloring.collection_heading_background", false));
2301 JPanel center_pane = new JPanel();
2302 center_pane.setOpaque(false);
2303 JPanel inner_pane = new JPanel();
2304 inner_pane.setOpaque(false);
2305 JPanel subject_tree_pane = new JPanel();
2306 subject_tree_pane.setOpaque(false);
2307 JLabel subject_tree_label = new JLabel();
2308 subject_tree_label.setOpaque(false);
2309 Dictionary.setText(subject_tree_label, "GEMS.Subject");
2310 subject_tree = new SmarterTree();
2311 subject_tree.setBackground(config.getColor("coloring.collection_tree_background", false));
2312 subject_tree.setForeground(config.getColor("coloring.collection_tree_foreground", false));
2313 subject_tree.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
2314 subject_tree.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
2315 JPanel value_pane = new JPanel();
2316 value_pane.setOpaque(false);
2317 JLabel value_label = new JLabel();
2318 value_label.setOpaque(false);
2319 Dictionary.setText(value_label, "GEMS.Value");
2320 value = new JTextArea();
2321 value.setBackground(config.getColor("coloring.collection_tree_background", false));
2322 value.setForeground(config.getColor("coloring.collection_tree_foreground", false));
2323 value.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
2324 value.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
2325 Dictionary.setTooltip(value, "GEMS.Value_Tooltip");
2326
2327 JPanel button_pane = new JPanel();
2328 button_pane.setOpaque(false);
2329
2330 ok_button = new GLIButton();
2331 ok_button.setMnemonic(KeyEvent.VK_O);
2332 ok_button.setEnabled(false);
2333 Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
2334 cancel_button = new GLIButton();
2335 cancel_button.setMnemonic(KeyEvent.VK_C);
2336 Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
2337 TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button);
2338
2339 // Connect
2340 ok_button_enabler.add(value);
2341 cancel_button.addActionListener(this);
2342 ok_button.addActionListener(this);
2343 subject_tree.addTreeSelectionListener(this);
2344
2345 // Layout
2346 subject_tree_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
2347 subject_tree_pane.setLayout(new BorderLayout());
2348 subject_tree_pane.add(subject_tree_label, BorderLayout.NORTH);
2349 subject_tree_pane.add(new JScrollPane(subject_tree), BorderLayout.CENTER);
2350
2351 value_pane.setBorder(BorderFactory.createEmptyBorder(0,5,5,5));
2352 value_pane.setLayout(new BorderLayout());
2353 value_pane.add(value_label, BorderLayout.NORTH);
2354 value_pane.add(new JScrollPane(value), BorderLayout.CENTER);
2355
2356 inner_pane.setLayout(new GridLayout(2,1));
2357 inner_pane.add(subject_tree_pane);
2358 inner_pane.add(value_pane);
2359
2360 button_pane.setBorder(BorderFactory.createEmptyBorder(0,5,5,5));
2361 button_pane.setLayout(new GridLayout(1,2,5,5));
2362 button_pane.add(ok_button);
2363 button_pane.add(cancel_button);
2364
2365 content_pane.setLayout(new BorderLayout());
2366 content_pane.add(inner_pane, BorderLayout.CENTER);
2367 content_pane.add(button_pane, BorderLayout.SOUTH);
2368 setLocation((config.screen_size.width - ADD_OR_EDIT_VALUE_SIZE.width) / 2, (config.screen_size.height - ADD_OR_EDIT_VALUE_SIZE.height) / 2);
2369 }
2370 /** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to add a new metadata value to the assigned values tree.
2371 * @param event An <strong>ActionEvent</strong> containing information about the event.
2372 */
2373 public void actionPerformed(ActionEvent event) {
2374 Object source = event.getSource();
2375 if(source == ok_button) {
2376 String value_str = Codec.transform(Codec.transformUnicode(value.getText()), Codec.TEXT_TO_DOM);
2377 // Now we action as necessary
2378 GValueModel model = msm.getValueTree(current_element);
2379 if(add_type) {
2380 ///ystem.err.println("Add type - insert node: " + value.getText() + " into " + subject_node);
2381 // Add this value to the tree.
2382 model.addValue(value_str, subject_node);
2383 }
2384 else {
2385 // Rewrite this value in the DOM model. Note that this will automatically rewrite all assignments as they are live references.
2386 current_value_node.setValue(value_str);
2387 // Now insert the node into the currently selected subject, but only if the parent has changed.
2388 if(subject_node != current_value_node.getParent()) {
2389 GValueNode old_subject_node = (GValueNode) current_value_node.getParent();
2390 // Find the new values position in subject_nodes children.
2391 GValueNode sibling = null;
2392 int index = 0;
2393 boolean found = false;
2394 while(index < subject_node.getChildCount() && !found) {
2395 sibling = (GValueNode) subject_node.getChildAt(index);
2396 int order = current_value_node.toString().compareToIgnoreCase(sibling.toString());
2397 // If the sibling is 'greater than' or comes after current value then insert.
2398 if(order < 0) {
2399 // Insert. This will coincidently remove from original parent.
2400 Node parent_node = subject_node.getElement();
2401 Node child_node = current_value_node.getElement();
2402 Node sibling_node = sibling.getElement();
2403 parent_node.insertBefore(child_node, sibling_node);
2404 found = true;
2405 }
2406 // The value already exists exactly as is. In theory this case can never happenm but just incase do nothing more.
2407 else if(order == 0) {
2408 found = true;
2409 }
2410 // The sibling is 'less than' or before the current value, keep looking.
2411 else {
2412 index++;
2413 }
2414 }
2415 // If we haven't done so yet, insert the current node. This will coincidently remove from original parent.
2416 if(!found) {
2417 Node parent_node = subject_node.getElement();
2418 Node child_node = current_value_node.getElement();
2419 parent_node.appendChild(child_node);
2420 }
2421 // Inform the tree model what two nodes structures have changed (origin and destination).
2422 //subject_node.unmap();
2423 //old_subject_node.unmap();
2424 model.nodeStructureChanged(old_subject_node);
2425 model.nodeStructureChanged(subject_node);
2426 }
2427 // And if a data change was made tell the tree its data model is ka-bluey.
2428 else {
2429 model.nodeChanged(current_value_node);
2430 }
2431 }
2432 model = null;
2433 // Hide dialog
2434 setVisible(false);
2435 atLeastOneSetChanged = true;
2436 }
2437 else if(source == cancel_button) {
2438 // Hide dialog
2439 setVisible(false);
2440
2441 }
2442 else {
2443 // Reset dialog
2444 // current_value_node
2445 GValueModel model = msm.getValueTree(current_element);
2446 subject_tree.setModel(model);
2447 // Task specific
2448 if(source == add_value) {
2449 add_type = true;
2450 if(current_value_node != null) {
2451 subject_node = current_value_node;
2452 }
2453 else {
2454 subject_node = (GValueNode) model.getRoot();
2455 }
2456 value.setText("");
2457 Dictionary.setText(this, "GEMS.AddValue");
2458 }
2459 else {
2460 add_type = false;
2461 if(current_value_node != null) {
2462 subject_node = (GValueNode) current_value_node.getParent();
2463 }
2464 else {
2465 subject_node = (GValueNode) model.getRoot();
2466 }
2467 value.setText(Codec.transform(current_value_node.toString(), Codec.DOM_TO_TEXT));
2468 Dictionary.setText(this, "GEMS.EditValue");
2469 }
2470 model = null;
2471 if(subject_node != null) {
2472 TreePath path = new TreePath(subject_node.getPath());
2473 subject_tree.scrollPathToVisible(path);
2474 subject_tree.setSelectionPath(path);
2475 path = null;
2476 }
2477 // Display
2478 setVisible(true);
2479 }
2480 }
2481
2482 public void dispose() {
2483 cancel_button = null;
2484 ok_button = null;
2485 subject_node = null;
2486 subject_tree = null;
2487 value = null;
2488 ///ystem.err.println("Dispose AddOrEditValueActionListener");
2489 super.dispose();
2490 }
2491
2492 public void valueChanged(TreeSelectionEvent event) {
2493 if(subject_tree.getSelectionCount() > 0 && !ignore) {
2494 ignore = true;
2495 TreePath selected_path = subject_tree.getSelectionPath();
2496 GValueNode requested_node = (GValueNode) selected_path.getLastPathComponent();
2497 // Ensure the requested node is not a descendant of the current_value_node
2498 if(current_value_node != null) {
2499 if(!add_type && current_value_node.isNodeDescendant(requested_node)) {
2500 TreePath path = new TreePath(subject_node.getPath());
2501 subject_tree.scrollPathToVisible(path);
2502 subject_tree.setSelectionPath(path);
2503 }
2504 else {
2505 subject_node = requested_node;
2506 }
2507 }
2508 selected_path = null;
2509 ignore = false;
2510 }
2511 }
2512 }
2513
2514
2515 /** This listener is responsible for keeping the root node of a value tree expanded where and when possible. */
2516 private class KeepTreeRootExpandedListener
2517 implements TreeModelListener {
2518 /** Invoked after a node (or a set of siblings) has changed in some way. */
2519 public void treeNodesChanged(TreeModelEvent e) {
2520 }
2521 /** Invoked after nodes have been inserted into the tree. */
2522 public void treeNodesInserted(TreeModelEvent e) {
2523 // if(element_values != null && element_values.getModel() != null && element_values.getModel().getRoot() != null) {
2524 // element_values.expandPath(new TreePath(element_values.getModel().getRoot()));
2525 // }
2526 }
2527 /** Invoked after nodes have been removed from the tree. */
2528 public void treeNodesRemoved(TreeModelEvent e) {
2529 }
2530 /** Invoked after the tree has drastically changed structure from a given node down. */
2531 public void treeStructureChanged(TreeModelEvent e) {
2532 // element_values.expandPath(new TreePath(element_values.getModel().getRoot()));
2533 }
2534 }
2535
2536 private class RemoveAttributeActionListener
2537 implements ActionListener {
2538 /** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to
2539 * @param event An <strong>ActionEvent</strong> containing information about the event.
2540 */
2541 public void actionPerformed(ActionEvent event) {
2542 if(current_attribute != -1) {
2543 int result = JOptionPane.showOptionDialog(self, Dictionary.get("GEMS.Confirm_Removal", Dictionary.get("GEMS.Attribute")), Dictionary.get("GEMS.Confirm_Removal_Title"), JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, dialog_options, dialog_options[0]);
2544 // Remove this attribute
2545 if(result == 0) {
2546 ignore = true;
2547 // Attributes are tricky little beasties, as they can come from several different places and depend upon what other little beasties have been selected
2548 // Has a collection file been selected...
2549 if(current_collection_file != null) {
2550 // Remove a profile
2551 String source = (String) profile_attributes.getValueAt(current_attribute, 0);
2552 // !!! msm.profiler.removeAction(current_collection_file, source);
2553 source = null;
2554 // Refresh table
2555 ((AttributeTableModel)profile_attributes.getModel()).removeRow(current_attribute);
2556 }
2557 // or has an element been selected
2558 else if(current_element != null) {
2559 // Remove element attribute
2560 String name = (String) element_attributes.getValueAt(current_attribute, 0);
2561 String language = (String) element_attributes.getValueAt(current_attribute, 1);
2562 String value = (String) element_attributes.getValueAt(current_attribute, 2);
2563 current_element.removeAttribute(name, language, value);
2564
2565 // Refresh table
2566 ((AttributeTableModel)element_attributes.getModel()).removeRow(current_attribute);
2567 }
2568 else if(current_set != null) {
2569 String name = (String) set_attributes.getValueAt(current_attribute, 0);
2570 // Remove set attribute
2571 current_set.removeAttribute(name);
2572 // Refresh table
2573 ((AttributeTableModel)set_attributes.getModel()).removeRow(current_attribute);
2574 }
2575 // Disable buttons
2576 // edit_attribute.setEnabled(false);
2577 remove_attribute.setEnabled(false);
2578 ignore = false;
2579
2580 atLeastOneSetChanged= true;
2581 }
2582 }
2583 }
2584 }
2585
2586 private class RemoveElementActionListener
2587 implements ActionListener {
2588 /** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to provide an editing prompt.
2589 * @param event An <strong>ActionEvent</strong> containing information about the event.
2590 */
2591 public void actionPerformed(ActionEvent event) {
2592
2593 if(current_element != null) {
2594 int result = JOptionPane.showOptionDialog(self, Dictionary.get("GEMS.Confirm_Removal", Dictionary.get("GEMS.Element")), Dictionary.get("GEMS.Confirm_Removal_Title"), JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, dialog_options, dialog_options[0]);
2595 // Remove this attribute
2596 if(result == 0) {
2597 ignore = true;
2598 msm.removeElement(current_element);
2599 // Clear selection
2600 mds_tree.clearSelection();
2601 model.remove(current_element.toString(), GEMSNode.ELEMENT);
2602 // Meanwhile disable/enable controls given we had an element selected, but no longer do.
2603 remove_element.setEnabled(false);
2604 // Show a blank panel.
2605 card_layout.show(details_pane, BLANK);
2606 ignore = false;
2607
2608 atLeastOneSetChanged = true;
2609 }
2610 }
2611 else {
2612 ///ystem.err.println("No current element selected.");
2613 }
2614 }
2615 }
2616
2617 private class RemoveFileActionListener
2618 implements ActionListener {
2619 /** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to provide an editing prompt.
2620 * @param event An <strong>ActionEvent</strong> containing information about the event.
2621 */
2622 public void actionPerformed(ActionEvent event) {
2623 if(current_collection_file != null) {
2624 int result = JOptionPane.showOptionDialog(self, Dictionary.get("GEMS.Confirm_Removal", Dictionary.get("GEMS.File")), Dictionary.get("GEMS.Confirm_Removal_Title"), JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, dialog_options, dialog_options[0]);
2625 // Remove the current collection file profile from the profiler.
2626 if(result == 0) {
2627 ignore = true;
2628 // !!! msm.profiler.removeProfile(current_collection_file);
2629 // Clear selection
2630 mds_tree.clearSelection();
2631 model.remove(current_collection_file, GEMSNode.COLLECTION);
2632 // Meanwhile disable/enable controls given we had a set selected, but no longer do.
2633 remove_file.setEnabled(false);
2634 // Show a blank panel.
2635 card_layout.show(details_pane, BLANK);
2636 ignore = false;
2637 }
2638 }
2639 }
2640 }
2641
2642 private class RemoveSetActionListener
2643 implements ActionListener {
2644 /** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to
2645 * @param event An <strong>ActionEvent</strong> containing information about the event.
2646 */
2647 public void actionPerformed(ActionEvent event) {
2648 if(current_set != null) {
2649
2650 //If the current_set_filename is dls or dublin or ex and in the METADATA_DIR, then do
2651 //not let anyone remove them --Attila
2652 // System.out.println(current_set.getName());
2653 //
2654
2655 File current_set_filename = current_set.getFile();
2656 // System.out.println(current_set_filename.toString());
2657
2658 if(current_set_filename.toString().compareTo(new String(Utility.METADATA_DIR+"dls.mds")) == 0 ||
2659 current_set_filename.toString().compareTo(new String(Utility.METADATA_DIR+"dublin.mds")) == 0 ||
2660 current_set_filename.toString().compareTo(new String(Utility.METADATA_DIR+"ex.mds")) == 0){
2661
2662 JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Cannot_Delete_Core_Sets_Error"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
2663 return;
2664 }
2665
2666
2667 int result = JOptionPane.showOptionDialog(self, Dictionary.get("GEMS.Confirm_Removal", Dictionary.get("GEMS.Set")), Dictionary.get("GEMS.Confirm_Removal_Title"), JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, dialog_options, dialog_options[0]);
2668 // Remove the currently selected set
2669 if(result == 0) {
2670
2671 ignore = true;
2672 msm.removeSet(current_set);
2673 // Clear selection
2674 mds_tree.clearSelection();
2675 model.remove(current_set.toString(), GEMSNode.SET);
2676 // Meanwhile disable/enable controls given we had a set selected, but no longer do.
2677 remove_set.setEnabled(false);
2678 // Show a blank panel.
2679 card_layout.show(details_pane, BLANK);
2680 ignore = false;
2681
2682
2683 //We do not need to set the following var because by this point the set was
2684 //completetely removed
2685 //atLeastOneSetChanged
2686
2687
2688 }
2689 }
2690 }
2691 }
2692 /** This class will remove the currently selected metadata or profile value when any registered control is actioned. Note that removing a value acts differently from the other removes in that if you remove a value which is still assigned somewhere the values are restored next time said assignment is viewed. This turned out far easier and reasonable to code than attempting to remove all remaining values when you delete its reference in the GValueModel. */
2693 private class RemoveValueActionListener
2694 implements ActionListener {
2695 /** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to
2696 * @param event An <strong>ActionEvent</strong> containing information about the event.
2697 */
2698 public void actionPerformed(ActionEvent event) {
2699 if(current_value_node != null) {
2700 int result = JOptionPane.showOptionDialog(self, Dictionary.get("GEMS.Confirm_Removal", Dictionary.get("GEMS.Value")), Dictionary.get("GEMS.Confirm_Removal_Title"), JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, dialog_options, dialog_options[0]);
2701 // Remove the current selected value
2702 if(result == 0) {
2703 ignore = true;
2704 // GValueModel model = (GValueModel) element_values.getModel();
2705 // model.removeValue(current_value_node);
2706 // Meanwhile disable/enable controls given we had a value selected, but no longer do.
2707 edit_value.setEnabled(false);
2708 remove_value.setEnabled(false);
2709 ignore = false;
2710
2711 //does this every get called?
2712 System.out.println("\nGEMS.RemovevalueActionListener called");
2713 atLeastOneSetChanged = true;
2714 }
2715 }
2716 }
2717 }
2718
2719 /** Used to enable a certain target component if and only if all the registered text fields contain non-zero length strings. */
2720 private class TextFieldEnabler
2721 implements DocumentListener {
2722 private boolean ignore = false;
2723 private Component target = null;
2724 private JTextComponent[] fields = null;
2725 public TextFieldEnabler(Component target) {
2726 super();
2727 this.target = target;
2728 }
2729 public void add(JTextComponent field) {
2730 // Record this field as being one we depend upon
2731 if(fields == null) {
2732 fields = new JTextComponent[1];
2733 fields[0] = field;
2734 }
2735 else {
2736 JTextComponent[] temp = new JTextComponent[fields.length + 1];
2737 System.arraycopy(fields, 0, temp, 0, fields.length);
2738 temp[fields.length] = field;
2739 fields = temp;
2740 temp = null;
2741 }
2742 // Add the appropriate listener
2743 field.getDocument().addDocumentListener(this);
2744 }
2745 /** Gives notification that an attribute or set of attributes changed. */
2746 public void changedUpdate(DocumentEvent e) {
2747 canEnable();
2748 }
2749 /** Gives notification that there was an insert into the document. */
2750 public void insertUpdate(DocumentEvent e) {
2751 canEnable();
2752 }
2753 /** Gives notification that a portion of the document has been removed. */
2754 public void removeUpdate(DocumentEvent e) {
2755 canEnable();
2756 }
2757 private void canEnable() {
2758 if(!ignore) {
2759 ignore = true;
2760 boolean can_enable = true;
2761 for(int i = 0; can_enable && i < fields.length; i++) {
2762 can_enable = can_enable && (fields[i].getText().length() > 0);
2763 }
2764 target.setEnabled(can_enable);
2765 ignore = false;
2766 }
2767 }
2768 }
2769
2770 private class AttributesListSelectionListener
2771 implements ListSelectionListener {
2772 private JTable table = null;
2773 public AttributesListSelectionListener(JTable table) {
2774 this.table = table;
2775 }
2776 public void valueChanged(ListSelectionEvent event) {
2777 if(!event.getValueIsAdjusting()) {
2778 if((current_attribute = table.getSelectedRow()) != -1) {
2779 // edit_attribute.setEnabled(true);
2780 // remove_attribute.setEnabled(true);
2781 // System.out.println("curr_attr != -1");
2782
2783 }
2784 else {
2785 // System.out.println("curr_attr = -1");
2786 current_attribute = -1;
2787 // edit_attribute.setEnabled(false);
2788 // remove_attribute.setEnabled(false);
2789 }
2790 }
2791 }
2792 }
2793
2794 private class ElementValuesTreeSelectionListener
2795 implements TreeSelectionListener {
2796 public void valueChanged(TreeSelectionEvent event) {
2797 if(element_values.getSelectionCount() > 0) {
2798 // Retrieve the selected value node.
2799 TreePath selected_path = element_values.getSelectionPath();
2800 current_value_node = (GValueNode) selected_path.getLastPathComponent();
2801 edit_value.setEnabled(true);
2802 remove_value.setEnabled(true);
2803 }
2804 else {
2805 current_value_node = null;
2806 edit_value.setEnabled(false);
2807 remove_value.setEnabled(false);
2808 }
2809 }
2810 }
2811
2812 private class MDSTreeSelectionListener
2813 implements TreeSelectionListener {
2814 public void valueChanged(TreeSelectionEvent event) {
2815 if(!ignore) {
2816 // Clear all variables based on previous tree selection
2817 current_collection_file = null;
2818 current_element = null;
2819 current_set = null;
2820 // Now process the node selected
2821 TreePath path = event.getPath();
2822 current_node = (GEMSNode)path.getLastPathComponent();
2823 // What we show depends on the node type...
2824 AttributeTableModel atm = null;
2825 TreeSet attributes = null;
2826 current_attribute_type = current_node.getType();
2827 switch(current_attribute_type) {
2828 case GEMSNode.COLLECTION:
2829 current_collection_file = (String) current_node.getUserObject();
2830 atm = current_node.getModel();
2831 if(atm == null) {
2832 // !!! ArrayList sources = msm.profiler.getSources(current_collection_file);
2833 attributes = new TreeSet();
2834 // for(int i = 0; i < sources.size(); i++) {
2835 // String source = (String) sources.get(i);
2836 // !!! String action = msm.profiler.getAction(current_collection_file, source);
2837 // if (action == null) {
2838 // action = Dictionary.get("GEMS.Ignore");
2839 // }
2840 // attributes.add(new Attribute(source, action));
2841 // }
2842 atm = new AttributeTableModel(attributes, Dictionary.get("GEMS.Source"), Dictionary.get("GEMS.Target"), Dictionary.get("GEMS.Ignore"));
2843 //current_node.setModel(atm);
2844 }
2845 profile_attributes.setModel(atm);
2846 atm.setScrollPane(profile_attributes_scroll);
2847 atm.setTable(profile_attributes);
2848
2849 card_layout.show(details_pane, PROFILE);
2850 // setControls(true, false, false, true, false, false, true, false, false, false, false, false);
2851 break;
2852 case GEMSNode.ELEMENT:
2853 current_element = current_node.getElement();
2854 atm = current_node.getModel();
2855 if(atm == null) {
2856 atm = new AttributeTableModel(current_element.getAttributes(), Dictionary.get("GEMS.Name"), Dictionary.get("GEMS.Language_Code"), Dictionary.get("GEMS.Value"), "");
2857 //current_node.setModel(atm);
2858 }
2859 element_attributes.setModel(atm);
2860 atm.setScrollPane(element_attributes_scroll);
2861 atm.setTable(element_attributes);
2862
2863 // Be careful not to add the keep_root_expanded_listener over and over!
2864 GValueModel value_model = msm.getValueTree(current_element);
2865 if(value_model != null) {
2866 value_model.removeTreeModelListener(keep_root_expanded_listener); // Remove it if its already there
2867 value_model.addTreeModelListener(keep_root_expanded_listener); // Then add again.
2868 element_values.setModel(value_model);
2869 element_values_layout.show(element_values_pane, VALUES);
2870 // Meanwhile disable/enable controls depending on this Element selection.
2871 //setControls(true, false, false, false, false, true, true, false, false, true, false, false);
2872 }
2873 else {
2874 element_values_layout.show(element_values_pane, BLANK);
2875 // Meanwhile disable/enable controls depending on this Element selection.
2876 //setControls(true, false, false, false, false, false, true, false, false, false, false, false);
2877 }
2878 card_layout.show(details_pane, ELEMENT);
2879 break;
2880 case GEMSNode.SET:
2881 current_set = current_node.getSet();
2882 atm = current_node.getModel();
2883 if(atm == null) {
2884 NamedNodeMap temp = current_set.getAttributes();
2885 attributes = new TreeSet();
2886 for(int i = 0; i < temp.getLength(); i++) {
2887 Attr attribute = (Attr) temp.item(i);
2888 // We don't show the namespace attribute, as it is used as a unique primary key and should never be changed or removed in itself.
2889 if(!attribute.getName().equals("namespace")) {
2890 attributes.add(new Attribute(attribute.getName(), attribute.getValue()));
2891 }
2892 attribute = null;
2893 }
2894 atm = new AttributeTableModel(attributes, Dictionary.get("GEMS.Name"), Dictionary.get("GEMS.Value"), "");
2895 //current_node.setModel(atm);
2896 temp = null;
2897 }
2898 set_attributes.setModel(atm);
2899 atm.setScrollPane(set_attributes_scroll);
2900 atm.setTable(set_attributes);
2901
2902 card_layout.show(details_pane, SET);
2903 attributes = null;
2904 // Meanwhile disable/enable controls depending on this Element selection.
2905 // setControls(true, true, false, false, true, false, true, false, false, false, false, false);
2906 break;
2907 case GEMSNode.PROFILER:
2908 // Meanwhile disable/enable controls depending on this Element selection.
2909 //setControls(true, false, true, false, false, false, false, false, false, false, false, false);
2910 default:
2911 // Show a blank panel.
2912 card_layout.show(details_pane, BLANK);
2913 }
2914 attributes = null;
2915 path = null;
2916 atm = null;
2917
2918 //System.out.println("Tree eventselection");
2919 }
2920 }
2921 }
2922
2923 private class GEMSTreeCellRenderer
2924 extends DefaultTreeCellRenderer {
2925 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
2926 super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
2927 setToolTipText(value.toString());
2928 return this;
2929 }
2930 }
2931
2932 //PopupListener is our main manager for all right-click popups
2933 class PopupListener extends MouseAdapter implements ActionListener{
2934 JPopupMenu setPopup;
2935 JPopupMenu subfieldPopup;
2936 JPopupMenu elementPopup;
2937 JPopupMenu attributePopup;
2938 //all of our popup menu items EVER!
2939 JMenuItem menuAddSet;
2940 JMenuItem menuRenameSet;
2941 JMenuItem menuAddElement;
2942 JMenuItem menuAddAttributeSet;
2943
2944 JMenuItem menuRenameSubfield;
2945 JMenuItem menuDeleteSubfield;
2946 JMenuItem menuAddAttributeSubfield;
2947 JMenuItem menuRenameElement;
2948
2949 JMenuItem menuDeleteElement;
2950 JMenuItem menuAddAttributeElement;
2951 JMenuItem menuAddSubfield;
2952
2953 JMenuItem menuEditValue;
2954 JMenuItem menuDeleteAttribute;
2955 JMenuItem menuAddAttributeAttribute;
2956
2957 JMenuItem menuRemoveSet;
2958 //all of our popup menu items above
2959 static final public int COLLECTION = 0;
2960 static final public int ELEMENT = 1;
2961 static final public int PROFILER = 2;
2962 static final public int ROOT = 3;
2963 static final public int SET = 4;
2964
2965 GEMS GEMSRef = null;
2966 PopupListener(GEMS g) {
2967 setPopup = new JPopupMenu();
2968 subfieldPopup = new JPopupMenu();
2969 elementPopup = new JPopupMenu();
2970 attributePopup = new JPopupMenu();
2971
2972 //reference to our parent(GEMS), because some of the actionlisteners would not
2973 //work unless they were declared in GEMS, and I need a way to reference GEMS
2974
2975 GEMSRef = g;
2976
2977 //create the MenuItems
2978
2979 //set related popups
2980 menuAddSet = new JMenuItem();
2981 //Dictionary.setText(menuAddSet,"GEMS.Popup.menuAddSet");
2982 //Dictionary.setText(menuAddSet,"GEMS.Add_Set_Tooltip");
2983
2984 menuRenameSet = new JMenuItem();
2985 Dictionary.setText(menuRenameSet,"GEMS.Popup.menuRenameSet");
2986
2987 menuAddElement =new JMenuItem();
2988 // Dictionary.setText(menuAddElement,"GEMS.Popup.menuAddElement");
2989 Dictionary.setText(menuAddElement,"GEMS.Add_Element_Tooltip");
2990
2991 menuAddAttributeSet = new JMenuItem();
2992 // Dictionary.setText(menuAddAttributeSet, "GEMS.Popup.menuAddAttribute");
2993 Dictionary.setText(menuAddAttributeSet, "GEMS.Add_Attribute_Tooltip");
2994
2995
2996 menuRemoveSet = new JMenuItem();
2997 //Dictionary.setText(menuRemoveSet,"GEMS.Popup.menuRemoveSet");
2998 Dictionary.setText(menuRemoveSet,"GEMS.Remove_Set_Tooltip");
2999
3000 //subfield related GEMS.Popups
3001 menuRenameSubfield = new JMenuItem();
3002 Dictionary.setText(menuRenameSubfield,"GEMS.Popup.menuRenameSubfield");
3003
3004 menuDeleteSubfield=new JMenuItem();
3005 Dictionary.setText(menuDeleteSubfield,"GEMS.Popup.menuRemoveSubfield");
3006
3007 menuAddAttributeSubfield=new JMenuItem();
3008 // Dictionary.setText(menuAddAttributeSubfield,"GEMS.Popup.menuAddAttribute");
3009 Dictionary.setText(menuAddAttributeSubfield,"GEMS.Add_Attribute_Tooltip");
3010
3011 //element related GEMS.Popups
3012 menuRenameElement=new JMenuItem();
3013 // Dictionary.setText(menuRenameElement,"GEMS.Popup.menuRenameElement");
3014 //Dictionary.setText(menuRenameElement,"GEMS.Rename_Element_Tooltip");
3015
3016 menuDeleteElement=new JMenuItem();
3017 // Dictionary.setText(menuDeleteElement,"GEMS.Popup.menuRemoveElement");
3018 Dictionary.setText(menuDeleteElement,"GEMS.Remove_Element_Tooltip");
3019
3020 menuAddAttributeElement=new JMenuItem();
3021 //Dictionary.setText(menuAddAttributeElement,"GEMS.Popup.menuAddAttribute");
3022 Dictionary.setText(menuAddAttributeElement,"GEMS.Add_Attribute_Tooltip");
3023
3024 menuAddSubfield=new JMenuItem();
3025 Dictionary.setText(menuAddSubfield,"GEMS.Popup.menuAddSubfield");
3026 //Dictionary.setText(menuAddSubfield,"GEMS.Add_Subfield");
3027
3028 //attribute related GEMS.Popups
3029 menuEditValue=new JMenuItem();
3030 //Dictionary.setText(menuEditValue,"GEMS.Popup.menuEditValue");
3031 Dictionary.setText(menuEditValue,"GEMS.Edit_Value_Tooltip");
3032
3033 menuDeleteAttribute=new JMenuItem();
3034 // Dictionary.setText(menuDeleteAttribute,"GEMS.Popup.menuRemoveAttribute");
3035 Dictionary.setText(menuDeleteAttribute,"GEMS.Remove_Attribute_Tooltip");
3036
3037 menuAddAttributeAttribute=new JMenuItem();
3038 // Dictionary.setText(menuAddAttributeAttribute,"GEMS.Popup.menuAddAttribute");
3039 Dictionary.setText(menuAddAttributeAttribute,"GEMS.Add_Attribute_Tooltip");
3040
3041 //start Associate the menu items with the appropriate popups:
3042 //setPopup.add(menuRenameSet);
3043 setPopup.add(menuAddSet);
3044 setPopup.add(menuAddAttributeSet);
3045 setPopup.add(menuAddElement);
3046 setPopup.add(menuRemoveSet);
3047
3048 //subfieldPopup.add(menuRenameSubfield);
3049 subfieldPopup.add(menuDeleteSubfield);
3050 subfieldPopup.add(menuAddAttributeSubfield);
3051
3052 //elementPopup.add(menuRenameElement);
3053 elementPopup.add(menuDeleteElement);
3054 elementPopup.add(menuAddAttributeElement);
3055 //elementPopup.add(menuAddSubfield);
3056
3057 attributePopup.add(menuEditValue);
3058 attributePopup.add(menuDeleteAttribute);
3059 attributePopup.add(menuAddAttributeAttribute);
3060 //end Associate the menu items with the appropriate popups:
3061
3062
3063 menuRemoveSet.addActionListener(new RemoveSetActionListener());
3064 menuAddSet.addActionListener(new AddSetActionListener());
3065 menuAddElement.addActionListener(new AddElementActionListener());
3066 menuAddAttributeSet.addActionListener(new AddOrEditAttributeActionListener());
3067 menuRenameSubfield.addActionListener(this);
3068 menuDeleteSubfield.addActionListener(this);
3069 menuAddAttributeSubfield.addActionListener(this);
3070
3071 menuRenameElement.addActionListener(this);
3072 menuDeleteElement.addActionListener(new RemoveElementActionListener());
3073 menuAddAttributeElement.addActionListener(new AddOrEditAttributeActionListener());
3074 menuAddSubfield.addActionListener(this);
3075
3076 // menuEditValue.addActionListener(new AddOrEditAttributeActionListener());
3077 AddOrEditAttributeActionListener tes = new AddOrEditAttributeActionListener();
3078
3079 menuEditValue.addActionListener(new AddOrEditAttributeActionListener());
3080
3081 //menuEditValue.addActionListener(this);
3082
3083 menuDeleteAttribute.addActionListener(new RemoveAttributeActionListener());
3084 menuAddAttributeAttribute.addActionListener(new AddOrEditAttributeActionListener());
3085
3086 }
3087 public void mouseClicked(MouseEvent e) {
3088 maybeShowPopup(e);
3089 }
3090 public void mousePressed(MouseEvent e){
3091 maybeShowPopup(e);
3092
3093 }
3094 public void mouseReleased(MouseEvent e) {
3095 maybeShowPopup(e);
3096 }
3097
3098 private void maybeShowPopup(MouseEvent e) {
3099
3100 //TreeNode oTreeNode = e.getSource().
3101 int selRow = mds_tree.getRowForLocation(e.getX(), e.getY());
3102 TreePath selPath = mds_tree.getPathForLocation(e.getX(), e.getY());
3103 if (e.isPopupTrigger()) {
3104 // setPopup.show(e.getComponent(),
3105 // e.getX(), e.getY());
3106 //System.out.println(e.getSource().toString());
3107
3108 //SmarterTable table = (SmarterTable) e.getSource();
3109
3110 /* if(table.getSelectedRow() <= -1) {
3111
3112 System.out.println("blahasdf");
3113 }
3114
3115 table.getComponent(0)
3116
3117 System.out.println(.get);
3118
3119
3120 */
3121
3122 if(e.getSource() == mds_tree) {
3123 try {
3124
3125 GEMSNode t = (GEMSNode)selPath.getLastPathComponent();
3126
3127
3128
3129 if(t.type == ELEMENT){
3130
3131 elementPopup.show(e.getComponent(),
3132 e.getX(), e.getY());
3133 }
3134 else if(t.type == ELEMENT){
3135
3136 subfieldPopup.show(e.getComponent(),
3137 e.getX(), e.getY());
3138 }
3139 else if(t.type == ROOT){
3140
3141 setPopup.show(e.getComponent(),
3142 e.getX(), e.getY());
3143 }
3144 else if(t.type == SET){
3145
3146 setPopup.show(e.getComponent(),
3147 e.getX(), e.getY());
3148 }
3149 }
3150 finally {
3151 ;
3152
3153 }
3154
3155
3156 }
3157 else if(e.getSource() == set_attributes){
3158
3159 attributePopup.show(e.getComponent(),
3160 e.getX(), e.getY());
3161
3162 }
3163 else if(e.getSource() == element_attributes) {
3164 attributePopup.show(e.getComponent(),
3165 e.getX(), e.getY());
3166
3167 }
3168
3169
3170
3171 }
3172
3173 }
3174
3175 public void actionPerformed(ActionEvent e) {
3176 // GEMSRef.add_or_edit_attribute_action_listener.actionPerformed(e);
3177 System.out.println("NO way hose");
3178 }
3179
3180 }
3181
3182 /** Wrap a ElementWrapper so we get its name when we ask for toString(), not its identifier. */
3183 private class NameElementWrapperEntry
3184 implements Comparable {
3185 private ElementWrapper element_wrapper = null;
3186 public NameElementWrapperEntry(Object object) {
3187 this.element_wrapper = (ElementWrapper) object;
3188 }
3189 public int compareTo(Object object) {
3190 return element_wrapper.compareTo(object);
3191 }
3192 public boolean equals(Object object) {
3193 return element_wrapper.equals(object);
3194 }
3195 public String toString() {
3196 return element_wrapper.getName();
3197 }
3198 }
3199}
Note: See TracBrowser for help on using the repository browser.