Changeset 8971 for trunk/gli/src/org/greenstone/gatherer/gems/GEMS.java
- Timestamp:
- 2005-02-07T10:36:51+13:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/gems/GEMS.java
r8932 r8971 36 36 package org.greenstone.gatherer.gems; 37 37 38 39 38 import java.awt.*; 40 39 import java.awt.event.*; … … 87 86 static final private Dimension ADD_ELEMENT_SIZE = new Dimension(400,125); 88 87 static final private Dimension RENAME_ELEMENT_SIZE = new Dimension(400, 95); 89 static final private Dimension ADD_FILE_SIZE = new Dimension(400,125);90 88 static final private Dimension ADD_SET_SIZE = new Dimension(400,150); 91 89 static final private Dimension RENAME_SET_SIZE = new Dimension(400,120); 92 90 static final private Dimension OPEN_SETS_SIZE = new Dimension(400,135); 93 91 static final private Dimension ADD_OR_EDIT_ATTRIBUTE_SIZE = new Dimension(600,325); 94 static final private Dimension ADD_OR_EDIT_VALUE_SIZE = new Dimension(600,440);95 96 92 static final private Dimension COMPONENT_SIZE = new Dimension(300,30); 97 93 static final private Dimension SIZE = new Dimension(800,480); 98 94 static final private String BLANK = "blank"; 99 95 static final private String ELEMENT = "element"; 100 static final private String PROFILE = "profile";101 96 static final private String SET = "set"; 102 static final private String SUBELEMENT = "subelement";103 static final private String VALUES = "values";104 97 105 98 static final public String METADATA_SET_TEMPLATE = "xml/template.mds"; … … 109 102 static final public int T_COLLECTION = 0; 110 103 static final public int T_ELEMENT = 1; 111 static final public int T_PROFILER = 2;112 static final public int T_ROOT = 3;113 104 static final public int T_SET = 4; 114 static final public int T_SUBELEMENT = 5; 115 116 // static final public String MAX_LOADED_SETS = 64; 105 106 //static final public String MAX_LOADED_SETS = 64; 117 107 static public Configuration config = null; 118 108 private MetadataSetManager msm = new MetadataSetManager(this); 119 109 120 110 public AddElementActionListener add_element_action_listener = null; 121 private AddFileActionListener add_file_action_listener = null;122 111 public AddSetActionListener add_set_action_listener = null; 123 112 /** The class used to handle add or edit attribute actions has to be globally available so that we can dispose of its dialog properly. */ 124 113 public AddOrEditAttributeActionListener add_or_edit_attribute_action_listener = null; 125 /** The class used to handle add or edit value actions has to be globally available so that we can dispose of its dialog properly. */126 //public AddOrEditValueActionListener add_or_edit_value_action_listener = null;127 114 private boolean ignore = false; 128 115 /** A card layout is used to switch between the two differing detail views. */ 129 116 private CardLayout card_layout = null; 130 /** A card layout is used to switch between a value tree or an empty placeholder (if no value tree available). */131 private CardLayout element_values_layout = null;132 117 133 118 /** Um, the size of the screen I'd guess. */ 134 119 private Dimension screen_size = null; 135 120 private ElementWrapper current_element = null; 136 private ElementWrapper current_subelement = null;137 private GValueNode current_value_node = null;138 121 /** A reference to ourselves so our inner classes can dispose of us. */ 139 122 private GEMS self = null; … … 142 125 private int current_attribute_type = -1; 143 126 144 private JLabel element_name = null; 145 private JLabel profile_name = null; 127 //private JLabel element_name = null; 146 128 private JLabel set_name = null; 147 129 private JScrollPane element_attributes_scroll = null; 148 private JScrollPane profile_attributes_scroll = null;149 130 private JScrollPane set_attributes_scroll = null; 150 private JScrollPane subelement_attributes_scroll = null;151 131 private JPanel details_pane = null; 152 private JPanel element_values_pane = null;153 private KeepTreeRootExpandedListener keep_root_expanded_listener = null;154 132 private GEMSModel model = null; 155 133 private GEMSNode current_node = null; 156 134 private MetadataSet current_set = null; 157 private Object target = null;158 135 public RemoveSetActionListener remove_set_action_listener; 159 private SmarterTable subelement_attributes = null;160 136 private SmarterTable element_attributes = null; 161 private SmarterTable profile_attributes = null;162 137 private SmarterTable set_attributes = null; 163 private SmarterTree element_values = null;164 138 public org.w3c.dom.Element rootelement; 165 139 … … 171 145 /** A tree that represents the current metadata sets associated with this collection. */ 172 146 private SmarterTree mds_tree = null; 173 private String current_collection_file = null;174 147 private String dialog_options[] = null; 175 148 private boolean atLeastOneSetChanged = false; … … 195 168 196 169 config = new Configuration(go.gsdl_path, null, null); 197 198 199 170 } 200 171 catch (Exception exception) { … … 226 197 dialog_options[1] = Dictionary.get("General.Cancel"); 227 198 228 // Creation229 setDefaultCloseOperation(DISPOSE_ON_CLOSE);230 setSize(SIZE);231 setJMenuBar(new GEMSMenuBar());232 Dictionary.setText(this, "GEMS.Title");233 234 JPanel content_pane = (JPanel) getContentPane();235 content_pane.setBackground(config.getColor("coloring.collection_heading_background", false));236 237 JPanel upper_pane = new JPanel();238 upper_pane.setOpaque(false);239 240 199 // Load all the core metadata sets (in the GLI "metadata" directory) 241 200 model = new GEMSModel(); … … 254 213 } 255 214 215 // Creation 216 setDefaultCloseOperation(DISPOSE_ON_CLOSE); 217 setSize(SIZE); 218 setJMenuBar(new GEMSMenuBar()); 219 Dictionary.setText(this, "GEMS.Title"); 220 221 JPanel content_pane = (JPanel) getContentPane(); 222 content_pane.setBackground(config.getColor("coloring.collection_heading_background", false)); 223 JPanel upper_pane = new JPanel(); 224 upper_pane.setOpaque(false); 225 JPanel set_details_pane = new JPanel(); 226 set_details_pane.setOpaque(false); 227 JPanel set_name_pane = new JPanel(); 228 set_name_pane.setOpaque(false); 229 JLabel set_name_label = new JLabel(); 230 set_name_label.setOpaque(false); 231 JPanel element_details_pane = new JPanel(); 232 element_details_pane.setOpaque(false); 233 JPanel element_inner_pane = new JPanel(); 234 element_inner_pane.setOpaque(false); 235 JPanel blank_pane = new JPanel(); // Some blank panel 236 blank_pane.setOpaque(false); 237 238 details_pane = new JPanel(); 239 details_pane.setOpaque(false); 240 card_layout = new CardLayout(); 241 set_name = new JLabel(); 242 256 243 JPanel mds_tree_pane = new JPanel(); 257 244 mds_tree_pane.setOpaque(false); 258 245 mds_tree_pane.setPreferredSize(new Dimension(300,500)); 246 259 247 mds_tree = new SmarterTree(model); 260 248 mds_tree.setCellRenderer(new GEMSTreeCellRenderer()); … … 264 252 mds_tree.setSelectionColor(config.getColor("coloring.collection_selection_background", false)); 265 253 mds_tree.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false)); 266 267 254 //add popupevent handler for tree items 268 269 255 mds_tree.addMouseListener(popupListener); 270 256 mds_tree.addKeyListener(new KeyPressedHandler()); 271 details_pane = new JPanel(); 272 details_pane.setOpaque(false); 273 card_layout = new CardLayout(); 274 275 JPanel set_details_pane = new JPanel(); 276 set_details_pane.setOpaque(false); 277 278 JPanel set_name_pane = new JPanel(); 279 set_name_pane.setOpaque(false); 280 JLabel set_name_label = new JLabel(); 281 set_name_label.setOpaque(false); 282 set_name = new JLabel(); 257 mds_tree.addTreeSelectionListener(new MDSTreeSelectionListener()); 283 258 284 259 JPanel set_attributes_pane = new JPanel(); … … 300 275 set_attributes.addMouseListener(new AddOrEditAttributeActionListener()); 301 276 set_attributes.addKeyListener(new RemoveAttributeActionListener()); //Listen for DELETE key 302 JPanel element_details_pane = new JPanel(); 303 element_details_pane.setOpaque(false); 304 305 JPanel element_name_pane = new JPanel(); 306 element_name_pane.setOpaque(false); 307 JLabel element_name_label = new JLabel(); 308 element_name_label.setOpaque(false); 309 310 JPanel element_inner_pane = new JPanel(); 311 element_inner_pane.setOpaque(false); 277 set_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(set_attributes)); 312 278 313 279 JPanel element_attributes_pane = new JPanel(); … … 328 294 element_attributes.addMouseListener(new AddOrEditAttributeActionListener()); 329 295 element_attributes.addKeyListener(new RemoveAttributeActionListener()); //For the DELETE key 330 331 element_values_layout = new CardLayout(); 332 element_values_pane = new JPanel(); 333 element_values_pane.setOpaque(false); 334 element_values = new SmarterTree(); 335 element_values.setBackground(config.getColor("coloring.collection_tree_background", false)); 336 element_values.setForeground(config.getColor("coloring.collection_tree_foreground", false)); 337 element_values.setRootVisible(false); 338 element_values.setSelectionColor(config.getColor("coloring.collection_selection_background", false)); 339 element_values.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false)); 340 341 JPanel subelement_details_pane = new JPanel(); 342 subelement_details_pane.setOpaque(false); 343 JPanel subelement_name_pane = new JPanel(); 344 subelement_name_pane.setOpaque(false); 345 JLabel subelement_name_label = new JLabel(); 346 subelement_name_label.setOpaque(false); 347 JPanel subelement_inner_pane = new JPanel(); 348 subelement_inner_pane.setOpaque(false); 349 350 JPanel subelement_attributes_pane = new JPanel(); 351 subelement_attributes_pane.setOpaque(false); 352 subelement_attributes_scroll = new JScrollPane(); 353 subelement_attributes_scroll.getViewport().setBackground(config.getColor("coloring.collection_tree_background", false)); 354 subelement_attributes_scroll.setOpaque(true); 355 subelement_attributes = new SmarterTable(); 356 subelement_attributes.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); 357 subelement_attributes.setBackground(config.getColor("coloring.collection_tree_background", false)); 358 subelement_attributes.setForeground(config.getColor("coloring.collection_tree_foreground", false)); 359 subelement_attributes.setHeadingBackground(config.getColor("coloring.collection_heading_background", false)); 360 subelement_attributes.setHeadingForeground(config.getColor("coloring.collection_heading_foreground", false)); 361 subelement_attributes.setSelectionColor(config.getColor("coloring.collection_selection_background", false)); 362 subelement_attributes.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false)); 363 subelement_attributes.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 364 subelement_attributes.addMouseListener(popupListener); 365 subelement_attributes.addMouseListener(new AddOrEditAttributeActionListener()); 366 subelement_attributes.addKeyListener(new RemoveAttributeActionListener()); //For the DELETE key 367 368 JPanel element_novalues_pane = new JPanel(); 369 370 keep_root_expanded_listener = new KeepTreeRootExpandedListener(); 371 372 JPanel profile_details_pane = new JPanel(); 373 profile_details_pane.setOpaque(false); 374 JPanel profile_name_pane = new JPanel(); 375 profile_name_pane.setOpaque(false); 376 JLabel profile_name_label = new JLabel(); 377 profile_name_label.setOpaque(false); 378 profile_name = new JLabel(); 379 profile_name.setBorder(BorderFactory.createLoweredBevelBorder()); 380 profile_name.setOpaque(false); 381 382 JPanel profile_attributes_pane = new JPanel(); 383 profile_attributes_pane.setOpaque(false); 384 profile_attributes_scroll = new JScrollPane(); 385 profile_attributes_scroll.getViewport().setBackground(config.getColor("coloring.collection_tree_background", false)); 386 profile_attributes_scroll.setOpaque(true); 387 profile_attributes = new SmarterTable(); 388 profile_attributes.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); 389 profile_attributes.setBackground(config.getColor("coloring.collection_tree_background", false)); 390 profile_attributes.setForeground(config.getColor("coloring.collection_tree_foreground", false)); 391 profile_attributes.setHeadingBackground(config.getColor("coloring.collection_heading_background", false)); 392 profile_attributes.setHeadingForeground(config.getColor("coloring.collection_heading_foreground", false)); 393 profile_attributes.setSelectionColor(config.getColor("coloring.collection_selection_background", false)); 394 profile_attributes.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false)); 395 profile_attributes.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 396 397 JPanel button_pane = new JPanel(); 398 button_pane.setOpaque(false); 399 400 JPanel button_label_pane = new JPanel(); 401 button_label_pane.setOpaque(false); 402 403 JLabel attribute_label = new JLabel(); 404 attribute_label.setOpaque(false); 405 Dictionary.setText(attribute_label, "GEMS.Attribute"); 406 407 JLabel element_label = new JLabel(); 408 element_label.setOpaque(false); 409 Dictionary.setText(element_label, "GEMS.Element"); 410 411 JLabel file_label = new JLabel(); 412 file_label.setOpaque(false); 413 Dictionary.setText(file_label, "GEMS.File"); 414 415 JLabel set_label = new JLabel(); 416 set_label.setOpaque(false); 417 Dictionary.setText(set_label, "GEMS.Set"); 418 419 JLabel value_label = new JLabel(); 420 value_label.setOpaque(false); 421 Dictionary.setText(value_label, "GEMS.Value"); 422 423 JPanel inner_button_pane = new JPanel(); 424 inner_button_pane.setOpaque(false); 296 element_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(element_attributes)); 425 297 426 298 add_element_action_listener = new AddElementActionListener(); 427 add_file_action_listener = new AddFileActionListener();428 299 add_set_action_listener = new AddSetActionListener(); 429 300 add_or_edit_attribute_action_listener = new AddOrEditAttributeActionListener(); 430 301 remove_set_action_listener = new RemoveSetActionListener(); 431 432 // Some blank panel433 JPanel blank_pane = new JPanel();434 blank_pane.setOpaque(false);435 JPanel edit_file_pane = new JPanel();436 edit_file_pane.setOpaque(false);437 JPanel edit_element_pane = new JPanel();438 edit_element_pane.setOpaque(false);439 JPanel edit_set_pane = new JPanel();440 edit_set_pane.setOpaque(false);441 442 element_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(element_attributes));443 subelement_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(subelement_attributes));444 profile_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(profile_attributes));445 set_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(set_attributes));446 mds_tree.addTreeSelectionListener(new MDSTreeSelectionListener());447 302 448 303 // Layout … … 450 305 mds_tree_pane.add(new JScrollPane(mds_tree), BorderLayout.CENTER); 451 306 307 //Set panes 452 308 set_name_pane.setLayout(new BorderLayout()); 453 309 set_name_pane.add(set_name_label, BorderLayout.WEST); … … 455 311 456 312 set_attributes_scroll.setViewportView(set_attributes); 457 458 313 set_attributes_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Attributes")), BorderFactory.createEmptyBorder(2,2,2,2))); 459 314 set_attributes_pane.setLayout(new BorderLayout()); … … 464 319 set_details_pane.add(set_name_pane, BorderLayout.NORTH); 465 320 set_details_pane.add(set_attributes_pane, BorderLayout.CENTER); 466 467 element_name_pane.setLayout(new BorderLayout()); 468 //element_name_pane.add(element_name_label, BorderLayout.WEST); 469 //element_name_pane.add(element_name, BorderLayout.CENTER); 470 321 322 //Element panes 471 323 element_attributes_scroll.setViewportView(element_attributes); 472 473 324 element_attributes_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Attributes")), BorderFactory.createEmptyBorder(2,2,2,2))); 474 325 element_attributes_pane.setLayout(new BorderLayout()); 475 326 element_attributes_pane.add(element_attributes_scroll, BorderLayout.CENTER); 476 327 477 element_values_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Values")), BorderFactory.createEmptyBorder(2,2,2,2)));478 element_values_pane.setLayout(new BorderLayout());479 element_values_pane.add(new JScrollPane(element_values), BorderLayout.CENTER);480 element_values_pane.setLayout(element_values_layout);481 //element_values_pane.add(element_novalues_pane, BLANK);482 //element_values_pane.add(new JScrollPane(element_values), VALUES);483 484 328 element_inner_pane.setLayout(new BorderLayout()); 485 329 element_inner_pane.add(element_attributes_pane); 486 //element_inner_pane.add(element_values_pane);487 330 488 331 element_details_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Element_Details")), BorderFactory.createEmptyBorder(2,2,2,2))); 489 332 element_details_pane.setLayout(new BorderLayout()); 490 //element_details_pane.add(element_name_pane, BorderLayout.NORTH);491 333 element_details_pane.add(element_inner_pane, BorderLayout.CENTER); 492 493 subelement_name_pane.setLayout(new BorderLayout()); 494 subelement_attributes_scroll.setViewportView(subelement_attributes); 495 subelement_attributes_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Attributes")), BorderFactory.createEmptyBorder(2,2,2,2))); 496 subelement_attributes_pane.setLayout(new BorderLayout()); 497 subelement_attributes_pane.add(subelement_attributes_scroll, BorderLayout.CENTER); 498 499 500 subelement_inner_pane.setLayout(new BorderLayout()); 501 subelement_inner_pane.add(subelement_attributes_pane); 502 subelement_details_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Subelement_Details")), BorderFactory.createEmptyBorder(2,2,2,2))); 503 subelement_details_pane.setLayout(new BorderLayout()); 504 subelement_details_pane.add(subelement_inner_pane, BorderLayout.CENTER); 505 506 profile_name_pane.setLayout(new BorderLayout()); 507 profile_name_pane.add(profile_name_label, BorderLayout.WEST); 508 profile_name_pane.add(profile_name, BorderLayout.CENTER); 509 510 profile_attributes_scroll.setViewportView(profile_attributes); 511 512 profile_attributes_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Profiles")), BorderFactory.createEmptyBorder(2,2,2,2))); 513 profile_attributes_pane.setLayout(new BorderLayout()); 514 profile_attributes_pane.add(profile_attributes_scroll, BorderLayout.CENTER); 515 516 profile_details_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Profile_Details")), BorderFactory.createEmptyBorder(2,2,2,2))); 517 profile_details_pane.setLayout(new BorderLayout()); 518 //profile_details_pane.add(profile_name_pane, BorderLayout.NORTH); 519 profile_details_pane.add(profile_attributes_pane, BorderLayout.CENTER); 520 334 335 //General panes 521 336 details_pane.setBorder(BorderFactory.createEmptyBorder(0,5,0,0)); 522 337 details_pane.setLayout(card_layout); … … 524 339 details_pane.add(set_details_pane, SET); 525 340 details_pane.add(element_details_pane, ELEMENT); 526 details_pane.add(subelement_details_pane, SUBELEMENT);527 details_pane.add(profile_details_pane, PROFILE);528 341 529 342 upper_pane.setLayout(new BorderLayout()); 530 343 upper_pane.add(mds_tree_pane, BorderLayout.WEST); 531 344 upper_pane.add(details_pane, BorderLayout.CENTER); 532 533 button_label_pane.setLayout(new GridLayout(4,1,0,2));534 button_label_pane.setBorder(BorderFactory.createEmptyBorder(0,0,0,2));535 536 inner_button_pane.setLayout(new GridLayout(4,3,0,2));537 538 button_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));539 button_pane.setLayout(new BorderLayout());540 //button_pane.add(button_label_pane, BorderLayout.WEST);541 //button_pane.add(inner_button_pane, BorderLayout.CENTER);542 345 543 346 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 544 347 content_pane.setLayout(new BorderLayout()); 545 348 content_pane.add(upper_pane, BorderLayout.CENTER); 546 content_pane.add(button_pane, BorderLayout.SOUTH);547 349 548 350 // initialise the selection … … 628 430 file_save.addActionListener(this); 629 431 file_save.setMnemonic(KeyEvent.VK_S); 630 // Dictionary.registerText(file_save, "GEMS.Menu.File_Save");631 432 Dictionary.registerText(file_save, "Menu.File_Save"); 632 433 … … 634 435 file_delete.addActionListener(new KeyPressedHandler()); //KeyPressedHandler handles deleting stuff. 635 436 file_delete.setMnemonic(KeyEvent.VK_S); 636 // Dictionary.registerText(file_delete, "GEMS.Menu.File_Delete");637 437 Dictionary.registerText(file_delete, "Menu.File_Delete"); 638 438 … … 640 440 file_preferences.addActionListener(this); 641 441 file_preferences.setMnemonic(KeyEvent.VK_S); 642 //Dictionary.registerText(file_preferences, "GEMS.Menu.File_Preferences");643 442 Dictionary.registerText(file_preferences, "Menu.File_Options"); 644 443 … … 678 477 edit.add(edit_paste); 679 478 680 // Help menu 479 // Help menu. Is not used! --Matthew 681 480 help = new JMenu(); 682 481 help.setIcon(Utility.HELP_ICON); … … 805 604 { 806 605 String file_name = file.getName().toLowerCase(); 807 if (file_name.endsWith(".mds") || file_name.indexOf(".") == -1) { 808 return true; 809 } 810 811 return false; 606 return(file_name.endsWith(".mds") || file_name.indexOf(".") == -1); 812 607 } 813 608 … … 860 655 exit(); 861 656 } 862 863 864 657 } 865 658 //called from MetadataSetManager...I don't think it should be here anymore, but for now it's ok … … 889 682 element_attributes = null; 890 683 set_attributes = null; 891 subelement_attributes = null;892 element_name = null;893 684 set_name = null; 894 element_values = null;895 685 mds_tree = null; 896 target = null;897 686 898 687 popupListener = null; … … 916 705 Class to handle adding or modifying element attributes. 917 706 */ 918 private class AddOrEditAttributeActionListener707 private class AddOrEditAttributeActionListener 919 708 extends ModalDialog 920 709 implements ActionListener, MouseListener { 921 922 923 924 925 926 927 928 929 930 931 710 private boolean add_type = true; 711 private ComboArea value = null; 712 private JButton cancel_button = null; 713 private JButton ok_button = null; 714 private JComboBox language_box = null; 715 private GComboBox name = null; 716 private HashMap name_to_values = null; 717 private JLabel target = null; 718 private JLabel target_label = null; 719 private Vector attributeLists = null; 720 932 721 //org.w3c.dom.Document lang = Utility.parse("/home/arosmain/gsdl/gli/classes/xml/languages.xml", false); 933 934 722 org.w3c.dom.Document lang = Utility.parse(Configuration.gsdl_path + "/gli/classes/xml/languages.xml", false); 723 935 724 /** Constructor. */ 936 725 public AddOrEditAttributeActionListener() { … … 938 727 setModal(true); 939 728 attributeLists = new Vector(); 940 //941 729 attributeLists.add("identifier"); 942 730 attributeLists.add("comment"); 943 731 attributeLists.add("definition"); 944 732 attributeLists.add("name"); 945 733 946 734 attributeLists.add("creator"); 947 735 attributeLists.add("date"); … … 1009 797 ok_button = new GLIButton(); 1010 798 ok_button.setMnemonic(KeyEvent.VK_O); 799 getRootPane().setDefaultButton(ok_button); 1011 800 Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip"); 1012 801 cancel_button = new GLIButton(); … … 1073 862 public void mouseClicked(MouseEvent e) 1074 863 { 1075 if(e.getSource() == element_attributes || e.getSource() == set_attributes || e.getSource() == subelement_attributes)864 if(e.getSource() == element_attributes || e.getSource() == set_attributes) 1076 865 { 1077 866 if(e.getClickCount() == 2) //Double click … … 1083 872 } 1084 873 } 1085 //required by MouseListener 1086 public void mouseEntered(MouseEvent e) 1087 { 1088 } 1089 //required by MouseListener 1090 public void mouseExited(MouseEvent e) 1091 { 1092 } 1093 //required by MouseListener 1094 public void mousePressed(MouseEvent e) 1095 { 1096 } 1097 //required by MouseListener 1098 public void mouseReleased(MouseEvent e) 1099 { 1100 } 874 //These methods are required by interface MouseListener 875 public void mouseEntered(MouseEvent e){} 876 public void mouseExited(MouseEvent e){} 877 public void mousePressed(MouseEvent e){} 878 public void mouseReleased(MouseEvent e){} 1101 879 1102 880 /** 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. … … 1105 883 public void actionPerformed(ActionEvent event) { 1106 884 Object source = event.getSource(); 1107 AttributeTableModel tablemodel = null;1108 885 AttributeTableModel model = null; 1109 String prevLang = new String("");1110 String prevValue = new String("");1111 886 1112 887 if(current_element != null) … … 1120 895 target.setText(current_set.toString()); 1121 896 Dictionary.setText(target_label, "GEMS.Target"); 1122 }1123 else if(current_subelement != null)1124 {1125 target.setText(current_subelement.getName());1126 Dictionary.setText(target_label, "GEMS.Subelement");1127 897 } 1128 898 … … 1135 905 boolean success = true; 1136 906 1137 // Add or edit a collect/set/element attribute907 // Add or edit a set/element attribute 1138 908 switch(current_attribute_type) { 1139 case GEMSNode.COLLECTION:1140 model = (AttributeTableModel) profile_attributes.getModel();1141 success = addOrEditCollectionAttribute(model);1142 break;1143 909 case GEMSNode.SET: 1144 910 model = (AttributeTableModel) set_attributes.getModel(); 1145 success = addOrEditSetAttribute(model); 1146 911 success = addOrEditSetAttribute(model); 1147 912 break; 1148 913 case GEMSNode.ELEMENT: … … 1150 915 success = addOrEditElementAttribute(model); 1151 916 break; 1152 1153 case GEMSNode.SUBELEMENT:1154 model = (AttributeTableModel) subelement_attributes.getModel();1155 success = addOrEditSubelementAttribute(model);1156 break;1157 1158 917 } 1159 918 1160 919 if (success) { 1161 920 // Hide dialog 1162 1163 921 atLeastOneSetChanged = true; 1164 922 setVisible(false); … … 1180 938 if(object != null) { 1181 939 java.util.List values = (java.util.List) name_to_values.get(object.toString()); 1182 if(values == null && current_attribute_type==GEMSNode.COLLECTION) {1183 values = msm.getElements();1184 }1185 940 1186 941 if(value != null && values != null){ … … 1192 947 } 1193 948 } 1194 else if (source == popupListener.menuAddAttributeAttribute || source == popupListener.menuAddAttributeSet || source == popupListener.menuAddAttributeElement || source == popupListener.menuAddAttributeSubelement){949 else if (source == popupListener.menuAddAttributeAttribute || source == popupListener.menuAddAttributeSet || source == popupListener.menuAddAttributeElement){ 1195 950 1196 951 Dictionary.setText(this, "GEMS.AddAttribute"); … … 1199 954 1200 955 } 1201 1202 1203 956 name.setEnabled(true); 1204 957 setVisible(true); 1205 958 } 1206 /* else if (source == popupListener.menuAddAttributeAttribute){ 1207 System.out.println("add attr\n"); 1208 1209 name.setEnabled(true); 1210 1211 }*/ 1212 /* else{ 1213 // Name combo box is enabled except when attributes are edited 1214 //name.setEnabled((source != popupListener.menuEditValue)); 1215 //System.out.println("elsed"); 1216 name_to_values.clear(); 1217 name.clear(); 1218 value.clear(); 1219 value.setText(""); 1220 // Build the correct name_to_values mapping 1221 // Attributes are slightly tricky as they can come from several sources. Has a collection file been selected... 1222 if(current_collection_file != null) { 1223 target.setText(current_collection_file); 1224 // Name is empty in this one, however values must be the current elements in the collection. 1225 language_box.setEnabled(false); 1226 } 1227 // or has an element been selected 1228 else if(current_element != null) { 1229 target.setText(current_element.toString()); 1230 // Develop a model for name based on known attributes from all other elements. 1231 java.util.List elements = msm.getElements(); 1232 for(int i = 0; i < elements.size(); i++) { 1233 ElementWrapper element = (ElementWrapper) elements.get(i); 1234 TreeSet attributes = element.getAttributes(); 1235 for(Iterator attribute_iterator = attributes.iterator(); attribute_iterator.hasNext(); ) { 1236 Attribute attribute = (Attribute) attribute_iterator.next(); 1237 java.util.List values = (java.util.List) name_to_values.get(attribute.name); 1238 if(values == null) { 1239 values = new ArrayList(); 1240 name_to_values.put(attribute.name, values); 1241 } 1242 if(!values.contains(attribute.value)) { 1243 values.add(attribute.value); 1244 } 1245 values = null; 1246 attribute = null; 1247 } 1248 attributes = null; 1249 element = null; 1250 } 1251 elements = null; 1252 language_box.setEnabled(true); 1253 } 1254 else if(current_set != null) { 1255 target.setText(current_set.toString()); 1256 // 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. 1257 java.util.List sets = msm.getSets(); 1258 for(int i = 0; i < sets.size(); i++) { 1259 MetadataSet set = (MetadataSet) sets.get(i); 1260 NamedNodeMap attributes = set.getAttributes(); 1261 for(int j = 0; j < attributes.getLength(); j++) { 1262 Attr attribute = (Attr) attributes.item(j); 1263 String name_str = attribute.getName(); 1264 String value_str = attribute.getValue(); 1265 java.util.List values = (java.util.List) name_to_values.get(name_str); 1266 if(values == null) { 1267 values = new ArrayList(); 1268 name_to_values.put(name_str, values); 1269 } 1270 if(!values.contains(value_str)) { 1271 values.add(value_str); 1272 } 1273 values = null; 1274 value_str = null; 1275 name_str = null; 1276 attribute = null; 1277 } 1278 attributes = null; 1279 set = null; 1280 language_box.setEnabled(false); 1281 } 1282 sets = null; 1283 // If this is an add remove all the attributes already present in the current set. 1284 if(source == add_attribute) { 1285 name.setEnabled(true); 1286 NamedNodeMap attributes = current_set.getAttributes(); 1287 for(int i = 0; i < attributes.getLength(); i++) { 1288 Attr attribute = (Attr) attributes.item(i); 1289 String name_str = attribute.getName(); 1290 name_to_values.remove(name_str); 1291 name_str = null; 1292 attribute = null; 1293 } 1294 attributes = null; 1295 } 1296 } 1297 // Otherwise we actually disable the name combobox 1298 else { 1299 name.setEnabled(false); 1300 } 1301 // Now name_to_values should contain a list of unique attribute names each mapping to a list of attribute values. 1302 for(Iterator name_iterator = name_to_values.keySet().iterator(); name_iterator.hasNext(); ) { 1303 name.add(name_iterator.next()); 1304 } 1305 // Now pritty up the dialog depending on the action type 1306 if(source == add_attribute || source == popupListener.menuAddAttributeSet || source == popupListener.menuAddAttributeElement || source == popupListener.menuAddAttributeAttribute) { 1307 add_type = true; 1308 Dictionary.setText(this, "GEMS.AddAttribute"); 1309 if(current_collection_file != null) { 1310 // Name is empty in this one, however values must be the current elements in the collection. 1311 java.util.List values = msm.getElements(); 1312 for(int i = 0; i < values.size(); i++) { 1313 value.add(new NameElementWrapperEntry(values.get(i))); 1314 } 1315 values = null; 1316 } 1317 setVisible(true); 1318 }*/ 1319 // else if(source == popupListener.menuAddAttributeAttribute){ 1320 1321 // System.out.println("fromattrib table"); 1322 // } 1323 // else if(source == popupListener.menuAddAttributeElement){ 1324 1325 // System.out.println("from elements"); 1326 // }*/ 959 1327 960 else if(current_attribute != -1) { 1328 961 this.editAttribute(); … … 1342 975 //grab the table model based on what is currently selected 1343 976 switch(current_attribute_type) { 1344 case GEMSNode.COLLECTION:1345 tablemodel = (AttributeTableModel) profile_attributes.getModel();1346 1347 break;1348 977 case GEMSNode.SET: 1349 978 tablemodel = (AttributeTableModel) set_attributes.getModel(); … … 1360 989 1361 990 break; 1362 1363 case GEMSNode.SUBELEMENT:1364 tablemodel = (AttributeTableModel) subelement_attributes.getModel();1365 //grab values in table1366 prevLang = tablemodel.getValueAt(current_attribute,1).toString();1367 prevValue = tablemodel.getValueAt(current_attribute,2).toString();1368 break;1369 1370 991 default: 1371 992 //by default grab element_attr's … … 1407 1028 1408 1029 switch(current_attribute_type) { 1409 case GEMSNode.COLLECTION:1410 model = (AttributeTableModel) profile_attributes.getModel();1411 break;1412 1030 case GEMSNode.ELEMENT: 1413 1031 model = (AttributeTableModel) element_attributes.getModel(); 1414 1032 break; 1415 1416 case GEMSNode.SUBELEMENT:1417 model = (AttributeTableModel) subelement_attributes.getModel();1418 break;1419 1420 1033 case GEMSNode.SET: 1421 1034 model = (AttributeTableModel) set_attributes.getModel(); … … 1449 1062 } 1450 1063 1451 //Is this method ever used? What's a collection attribute? --Matthew1452 private boolean addOrEditCollectionAttribute(AttributeTableModel model)1453 {1454 System.err.println("addOrEditCollectionAttribute was actually used!!"); //if this is ever used!!1455 String name_str = name.getSelectedItem().toString();1456 String value_str = Codec.transform(Codec.transformUnicode(value.getText()), Codec.TEXT_TO_DOM);1457 1458 // Remove the existing attribute if this is an edit1459 if(!add_type && current_attribute != -1) {1460 String old_source = (String) model.getValueAt(current_attribute, 0);1461 old_source = null;1462 model.removeRow(current_attribute);1463 }1464 1465 boolean cont = true;1466 // Check that there isn't already an entry for this attribute1467 if (!model.contains(name_str, 0)) {1468 // Update attribute table1469 model.add(new Attribute(name_str, value_str));1470 }1471 // Otherwise show an error message and do not proceed1472 else {1473 cont = false;1474 JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Attribute_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);1475 }1476 1477 value_str = null;1478 name_str = null;1479 return cont;1480 }1481 1482 1483 1064 private boolean addOrEditSetAttribute(AttributeTableModel model) 1484 1065 { … … 1553 1134 1554 1135 // Add the new attribute 1136 //System.err.println("current_element is: " + current_element.toString()); //debug 1555 1137 current_element.addAttribute(new_name_str, language_code, value_str); 1556 1138 // Update the attribute table … … 1571 1153 return cont; 1572 1154 } 1573 1574 //Very similar to addOrEditElementAttribute1575 private boolean addOrEditSubelementAttribute(AttributeTableModel model)1576 {1577 String new_name_str = name.getSelectedItem().toString();1578 String old_name_str = null;1579 String language_code = (String) language_box.getSelectedItem();1580 String value_str = Codec.transform(Codec.transformUnicode(value.getText()), Codec.TEXT_TO_DOM);1581 String old_value_str = null;1582 String old_lang_code = null;1583 boolean edit = false;1584 boolean cont = false;1585 1586 if(!add_type && current_attribute != -1) //An edit1587 {1588 Attribute old_attribute = model.getAttribute(current_attribute);1589 old_value_str = old_attribute.value;1590 old_lang_code = old_attribute.language;1591 old_name_str = (String) subelement_attributes.getValueAt(current_attribute, 0); //get the old name.1592 edit = true;1593 }1594 1595 //Check that there isn't already an entry for this attribute1596 if (!model.contains(new_name_str, 0) || (edit && new_name_str.equals(old_name_str)))1597 {1598 if(edit) //If this is an edit, remove the old attribute1599 {1600 current_subelement.removeAttribute(old_name_str, old_lang_code, old_value_str);1601 model.removeRow(current_attribute);1602 }1603 1604 // Add the new attribute1605 current_subelement.addAttribute(new_name_str, language_code, value_str);1606 // Update the attribute table1607 int row = model.add(new Attribute(new_name_str, language_code, value_str));1608 subelement_attributes.setRowSelectionInterval(row, row);1609 cont = true;1610 }1611 // Otherwise show an error message and do not proceed1612 else1613 {1614 cont = false;1615 JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Attribute_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);1616 }1617 1618 value_str = null;1619 language_code = null;1620 new_name_str = null;1621 return cont;1622 }1623 1624 1625 public void dispose() {1626 cancel_button = null;1627 name = null;1628 name_to_values = null;1629 ok_button = null;1630 target = null;1631 value = null;1632 super.dispose();1633 }1634 1155 } 1635 1156 1636 1637 private class AddSubelementActionListener extends ModalDialog implements ActionListener { 1638 private JButton cancel_button = null; 1639 private JButton ok_button = null; 1640 private JLabel element_field = null; 1641 private NonWhitespaceField name_field = null; 1157 1158 private class AddSubelementActionListener extends AddElementActionListener implements ActionListener { 1642 1159 1643 1160 public AddSubelementActionListener() { 1644 super(self);1645 setModal(true);1646 setSize(ADD_ELEMENT_SIZE);1647 // Creation1648 JPanel content_pane = (JPanel) getContentPane();1649 content_pane.setBackground(config.getColor("coloring.collection_heading_background", false));1650 JPanel center_pane = new JPanel();1651 center_pane.setOpaque(false);1652 1161 Dictionary.setText(this, "GEMS.Popup.menuAddSubelement"); 1653 1654 JPanel labels_pane = new JPanel();1655 labels_pane.setOpaque(false);1656 JLabel element_label = new JLabel();1657 element_label.setOpaque(false);1658 Dictionary.setText(element_label, "GEMS.Element");1659 element_field = new JLabel();1660 element_field.setOpaque(false);1661 1662 JPanel values_pane = new JPanel();1663 values_pane.setOpaque(false);1664 JLabel name_label = new JLabel();1665 name_label.setOpaque(false);1666 Dictionary.setText(name_label, "GEMS.Name");1667 name_field = new NonWhitespaceField();1668 name_field.setBackground(config.getColor("coloring.collection_tree_background", false));1669 name_field.setForeground(config.getColor("coloring.collection_tree_foreground", false));1670 name_field.setSelectionColor(config.getColor("coloring.collection_selection_background", false));1671 name_field.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));1672 1162 Dictionary.setTooltip(name_field, "GEMS.Subelement_Name_Tooltip"); 1673 1674 JPanel button_pane = new JPanel();1675 button_pane.setOpaque(false);1676 1677 ok_button = new GLIButton();1678 ok_button.setMnemonic(KeyEvent.VK_O);1679 getRootPane().setDefaultButton(ok_button);1680 Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");1681 cancel_button = new GLIButton();1682 cancel_button.setMnemonic(KeyEvent.VK_C);1683 Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");1684 1685 TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button);1686 1687 // Connection1688 cancel_button.addActionListener(this);1689 ok_button.addActionListener(this);1690 ok_button_enabler.add(name_field);1691 1692 // Layout1693 labels_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));1694 labels_pane.setLayout(new GridLayout(2,1));1695 labels_pane.add(element_label);1696 labels_pane.add(name_label);1697 1698 values_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));1699 values_pane.setLayout(new GridLayout(2,1));1700 values_pane.add(element_field);1701 values_pane.add(name_field);1702 1703 center_pane.setLayout(new BorderLayout(5,5));1704 center_pane.add(labels_pane, BorderLayout.WEST);1705 center_pane.add(values_pane, BorderLayout.CENTER);1706 1707 button_pane.setLayout(new GridLayout(1,2,0,5));1708 button_pane.add(ok_button);1709 button_pane.add(cancel_button);1710 1711 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));1712 content_pane.setLayout(new BorderLayout());1713 content_pane.add(center_pane, BorderLayout.CENTER);1714 content_pane.add(button_pane, BorderLayout.SOUTH);1715 1716 //use size of Add Element dialog1717 setLocation((config.screen_size.width - ADD_ELEMENT_SIZE.width) / 2, (config.screen_size.height - ADD_ELEMENT_SIZE.height) / 2);1718 1163 } 1719 1164 1720 1165 public void actionPerformed(ActionEvent event) 1721 1166 { 1722 //System.err.println("You chose to add a new subelement!!\n"); //debug1723 1167 Object source = event.getSource(); 1724 GEMSNode new_node = null;1725 1168 current_element = current_node.getElement(); //current_element here is used generically for a element or subelement. 1726 1169 … … 1728 1171 { 1729 1172 String name_str = Codec.transform(Codec.transformUnicode(name_field.getText()), Codec.TEXT_TO_DOM); 1730 1731 1173 current_set = msm.getSet(current_element.getNamespace()); 1732 //System.err.println("current_element.getNamespace(): " + current_element.getNamespace()); //debug1733 1174 if(current_set != null) 1734 1175 { … … 1740 1181 ElementWrapper subelement = current_set.addElement(name_str, language_code, current_node); 1741 1182 1742 // Then update the tree 1743 new_node = model.add(current_node, subelement, GEMSNode.SUBELEMENT); 1744 //Expand element so can see subelement. 1745 mds_tree.expandPath(new TreePath(current_node.getPath())); 1746 //Would like to select new subelement, but this doesn't seem to work. 1183 final GEMSNode new_node = model.add(current_node, subelement, GEMSNode.ELEMENT); //Then update the tree. 1184 1185 //SwingUtilities.invokeLater is used so that expandPath works on new parents. 1186 SwingUtilities.invokeLater(new Runnable() { 1187 public void run() { 1188 mds_tree.expandPath(new TreePath(current_node.getPath())); //Expand element so can see subelement. 1189 mds_tree.getSelectionModel().setSelectionPath(new TreePath(new_node)); //works, but node on tree doesn't look hilighted!! 1190 } 1191 }); 1747 1192 1748 1193 //Done. Finish up. … … 1769 1214 else 1770 1215 { 1771 element_field.setText(current_node.toString()); //set to the name of theelement1216 set_field.setText(current_node.toString()); //set to the name of the subelement 1772 1217 name_field.setText(""); 1773 1218 setVisible(true); … … 1780 1225 ok_button = null; 1781 1226 name_field = null; 1782 element_field = null;1227 set_field = null; 1783 1228 super.dispose(); 1784 1229 } … … 1789 1234 extends ModalDialog 1790 1235 implements ActionListener { 1791 pr ivateJButton cancel_button = null;1792 pr ivateJButton ok_button = null;1793 pr ivateJLabel set_field = null;1794 pr ivateNonWhitespaceField name_field = null;1236 protected JButton cancel_button = null; 1237 protected JButton ok_button = null; 1238 protected JLabel set_field = null; 1239 protected NonWhitespaceField name_field = null; 1795 1240 public AddElementActionListener() { 1796 1241 super(self); … … 1882 1327 String language_code = config.getLanguage(); 1883 1328 ElementWrapper element = current_set.addElement(name_str, language_code, null); 1329 1884 1330 // Then update the tree 1885 1331 model.add(current_node, element, GEMSNode.ELEMENT); 1886 mds_tree.expandPath(new TreePath(current_node.getPath())); //expand set. 1887 1332 //SwingUtilities.invokeLater is used so that expandPath works on new parents. 1333 SwingUtilities.invokeLater(new Runnable() { 1334 public void run() { 1335 mds_tree.expandPath(new TreePath(current_node.getPath())); //expand set. 1336 } 1337 }); 1338 1888 1339 // Done 1889 1340 element = null; … … 1929 1380 name_field = null; 1930 1381 set_field = null; 1931 ///ystem.err.println("Dispose AddElementActionListener");1932 1382 super.dispose(); 1933 1383 } 1934 1384 } 1935 1385 1936 private class AddFileActionListener 1937 extends ModalDialog 1938 implements ActionListener { 1939 private JButton cancel_button = null; 1940 private JButton ok_button = null; 1941 private JTextField name_field = null; 1942 public AddFileActionListener() { 1943 super(self); 1944 setModal(true); 1945 setSize(ADD_FILE_SIZE); 1946 // Creation 1947 JPanel content_pane = (JPanel) getContentPane(); 1948 content_pane.setBackground(config.getColor("coloring.collection_heading_background", false)); 1949 JPanel center_pane = new JPanel(); 1950 center_pane.setOpaque(false); 1951 JPanel profile_pane = new JPanel(); 1952 profile_pane.setOpaque(false); 1953 JLabel profile_label = new JLabel(); 1954 profile_label.setOpaque(false); 1955 Dictionary.setText(profile_label, "GEMS.Profile"); 1956 1957 JPanel name_pane = new JPanel(); 1958 name_pane.setOpaque(false); 1959 JLabel name_label = new JLabel(); 1960 name_label.setOpaque(false); 1961 Dictionary.setText(name_label, "GEMS.Name"); 1962 name_field = new JTextField(); 1963 name_field.setBackground(config.getColor("coloring.collection_tree_background", false)); 1964 name_field.setForeground(config.getColor("coloring.collection_tree_foreground", false)); 1965 name_field.setSelectionColor(config.getColor("coloring.collection_selection_background", false)); 1966 name_field.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false)); 1967 Dictionary.setTooltip(name_field, "GEMS.Profile_Name_Tooltip"); 1968 1969 JPanel button_pane = new JPanel(); 1970 button_pane.setOpaque(false); 1971 1972 ok_button = new GLIButton(); 1973 ok_button.setMnemonic(KeyEvent.VK_O); 1974 Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip"); 1975 cancel_button = new GLIButton(); 1976 cancel_button.setMnemonic(KeyEvent.VK_C); 1977 Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip"); 1978 1979 TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button); 1980 1981 // Connection 1982 cancel_button.addActionListener(this); 1983 ok_button.addActionListener(this); 1984 ok_button_enabler.add(name_field); 1985 1986 // Layout 1987 profile_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0)); 1988 profile_pane.setLayout(new BorderLayout()); 1989 profile_pane.add(profile_label, BorderLayout.CENTER); 1990 1991 name_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,5)); 1992 name_pane.setLayout(new BorderLayout(5,0)); 1993 name_pane.add(name_label, BorderLayout.WEST); 1994 name_pane.add(name_field, BorderLayout.CENTER); 1995 1996 center_pane.setLayout(new GridLayout(2,1,0,0)); 1997 center_pane.add(profile_pane); 1998 center_pane.add(name_pane); 1999 2000 button_pane.setLayout(new GridLayout(1,2,0,5)); 2001 button_pane.add(ok_button); 2002 button_pane.add(cancel_button); 2003 2004 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 2005 content_pane.setLayout(new BorderLayout()); 2006 content_pane.add(center_pane, BorderLayout.CENTER); 2007 content_pane.add(button_pane, BorderLayout.SOUTH); 2008 2009 setLocation((config.screen_size.width - ADD_FILE_SIZE.width) / 2, (config.screen_size.height - ADD_FILE_SIZE.height) / 2); 2010 } 2011 /** 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 2012 * @param event An <strong>ActionEvent</strong> containing information about the event. 2013 */ 2014 public void actionPerformed(ActionEvent event) { 2015 Object source = event.getSource(); 2016 if(source == ok_button) { 2017 String name_str = Codec.transform(Codec.transformUnicode(name_field.getText()), Codec.TEXT_TO_DOM); 2018 // Ensure that this source doesn't already exist. 2019 // if(!msm.profiler.containsSource(name_str)) { 2020 // // Add source with empty hashmap of actions. 2021 // msm.profiler.addSource(name_str); 2022 // // Add to tree 2023 // model.add(model.getProfileNode(), name_str, GEMSNode.COLLECTION); 2024 // setVisible(false); 2025 // } 2026 // Otherwise warn the user and don't hide the prompt. 2027 // else { 2028 JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.File_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE); 2029 // } 2030 name_str = null; 2031 } 2032 else if(source == cancel_button) { 2033 setVisible(false); 2034 } 2035 else { 2036 name_field.setText(""); 2037 setVisible(true); 2038 } 2039 source = null; 2040 } 2041 2042 public void dispose() { 2043 cancel_button = null; 2044 ok_button = null; 2045 name_field = null; 2046 ///ystem.err.println("Dispose AddFileActionListener"); 2047 super.dispose(); 2048 } 2049 } 2050 1386 2051 1387 private class AddSetActionListener 2052 1388 extends ModalDialog … … 2135 1471 //add sets to existingSetJComboBox 2136 1472 2137 //String tempstr = new String();2138 1473 JLabel dummyl = new JLabel(); 2139 1474 Dictionary.setText(dummyl, "GEMS.Add_Set.No_Inherit"); … … 2180 1515 Object source = event.getSource(); 2181 1516 2182 2183 // if(a_set_exists_with_this_namespace(namespace_field.getText()) == false){2184 1517 if(source == ok_button) { 2185 1518 //this code below handles whether we inherit from an existing set or not … … 2289 1622 ok_button = null; 2290 1623 name_field = null; 2291 ///ystem.err.println("Dispose AddSetActionListener");2292 1624 super.dispose(); 2293 1625 } … … 2327 1659 cancel_button.setMnemonic(KeyEvent.VK_C); 2328 1660 Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip"); 2329 TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button);1661 //TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button); 2330 1662 2331 1663 // Connection … … 2339 1671 Dictionary.setText(inheritJLabel, "GEMS.inheritMetadataSet"); 2340 1672 2341 int getSetsLen = msm.getSets().toArray().length;2342 Vector theSets = msm.getSets();2343 1673 File[] col_dir = new File(Configuration.gsdl_path + "/collect").listFiles(); 2344 1674 … … 2358 1688 2359 1689 existingSetJComboBox.setSelectedIndex(0); 2360 //String tempstr = new String();2361 1690 JLabel dummyl = new JLabel(); 2362 1691 Dictionary.setText(dummyl, "GEMS.Add_Set.No_Inherit"); … … 2416 1745 } 2417 1746 else { 2418 //name_field.setText("");2419 1747 setVisible(true); 2420 1748 } … … 2427 1755 } 2428 1756 } 2429 2430 2431 2432 /** This listener is responsible for keeping the root node of a value tree expanded where and when possible. */ 2433 private class KeepTreeRootExpandedListener 2434 implements TreeModelListener { 2435 /** Invoked after a node (or a set of siblings) has changed in some way. */ 2436 public void treeNodesChanged(TreeModelEvent e) { 2437 } 2438 /** Invoked after nodes have been inserted into the tree. */ 2439 public void treeNodesInserted(TreeModelEvent e) { 2440 // if(element_values != null && element_values.getModel() != null && element_values.getModel().getRoot() != null) { 2441 // element_values.expandPath(new TreePath(element_values.getModel().getRoot())); 2442 // } 2443 } 2444 /** Invoked after nodes have been removed from the tree. */ 2445 public void treeNodesRemoved(TreeModelEvent e) { 2446 } 2447 /** Invoked after the tree has drastically changed structure from a given node down. */ 2448 public void treeStructureChanged(TreeModelEvent e) { 2449 // element_values.expandPath(new TreePath(element_values.getModel().getRoot())); 2450 } 2451 } 2452 1757 1758 /* 1759 Class to handle removing set or element attributes. 1760 */ 2453 1761 private class RemoveAttributeActionListener 2454 1762 implements ActionListener, KeyListener { … … 2457 1765 Any implementation of KeyListener must include these mothods. 2458 1766 When the DELETE key is pressed, fire the actionPerformed event. 1767 @param e A <strong>KeyEvent</strong> containing information about the event. 2459 1768 */ 2460 1769 public void keyTyped(KeyEvent e){ … … 2466 1775 { 2467 1776 //DELETE key pressed 2468 actionPerformed((ActionEvent)null); 1777 actionPerformed((ActionEvent)null); //is there a better way? 2469 1778 } 2470 1779 } … … 2482 1791 if(result == 0) { 2483 1792 ignore = true; 2484 // Attributes are tricky little beasties, as they can come from several different places and depend upon what other little beasties have been selected 2485 // Has a collection file been selected... 2486 if(current_collection_file != null) { 2487 // Remove a profile 2488 String source = (String) profile_attributes.getValueAt(current_attribute, 0); 2489 // !!! msm.profiler.removeAction(current_collection_file, source); 2490 source = null; 2491 // Refresh table 2492 ((AttributeTableModel)profile_attributes.getModel()).removeRow(current_attribute); 2493 } 2494 // or has an element been selected 2495 else if(current_element != null) { 1793 //Attributes are tricky little beasties, as they can come from several different places and depend upon what other little beasties have been selected 1794 //Has an element been selected 1795 if(current_element != null) { 2496 1796 // Remove element attribute 2497 1797 String name = (String) element_attributes.getValueAt(current_attribute, 0); … … 2510 1810 ((AttributeTableModel)set_attributes.getModel()).removeRow(current_attribute); 2511 1811 } 2512 else if(current_subelement != null)2513 {2514 //Remove subelement attribute2515 String name = (String)subelement_attributes.getValueAt(current_attribute, 0);2516 String language = (String) subelement_attributes.getValueAt(current_attribute, 1);2517 String value = (String) subelement_attributes.getValueAt(current_attribute, 2);2518 current_subelement.removeAttribute(name, language, value);2519 2520 //Refresh table2521 ((AttributeTableModel)subelement_attributes.getModel()).removeRow(current_attribute);2522 }2523 1812 ignore = false; 2524 1813 2525 1814 atLeastOneSetChanged= true; 2526 1815 } 2527 1816 } … … 2533 1822 } 2534 1823 2535 /** 2536 Class to handle deletion of subelements. 2537 This class can be created from either PopupHandler or KeyPressedHandler. KeyPressedHandler passes a null ActionEvent!! 2538 @author: Matthew Whyte 2539 @Date last modified: 18/01/05 2540 25/01/05 2541 */ 2542 private class RemoveSubelementActionListener implements ActionListener { 2543 /** 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. 2544 * @param event An <strong>ActionEvent</strong> containing information about the event. 2545 */ 2546 public void actionPerformed(ActionEvent event) 2547 { 2548 if(current_subelement != null) 2549 { 2550 int result = JOptionPane.showOptionDialog(self, Dictionary.get("GEMS.Confirm_Removal", Dictionary.get("GEMS.Subelement")), Dictionary.get("GEMS.Confirm_Removal_Title"), JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, dialog_options, dialog_options[0]); 2551 if(result ==0) //Continue with remove 2552 { 2553 TreeNode selPath = current_node.getParent(); 2554 GEMSNode parent = (GEMSNode)selPath; 2555 current_element = parent.getElement(); 2556 2557 ignore = true; 2558 msm.removeElement(current_subelement, current_element); //remove the subelement. 2559 2560 // Clear selection 2561 mds_tree.clearSelection(); 2562 model.remove(current_node); //This is the new way of doing things :-) 2563 card_layout.show(details_pane, BLANK); //Show a blank panel. 2564 ignore = false; 2565 2566 atLeastOneSetChanged = true; 2567 } 2568 } 2569 else 2570 { 2571 System.err.println("No subelement is selected."); //This should not happen 2572 } 2573 } 2574 2575 } 2576 1824 /* 1825 Class to handle deletion of elements (including subelements). 1826 1827 Last modified 2/02/05 by Matthew Whyte 1828 */ 2577 1829 private class RemoveElementActionListener 2578 1830 implements ActionListener { … … 2587 1839 // Remove this attribute 2588 1840 if(result == 0) { 1841 //Get the parent element 1842 GEMSNode parent_node = (GEMSNode)current_node.getParent(); 1843 ElementWrapper parent_wrapped = parent_node.getElement(); 1844 2589 1845 ignore = true; 2590 //System.err.println("Current element's getElement: " + current_element.getElement()); //Debug 2591 msm.removeElement(current_element, null); 1846 msm.removeElement(current_element, parent_wrapped); 2592 1847 // Clear selection 2593 1848 mds_tree.clearSelection(); 2594 model.remove(current_element.getName(), GEMSNode.ELEMENT); //Need to use .getName() not .toString!! 2595 2596 // Meanwhile disable/enable controls given we had an element selected, but no longer do. 2597 //remove_element.setEnabled(false); 1849 model.remove(current_node); 1850 2598 1851 // Show a blank panel. 2599 1852 card_layout.show(details_pane, BLANK); … … 2604 1857 } 2605 1858 else { 2606 ///ystem.err.println("No current element selected.");1859 System.err.println("No element currently selected."); //This should not happen! 2607 1860 } 2608 1861 } 2609 1862 } 2610 2611 2612 2613 2614 private class RemoveFileActionListener2615 implements ActionListener {2616 /** 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.2617 * @param event An <strong>ActionEvent</strong> containing information about the event.2618 */2619 public void actionPerformed(ActionEvent event) {2620 if(current_collection_file != null) {2621 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]);2622 // Remove the current collection file profile from the profiler.2623 if(result == 0) {2624 ignore = true;2625 2626 // Clear selection2627 mds_tree.clearSelection();2628 model.remove(current_collection_file, GEMSNode.COLLECTION);2629 card_layout.show(details_pane, BLANK); //Show a blank panel.2630 ignore = false;2631 }2632 }2633 }2634 }2635 2636 1863 2637 1864 … … 2639 1866 Class to handle renaming of a set and/or it's namespace. 2640 1867 2641 Author: Matthew Whyte1868 @author: Matthew Whyte 2642 1869 Date last modified: 10/01/05 2643 1870 */ … … 2736 1963 } 2737 1964 } 2738 2739 1965 return flag; 2740 1966 } … … 2761 1987 //Hide the set that are about to rename 2762 1988 mds_tree.clearSelection(); 2763 model.remove(current_ set.toString(), GEMSNode.SET);1989 model.remove(current_node); 2764 1990 2765 1991 //Rename set & namespace … … 2809 2035 } 2810 2036 2811 /** 2812 Class to handle renaming of a subelement 2813 2814 Author: Matthew Whyte 2815 Date last modified: 18/01/05 2816 */ 2817 private class RenameSubelementActionListener extends RenameElementActionListener implements ActionListener { 2818 2819 /** 2820 Any implementation of ActionListener must include this method so that we can be informed when an action has occured. 2821 @param event An <string>ActionEvent</strong> containing information about the event. 2822 */ 2823 public void actionPerformed(ActionEvent event) 2824 { 2825 Object source = event.getSource(); 2826 2827 if(source == ok_button) 2828 { 2829 TreeNode selPath = current_node.getParent(); 2830 GEMSNode parent = (GEMSNode)selPath; 2831 current_element = parent.getElement(); 2832 //MetadataSet currentSet = msm.getSet(current_subelement.getNamespace()); 2833 String name_str = Codec.transform(Codec.transformUnicode(name_field.getText()), Codec.TEXT_TO_DOM); 2834 2835 if(!current_element.containsSubelement(name_str)) //Hopefully this works! 2836 { 2837 //Hide the element that are about to rename 2838 mds_tree.clearSelection(); 2839 model.remove(current_node); 2840 2841 msm.renameElement(current_subelement, name_str); //rename the element 2842 model.add(parent, current_subelement, GEMSNode.SUBELEMENT); 2843 2844 //Finish up 2845 ignore = false; 2846 atLeastOneSetChanged = true; 2847 setVisible(false); 2848 } 2849 2850 // Otherwise show an error message and do not proceed. 2851 else 2852 { 2853 JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Subelement_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE); 2854 } 2855 2856 name_str = null; 2857 } 2858 2859 else if(source == cancel_button) 2860 { 2861 setVisible(false); //hide dialog 2862 } 2863 else 2864 { 2865 Dictionary.setText(this, "GEMS.Popup.menuRenameSubelement"); //Set title of dialog 2866 name_field.setText(current_subelement.getNameOnly()); //show old name 2867 setVisible(true); //Show the dialog 2868 } 2869 2870 source = null; 2871 } 2872 } 2037 2873 2038 2874 2039 /** 2875 2040 Class to handle renaming of an element. 2876 2041 2877 Author: Matthew Whyte2042 @author: Matthew Whyte 2878 2043 Date last modified: 10/01/05 2879 2044 */ … … 2970 2135 TreeNode selPath = current_node.getParent(); 2971 2136 GEMSNode parent = (GEMSNode)selPath; 2972 GEMSNode new_node = null;2973 2137 MetadataSet currentSet = msm.getSet(current_element.getNamespace()); 2974 2138 String name_str = Codec.transform(Codec.transformUnicode(name_field.getText()), Codec.TEXT_TO_DOM); 2975 G ValueModel value_model = msm.getValueTree(current_element);2976 2139 GEMSNode new_node = null; 2140 2977 2141 // If this element doesn't already exist. 2978 2142 if(!currentSet.containsElement(name_str)) //Do the renaming! 2979 2143 { 2980 //Hide the element that are about to rename 2981 //mds_tree.clearSelection(); 2982 model.remove(current_element.getName(), GEMSNode.ELEMENT); 2144 model.remove(current_node); //Hide the element that are about to rename 2145 msm.renameElement(current_element, name_str); //rename the element 2146 //Add the new element 2147 new_node = model.add(parent, current_element, GEMSNode.ELEMENT); 2983 2148 2984 msm.renameElement(current_element, name_str); //rename the element 2149 //mds_tree.setSelectionPath(new_node_path); //would like to do this but doesn't hilight tree :-( 2150 card_layout.show(details_pane, BLANK); // Show a blank panel. 2985 2151 2986 new_node = model.add(parent, current_element, GEMSNode.ELEMENT); 2987 TreePath new_node_path = new TreePath(new_node.getPath()); 2988 2989 value_model.nodeChanged((TreeNode)current_node); //trial! 2990 value_model.nodeStructureChanged((TreeNode)current_node); 2991 mds_tree.repaint(); 2992 2993 //mds_tree.setSelectionPath(new_node_path); 2994 //Could now select the new element, but for now will just clean up ;-) 2995 // Disable/enable controls given we had an element selected, but no longer do. 2996 //card_layout.show(details_pane, BLANK); // Show a blank panel. 2997 //ignore = false; 2998 2152 //finish up 2999 2153 currentSet.setSetChanged(true); 3000 2154 atLeastOneSetChanged = true; … … 3037 2191 /** 3038 2192 Class to handle DELETE key presses on the tree. 3039 The class then fires the appropriate event to remove that subelement/element/set.2193 The class then fires the appropriate event to remove that element/set. 3040 2194 Attributes in the table are handled directly by the RemoveAttributeActionListener 3041 2195 … … 3086 2240 if(cont) 3087 2241 { 3088 3089 2242 //Check to see if pressed on Set or Element. 3090 2243 TreePath selPath = mds_tree.getSelectionPath(); 3091 2244 GEMSNode t = (GEMSNode)selPath.getLastPathComponent(); 3092 2245 3093 if(t.type == T_ SUBELEMENT) //Remove the subelement2246 if(t.type == T_ELEMENT) //Remove the element 3094 2247 { 3095 RemoveSubelementActionListener removeSubelement = new RemoveSubelementActionListener();3096 removeSubelement.actionPerformed((ActionEvent)null);3097 }3098 else if(t.type == T_ELEMENT) //Remove the element3099 {3100 //System.err.println("element");3101 2248 RemoveElementActionListener removeElement = new RemoveElementActionListener(); 3102 2249 removeElement.actionPerformed((ActionEvent)null); 3103 2250 } 3104 3105 else if(t.type == T_ROOT)3106 {3107 //Do nothing3108 System.err.println("Tree type of ROOT: this should not happen!");3109 }3110 2251 else if(t.type == T_SET) //Remove the whole set 3111 2252 { 3112 //System.err.println("set");3113 2253 RemoveSetActionListener removeSet = new RemoveSetActionListener(); 3114 2254 removeSet.actionPerformed((ActionEvent)null); … … 3118 2258 } 3119 2259 3120 3121 3122 3123 2260 3124 2261 private class RemoveSetActionListener … … 3151 2288 // Clear selection 3152 2289 mds_tree.clearSelection(); 3153 model.remove(current_ set.toString(), GEMSNode.SET);2290 model.remove(current_node); 3154 2291 card_layout.show(details_pane, BLANK); //Show a blank panel. 3155 2292 ignore = false; 3156 2293 3157 }3158 }3159 }3160 }3161 3162 /** 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. */3163 private class RemoveValueActionListener3164 implements ActionListener {3165 /** 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 to3166 * @param event An <strong>ActionEvent</strong> containing information about the event.3167 */3168 public void actionPerformed(ActionEvent event) {3169 if(current_value_node != null) {3170 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]);3171 // Remove the current selected value3172 if(result == 0) {3173 ignore = true;3174 ignore = false; //What the heck?? --Matthew3175 3176 //does this ever get called?3177 System.out.println("\nGEMS.RemovevalueActionListener called");3178 atLeastOneSetChanged = true;3179 2294 } 3180 2295 } … … 3247 2362 { 3248 2363 current_attribute = table.getSelectedRow(); 3249 /* 3250 if((current_attribute = table.getSelectedRow()) != -1) 3251 { 3252 } 3253 else 3254 { 3255 current_attribute = -1; 3256 } 3257 */ 3258 } 3259 } 3260 } 3261 3262 private class ElementValuesTreeSelectionListener 3263 implements TreeSelectionListener { 3264 public void valueChanged(TreeSelectionEvent event) { 3265 if(element_values.getSelectionCount() > 0) { 3266 // Retrieve the selected value node. 3267 TreePath selected_path = element_values.getSelectionPath(); 3268 current_value_node = (GValueNode) selected_path.getLastPathComponent(); 3269 } 3270 else { 3271 current_value_node = null; 3272 } 2364 } 3273 2365 } 3274 2366 } … … 3278 2370 public void valueChanged(TreeSelectionEvent event) { 3279 2371 if(!ignore) { 3280 GValueModel value_model = null;3281 2372 // Clear all variables based on previous tree selection 3282 current_collection_file = null;3283 2373 current_element = null; 3284 2374 current_set = null; … … 3291 2381 current_attribute_type = current_node.getType(); 3292 2382 switch(current_attribute_type) { 3293 case GEMSNode.COLLECTION:3294 current_collection_file = (String) current_node.getUserObject();3295 atm = current_node.getModel();3296 if(atm == null) {3297 attributes = new TreeSet();3298 3299 atm = new AttributeTableModel(attributes, Dictionary.get("GEMS.Source"), Dictionary.get("GEMS.Target"), Dictionary.get("GEMS.Ignore"));3300 }3301 profile_attributes.setModel(atm);3302 atm.setScrollPane(profile_attributes_scroll);3303 atm.setTable(profile_attributes);3304 3305 card_layout.show(details_pane, PROFILE);3306 break;3307 3308 case GEMSNode.SUBELEMENT:3309 current_subelement = current_node.getSubelement();3310 3311 atm = current_node.getModel();3312 if(atm == null) {3313 atm = new AttributeTableModel(current_subelement.getAttributes(), Dictionary.get("GEMS.Name"), Dictionary.get("GEMS.Language_Code"), Dictionary.get("GEMS.Value"), "");3314 }3315 3316 subelement_attributes.setModel(atm);3317 atm.setScrollPane(subelement_attributes_scroll);3318 atm.setTable(subelement_attributes);3319 //System.err.println("atm is: " + atm); //debug3320 3321 card_layout.show(details_pane, SUBELEMENT);3322 break;3323 2383 3324 2384 case GEMSNode.ELEMENT: … … 3333 2393 atm.setTable(element_attributes); 3334 2394 3335 // Be careful not to add the keep_root_expanded_listener over and over!3336 value_model = msm.getValueTree(current_element);3337 if(value_model != null) {3338 value_model.removeTreeModelListener(keep_root_expanded_listener); // Remove it if its already there3339 value_model.addTreeModelListener(keep_root_expanded_listener); // Then add again.3340 element_values.setModel(value_model);3341 element_values_layout.show(element_values_pane, VALUES);3342 }3343 else {3344 //this shouldn't happen!3345 element_values_layout.show(element_values_pane, BLANK);3346 }3347 2395 card_layout.show(details_pane, ELEMENT); 3348 2396 break; … … 3371 2419 attributes = null; 3372 2420 break; 3373 case GEMSNode.PROFILER:3374 2421 3375 2422 default: … … 3395 2442 3396 2443 //PopupListener is our main manager for all right-click popups 3397 class PopupListener extends MouseAdapter implements ActionListener{ 3398 JPopupMenu setPopup; 3399 JPopupMenu subelementPopup; 3400 JPopupMenu elementPopup; 3401 JPopupMenu attributePopup; 3402 //all of our popup menu items EVER! 3403 JMenuItem menuAddSet; 3404 JMenuItem menuRenameSet; 3405 JMenuItem menuAddElement; 3406 JMenuItem menuAddAttributeSet; 3407 3408 JMenuItem menuRenameSubelement; 3409 JMenuItem menuDeleteSubelement; 3410 JMenuItem menuAddAttributeSubelement; 3411 JMenuItem menuRenameElement; 3412 3413 JMenuItem menuDeleteElement; 3414 JMenuItem menuAddAttributeElement; 3415 JMenuItem menuAddSubelement; 3416 JMenuItem menuAddSubelementCopy; 3417 3418 JMenuItem menuEditValue; 3419 JMenuItem menuDeleteAttribute; 3420 JMenuItem menuAddAttributeAttribute; 3421 3422 JMenuItem menuRemoveSet; 3423 2444 class PopupListener extends MouseAdapter implements ActionListener{ 2445 JPopupMenu setPopup; 2446 JPopupMenu elementPopup; 2447 JPopupMenu attributePopup; 2448 2449 //all of our popup menu items EVER! 2450 JMenuItem menuAddAttributeSet; 2451 JMenuItem menuAddElement; 2452 JMenuItem menuRenameSet; 2453 JMenuItem menuRemoveSet; 2454 2455 JMenuItem menuAddAttributeElement; 2456 JMenuItem menuAddSubelement; 2457 JMenuItem menuRenameElement; 2458 JMenuItem menuDeleteElement; 2459 2460 JMenuItem menuAddAttributeAttribute; 2461 JMenuItem menuEditValue; 2462 JMenuItem menuDeleteAttribute; 2463 3424 2464 GEMS GEMSRef = null; 3425 2465 PopupListener(GEMS g) { 3426 2466 setPopup = new JPopupMenu(); 3427 subelementPopup = new JPopupMenu();3428 2467 elementPopup = new JPopupMenu(); 3429 2468 attributePopup = new JPopupMenu(); … … 3431 2470 //reference to our parent(GEMS), because some of the actionlisteners would not 3432 2471 //work unless they were declared in GEMS, and I need a way to reference GEMS 3433 3434 2472 GEMSRef = g; 3435 2473 3436 // create the MenuItems3437 3438 //set related popups3439 menuAdd Set =new JMenuItem();3440 2474 //Create the menu items 2475 menuAddAttributeSet = new JMenuItem(); 2476 Dictionary.setText(menuAddAttributeSet, "GEMS.Popup.menuAddAttribute"); 2477 menuAddElement =new JMenuItem(); 2478 Dictionary.setText(menuAddElement,"GEMS.Popup.menuAddElement"); 3441 2479 menuRenameSet = new JMenuItem(); 3442 2480 Dictionary.setText(menuRenameSet,"GEMS.Popup.menuRenameSet"); 3443 3444 menuAddElement =new JMenuItem();3445 // Dictionary.setText(menuAddElement,"GEMS.Popup.menuAddElement");3446 Dictionary.setText(menuAddElement,"GEMS.Add_Element_Tooltip");3447 3448 menuAddAttributeSet = new JMenuItem();3449 // Dictionary.setText(menuAddAttributeSet, "GEMS.Popup.menuAddAttribute");3450 Dictionary.setText(menuAddAttributeSet, "GEMS.Add_Attribute_Tooltip");3451 3452 3453 2481 menuRemoveSet = new JMenuItem(); 3454 Dictionary.setText(menuRemoveSet,"GEMS.Remove_Set_Tooltip"); 3455 3456 //subelement related GEMS.Popups 3457 menuRenameSubelement = new JMenuItem(); 3458 Dictionary.setText(menuRenameSubelement,"GEMS.Popup.menuRenameSubelement"); 3459 3460 menuDeleteSubelement=new JMenuItem(); 3461 Dictionary.setText(menuDeleteSubelement,"GEMS.Popup.menuRemoveSubelement"); 3462 3463 menuAddAttributeSubelement=new JMenuItem(); 3464 // Dictionary.setText(menuAddAttributeSubelement,"GEMS.Popup.menuAddAttribute"); 3465 Dictionary.setText(menuAddAttributeSubelement,"GEMS.Add_Attribute_Tooltip"); 3466 3467 //element related GEMS.Popups 2482 Dictionary.setText(menuRemoveSet, "GEMS.Popup.menuRemoveSet"); 2483 2484 menuAddAttributeElement=new JMenuItem(); 2485 Dictionary.setText(menuAddAttributeElement,"GEMS.Popup.menuAddAttribute"); 2486 menuAddSubelement=new JMenuItem(); 2487 Dictionary.setText(menuAddSubelement,"GEMS.Popup.menuAddSubelement"); 3468 2488 menuRenameElement=new JMenuItem(); 3469 2489 Dictionary.setText(menuRenameElement,"GEMS.Popup.menuRenameElement"); 3470 // Dictionary.setText(menuRenameElement,"GEMS.Rename_Element_Tooltip");3471 3472 2490 menuDeleteElement=new JMenuItem(); 3473 // Dictionary.setText(menuDeleteElement,"GEMS.Popup.menuRemoveElement"); 3474 Dictionary.setText(menuDeleteElement,"GEMS.Remove_Element_Tooltip"); 3475 3476 menuAddAttributeElement=new JMenuItem(); 3477 //Dictionary.setText(menuAddAttributeElement,"GEMS.Popup.menuAddAttribute"); 3478 Dictionary.setText(menuAddAttributeElement,"GEMS.Add_Attribute_Tooltip"); 3479 3480 menuAddSubelement=new JMenuItem(); 3481 Dictionary.setText(menuAddSubelement,"GEMS.Popup.menuAddSubelement"); 3482 //Dictionary.setText(menuAddSubelement,"GEMS.Add_Subelement"); 3483 menuAddSubelementCopy = new JMenuItem(); //A copy of menuAddSubelement 3484 Dictionary.setText(menuAddSubelementCopy, "GEMS.Popup.menuAddSubelement"); 3485 3486 //attribute related GEMS.Popups 2491 Dictionary.setText(menuDeleteElement,"GEMS.Popup.menuRemoveElement"); 2492 2493 menuAddAttributeAttribute=new JMenuItem(); 2494 Dictionary.setText(menuAddAttributeAttribute,"GEMS.Popup.menuAddAttribute"); 3487 2495 menuEditValue=new JMenuItem(); 3488 //Dictionary.setText(menuEditValue,"GEMS.Popup.menuEditValue"); 3489 Dictionary.setText(menuEditValue,"GEMS.Edit_Value_Tooltip"); 3490 2496 Dictionary.setText(menuEditValue,"GEMS.Popup.menuEditValue"); 3491 2497 menuDeleteAttribute=new JMenuItem(); 3492 // Dictionary.setText(menuDeleteAttribute,"GEMS.Popup.menuRemoveAttribute"); 3493 Dictionary.setText(menuDeleteAttribute,"GEMS.Remove_Attribute_Tooltip"); 3494 3495 menuAddAttributeAttribute=new JMenuItem(); 3496 // Dictionary.setText(menuAddAttributeAttribute,"GEMS.Popup.menuAddAttribute"); 3497 Dictionary.setText(menuAddAttributeAttribute,"GEMS.Add_Attribute_Tooltip"); 2498 Dictionary.setText(menuDeleteAttribute,"GEMS.Popup.menuRemoveAttribute"); 3498 2499 3499 //start Associate the menu items with the appropriate popups: 3500 setPopup.add(menuAddAttributeSet); 3501 setPopup.add(menuAddElement); 3502 setPopup.add(menuRenameSet); 3503 setPopup.add(menuRemoveSet); 3504 3505 elementPopup.add(menuAddAttributeElement); 3506 elementPopup.add(menuAddSubelement); 3507 elementPopup.add(menuRenameElement); 3508 elementPopup.add(menuDeleteElement); 3509 3510 subelementPopup.add(menuAddAttributeSubelement); 3511 //subelementPopup.add(menuAddSubelementCopy); 3512 subelementPopup.add(menuRenameSubelement); 3513 subelementPopup.add(menuDeleteSubelement); 3514 3515 attributePopup.add(menuAddAttributeAttribute); 3516 attributePopup.add(menuEditValue); 3517 attributePopup.add(menuDeleteAttribute); 3518 //end Associate the menu items with the appropriate popups: 3519 3520 menuRemoveSet.addActionListener(new RemoveSetActionListener()); 3521 menuAddElement.addActionListener(new AddElementActionListener()); 3522 menuAddAttributeSet.addActionListener(new AddOrEditAttributeActionListener()); 3523 menuRenameSubelement.addActionListener(new RenameSubelementActionListener()); 3524 menuDeleteSubelement.addActionListener(new RemoveSubelementActionListener()); 3525 menuAddAttributeSubelement.addActionListener(new AddOrEditAttributeActionListener()); 3526 3527 menuRenameSet.addActionListener(new RenameSetActionListener()); 3528 menuRenameElement.addActionListener(new RenameElementActionListener()); 3529 menuDeleteElement.addActionListener(new RemoveElementActionListener()); 3530 menuAddAttributeElement.addActionListener(new AddOrEditAttributeActionListener()); 3531 menuAddSubelement.addActionListener(new AddSubelementActionListener()); 3532 menuAddSubelementCopy.addActionListener(new AddSubelementActionListener()); 3533 menuEditValue.addActionListener(new AddOrEditAttributeActionListener()); 3534 menuDeleteAttribute.addActionListener(new RemoveAttributeActionListener()); 3535 menuAddAttributeAttribute.addActionListener(new AddOrEditAttributeActionListener()); 3536 2500 //Associate the menu items with the appropriate popups: 2501 setPopup.add(menuAddAttributeSet); 2502 setPopup.add(menuAddElement); 2503 setPopup.add(menuRenameSet); 2504 setPopup.add(menuRemoveSet); 2505 2506 elementPopup.add(menuAddAttributeElement); 2507 elementPopup.add(menuAddSubelement); 2508 elementPopup.add(menuRenameElement); 2509 elementPopup.add(menuDeleteElement); 2510 2511 attributePopup.add(menuAddAttributeAttribute); 2512 attributePopup.add(menuEditValue); 2513 attributePopup.add(menuDeleteAttribute); 2514 2515 //Add appropriate action listeners to the menu items. 2516 menuAddAttributeSet.addActionListener(new AddOrEditAttributeActionListener()); 2517 menuAddElement.addActionListener(new AddElementActionListener()); 2518 menuRenameSet.addActionListener(new RenameSetActionListener()); 2519 menuRemoveSet.addActionListener(new RemoveSetActionListener()); 2520 2521 menuAddAttributeElement.addActionListener(new AddOrEditAttributeActionListener()); 2522 menuAddSubelement.addActionListener(new AddSubelementActionListener()); 2523 menuRenameElement.addActionListener(new RenameElementActionListener()); 2524 menuDeleteElement.addActionListener(new RemoveElementActionListener()); 2525 2526 menuEditValue.addActionListener(new AddOrEditAttributeActionListener()); 2527 menuDeleteAttribute.addActionListener(new RemoveAttributeActionListener()); 2528 menuAddAttributeAttribute.addActionListener(new AddOrEditAttributeActionListener()); 3537 2529 } 2530 3538 2531 public void mouseClicked(MouseEvent e) { 3539 2532 maybeShowPopup(e); … … 3541 2534 public void mousePressed(MouseEvent e){ 3542 2535 maybeShowPopup(e); 3543 3544 } 2536 } 3545 2537 public void mouseReleased(MouseEvent e) { 3546 2538 maybeShowPopup(e); … … 3548 2540 3549 2541 private void maybeShowPopup(MouseEvent e) { 3550 3551 int selRow = mds_tree.getRowForLocation(e.getX(), e.getY()); 3552 TreePath selPath = mds_tree.getPathForLocation(e.getX(), e.getY()); 3553 Point p = null; 2542 TreePath selPath = mds_tree.getPathForLocation(e.getX(), e.getY()); 2543 Point p = null; 3554 2544 if (e.isPopupTrigger()) { 3555 3556 if(e.getSource() == mds_tree) { 3557 try { 3558 3559 GEMSNode t = (GEMSNode)selPath.getLastPathComponent(); 3560 3561 mds_tree.setSelectionPath(selPath); //Select node right-clicked on 3562 3563 if(t.type == T_ELEMENT){ 2545 2546 if(e.getSource() == mds_tree) { 2547 try { 2548 GEMSNode t = (GEMSNode)selPath.getLastPathComponent(); 3564 2549 3565 elementPopup.show(e.getComponent(), 3566 e.getX(), e.getY()); 2550 mds_tree.setSelectionPath(selPath); //Select node right-clicked on 2551 2552 if(t.type == T_ELEMENT){ 2553 elementPopup.show(e.getComponent(), e.getX(), e.getY()); 2554 } 2555 else if(t.type == T_SET){ 2556 setPopup.show(e.getComponent(), e.getX(), e.getY()); 2557 } 3567 2558 } 3568 3569 else if(t.type == T_SUBELEMENT) 3570 { 3571 subelementPopup.show(e.getComponent(), e.getX(), e.getY()); 3572 } 3573 3574 else if(t.type == T_ROOT){ 3575 3576 setPopup.show(e.getComponent(), 3577 e.getX(), e.getY()); 2559 catch(Exception NullPointerException) { 2560 //Right-clicked in tree area, but no item to select. Do nothing. 3578 2561 } 3579 else if(t.type == T_SET){ 3580 3581 setPopup.show(e.getComponent(), 3582 e.getX(), e.getY()); 3583 } 3584 } 3585 catch(Exception NullPointerException) { 3586 //Right-clicked in tree area, but no item to select. Do nothing. 3587 } 3588 3589 finally { 3590 ; 3591 3592 } 3593 3594 3595 } 3596 else if(e.getSource() == set_attributes){ //When right-click on table of set attributes 3597 3598 //Select the table row that was right-clicked on. 3599 p = e.getPoint(); 3600 set_attributes.changeSelection(set_attributes.rowAtPoint(p), set_attributes.columnAtPoint(p), false, false); 3601 3602 attributePopup.show(e.getComponent(), 3603 e.getX(), e.getY()); 3604 } 3605 else if(e.getSource() == element_attributes) { //When right-click on table of element attributes 3606 3607 //Select the table row that was right-clicked on. 3608 p = e.getPoint(); 3609 element_attributes.changeSelection(element_attributes.rowAtPoint(p), element_attributes.columnAtPoint(p), false, false); 3610 3611 attributePopup.show(e.getComponent(), 3612 e.getX(), e.getY()); 3613 } 3614 else if(e.getSource() == subelement_attributes) { //When right-click on table of subelement attributes 3615 3616 //Select the table row that was right-clicked on. 3617 p = e.getPoint(); 3618 subelement_attributes.changeSelection(subelement_attributes.rowAtPoint(p), subelement_attributes.columnAtPoint(p), false, false); 3619 3620 attributePopup.show(e.getComponent(), 3621 e.getX(), e.getY()); 3622 } 2562 } 2563 else if(e.getSource() == set_attributes){ //When right-click on table of set attributes 2564 //Select the table row that was right-clicked on. 2565 p = e.getPoint(); 2566 set_attributes.changeSelection(set_attributes.rowAtPoint(p), set_attributes.columnAtPoint(p), false, false); 2567 attributePopup.show(e.getComponent(), e.getX(), e.getY()); 2568 } 2569 else if(e.getSource() == element_attributes) { //When right-click on table of element attributes 2570 //Select the table row that was right-clicked on. 2571 p = e.getPoint(); 2572 element_attributes.changeSelection(element_attributes.rowAtPoint(p), element_attributes.columnAtPoint(p), false, false); 2573 attributePopup.show(e.getComponent(), e.getX(), e.getY()); 2574 } 3623 2575 } 3624 2576 } 3625 3626 3627 3628 System.out.println("NO way hose");3629 2577 2578 public void actionPerformed(ActionEvent e) { 2579 //This should never happen!! 2580 System.err.println("Error: actionPerformed was called in class PopupListener. This should never happen!"); 2581 } 3630 2582 } 3631 2583
Note:
See TracChangeset
for help on using the changeset viewer.