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