Changeset 4592
- Timestamp:
- 2003-06-12T11:36:04+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/SubcollectionManager.java
r4583 r4592 417 417 */ 418 418 public Control() { 419 419 // Create 420 420 JPanel border_pane = new JPanel(); 421 421 JPanel header_pane = new JPanel(); … … 429 429 JLabel title = new JLabel(get("Title")); 430 430 title.setHorizontalAlignment(JLabel.CENTER); 431 createSub collection();432 createSub index();431 createSubCollection(); 432 createSubIndex(); 433 433 // Add listeners 434 434 // Layout … … 449 449 } 450 450 /** Create the subcollection controls. 451 452 453 454 455 456 457 458 public void createSub collection() {451 * @see org.greenstone.gatherer.Gatherer 452 * @see org.greenstone.gatherer.cdm.SubcollectionManager.Control.AddListener 453 * @see org.greenstone.gatherer.cdm.SubcollectionManager.Control.ListListener 454 * @see org.greenstone.gatherer.cdm.SubcollectionManager.Control.RemoveListener 455 * @see org.greenstone.gatherer.collection.CollectionManager 456 * @see org.greenstone.gatherer.msm.MetadataSetManager 457 */ 458 public void createSubCollection() { 459 459 // Create 460 460 add = new JButton(get("Add")); 461 461 add.setMnemonic(KeyEvent.VK_A); 462 add.setEnabled(false); 462 463 JPanel button_pane = new JPanel(); 463 464 JPanel button_pane_1 = new JPanel(); … … 477 478 remove = new JButton(get("Remove")); 478 479 remove.setMnemonic(KeyEvent.VK_R); 480 remove.setEnabled(false); 479 481 Vector source_model = gatherer.c_man.msm.getAssignedElements(); 480 482 source_model.add(0, "Filename"); … … 492 494 493 495 // Add listeners 494 add.addActionListener(new AddListener()); 495 remove.addActionListener(new RemoveListener()); 496 subcollection_list.addListSelectionListener(new ListListener()); 496 SubCollectionChangeListener cl = new SubCollectionChangeListener(); 497 add.addActionListener(new AddSubCollectionListener()); 498 remove.addActionListener(new RemoveSubCollectionListener()); 499 subcollection_list.addListSelectionListener(new SubCollectionListListener()); 500 //exclude.addActionListener(cl); 501 //include.addActionListener(cl); 502 //source.addActionListener(cl); 503 //flags.addDocumentListener(cl); 504 match.getDocument().addDocumentListener(cl); 505 name.getDocument().addDocumentListener(cl); 497 506 498 507 // Layout … … 535 544 * @see org.greenstone.gatherer.util.ExclusiveListListener 536 545 */ 537 public void createSub index() {546 public void createSubIndex() { 538 547 // Creation 539 548 JPanel subindex_name_panel = new JPanel(); … … 577 586 578 587 // Add listeners 579 ChangeListener cl = new ChangeListener();580 588 ExclusiveListSelectionListener ell = new ExclusiveListSelectionListener(); 581 589 ell.add(subcollection_list_2); 582 590 ell.add(subindexes_list); 583 591 add_index.addActionListener(new AddSubIndexListener()); 584 clear_default.addActionListener(new ClearDefaultListener()); 585 exclude.addActionListener(cl); 586 include.addActionListener(cl); 592 clear_default.addActionListener(new ClearDefaultSubIndexListener()); 587 593 remove_index.addActionListener(new RemoveSubIndexListener()); 588 set_default.addActionListener(new SetDefaultListener()); 589 source.addActionListener(cl); 590 flags.addKeyListener(cl); 591 match.addKeyListener(cl); 592 name.addKeyListener(cl); 594 set_default.addActionListener(new SetDefaultSubIndexListener()); 593 595 594 596 subindex_name.getDocument().addDocumentListener(new SubIndexNameDocumentListener()); 595 subcollection_list_2.addListSelectionListener(new Sub collectionListSelectionListener());597 subcollection_list_2.addListSelectionListener(new SubCollectionList2Listener()); 596 598 597 599 // Layout … … 634 636 subindex_pane.add(button_pane_2, BorderLayout.SOUTH); 635 637 } 636 637 private class SubIndexListCellRenderer638 extends DefaultListCellRenderer {639 640 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {641 StringBuffer text = new StringBuffer(value.toString());642 // Retrieve the indexes name if any.643 CollectionMeta metadata = manager.collectionmetadatum.getMetadata(value, manager.languages.getDefaultLanguage(), true);644 if(metadata != null) {645 text.append(" \"");646 text.append(metadata.getValue());647 text.append("\"");648 }649 return super.getListCellRendererComponent(list, text.toString(), index, isSelected, cellHasFocus);650 }651 652 }653 654 private class SubcollectionListSelectionListener655 implements ListSelectionListener {656 657 public void valueChanged(ListSelectionEvent event) {658 if(!event.getValueIsAdjusting()) {659 add_index.setEnabled(!subcollection_list_2.isSelectionEmpty() && subindex_name.getText().length() > 0);660 }661 }662 }663 638 664 private class SubIndexNameDocumentListener 665 implements DocumentListener { 666 /** Gives notification that an attribute or set of attributes changed. */ 667 public void changedUpdate(DocumentEvent e) { 668 update(); 669 } 670 /** Gives notification that there was an insert into the document. */ 671 public void insertUpdate(DocumentEvent e) { 672 update(); 673 } 674 /** Gives notification that a portion of the document has been removed. */ 675 public void removeUpdate(DocumentEvent e) { 676 update(); 677 } 678 /** The text area has changed in some way. Given that this can only happed when we are editing or adding a text fragment we better respond appropriately. */ 679 private void update() { 680 add_index.setEnabled(!subcollection_list_2.isSelectionEmpty() && subindex_name.getText().length() > 0); 681 } 682 } 683 639 684 640 /** Method to unregister any listeners to avoid memory leaks. 685 641 */ … … 687 643 } 688 644 /** We have overriden this method to provide completely different functionality, given that our JPanel will never actually have focus. We call this method in GUI on the view we are about to replace, and this method checks if a change has occured and if so updates the current object. 689 690 691 645 * @return A <i>boolean</i> which is always <i>false</i>. 646 * @see org.greenstone.gatherer.msm.ElementWrapper 647 */ 692 648 public boolean hasFocus() { 693 649 // If we have a current metadata open, and something has changed then save the change. 694 650 if(changed && current != null) { 695 651 String n = name.getText(); … … 716 672 } 717 673 /** Overriden to ensure the instructions are scrolled to top. 718 674 */ 719 675 public void updateUI() { 720 676 if(instructions != null) { … … 723 679 super.updateUI(); 724 680 } 681 682 /** Method to validate the current subcollection editor values, and enable or disable controls (add button) based on said values. 683 * we want to disable add until a new name is present 684 */ 685 protected void validateAdd() { 686 if(changed && name.getText().length() > 0 && match.getText().length() > 0) { 687 System.out.println("in validate, name="+name.getText()); 688 if (subcollections.containsKey(name.getText())) { 689 add.setEnabled(false); 690 } else { 691 add.setEnabled(true); 692 } 693 } 694 else { 695 add.setEnabled(false); 696 } 697 } 725 698 /** Listens for actions apon the 'add' button in the SubcollectionManager controls, and if detected calls the addSubcollection method of the manager with a newly created subcollection. */ 726 private class Add Listener699 private class AddSubCollectionListener 727 700 implements ActionListener { 728 701 /** Any implementation of ActionListener must include this method so we can be informed when an action has been performed on one of our target controls. In this case we wish to retrieve information from the various edit controls, and if we have sufficient data to build a new subcollection do so. … … 750 723 } 751 724 changed = false; 725 validateAdd(); 752 726 } 753 727 } … … 775 749 } 776 750 /** This class listens for any key entry in a text field, selection change in a combobox or button click, and when detected sets the changed flag to true. Its also convenient to use this class to test if the add button should be active yet. */ 777 public class ChangeListener 778 extends KeyAdapter 779 implements ActionListener { 751 private class SubCollectionChangeListener 752 implements DocumentListener, ActionListener { 780 753 /** Any implementation of ActionListener must include this method so we can be informed when an action has been performed on one of our target controls. In this case we want to record that somethings changed, then validate the controls. 781 754 * @param event An <strong>ActionEvent</strong> containing information about the event. … … 783 756 public void actionPerformed(ActionEvent event) { 784 757 changed = true; 785 validate(); 758 validateAdd(); 759 } 760 761 public void changedUpdate(DocumentEvent event) { 762 System.out.println("changed"); 763 changed = true; 764 validateAdd(); 765 } 766 public void insertUpdate(DocumentEvent event) { 767 System.out.println("inserted"); 768 changed = true; 769 validateAdd(); 770 771 } 772 773 public void removeUpdate(DocumentEvent event) { 774 System.out.println("removed"); 775 changed = true; 776 validateAdd(); 786 777 } 787 778 /** Any inheritor of KeyAdapter can override this method so we can be informed when an key has been type in one of our target controls. In this case we want to record that somethings changed, then validate the controls. 788 779 * @param event An <strong>KeyEvent</strong> containing information about the event. 789 780 */ 790 public void keyPressed(KeyEvent event) { 791 changed = true; 792 validate(); 793 } 794 /** Method to validate the current editor values, and enable or disable controls based on said values. */ 795 private void validate() { 796 if(changed && name.getText().length() > 0 && match.getText().length() > 0) { 797 add.setEnabled(true); 798 } 799 else { 800 add.setEnabled(false); 801 } 802 } 781 // public void keyPressed(KeyEvent event) { 782 //changed = true; 783 //validate(); 784 // } 785 803 786 } 804 787 /** Listens for actions apon the 'clear default subindex' button in the SubcollectionManager controls, and if detected calls the setDefaultSubIndex() method of the manager with <i>null</i>. */ 805 private class ClearDefault Listener788 private class ClearDefaultSubIndexListener 806 789 implements ActionListener { 807 790 /** Any implementation of ActionListener must include this method so we can be informed when an action has been performed on one of our target controls. In this case we want to clear the default subindex. … … 814 797 } 815 798 } 799 /** Listens for actions apon the 'remove' button in the SubcollectionManager controls, and if detected calls the remove method of the manager with the SubIndex selected for removal. */ 800 private class RemoveSubCollectionListener 801 implements ActionListener { 802 /** Any implementation of ActionListener must include this method so we can be informed when an action has been performed on one of our target controls. In this case we want to check if they have a subcolleciton selected, and if so remove both it and any subindexes based on it. 803 * @param event An <strong>ActionEvent</strong> containing information about the event. 804 * @see org.greenstone.gatherer.cdm.Subcollection 805 */ 806 public void actionPerformed(ActionEvent event) { 807 if(!subcollection_list.isSelectionEmpty()) { 808 Subcollection sub_col = (Subcollection)subcollection_list.getSelectedValue(); 809 removeSubIndexes(sub_col); 810 removeSubcollection(sub_col); 811 } 812 } 813 } 814 /** Listens for actions apon the 'remove subindex' button in the SubcollectionManager controls, and if detected calls the removeSubIndex method of the manager with the SubIndex selected for removal. */ 815 private class RemoveSubIndexListener 816 implements ActionListener { 817 /** Any implementation of ActionListener must include this method so we can be informed when an action has been performed on one of our target controls. In this case we want to check if they have a subindex selected, and if so remove it. 818 * @param event An <strong>ActionEvent</strong> containing information about the event. 819 * @see org.greenstone.gatherer.cdm.SubIndex 820 */ 821 public void actionPerformed(ActionEvent event) { 822 if(!subindexes_list.isSelectionEmpty()) { 823 removeSubIndex((SubIndex)subindexes_list.getSelectedValue()); 824 } 825 } 826 } 827 /** Listens for actions apon the 'set default subindex' button in the SubcollectionManager controls, and if detected calls the setDefaultSubIndex method of the manager with the SubIndex selected for default. */ 828 private class SetDefaultSubIndexListener 829 implements ActionListener { 830 /** Any implementation of ActionListener must include this method so we can be informed when an action has been performed on one of our target controls. In this case we want to check if they have a subindex selected, and if so set it as default. 831 * @param event An <strong>ActionEvent</strong> containing information about the event. 832 * @see org.greenstone.gatherer.cdm.DefaultSubIndex 833 * @see org.greenstone.gatherer.cdm.SubIndex 834 */ 835 public void actionPerformed(ActionEvent event) { 836 if(!subindexes_list.isSelectionEmpty()) { 837 setDefaultSubIndex(new DefaultSubIndex((SubIndex)subindexes_list.getSelectedValue())); 838 clear_default.setEnabled(true); 839 default_value.setText(default_index.getSubIndex().toString()); 840 } 841 } 842 } 843 844 816 845 /** This class listens for selections in the list on the subcollections pane of the SubcollectionManager, and updates the controls as necessary to reflect selection. */ 817 private class ListListener846 private class SubCollectionListListener 818 847 implements ListSelectionListener { 819 848 /** Any implementation of ListSelectionListener must include this method so we can be informed when the selection changes. In this case we want to execute any changes the users made to the entry, then update the controls with details of the new selection. … … 891 920 // Have to do this after so we don't get called when nothings actually changed. 892 921 changed = false; 893 } 894 } 895 /** Listens for actions apon the 'remove' button in the SubcollectionManager controls, and if detected calls the remove method of the manager with the SubIndex selected for removal. */ 896 private class RemoveListener 897 implements ActionListener { 898 /** Any implementation of ActionListener must include this method so we can be informed when an action has been performed on one of our target controls. In this case we want to check if they have a subcolleciton selected, and if so remove both it and any subindexes based on it. 899 * @param event An <strong>ActionEvent</strong> containing information about the event. 900 * @see org.greenstone.gatherer.cdm.Subcollection 901 */ 902 public void actionPerformed(ActionEvent event) { 903 if(!subcollection_list.isSelectionEmpty()) { 904 Subcollection sub_col = (Subcollection)subcollection_list.getSelectedValue(); 905 removeSubIndexes(sub_col); 906 removeSubcollection(sub_col); 907 } 908 } 909 } 910 /** Listens for actions apon the 'remove subindex' button in the SubcollectionManager controls, and if detected calls the removeSubIndex method of the manager with the SubIndex selected for removal. */ 911 private class RemoveSubIndexListener 912 implements ActionListener { 913 /** Any implementation of ActionListener must include this method so we can be informed when an action has been performed on one of our target controls. In this case we want to check if they have a subindex selected, and if so remove it. 914 * @param event An <strong>ActionEvent</strong> containing information about the event. 915 * @see org.greenstone.gatherer.cdm.SubIndex 916 */ 917 public void actionPerformed(ActionEvent event) { 918 if(!subindexes_list.isSelectionEmpty()) { 919 removeSubIndex((SubIndex)subindexes_list.getSelectedValue()); 920 } 921 } 922 } 923 /** Listens for actions apon the 'set default subindex' button in the SubcollectionManager controls, and if detected calls the setDefaultSubIndex method of the manager with the SubIndex selected for default. */ 924 private class SetDefaultListener 925 implements ActionListener { 926 /** Any implementation of ActionListener must include this method so we can be informed when an action has been performed on one of our target controls. In this case we want to check if they have a subindex selected, and if so set it as default. 927 * @param event An <strong>ActionEvent</strong> containing information about the event. 928 * @see org.greenstone.gatherer.cdm.DefaultSubIndex 929 * @see org.greenstone.gatherer.cdm.SubIndex 930 */ 931 public void actionPerformed(ActionEvent event) { 932 if(!subindexes_list.isSelectionEmpty()) { 933 setDefaultSubIndex(new DefaultSubIndex((SubIndex)subindexes_list.getSelectedValue())); 934 clear_default.setEnabled(true); 935 default_value.setText(default_index.getSubIndex().toString()); 936 } 937 } 938 } 922 923 } 924 } 925 926 private class SubCollectionList2Listener 927 implements ListSelectionListener { 928 929 public void valueChanged(ListSelectionEvent event) { 930 if(!event.getValueIsAdjusting()) { 931 add_index.setEnabled(!subcollection_list_2.isSelectionEmpty() && subindex_name.getText().length() > 0); 932 } 933 } 934 } 935 936 private class SubIndexListCellRenderer 937 extends DefaultListCellRenderer { 938 939 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 940 StringBuffer text = new StringBuffer(value.toString()); 941 // Retrieve the indexes name if any. 942 CollectionMeta metadata = manager.collectionmetadatum.getMetadata(value, manager.languages.getDefaultLanguage(), true); 943 if(metadata != null) { 944 text.append(" \""); 945 text.append(metadata.getValue()); 946 text.append("\""); 947 } 948 return super.getListCellRendererComponent(list, text.toString(), index, isSelected, cellHasFocus); 949 } 950 951 } 952 953 private class SubIndexNameDocumentListener 954 implements DocumentListener { 955 /** Gives notification that an attribute or set of attributes changed. */ 956 public void changedUpdate(DocumentEvent e) { 957 update(); 958 } 959 /** Gives notification that there was an insert into the document. */ 960 public void insertUpdate(DocumentEvent e) { 961 update(); 962 } 963 /** Gives notification that a portion of the document has been removed. */ 964 public void removeUpdate(DocumentEvent e) { 965 update(); 966 } 967 /** The text area has changed in some way. Given that this can only happed when we are editing or adding a text fragment we better respond appropriately. */ 968 private void update() { 969 add_index.setEnabled(!subcollection_list_2.isSelectionEmpty() && subindex_name.getText().length() > 0); 970 } 971 } 972 939 973 } 940 974 }
Note:
See TracChangeset
for help on using the changeset viewer.