Changeset 8971
- Timestamp:
- 2005-02-07T10:36:51+13:00 (19 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer/gems
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/gems/ElementWrapper.java
r8932 r8971 63 63 private String namespace = ""; 64 64 private ArrayList subelements = null; //The list of subelements 65 // private XMLTools xmlTools = new XMLTools(); //uh, a class of XML tools, i guess66 67 65 private Troolean is_extracted = new Troolean(); 66 68 67 /** Constructor for elements with no namespace necessary. 69 68 * @param element The DOM <strong>Element</strong> this is to be based on. … … 95 94 @param name the name of the subelement to check for, as a <strong>String</strong> 96 95 @author Matthew Whyte 97 @date last modified: 19/01/0496 Date last modified: 19/01/04 98 97 */ 99 98 public boolean containsSubelement(String name) … … 113 112 } 114 113 114 /* 115 Check to see if the element contains any subelements 116 @return tree if element contains subelements 117 @author Matthew Whyte 118 Date last modified: 2/02/05 119 */ 120 public boolean containsSubelements() 121 { 122 return(subelements.size() != 0); 123 } 124 115 125 /** 116 126 Method to add a subelement to the list of subelements. … … 122 132 { 123 133 subelements.add(element); 134 } 135 136 /** 137 Method to remove a subelement from the list of subelements. 138 @param element the subelement to remove from the list, as a <strong>Element</strong> 139 @author Matthew Whyte 140 Date last modified: 27/01/05 141 */ 142 public void removeSubelementFromList(Element element) 143 { 144 subelements.remove(element); 124 145 } 125 146 -
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 -
trunk/gli/src/org/greenstone/gatherer/gems/GEMSLanguageManager.java
r8581 r8971 1 /*2 * GEMSLanguageManager.java1 /** 2 *######################################################################### 3 3 * 4 * Created on October 27, 2004, 3:31 PM 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 *############################################## ########################## 5 36 */ 6 37 … … 35 66 * @author John Thompson, Greenstone Digital Library, University of Waikato 36 67 * @version 2.3 68 * Created on October 27, 2004, 3:31 PM 69 * Modified 1/02/05 by Matthew Whyte 37 70 */ 38 71 public class GEMSLanguageManager { 39 private Document document; 40 private DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 41 private Vector languageCodes; 42 public GEMSLanguageManager(String languagexml_location) { 43 44 this.languageCodes = new Vector(); 72 private Document document; 73 private DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 74 private Vector languageCodes; 75 private Vector languageCodesAndNames; 76 public GEMSLanguageManager(String languagexml_location) { 77 78 this.languageCodes = new Vector(); 79 this.languageCodesAndNames = new Vector(); 45 80 46 try { 47 48 File f = new File(languagexml_location); 49 50 DocumentBuilder builder = factory.newDocumentBuilder(); 51 document = builder.parse(f); 52 org.w3c.dom.Element docelement = document.getDocumentElement(); 53 54 //get all language nodes 55 NodeList mynodelist = docelement.getChildNodes(); 56 57 //get a single language text 58 //System.out.println(mynodelist.item(1).getChildNodes().item(0).getNodeValue()); 59 60 for(int j = 1; j < mynodelist.getLength(); j++){ 61 62 //read text value for the element 63 64 NodeList childnodesofelement = mynodelist.item(j).getChildNodes(); 65 66 67 NamedNodeMap nnm = mynodelist.item(j).getAttributes(); 68 69 70 if(childnodesofelement.getLength() == 1){ 71 72 String code = nnm.item(0).getNodeValue(); 73 String name = nnm.item(4).getNodeValue(); 74 String name_value = childnodesofelement.item(0).getNodeValue(); 75 //language_box.addItem(code.toLowerCase()); 76 this.languageCodes.add(code.toLowerCase()); 77 } 78 79 80 81 82 83 }//end for 84 85 } 86 catch(SAXException sxe) { 87 88 System.out.println("sxe exception\n"); 89 } 90 catch(ParserConfigurationException pce) { 81 try { 82 83 File f = new File(languagexml_location); 84 85 DocumentBuilder builder = factory.newDocumentBuilder(); 86 document = builder.parse(f); 87 org.w3c.dom.Element docelement = document.getDocumentElement(); 88 89 //get all language nodes 90 NodeList mynodelist = docelement.getChildNodes(); 91 92 //get a single language text 93 //System.out.println(mynodelist.item(1).getChildNodes().item(0).getNodeValue()); //debug 94 95 for(int j = 1; j < mynodelist.getLength(); j++){ 96 97 //read text value for the element 98 NodeList childnodesofelement = mynodelist.item(j).getChildNodes(); 99 NamedNodeMap nnm = mynodelist.item(j).getAttributes(); 100 101 if(childnodesofelement.getLength() == 1) 102 { 103 String code = nnm.item(0).getNodeValue(); 104 String name = nnm.item(4).getNodeValue(); 105 String name_value = childnodesofelement.item(0).getNodeValue(); 106 //language_box.addItem(code.toLowerCase()); 107 this.languageCodes.add(code.toLowerCase()); 108 this.languageCodesAndNames.add(name.toLowerCase() + " \t(" + code.toLowerCase() + ")"); 109 } //end if 110 }//end for 111 } //end try 112 catch(SAXException sxe) { 113 System.out.println("sxe exception\n"); 114 } 115 catch(ParserConfigurationException pce) { 91 116 System.out.println("pce exception\n"); 92 93 } 94 catch(IOException ioe){ 95 96 System.out.println("ioe exc\n"); 97 98 } 99 100 //end create dom object for language_box101 102 103 public Vector getLanguageCodes() { 104 return languageCodes;105 } 106 public Object[] getLanguageCodesToArray() {107 return languageCodes.toArray();108 } 109 public String getEnabledLanguageCodes() {110 String enabled_languages = Configuration.getString("Gems.Preferences.Selected_Languages", true);111 return enabled_languages; 112 } 113 public String[] getEnabledLanguageCodesToArray() {114 String enabled_languages = Configuration.getString("Gems.Preferences.Selected_Languages", true);115 String [] enabled_languages_split = enabled_languages.split(","); 116 // String [] trimmed_enabled_lang_split = null;117 118 // for(int p = 0; p < enabled_languages_split.length; p++) { 119 //trimmed_enabled_lang_split[p] = enabled_languages_split[p].trim(); 120 // System.out.println("gemslang: trimm: " + trimmed_enabled_lang_split[p] + " orig: "+ enabled_languages_split[p].trim()); 121 // }//for p < enabled lang split 122 123 return enabled_languages_split; 124 } 125 126 117 } 118 catch(IOException ioe){ 119 System.out.println("ioe exception\n"); 120 } 121 122 //end create dom object for language_box 123 124 } 125 public Vector getLanguageCodesAndNames() { 126 return languageCodesAndNames; 127 } 128 129 public Vector getLanguageCodes() { 130 return languageCodes; 131 } 132 public Object[] getLanguageCodesToArray() { 133 return languageCodes.toArray(); 134 } 135 public String getEnabledLanguageCodes() { 136 String enabled_languages = Configuration.getString("Gems.Preferences.Selected_Languages", true); 137 return enabled_languages; 138 } 139 public String[] getEnabledLanguageCodesToArray() { 140 String enabled_languages = Configuration.getString("Gems.Preferences.Selected_Languages", true); 141 String [] enabled_languages_split = enabled_languages.split(","); 142 // String [] trimmed_enabled_lang_split = null; 143 144 // for(int p = 0; p < enabled_languages_split.length; p++) { 145 //trimmed_enabled_lang_split[p] = enabled_languages_split[p].trim(); 146 // System.out.println("gemslang: trimm: " + trimmed_enabled_lang_split[p] + " orig: "+ enabled_languages_split[p].trim()); 147 // }//for p < enabled lang split 148 149 return enabled_languages_split; 150 } 151 } -
trunk/gli/src/org/greenstone/gatherer/gems/GEMSModel.java
r8932 r8971 66 66 } 67 67 68 public void remove(String name, int type) {69 GEMSNode current = (GEMSNode) root;70 for(int i = 0; i < current.getChildCount(); i++) {71 GEMSNode child = (GEMSNode) current.getChildAt(i);72 if(child.toString().equals(name) && type == GEMSNode.SET) {73 // Place on AWT event thread to avoid errors.74 SynchronizedTreeModelTools.removeNodeFromParent(this, child);75 return;76 }77 // This may be the profiler root node, in which case we descend into its children if we're looking for collection file matches.78 else if(type == GEMSNode.COLLECTION && child.getType() == GEMSNode.PROFILER) {79 for(int j = 0; j < child.getChildCount(); j++) {80 GEMSNode inner_child = (GEMSNode) child.getChildAt(j);81 if(inner_child.toString().equals(name)) {82 // Place on AWT event thread to avoid errors.83 SynchronizedTreeModelTools.removeNodeFromParent(this, inner_child);84 return;85 }86 }87 }88 // If this is a set and we are looking for an element or subelement, then iterate through its children. Can't really do this recursively.89 else if((type == GEMSNode.ELEMENT || type == GEMSNode.SUBELEMENT) && child.getType() == GEMSNode.SET) {90 for(int j = 0; j < child.getChildCount(); j++) {91 GEMSNode inner_child = (GEMSNode) child.getChildAt(j);92 //Go through looking for element93 if(type == GEMSNode.ELEMENT)94 {95 if(inner_child.toString().equals(name)) {96 // Place on AWT event thread to avoid errors.97 SynchronizedTreeModelTools.removeNodeFromParent(this, inner_child);98 return;99 }100 }101 //Go through element looking for subelement102 else if(type == GEMSNode.SUBELEMENT)103 {104 for(int k = 0; k < inner_child.getChildCount(); k++)105 {106 //the subelements107 GEMSNode innermost_child = (GEMSNode)inner_child.getChildAt(k);108 if(innermost_child.toString().equals(name))109 {110 // Place on AWT event thread to avoid errors.111 SynchronizedTreeModelTools.removeNodeFromParent(this, inner_child);112 return;113 }114 }115 }116 }117 }118 }119 120 System.err.println("Tried to remove \'" + name + "\' from the tree, but could not find it!"); //This should not happen!121 }122 123 68 /** 124 69 Remove a node from the tree. -
trunk/gli/src/org/greenstone/gatherer/gems/GEMSNode.java
r8932 r8971 51 51 * @author John Thompson, Greenstone Digital Library, University of Waikato 52 52 * @version 2.3 53 * Modified 2/02/05 by Matthew Whyte 53 54 */ 54 55 public class GEMSNode … … 62 63 static final public int ROOT = 3; 63 64 static final public int SET = 4; 64 static final public int SUBELEMENT = 5;65 //static final public int SUBELEMENT = 5; 65 66 66 67 public GEMSNode() { 67 68 this.type = ROOT; 68 69 69 } 70 70 … … 107 107 } 108 108 109 public ElementWrapper getSubelement() {110 ElementWrapper result = null;111 if(type == SUBELEMENT) {112 result = (ElementWrapper) userObject;113 }114 return result;115 }116 117 109 public int getIndex(TreeNode node) { 118 110 if(children == null) { … … 147 139 } 148 140 149 public String toString() { 150 if(text == null) { 151 if(userObject != null) { 152 if(userObject instanceof ElementWrapper) { 153 text = ((ElementWrapper)userObject).getName(); 154 } 155 // In the case of a 'collection' source path we need to examine the path closely. If it is a descendant of the greenstone collections path then supress everything but the collection name 156 // else if(type == COLLECTION) { 157 // try { 158 // boolean is_descendant = false; 159 // File source_path = new File((String)userObject); 160 // File collect_path; 161 // if (Gatherer.GS3) { 162 // collect_path = new File(Utility.getCollectDir(Configuration.gsdl3_path, Configuration.site_name)); 163 // } else { 164 // collect_path = new File(Utility.getCollectDir(Configuration.gsdl_path)); 165 // } 166 // File current_path = source_path; 167 // while(!is_descendant && current_path != null) { 168 // is_descendant = current_path.equals(collect_path); 169 // current_path = current_path.getParentFile(); 170 // } 171 // current_path = null; 172 // collect_path = null; 173 // // We've either found we are a descendant, or run out of path 174 // if(is_descendant) { 175 // // Create a basic config class 176 // File config_file = new File(source_path, Utility.CONFIG_FILE); 177 // if (config_file.exists()) { 178 // BasicCollectionConfiguration config = new BasicCollectionConfiguration(config_file); 179 // text = config.toString(); 180 // config = null; 181 // } else { 182 // text = source_path.getAbsolutePath(); 183 // } 184 // config_file = null; 185 // } 186 // else { 187 // text = source_path.getAbsolutePath(); 188 // } 189 // } 190 // catch(Exception exception) { 191 // DebugStream.println("Exception in GEMSNode.toString() - exception is unexpected"); 192 // DebugStream.printStackTrace(exception); 193 // text = userObject.toString(); 194 // } 195 // } 196 else { 197 text = userObject.toString(); 198 } 141 public String toString() 142 { 143 if(text == null) 144 { 145 if(userObject != null) 146 { 147 if(userObject instanceof ElementWrapper) 148 { 149 text = ((ElementWrapper)userObject).getName(); 150 } 151 else 152 { 153 text = userObject.toString(); 154 } 155 } 156 else 157 { 158 text = "error"; 159 } 199 160 } 200 else {201 text = "error";202 }203 }204 161 return text; 205 162 } 206 207 163 208 164 public void mapChildren() … … 221 177 } 222 178 } 223 if (type == ELEMENT) //Add subelements. This will need to be changed to cope with multiple levels of subelements.179 if (type == ELEMENT) //Add subelements. As elements and subelements are identical, this process continues. 224 180 { 225 181 ArrayList subelements = this.getElement().getSubelements(); 226 182 for(int j = 0; j < subelements.size(); j++) 227 183 { 228 children.add(new GEMSNode( SUBELEMENT, new ElementWrapper((Element)subelements.get(j)), this));184 children.add(new GEMSNode(ELEMENT, new ElementWrapper((Element)subelements.get(j)), this)); 229 185 } 230 186 } 231 232 187 } 233 188 234 189 class GemsNodeMouseAdapter 235 190 extends MouseAdapter { 236 237 238 191 239 192 public void mouseClicked(MouseEvent e) { 240 193 JPopupMenu setPopup = new JPopupMenu("asdf"); 241 if (e.isPopupTrigger()) { 242 243 setPopup.show(e.getComponent(), 194 if (e.isPopupTrigger()) { 195 setPopup.show(e.getComponent(), 244 196 e.getX(), e.getY()); 245 246 247 } 197 } 248 198 } 249 199 … … 256 206 public void mousePressed(MouseEvent e) { 257 207 JPopupMenu setPopup = new JPopupMenu("asdf"); 258 if (e.isPopupTrigger()) { 259 260 setPopup.show(e.getComponent(), 208 if (e.isPopupTrigger()) { 209 setPopup.show(e.getComponent(), 261 210 e.getX(), e.getY()); 262 263 264 } 265 } 266 211 } 212 } 213 267 214 public void mouseReleased(MouseEvent e) { 268 215 JPopupMenu setPopup = new JPopupMenu("asdf"); 269 if (e.isPopupTrigger()) { 270 271 setPopup.show(e.getComponent(), 272 e.getX(), e.getY()); 273 274 275 } 216 if (e.isPopupTrigger()) { 217 setPopup.show(e.getComponent(), 218 e.getX(), e.getY()); 219 } 276 220 } 277 278 279 221 } 280 281 222 } -
trunk/gli/src/org/greenstone/gatherer/gems/GEMSPreferences.java
r8932 r8971 35 35 import javax.swing.*; 36 36 import javax.swing.event.*; 37 import javax.swing.border.*; 37 38 import org.greenstone.gatherer.Configuration; 38 39 import org.greenstone.gatherer.Dictionary; … … 51 52 static final public String CONNECTION_PREFS = "connection"; 52 53 static final public String GENERAL_PREFS = "general"; 53 54 55 54 static final private Dimension LABEL_SIZE = new Dimension(280, 25); 56 static final private Dimension ROW_SIZE = new Dimension(640, 25);57 55 static final private Dimension SIZE = new Dimension(640, 345); 58 static final private String TRUE = "true"; 59 60 // private CheckList warning_preferences_check_list; 61 private EmailField email_field; 56 57 //private EmailField email_field; 62 58 private JButton apply_button; 63 59 private JButton cancel_button; 64 60 private JButton ok_button; 65 private JCheckBox use_subfields_checkbox; 66 61 67 62 private JCheckBox use_proxy_checkbox; 68 private JCheckBox view_extracted_metadata_checkbox;69 70 63 private JCheckBox workflow_create; 71 64 private JCheckBox workflow_mirror; … … 74 67 private JCheckBox workflow_design; 75 68 private JCheckBox workflow_export; 69 76 70 private JComboBox language_combobox; 77 private JList language_limited_jlist; 78 79 private JComboBox servlet_combobox; // GS380 private JComboBox site_combobox; // GS371 private JList language_limited_jlist; 72 private JList language_code_jlist; 73 private JComboBox servlet_combobox; 74 private JComboBox site_combobox; 81 75 private JLabel interface_language_label; 82 76 private JLabel language_label; 83 private JLabel library_path_label; 84 private JLabel predefined_label; 85 private JLabel program_label; 86 private JLabel proxy_host_label; 87 private JLabel proxy_port_label; 88 private JLabel title_label; 89 private JPanel servlet_pane; 77 90 78 private JRadioButton assistant_mode_radio_button; 91 79 private JRadioButton expert_mode_radio_button; 92 private JRadioButton librarian_mode_radio_button;93 80 private JRadioButton systems_mode_radio_button; 94 81 private JSpinner proxy_port_field; 95 82 private JTabbedPane tab_pane; 96 83 private JTextArea mode_description_textarea; 97 private JTextField library_path_field;98 private JTextField program_field;99 84 private JTextField proxy_host_field; 100 85 private GEMSPreferences self; 101 86 102 87 private String current_site_selection; 88 103 89 public GEMSPreferences() { 104 this(GENERAL_PREFS);105 }106 107 public GEMSPreferences(String initial_view) {108 90 // Initialize 109 91 super(Gatherer.g_man, true); … … 118 100 JPanel general_preferences = createGeneralPreferences(); 119 101 tab_pane.add("Preferences.General", general_preferences); 120 //tab_pane.add("Preferences.Mode", createModePreferences());121 // !! Temporarily disabled for the UNESCO CD-ROM !!122 // tab_pane.add("Preferences.Workflow", createWorkflowPreferences());123 //JPanel connection_preferences = createConnectionPreferences();124 //tab_pane.add("Preferences.Connection", connection_preferences);125 //tab_pane.add("Preferences.Warnings", createWarningPreferences());126 102 127 103 Dictionary.register(tab_pane); … … 155 131 content_pane.add(button_pane, BorderLayout.SOUTH); 156 132 157 Dimension frame_size;// = Gatherer.g_man.getSize();158 Point frame_location;// = Gatherer.g_man.getLocation();159 //setLocation(frame_location.x + ((frame_size.width - SIZE.width) / 2), frame_location.y + ((frame_size.height - SIZE.height)));160 //setLocation(((frame_size.width - SIZE.width) / 2), ((frame_size.height - SIZE.height)));161 133 setLocation(400, 300); 162 163 164 134 tab_pane.setSelectedComponent(general_preferences); 165 166 167 135 168 136 // Clean up 169 137 general_preferences = null; 170 //connection_preferences = null;171 frame_location = null;172 frame_size = null;173 138 cancel_button = null; 174 139 ok_button = null; … … 185 150 // Build the model of available languages 186 151 ArrayList dictionary_model = new ArrayList(); 187 188 // Old method for determining what languages should be available in the combobox189 /*190 dictionary_model.add(new DictionaryEntry(Locale.ENGLISH));191 File classes_folder = new File(Utility.BASE_DIR + StaticStrings.CLASSES_FOLDER);192 File[] possible_dictionaries = classes_folder.listFiles();193 for(int i = 0; i < possible_dictionaries.length; i++) {194 String filename = possible_dictionaries[i].getName();195 if(filename.endsWith(StaticStrings.PROPERTIES_FILE_EXTENSION) && filename.indexOf(StaticStrings.UNDERSCORE_CHARACTER) != -1) {196 StringTokenizer tokenizer = new StringTokenizer(filename.substring(filename.indexOf(StaticStrings.UNDERSCORE_CHARACTER) + 1, filename.indexOf(StaticStrings.STOP_CHARACTER)), StaticStrings.UNDERSCORE_CHARACTER);197 Locale locale = null;198 switch(tokenizer.countTokens()) {199 case 1:200 locale = new Locale(tokenizer.nextToken().toLowerCase());201 break;202 case 2:203 locale = new Locale(tokenizer.nextToken().toLowerCase(), tokenizer.nextToken().toUpperCase());204 break;205 }206 tokenizer = null;207 // Open the file and read the first line208 String description = null;209 try {210 BufferedReader br = new BufferedReader(new FileReader(possible_dictionaries[i]));211 String first_line = br.readLine();212 br.close();213 description = first_line.substring(first_line.indexOf(StaticStrings.COLON_CHARACTER) + 1);214 }215 catch(Exception error) {216 }217 DictionaryEntry entry = new DictionaryEntry(description, locale);218 description = null;219 locale = null;220 if(!dictionary_model.contains(entry)) {221 dictionary_model.add(entry);222 }223 entry = null;224 }225 filename = null;226 }227 possible_dictionaries = null;228 classes_folder = null;229 */230 152 231 153 // The new method makes use of the successor to the languages.dat file, classes/xml/languages.xml … … 254 176 interface_language_label.setPreferredSize(LABEL_SIZE); 255 177 256 257 178 Dictionary.registerText(interface_language_label, "GEMS.Preferences.Selected_Languages_Tooltip"); 258 email_field = new EmailField(Configuration.getColor("coloring.error_background", false)); 259 email_field.setText(Configuration.getEmail()); 260 Dictionary.registerTooltip(email_field, "GEMS.Preferences.Selected_Languages_Tooltip"); 261 262 // Extracted metadata 263 264 //Dictionary.registerBoth(view_extracted_metadata_checkbox, "Preferences.General.View_Extracted_Metadata", "Preferences.General.View_Extracted_Metadata_Tooltip"); 265 266 267 // Show file sizes 268 use_subfields_checkbox = new JCheckBox(); 269 JLabel use_subfields_checkbox_label = new JLabel(); 270 use_subfields_checkbox_label.setPreferredSize(new Dimension(225, 30)); 271 use_subfields_checkbox.setSelected(false); 272 use_subfields_checkbox.setVisible(false); 273 use_subfields_checkbox_label.setVisible(false); 274 275 // String blah = Configuration.getString("coloring.workspace_tree_background",true); 276 // System.out.println("before"+ blah); 277 278 if (Configuration.get("GEMS.Preferences.Use_Subelements", true)) { 279 use_subfields_checkbox.setSelected(true); 280 } 281 Dictionary.registerBoth(use_subfields_checkbox_label, "GEMS.Preferences.Use_Subelements", "GEMS.Preferences.Use_Subelements_Tooltip"); 282 179 //email_field = new EmailField(Configuration.getColor("coloring.error_background", false)); 180 //email_field.setText(Configuration.getEmail()); 181 //Dictionary.registerTooltip(email_field, "GEMS.Preferences.Selected_Languages_Tooltip"); 283 182 284 183 // Language … … 286 185 language_label = new JLabel(); 287 186 language_label.setPreferredSize(LABEL_SIZE); 288 289 187 290 188 Dictionary.registerText(language_label, "Preferences.General.Interface_Language"); … … 299 197 } 300 198 } 301 302 //create language_limited_jlist303 //String [] newer = {"blah", "asfd", "dfjdddd", "blee11" ,"asdfsdfsdf", "asdfdsf","asdfsdfsdf", "asdfdsf","asdfsdfsdf", "asdfdsf","safd", "safd", "safd", "safd"};304 305 306 199 307 200 //create language selected box, and high light the apprpropate ones 308 int [] selectedLanguages = new int[300]; 309 int selectedLanguagesLength = 0; 310 311 312 //GemsLanguageManager gemsLangManager = new GemsLanguageManager("/home/arosmain/gsdl/gli/classes/xml/languages.xml"); 201 int [] selectedLanguages = new int[300]; 202 int selectedLanguagesLength = 0; 203 204 //GemsLanguageManager gemsLangManager = new GemsLanguageManager("/home/arosmain/gsdl/gli/classes/xml/languages.xml"); 313 205 GEMSLanguageManager gemsLangManager = new GEMSLanguageManager(Configuration.gsdl_path + "/gli/classes/xml/languages.xml"); 314 315 316 language_limited_jlist = new JList(gemsLangManager.getLanguageCodesToArray()); 206 207 //Create the visible JList, and then another one with just the language codes. 208 language_code_jlist = new JList(gemsLangManager.getLanguageCodesToArray()); 209 language_limited_jlist = new JList(gemsLangManager.getLanguageCodesAndNames()); 210 211 //Set the list up to display tabs properly 212 TabListCellRenderer renderer = new TabListCellRenderer(); 213 renderer.setTabs(new int[] {50, 200, 300}); 214 language_limited_jlist.setCellRenderer(renderer); 215 317 216 String enabled_languages = Configuration.getString("GEMS.Preferences.Selected_Languages", true); 318 //we have a string 217 //we have a string: enabled_languages that contains an array of strings delimited by comma's 319 218 String []enabled_languages_split = enabled_languages.split(","); 320 219 Object []language_codes_array = gemsLangManager.getLanguageCodesToArray(); 321 220 322 //System.out.println("before: " +enabled_languages_split[0].toString() + " meh: " + enabled_languages); 323 Vector selected = new Vector(); 324 325 //for each enabled_languages_split 326 //check which languages match, and store the index in selectedLanguages 221 //for each enabled_languages_split, check which languages match, and store the index in selectedLanguages 327 222 for(int k = 0; k < enabled_languages_split.length; k++) { 328 223 … … 331 226 //if the codes match, then include the index p into the vector selectedLanguages 332 227 if (language_codes_array[p].toString().toLowerCase().trim().compareTo(enabled_languages_split[k].toLowerCase().trim()) == 0) 333 { 334 // System.out.println(language_codes_array[p].toString().toLowerCase().trim() + " " + enabled_languages_split[k].toLowerCase().trim()); 335 336 // selected.add(p); 337 selectedLanguages[selectedLanguagesLength] = p; 338 selectedLanguagesLength++; 339 language_limited_jlist.addSelectionInterval(p,p); 340 } 341 342 343 } 344 345 228 { 229 selectedLanguages[selectedLanguagesLength] = p; 230 selectedLanguagesLength++; 231 language_limited_jlist.addSelectionInterval(p,p); 232 } 233 } 346 234 } 347 235 348 //selectedLanguages should contain the indices of the languages that should be selected as349 //stated in enabled_languages350 351 //language_limited_jlist.setSelectedIndices(selectedLanguages);352 // language_limited_jlist.addSelectionInterval(1,1);353 //language_limited_jlist.setSelectedIndex(1);354 355 //because the very first language(index 0) gets chosen no matter what...356 //then I unselected the 0 index, and then check the config file to see if that particular language is357 //indeed selected358 // language_limited_jlist.set359 360 361 362 363 236 // Connect 364 237 language_combobox.addActionListener(new LanguageComboboxListener()); 365 238 366 239 // Layout 367 368 240 JScrollPane langScrollPane = new JScrollPane(language_limited_jlist); 369 370 //langScrollPane.getViewport().setView(language_limited_jlist);371 372 // langScrollPane.setSize(175, 100);373 241 langScrollPane.setPreferredSize(new Dimension(100, 100)); 374 242 lang_limited_pane.setLayout(new GridLayout(1,3)); … … 376 244 lang_limited_pane.add(langScrollPane); 377 245 378 379 246 language_pane.setLayout(new BorderLayout()); 380 247 language_pane.add(language_label, BorderLayout.WEST); … … 382 249 383 250 general_pane.setBorder(org.greenstone.gatherer.gui.BorderFactory.createEmptyBorder(5,5,5,5)); 384 //general_pane.setLayout(new GridLayout(4,1,0,5));385 251 general_pane.setLayout(null); 386 387 general_pane.add(lang_limited_pane); 252 general_pane.add(lang_limited_pane); 388 253 general_pane.add(language_pane); 389 254 //general_pane.add(view_extracted_metadata_checkbox); 390 general_pane.add(use_subfields_checkbox);391 general_pane.add(use_subfields_checkbox_label);392 255 Insets general_pane_insets = general_pane.getInsets(); 393 256 … … 397 260 language_pane.setBounds(20+general_pane_insets.left, 130+general_pane_insets.top, 398 261 language_pane.getPreferredSize().width, language_pane.getPreferredSize().height); 399 400 use_subfields_checkbox_label.setBounds(20+general_pane_insets.left, 200+general_pane_insets.top,401 use_subfields_checkbox_label.getPreferredSize().width, use_subfields_checkbox_label.getPreferredSize().height);402 403 use_subfields_checkbox.setBounds(295+general_pane_insets.left, 200+general_pane_insets.top,404 use_subfields_checkbox.getPreferredSize().width, use_subfields_checkbox.getPreferredSize().height);405 262 406 263 return general_pane; … … 416 273 public void actionPerformed(ActionEvent event) { 417 274 // Submit the various changes 418 // Connection preferences 419 /* String program_str = program_field.getText(); 420 if(program_str.length() > 0 && program_str.indexOf("%1") == -1) { 421 program_str = program_str + " %1"; 422 } 423 Configuration.setPreviewCommand(program_str); 424 425 boolean site_changed = false; 426 if (Gatherer.GS3) { 427 String current_site = Configuration.site_name; 428 String new_site =(String)site_combobox.getSelectedItem() ; 429 if (!new_site.equals(current_site)) { 430 site_changed = true; 431 } 432 Configuration.setSiteAndServlet(new_site, (String)servlet_combobox.getSelectedItem()); 433 } 434 435 Configuration.set("general.use_proxy", true, use_proxy_checkbox.isSelected()); 436 Configuration.setString("general.proxy_host", true, proxy_host_field.getText()); 437 Configuration.setString("general.proxy_port", true, proxy_port_field.getValue() + ""); 438 Gatherer.setProxy(); 439 440 // General preferences 441 Configuration.setEmail(email_field.getText()); 442 443 Configuration.set("general.show_file_size", Configuration.COLLECTION_SPECIFIC, use_subfields_checkbox.isSelected()); 444 // Force both workspace and collection trees to redraw 445 if (Gatherer.g_man != null) { 446 Gatherer.g_man.refreshWorkspaceTree(DragTree.TREE_DISPLAY_CHANGED); 447 Gatherer.g_man.refreshCollectionTree(DragTree.TREE_DISPLAY_CHANGED); 448 } 449 */ 450 //save selected languages list box 451 452 //goes here 453 454 //save subfield checkbox 455 456 Configuration.set("Gems.Preferences.Use_Subelements", true, use_subfields_checkbox.isSelected()); 457 // Gatherer.g_man.enrich_pane.valueChanged((TreeSelectionEvent) null); // Refresh metadata table 458 459 275 460 276 //save interface language 461 277 String current_lang = Configuration.getLanguage(); … … 465 281 } 466 282 467 468 469 //////////////////////save language limited jlist selections 470 471 Vector stringVector = new Vector(); 472 473 Object[] selectedValues = language_limited_jlist.getSelectedValues(); 474 String concatString = new String(); 475 476 for(int k = 0; k < selectedValues.length; k++) { 477 // System.out.println(language_limited_jlist.getComponent(0).toString());//allSelectedLanguages[k] 478 479 //System.out.println(selectedValues[k]); 480 481 if(selectedValues.length-k > 1) 482 concatString = concatString.concat(selectedValues[k].toString() +","); 483 else 484 concatString = concatString.concat(selectedValues[k].toString()); 485 283 //Set language_code_jlist to have the same selections as the language_limited_jlist. 284 //(before, there was only one JList, and it only contained the language codes). 285 int[] selection = language_limited_jlist.getSelectedIndices(); 286 language_code_jlist.setSelectedIndices(selection); 287 Object[] selectedValues = language_code_jlist.getSelectedValues(); 288 String concatString = new String(); 289 290 for(int k = 0; k < selectedValues.length; k++) { 291 if(selectedValues.length-k > 1) 292 concatString = concatString.concat(selectedValues[k].toString() +","); 293 else 294 concatString = concatString.concat(selectedValues[k].toString()); 486 295 } 487 296 488 489 // System.out.println("final cat string: "+ concatString);490 491 492 297 Configuration.setString("GEMS.Preferences.Selected_Languages",true, concatString); 493 298 494 ///////////////////495 /*496 // Mode preferences497 int current_mode = Configuration.getMode();498 int new_mode;499 if(assistant_mode_radio_button.isSelected()) {500 new_mode = Configuration.ASSISTANT_MODE;501 }502 else if(systems_mode_radio_button.isSelected()) {503 new_mode = Configuration.SYSTEMS_MODE;504 }505 else if(expert_mode_radio_button.isSelected()) {506 new_mode = Configuration.EXPERT_MODE;507 }508 else {509 new_mode = Configuration.LIBRARIAN_MODE;510 }511 // If there has been a change in modes, update the config, and also inform the persistant gui views that have a need to know512 if(new_mode != current_mode) {513 Configuration.setMode(new_mode);514 Collection collection = Gatherer.c_man.getCollection();515 if (collection != null) {516 collection.cdm.modeChanged(new_mode);517 }518 Gatherer.g_man.modeChanged(new_mode);519 }520 // Warning preferences521 for(int i = 0; i < warning_preferences_check_list.getEntryCount(); i++) {522 Entry entry = warning_preferences_check_list.get(i);523 Configuration.set(entry.getProperty(), true, entry.isSelected());524 }525 526 if (Gatherer.GS3 && site_changed && Gatherer.c_man.getCollection()!=null) {527 // shut down the collection528 System.err.println("shutting down teh collection");529 Gatherer.g_man.closeCurrentCollection();530 }531 */532 // Workflow preferences533 // Configuration.set("workflow.mirror", false, workflow_mirror.isSelected());534 // Configuration.set("workflow.gather", false, workflow_gather.isSelected());535 // Configuration.set("workflow.enrich", false, workflow_enrich.isSelected());536 // Configuration.set("workflow.design", false, workflow_design.isSelected());537 // Configuration.set("workflow.export", false, workflow_export.isSelected());538 // Configuration.set("workflow.create", false, workflow_create.isSelected());539 // Gatherer.g_man.workflowUpdate("Mirror", workflow_mirror.isSelected());540 // Gatherer.g_man.workflowUpdate("Gather", workflow_gather.isSelected());541 // Gatherer.g_man.workflowUpdate("Enrich", workflow_enrich.isSelected());542 // Gatherer.g_man.workflowUpdate("Design", (workflow_design.isSelected() && Configuration.getMode() > Configuration.ASSISTANT_MODE));543 // Gatherer.g_man.workflowUpdate("Export", workflow_export.isSelected());544 // Gatherer.g_man.workflowUpdate("Create", workflow_create.isSelected());545 546 299 // Always save configuration changes immediately (in case the GLI crashes) 547 300 Configuration.save(); … … 592 345 } 593 346 594 /** This listener updates the mode description depending on what mode is selected. */595 private class ModeRadioButtonListener596 implements ActionListener {597 public void actionPerformed(ActionEvent event) {598 Object source = event.getSource();599 if(source == assistant_mode_radio_button) {600 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Assistant_Description"));601 }602 else if(source == expert_mode_radio_button) {603 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Expert_Description"));604 }605 else if(source == systems_mode_radio_button) {606 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Systems_Description"));607 }608 else {609 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Librarian_Description"));610 }611 source = null;612 }613 }614 615 private class PredefinedActionListener616 implements ActionListener {617 public void actionPerformed(ActionEvent event) {618 JComboBox cb = (JComboBox) event.getSource();619 WorkflowElementWrapper element = (WorkflowElementWrapper) cb.getSelectedItem();620 CheckboxUpdater task = new CheckboxUpdater(element);621 SwingUtilities.invokeLater(task);622 }623 624 private class CheckboxUpdater625 implements Runnable {626 private WorkflowElementWrapper element;627 public CheckboxUpdater(WorkflowElementWrapper element) {628 this.element = element;629 }630 public void run() {631 workflow_create.setSelected(element.getEnabled("create"));632 workflow_mirror.setSelected(element.getEnabled("mirror"));633 workflow_gather.setSelected(element.getEnabled("gather"));634 workflow_enrich.setSelected(element.getEnabled("enrich"));635 workflow_design.setSelected(element.getEnabled("design"));636 workflow_export.setSelected(element.getEnabled("export"));637 }638 }639 }640 347 641 348 private class LanguageComboboxListener … … 651 358 } 652 359 } 653 654 private class SiteComboboxListener655 implements ActionListener {656 private boolean ignore_event=false;657 public void actionPerformed(ActionEvent event) {658 System.err.println("event occurred "+event.paramString());659 String site = (String) site_combobox.getSelectedItem();660 System.err.println("new site = "+site);661 if (!site.equals(current_site_selection)) {662 current_site_selection = site;663 System.err.println("changed the current selection");664 ArrayList servlet_options = Gatherer.servlet_config.getServletsForSite(current_site_selection);665 if (servlet_options == null) {666 System.err.println("no servlets for this site");667 servlet_combobox.setModel(new DefaultComboBoxModel());668 Dictionary.registerTooltip(servlet_combobox, "Preferences.Connection.Servlet_Tooltip2");669 servlet_combobox.setEnabled(false);670 671 } else {672 System.err.println(ArrayTools.objectArrayToString(servlet_options.toArray()));673 servlet_combobox.setModel(new DefaultComboBoxModel(servlet_options.toArray()));674 Dictionary.registerTooltip(servlet_combobox, "Preferences.Connection.Servlet_Tooltip");675 servlet_combobox.setEnabled(true);676 }677 }678 }679 }680 681 private class UseProxyListener682 implements ActionListener {683 public void actionPerformed(ActionEvent event) {684 boolean enabled = use_proxy_checkbox.isSelected();685 Configuration.set("general.use_proxy", true, enabled);686 // Fortunately this is already driven by the event thread.687 proxy_host_field.setEnabled(enabled);688 proxy_port_field.setEnabled(enabled);689 }690 }691 692 private class WorkflowElementWrapper {693 private Element element;694 private String text;695 public WorkflowElementWrapper(Element element) {696 this.element = element;697 }698 public boolean getEnabled(String name) {699 boolean result = true;700 if(element.getAttribute(name).equalsIgnoreCase("false")) {701 result = false;702 }703 return result;704 }705 public String toString() {706 if(text == null) {707 text = element.getFirstChild().getNodeValue();708 }709 return text;710 }711 }712 360 } 361 362 363 /** 364 A custom list renderer, to display tabs in the JList properly. 365 366 @see http://manning.com/sbe/files/uts2/Chapter10html/Chapter10.htm 367 Added by Matthew Whyte 368 Date last modified: 1/02/05 369 */ 370 class TabListCellRenderer extends JLabel implements ListCellRenderer 371 { 372 protected static Border m_noFocusBorder; 373 protected FontMetrics m_fm = null; 374 protected Insets m_insets = new Insets(0, 0, 0, 0); 375 376 protected int m_defaultTab = 50; 377 protected int[] m_tabs = null; 378 379 public TabListCellRenderer() 380 { 381 super(); 382 m_noFocusBorder = new EmptyBorder(1, 1, 1, 1); 383 setOpaque(true); 384 setBorder(m_noFocusBorder); 385 } 386 387 public Component getListCellRendererComponent(JList list, 388 Object value, int index, boolean isSelected, boolean cellHasFocus) 389 { 390 setText(value.toString()); 391 392 setBackground(isSelected ? list.getSelectionBackground() : list.getBackground()); 393 setForeground(isSelected ? list.getSelectionForeground() : list.getForeground()); 394 395 setFont(list.getFont()); 396 setBorder((cellHasFocus) ? UIManager.getBorder("List.focusCellHighlightBorder") : m_noFocusBorder); 397 398 return this; 399 } 400 401 public void setDefaultTab(int defaultTab) { m_defaultTab = defaultTab; } 402 403 public int getDefaultTab() { return m_defaultTab; } 404 405 public void setTabs(int[] tabs) { m_tabs = tabs; } 406 407 public int[] getTabs() { return m_tabs; } 408 409 public int getTab(int index) 410 { 411 if (m_tabs == null) 412 return m_defaultTab*index; 413 414 int len = m_tabs.length; 415 if (index >= 0 && index < len) 416 return m_tabs[index]; 417 418 return m_tabs[len-1] + m_defaultTab*(index-len+1); 419 } 420 421 422 public void paint(Graphics g) 423 { 424 m_fm = g.getFontMetrics(); 425 426 g.setColor(getBackground()); 427 g.fillRect(0, 0, getWidth(), getHeight()); 428 getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight()); 429 430 g.setColor(getForeground()); 431 g.setFont(getFont()); 432 m_insets = getInsets(); 433 int x = m_insets.left; 434 int y = m_insets.top + m_fm.getAscent(); 435 436 StringTokenizer st = new StringTokenizer(getText(), "\t"); 437 while (st.hasMoreTokens()) 438 { 439 String sNext = st.nextToken(); 440 g.drawString(sNext, x, y); 441 x += m_fm.stringWidth(sNext); 442 443 if (!st.hasMoreTokens()) 444 break; 445 int index = 0; 446 while (x >= getTab(index)) 447 index++; 448 x = getTab(index); 449 } 450 } 451 } -
trunk/gli/src/org/greenstone/gatherer/gems/MSMUtils.java
r8932 r8971 44 44 import org.greenstone.gatherer.util.StaticStrings; 45 45 import org.greenstone.gatherer.util.Utility; 46 import org.greenstone.gatherer.util.XMLTools; 46 47 import org.w3c.dom.*; 47 48 /** This class contains a plethora of methods associated with handling the content of <strong>MetadataSet</strong>s and the <strong>Element</strong>s within. For example this is where you will find methods for comparing various parts of two <strong>MetadataSet</strong>s for equality. It also has methods for extracting common and useful data from <strong>Element</strong>s such as the AssignedValue nodes. … … 93 94 attribute_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, attribute_name_str); 94 95 MSMUtils.setValue(attribute_element, value_str); 96 95 97 // Start off by determining if we have to add this node in the new multilingual optimized way 96 98 if(isAttributeLanguageDependant(document, attribute_name_str)) { 97 99 boolean found = false; 98 100 // Try to retrieve a language element for the given language code 99 NodeList language_elements = element_element.getElementsByTagName(StaticStrings.LANGUAGE_ELEMENT); 100 for(int i = 0; i < language_elements.getLength(); i++) { 101 Element language_element = (Element) language_elements.item(i); 101 //NodeList language_elements = element_element.getElementsByTagName(StaticStrings.LANGUAGE_ELEMENT); 102 ArrayList language_elements = XMLTools.getChildElementsByTagName(element_element, StaticStrings.LANGUAGE_ELEMENT); 103 for(int i = 0; i < language_elements.size(); i++) { 104 Element language_element = (Element) language_elements.get(i); 102 105 if(language_element.getAttribute(StaticStrings.CODE_ATTRIBUTE).equals(language_code_str)) { 103 106 found = true; … … 736 739 * @param attribute_name_str the name of the attribute we a testing as a String 737 740 * @see org.greenstone.gatherer.util.StaticStrings#LANGUAGEDEPENDANT_ATTRIBUTE 741 * Modified by Matthew Whyte 4/02/05 738 742 */ 739 743 static private boolean isAttributeLanguageDependant(Document document, String attribute_name_str) 740 744 { 745 //gives a list of comma seperated language specific attributes. 741 746 String language_specific_attributes = document.getDocumentElement().getAttribute(StaticStrings.LANGUAGEDEPENDANT_ATTRIBUTE).toLowerCase(); 742 return language_specific_attributes.indexOf(attribute_name_str) != -1; 747 //System.err.println("lang_specific: " + language_specific_attributes); //debug 748 749 //Seperate out language_specific_attributes 750 String[] attributes_split = language_specific_attributes.split(","); 751 752 //Compare each to attribute_name_str 753 for(int i = 0; i < attributes_split.length; i++) 754 { 755 if(attributes_split[i].trim().compareTo(attribute_name_str.toLowerCase()) == 0) 756 return true; 757 } 758 return false; 743 759 } 744 760 … … 802 818 */ 803 819 static public boolean removeElementAttribute(Element element_element, String attribute_name_str, String language_code_str, String value_str) { 804 // Multilingual Optimized version 805 // 1. Determine the if this is one of the language specific attributes 806 if(isAttributeLanguageDependant(element_element.getOwnerDocument(), attribute_name_str)) { 807 // Retrieve the language elements, and determine the correct one 808 NodeList language_elements = element_element.getElementsByTagName(StaticStrings.LANGUAGE_ELEMENT); 809 for(int i = 0; i < language_elements.getLength(); i++) { 810 Element language_element = (Element) language_elements.item(i); 811 if(language_element.getAttribute(StaticStrings.CODE_ATTRIBUTE).equalsIgnoreCase(language_code_str)) { 812 NodeList attribute_elements = language_element.getElementsByTagName(StaticStrings.ATTRIBUTE_ELEMENT); 813 for(int j = 0; j < attribute_elements.getLength(); j++) { 814 Element attribute_element = (Element) attribute_elements.item(j); 815 String target_name_str = attribute_element.getAttribute(StaticStrings.NAME_ATTRIBUTE); 816 String target_value_str = MSMUtils.getValue(attribute_element); 817 if(attribute_name_str.equals(target_name_str) && value_str.equals(target_value_str)) { 818 language_element.removeChild(attribute_element); 819 if(attribute_elements.getLength() == 0) { 820 element_element.removeChild(language_element); 821 } 822 target_value_str = null; 823 target_name_str = null; 824 attribute_element = null; 825 attribute_elements = null; 826 language_element = null; 827 language_elements = null; 828 return true; 820 //Determine the if this is one of the language specific attributes. 821 //This can sometimes give a false result, if an attribute is made language specific half way through creation of a metadata set (or vice versa). 822 if(isAttributeLanguageDependant(element_element.getOwnerDocument(), attribute_name_str)) 823 { 824 /* 825 Multilingual Optimized version, eg: 826 <Language code="en"> 827 <Attribute name="identifier">second</Attribute> 828 </Language> 829 */ 830 return removeElementAttributeNew(element_element, attribute_name_str, language_code_str, value_str, false); 831 } 832 else 833 { 834 /* 835 The old way, eg: 836 <Attribute language="en" name="identifier">second</Attribute> 837 */ 838 return removeElementAttributeOld(element_element, attribute_name_str, language_code_str, value_str, false); 839 } 840 841 } 842 static final private boolean removeElementAttributeNew(Element element_element, String attribute_name_str, String language_code_str, String value_str, boolean run_once) 843 { 844 // Retrieve the language elements, and determine the correct one 845 NodeList language_elements = element_element.getElementsByTagName(StaticStrings.LANGUAGE_ELEMENT); 846 for(int i = 0; i < language_elements.getLength(); i++) { 847 Element language_element = (Element) language_elements.item(i); 848 if(language_element.getAttribute(StaticStrings.CODE_ATTRIBUTE).equalsIgnoreCase(language_code_str)) { 849 NodeList attribute_elements = language_element.getElementsByTagName(StaticStrings.ATTRIBUTE_ELEMENT); 850 for(int j = 0; j < attribute_elements.getLength(); j++) { 851 Element attribute_element = (Element) attribute_elements.item(j); 852 String target_name_str = attribute_element.getAttribute(StaticStrings.NAME_ATTRIBUTE); 853 String target_value_str = MSMUtils.getValue(attribute_element); 854 if(attribute_name_str.equals(target_name_str) && value_str.equals(target_value_str)) { 855 language_element.removeChild(attribute_element); 856 if(attribute_elements.getLength() == 0) { 857 element_element.removeChild(language_element); 829 858 } 830 859 target_value_str = null; 831 860 target_name_str = null; 832 attribute_element = null; 861 attribute_element = null; 862 attribute_elements = null; 863 language_element = null; 864 language_elements = null; 865 return true; 833 866 } 834 attribute_elements = null; 835 } 836 language_element = null; 837 } 838 language_elements = null; 839 // Not found 840 //System.err.println("new optimised way failed."); //debug 841 return false; 842 } // end if 843 // Otherwise just use the old method 844 867 target_value_str = null; 868 target_name_str = null; 869 attribute_element = null; 870 } 871 attribute_elements = null; 872 } 873 language_element = null; 874 } 875 language_elements = null; 876 // Not found. Try the old way before failing. 877 if(!run_once) 878 return removeElementAttributeOld(element_element, attribute_name_str, language_code_str, value_str, true); 879 return false; 880 } 881 static final private boolean removeElementAttributeOld(Element element_element, String attribute_name_str, String language_code_str, String value_str, boolean run_once) 882 { 845 883 // Find the attribute to remove 846 884 NodeList attribute_elements = element_element.getElementsByTagName(StaticStrings.ATTRIBUTE_ELEMENT); … … 858 896 } 859 897 attribute_elements = null; 860 // No match found 861 //System.err.println("Old method failed."); //debug 898 // No match found. Try the new way before failing. 899 if(!run_once) 900 return removeElementAttributeNew(element_element, attribute_name_str, language_code_str, value_str, true); 862 901 return false; 863 902 } -
trunk/gli/src/org/greenstone/gatherer/gems/MetadataSet.java
r8932 r8971 496 496 /** Method to remove the given element from this metadata set. 497 497 * @param element The <strong>Element</strong> to be removed. 498 * @param parent The parent element, as an <strong>Element</strong>. If null, the parent is root. 499 */ 500 public void removeElement(Element element, Element parent) { 501 // we need to remove the value tree too!! 502 //System.err.println("removeElement in MetadataSet: element is: " + element); //Debug 503 498 * @param parent The parent element (wrapped, so can access its subelement list), as an <strong>ElementWrapper</strong>. If null, the parent is root. 499 */ 500 public void removeElement(Element element, ElementWrapper parent) { 504 501 try { 505 502 ElementWrapper element_wrapped = new ElementWrapper(element); … … 508 505 if(parent == null) 509 506 { 510 parent = root; 507 elements.remove(element); 508 root.removeChild(element); 511 509 } 512 513 //Want to remove subelement. 514 //System.err.println("Wanna remove subelement"); //debug 515 parent.removeChild(element); 510 else 511 { 512 parent.removeSubelementFromList(element); 513 parent.getElement().removeChild(element); 514 } 516 515 517 516 } catch(Exception DOMException) { //The element does not exist!! -
trunk/gli/src/org/greenstone/gatherer/gems/MetadataSetManager.java
r8932 r8971 405 405 if(st.nextToken().compareTo("collect") == 0) { 406 406 colName = st.nextToken(); 407 System.err.println("colName is: " + colName); //debug408 407 // metadata_set.old_filename = metadata_set.getName(); 409 408 // metadata_set.setName(new String("(" + colName + ") " + metadata_set.getName()) ); … … 431 430 @return void 432 431 Modified by Matthew Whyte 19/01/04 432 433 This should really be totally replaced by MetadataSet.removeElement --Matthew 433 434 */ 434 435 public void removeElement(ElementWrapper element, ElementWrapper parent) { … … 439 440 if(set != null) { 440 441 //Remove the element 441 if(parent == null) 442 { 443 set.removeElement(element.getElement(), null); //Let's not cause an exception! 444 } 445 else 446 { 447 set.removeElement(element.getElement(), parent.getElement()); 448 } 442 set.removeElement(element.getElement(), parent); 449 443 } 450 444 else { … … 463 457 public void renameElement(ElementWrapper oldElement, String newName) 464 458 { 465 GEMSNode node = null;466 467 459 //Retrive the metadata set this element belongs to. 468 460 String namespace = oldElement.getNamespace(); … … 491 483 for(int i = 0; i < all_values.size(); i++) { 492 484 GValueNode node = (GValueNode)all_values.get(i); 493 TreePath path = new TreePath(node.getPath());494 485 String full_value = node.getFullPath(false); 495 486 String index = model.getHIndex(full_value);
Note:
See TracChangeset
for help on using the changeset viewer.