Changeset 4436
- Timestamp:
- 2003-05-30T14:53:48+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/mem/MetadataEditorManager.java
r4420 r4436 77 77 /** A card layout is used to switch between the two differing detail views. */ 78 78 private CardLayout card_layout = null; 79 /** A card layout is used to switch between a value tree or an empty placeholder (if no value tree available). */ 80 private CardLayout element_values_layout = null; 79 81 /** Um, the size of the screen I'd guess. */ 80 82 private Dimension screen_size = null; … … 84 86 private MetadataEditorManager self = null; 85 87 private int current_attribute = -1; 88 private int current_attribute_type = -1; 86 89 private JButton add_attribute = null; 87 90 private JButton add_element = null; … … 104 107 private JScrollPane set_attributes_scroll = null; 105 108 private JPanel details_pane = null; 109 private JPanel element_values_pane = null; 106 110 private KeepTreeRootExpandedListener keep_root_expanded_listener = null; 107 111 private MEMModel model = null; … … 129 133 static final private String PROFILE = "profile"; 130 134 static final private String SET = "set"; 135 static final private String VALUES = "values"; 131 136 /** Constructor. */ 132 137 public MetadataEditorManager() { … … 225 230 element_attributes.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 226 231 227 JPanel element_values_pane = new JPanel(); 232 element_values_layout = new CardLayout(); 233 element_values_pane = new JPanel(); 228 234 element_values_pane.setOpaque(false); 229 235 element_values = new SmarterTree(); … … 233 239 element_values.setSelectionColor(Gatherer.config.getColor("coloring.collection_selection_background", false)); 234 240 element_values.setSelectedTextColor(Gatherer.config.getColor("coloring.collection_selection_foreground", false)); 241 242 JPanel element_novalues_pane = new JPanel(); 235 243 236 244 keep_root_expanded_listener = new KeepTreeRootExpandedListener(); … … 371 379 372 380 element_values_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(get("Values")), BorderFactory.createEmptyBorder(2,2,2,2))); 373 element_values_pane.setLayout(new BorderLayout()); 374 element_values_pane.add(new JScrollPane(element_values), BorderLayout.CENTER); 381 //element_values_pane.setLayout(new BorderLayout()); 382 //element_values_pane.add(new JScrollPane(element_values), BorderLayout.CENTER); 383 element_values_pane.setLayout(element_values_layout); 384 element_values_pane.add(element_novalues_pane, BLANK); 385 element_values_pane.add(new JScrollPane(element_values), VALUES); 375 386 376 387 element_inner_pane.setLayout(new GridLayout(2,1)); … … 531 542 setSize(ADD_OR_EDIT_ATTRIBUTE_SIZE); 532 543 name_to_values = new HashMap(); 533 544 // Creation 534 545 JPanel content_pane = (JPanel) getContentPane(); 535 546 content_pane.setBackground(Gatherer.config.getColor("coloring.collection_heading_background", false)); … … 625 636 if(source == ok_button) { 626 637 boolean cont = true; 638 AttributeTableModel model = null; 639 switch(current_attribute_type) { 640 case MEMNode.COLLECTION: 641 model = (AttributeTableModel) profile_attributes.getModel(); 642 break; 643 case MEMNode.ELEMENT: 644 model = (AttributeTableModel) element_attributes.getModel(); 645 break; 646 case MEMNode.SET: 647 model = (AttributeTableModel) set_attributes.getModel(); 648 break; 649 } 627 650 // Now we add the new or improved values, removing old values if this is an edit. 628 651 // Depends on what we are adding the attribute to. 629 if(current_collection_file != null) { 630 String name_str = name.getSelectedItem().toString(); 631 String value_str = value.getText(); 632 AttributeTableModel model = (AttributeTableModel) profile_attributes.getModel(); 633 // Remove the existing one if this is an edit. 634 if(!add_type && current_attribute != -1) { 635 String old_source = (String) profile_attributes.getValueAt(current_attribute, 0); 636 Gatherer.c_man.msm.profiler.removeAction(current_collection_file, old_source); 637 old_source = null; 638 model.removeRow(current_attribute); 639 } 640 // First thing we check from profiles is that there isn't already an entry for this name. 641 if(!model.contains(name_str, 0)) { 642 // Add profile 643 Gatherer.c_man.msm.profiler.addAction(current_collection_file, name_str, value_str); 644 // Update attribute table. 645 model.add(new Attribute(name_str, value_str)); 646 } 647 else { 648 // Show an error message and do not proceed. 649 cont = false; 650 JOptionPane.showMessageDialog(self, get("Attribute_Already_Exists"), get("General.Error"), JOptionPane.ERROR_MESSAGE); 652 if(model != null) { 653 if(current_collection_file != null) { 654 String name_str = name.getSelectedItem().toString(); 655 String value_str = value.getText(); 656 // Remove the existing one if this is an edit. 657 if(!add_type && current_attribute != -1) { 658 String old_source = (String) model.getValueAt(current_attribute, 0); 659 Gatherer.c_man.msm.profiler.removeAction(current_collection_file, old_source); 660 old_source = null; 661 model.removeRow(current_attribute); 662 } 663 // First thing we check from profiles is that there isn't already an entry for this name. 664 if(!model.contains(name_str, 0)) { 665 // Add profile 666 Gatherer.c_man.msm.profiler.addAction(current_collection_file, name_str, value_str); 667 // Update attribute table. 668 model.add(new Attribute(name_str, value_str)); 669 } 670 else { 671 // Show an error message and do not proceed. 672 cont = false; 673 JOptionPane.showMessageDialog(self, get("Attribute_Already_Exists"), get("General.Error"), JOptionPane.ERROR_MESSAGE); 674 } 675 value_str = null; 676 name_str = null; 677 } 678 else if(current_element != null) { 679 // Add the attribute, even if one of the same name already exists. Maybe one day someone would like to enforce the occurance rules but not me and not today. 680 String name_str = name.getSelectedItem().toString(); 681 String language_code = ((Language)language_box.getSelectedItem()).getCode(); 682 String value_str = value.getText(); 683 // Remove the existing one if this is an edit. 684 if(!add_type && current_attribute != -1) { 685 model.removeRow(current_attribute); 686 } 687 // Add attribute 688 current_element.addAttribute(name_str, language_code, value_str); 689 // Update the attribute table 690 model.add(new Attribute(name_str, language_code, value_str)); 691 value_str = null; 692 language_code = null; 693 name_str = null; 694 } 695 else if(current_set != null) { 696 String name_str = name.getSelectedItem().toString(); 697 String value_str = value.getText(); 698 // Remove the existing one if this is an edit. 699 if(!add_type && current_attribute != -1) { 700 model.removeRow(current_attribute); 701 } 702 // First thing we check from profiles is that there isn't already an entry for this name. 703 if(!model.contains(name_str, 0)) { 704 // Add profile 705 current_set.addAttribute(name_str, value_str); 706 // Update attribute table. 707 model.add(new Attribute(name_str, value_str)); 708 } 709 // Otherwise provide an error message and do not proceed. 710 else { 711 cont = false; 712 JOptionPane.showMessageDialog(self, get("Attribute_Already_Exists"), get("General.Error"), JOptionPane.ERROR_MESSAGE); 713 } 714 value_str = null; 715 name_str = null; 716 } 717 // Hide dialog if we are allowed to continue. 718 if(cont) { 719 setVisible(false); 651 720 } 652 721 model = null; 653 value_str = null;654 name_str = null;655 }656 else if(current_element != null) {657 // Add the attribute, even if one of the same name already exists. Maybe one day someone would like to enforce the occurance rules but not me and not today.658 String name_str = name.getSelectedItem().toString();659 String language_code = ((Language)language_box.getSelectedItem()).getCode();660 String value_str = value.getText();661 AttributeTableModel model = (AttributeTableModel) element_attributes.getModel();662 // Remove the existing one if this is an edit.663 if(!add_type && current_attribute != -1) {664 model.removeRow(current_attribute);665 }666 // Add attribute667 current_element.addAttribute(name_str, language_code, value_str);668 // Update the attribute table669 model.add(new Attribute(name_str, language_code, value_str));670 model = null;671 value_str = null;672 language_code = null;673 name_str = null;674 }675 else if(current_set != null) {676 String name_str = name.getSelectedItem().toString();677 String value_str = value.getText();678 // First thing we check from profiles is that there isn't already an entry for this name.679 AttributeTableModel model = (AttributeTableModel) set_attributes.getModel();680 // Remove the existing one if this is an edit.681 if(!add_type && current_attribute != -1) {682 model.removeRow(current_attribute);683 }684 // First thing we check from profiles is that there isn't already an entry for this name.685 if(!model.contains(name_str, 0)) {686 // Add profile687 current_set.addAttribute(name_str, value_str);688 // Update attribute table.689 model.add(new Attribute(name_str, value_str));690 }691 // Otherwise provide an error message and do not proceed.692 else {693 cont = false;694 JOptionPane.showMessageDialog(self, get("Attribute_Already_Exists"), get("General.Error"), JOptionPane.ERROR_MESSAGE);695 }696 model = null;697 value_str = null;698 name_str = null;699 }700 // Hide dialog if we are allowed to continue.701 if(cont) {702 setVisible(false);703 722 } 704 723 } … … 825 844 } 826 845 else if(current_attribute != -1) { 846 AttributeTableModel model = null; 847 switch(current_attribute_type) { 848 case MEMNode.COLLECTION: 849 model = (AttributeTableModel) profile_attributes.getModel(); 850 break; 851 case MEMNode.ELEMENT: 852 model = (AttributeTableModel) element_attributes.getModel(); 853 break; 854 case MEMNode.SET: 855 model = (AttributeTableModel) set_attributes.getModel(); 856 break; 857 } 827 858 add_type = false; 828 859 setTitle(get("EditAttribute")); 829 String name_str = (String) profile_attributes.getValueAt(current_attribute, 0); 830 String value_str = (String) profile_attributes.getValueAt(current_attribute, 1); 860 String name_str = (String) model.getValueAt(current_attribute, 0); 861 String value_str = (String) model.getValueAt(current_attribute, model.getColumnCount() - 1); 862 model = null; 831 863 // Retrieve the appropriate value model 832 864 java.util.List values = (java.util.List) name_to_values.get(name_str); … … 838 870 name_str = null; 839 871 for(int i = 0; i < values.size(); i++) { 840 value.add(new NameElementWrapperEntry(values.get(i))); 872 Object temp_value = values.get(i); 873 if(temp_value instanceof ElementWrapper) { 874 value.add(new NameElementWrapperEntry(temp_value)); 875 } 876 else { 877 value.add(temp_value); 878 } 841 879 } 842 880 values = null; … … 1678 1716 } 1679 1717 public void valueChanged(ListSelectionEvent event) { 1680 if((current_attribute = table.getSelectedRow()) != -1) { 1681 edit_attribute.setEnabled(true); 1682 remove_attribute.setEnabled(true); 1683 } 1684 else { 1685 current_attribute = -1; 1686 edit_attribute.setEnabled(false); 1687 remove_attribute.setEnabled(false); 1718 if(!event.getValueIsAdjusting()) { 1719 if((current_attribute = table.getSelectedRow()) != -1) { 1720 edit_attribute.setEnabled(true); 1721 remove_attribute.setEnabled(true); 1722 } 1723 else { 1724 current_attribute = -1; 1725 edit_attribute.setEnabled(false); 1726 remove_attribute.setEnabled(false); 1727 } 1688 1728 } 1689 1729 } … … 1722 1762 AttributeTableModel atm = null; 1723 1763 TreeSet attributes = null; 1724 switch(current_node.getType()) { 1764 current_attribute_type = current_node.getType(); 1765 switch(current_attribute_type) { 1725 1766 case MEMNode.COLLECTION: 1726 1767 current_collection_file = current_node.toString(); … … 1760 1801 // Be careful not to add the keep_root_expanded_listener over and over! 1761 1802 GValueModel value_model = Gatherer.c_man.msm.getValueTree(current_element); 1762 value_model.removeTreeModelListener(keep_root_expanded_listener); // Remove it if its already there 1763 value_model.addTreeModelListener(keep_root_expanded_listener); // Then add again. 1764 element_values.setModel(value_model); 1803 if(value_model != null) { 1804 value_model.removeTreeModelListener(keep_root_expanded_listener); // Remove it if its already there 1805 value_model.addTreeModelListener(keep_root_expanded_listener); // Then add again. 1806 element_values.setModel(value_model); 1807 element_values_layout.show(element_values_pane, VALUES); 1808 // Meanwhile disable/enable controls depending on this Element selection. 1809 setControls(true, false, false, false, false, true, true, false, false, true, false, false); 1810 } 1811 else { 1812 element_values_layout.show(element_values_pane, BLANK); 1813 // Meanwhile disable/enable controls depending on this Element selection. 1814 setControls(true, false, false, false, false, false, true, false, false, false, false, false); 1815 } 1765 1816 card_layout.show(details_pane, ELEMENT); 1766 // Meanwhile disable/enable controls depending on this Element selection.1767 setControls(true, false, false, false, false, true, true, false, false, true, false, false);1768 1817 break; 1769 1818 case MEMNode.SET:
Note:
See TracChangeset
for help on using the changeset viewer.