Changeset 9161
- Timestamp:
- 2005-02-23T17:02:05+13:00 (19 years ago)
- Location:
- trunk/gli
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/classes/dictionary.properties
r9154 r9161 329 329 CDM.SubcollectionIndexManager.Add_Subindex:Add Partition 330 330 CDM.SubcollectionIndexManager.Add_Subindex_Tooltip:Add the specified partition to this collection 331 CDM.SubcollectionIndexManager.Clear_Default_Subindex:Clear Default 332 CDM.SubcollectionIndexManager.Clear_Default_Subindex_Tooltip:Clear the default partition 333 CDM.SubcollectionIndexManager.Default_Subindex:Default: 331 CDM.SubcollectionIndexManager.Default_Partition_Indicator:[Default Partition] 334 332 CDM.SubcollectionIndexManager.PartitionName:Partition Name: 335 333 CDM.SubcollectionIndexManager.PartitionName_Tooltip:The name of the new partition 336 334 CDM.SubcollectionIndexManager.Remove_Subindex:Remove Partition 337 335 CDM.SubcollectionIndexManager.Remove_Subindex_Tooltip:Remove the selected partition from this collection 336 CDM.SubcollectionIndexManager.Replace_Subindex:Replace Partition 337 CDM.SubcollectionIndexManager.Replace_Subindex_Tooltip:Update the selected partition 338 338 CDM.SubcollectionIndexManager.Set_Default_Subindex:Set Default 339 339 CDM.SubcollectionIndexManager.Set_Default_Subindex_Tooltip:Make the selected partition the default 340 CDM.SubcollectionIndexManager.Subcollection:Defined Subcollection Filters 340 CDM.SubcollectionIndexManager.Source:Build partition on: 341 CDM.SubcollectionIndexManager.Source_Tooltip:The subcollection filters to build the partition on 341 342 CDM.SubcollectionIndexManager.Subindexes:Assigned Subcollection Partitions 342 343 CDM.SuperCollectionManager.Instructions:Cross-collection searching is where a single search is performed over several collections, as if all the collections were one. Specify the collections to include in a search by clicking on the appropriate collection's name in the list below. The current collection will automatically be included. \nWARNING: If the individual collections do not have the same indexes (including subcollection partitions and language partitions) as each other, cross-collection searching will not work properly. The user will only be able to search using indexes common to all collections. -
trunk/gli/src/org/greenstone/gatherer/cdm/IndexManager.java
r9077 r9161 200 200 } 201 201 202 private void moveIndex(Index index, boolean move_up) { 203 // Determine the indexes current position 202 203 private void moveIndex(Index index, boolean move_up) 204 { 205 // Determine the current position of the index 204 206 int position = indexOf(index); 205 // Determine if it can be moved, ie if its not already at the top trying to move up, or at the bottom trying to move down. 206 if(position == -1) { 207 if (position == -1) { 207 208 return; 208 209 } 209 if(position == 0 && move_up) { 210 return;211 }212 if(position == (getSize()) - 1 && !move_up) {213 return;214 }215 // Ok, move the index216 if(move_up) { 210 211 // Attempt to move the index up 212 if (move_up) { 213 // Check it's not already at the top 214 if (position == 0) { 215 return; 216 } 217 217 218 // Retrieve the index at position - 1 218 Index previous_index = (Index) getElementAt(position - 1); 219 // And add before. This will automatically remove the index first, as an Element can only exist once in a particular document 220 addBefore(index, previous_index); 221 } 219 Index preceeding_index = (Index) getElementAt(position - 1); 220 221 // This automatically removes the index first, as an Element can only exist once in a particular document 222 addBefore(index, preceeding_index); 223 } 224 225 // Attempt to move the index down 222 226 else { 227 // Check it's not already at the bottom 228 if (position == (getSize()) - 1) { 229 return; 230 } 231 223 232 // Retrieve the index at position + 1 224 Index next_index = (Index) getElementAt(position + 1); 225 // And add after. This will automatically remove the index first, as an Element can only exist once in a particular document 226 addAfter(index, next_index); 227 } 233 Index following_index = (Index) getElementAt(position + 1); 234 235 // This automatically removes the index first, as an Element can only exist once in a particular document 236 addAfter(index, following_index); 237 } 238 228 239 // Schedule the collection for saving 229 240 Gatherer.c_man.configurationChanged(); 230 241 } 242 231 243 232 244 private void moveLevel(Level level, boolean move_up) { … … 727 739 return; 728 740 } 729 String name = CollectionDesignManager.collectionmeta_manager.getMetadatum( CollectionConfiguration.STOP_CHARACTER+selected_index.getID()).getValue(true);741 String name = CollectionDesignManager.collectionmeta_manager.getMetadatum("." + id).getValue(true); 730 742 name_textfield.setText(name); 731 743 level_combobox.setSelectedIndex(selected_index.getLevel()); … … 736 748 } 737 749 738 private void validateAddButton() { 750 private void validateAddButton() 751 { 739 752 boolean add_enabled = false; 740 753 boolean replace_enabled = false; 754 741 755 // Indexes must have a name 742 if (name_textfield.getText().length() == 0) {756 if (name_textfield.getText().length() == 0) { 743 757 add_enabled = false; 744 758 } … … 747 761 add_enabled = false; 748 762 } 749 // If we get this far, create a dummy index and see if it s already assigned in the collection763 // If we get this far, create a dummy index and see if it's already assigned in the collection 750 764 else { 751 765 Object object[] = source_list.getSelected().toArray(); … … 757 771 Index index = new Index(level_combobox.getSelectedIndex(), sources); 758 772 sources = null; 759 if (model.contains(index)) {773 if (model.contains(index)) { 760 774 add_enabled = false; 761 // here we need to check if we have changed the name - if so, we can enable the replace button 775 776 // Here we need to check if we have changed the name - if so, we can enable the replace button 762 777 if (index_list.getSelectedIndex() != -1) { 763 778 Index selected_index = (Index)index_list.getSelectedValue(); … … 771 786 else { 772 787 add_enabled = true; 773 // we have a new index, do we have something selected in the index list? if so, enable the replace button 788 789 // We have a new index, do we have something selected in the index list? if so, enable the replace button 774 790 if (index_list.getSelectedIndex() != -1) { 775 791 replace_enabled = true; 776 792 } 777 778 779 } 793 } 794 } 795 780 796 // We should now know the add_button state 781 797 add_button.setEnabled(add_enabled); … … 783 799 } 784 800 785 /** Listens for actions apon the 'add' button in the IndexManager controls, and if detected calls the add method of the manager with a newly created index. */ 801 786 802 private class AddListener 787 implements ActionListener { 788 /** Method called when an action is performed on a registered component, and when it does we check if we have enough data to create a new index, and if so we create one. 789 * @param event An <strong>ActionEvent</strong> providing extra information about the event. 790 * @see org.greenstone.gatherer.cdm.CollectionDesignManager 791 * @see org.greenstone.gatherer.cdm.CollectionMeta 792 * @see org.greenstone.gatherer.cdm.CollectionMetaManager 793 * @see org.greenstone.gatherer.cdm.Index 794 * @see org.greenstone.gatherer.cdm.Language 795 * @see org.greenstone.gatherer.cdm.LanguageManager 796 */ 797 public void actionPerformed(ActionEvent event) { 803 implements ActionListener 804 { 805 public void actionPerformed(ActionEvent event) 806 { 798 807 String name = name_textfield.getText(); 799 System.err.println("Add button height: " + add_button.getHeight());800 System.err.println("Set default button height: " + set_default_button.getHeight());801 808 if (source_list.getSelected().size() > 0 && name.length() != 0) { 802 809 ArrayList sources = source_list.getSelected(); 803 810 Index index = new Index(level_combobox.getSelectedIndex(), sources); 804 sources = null; 805 // Before we add the index to the model, we have to add the collection metadata for this .811 812 // Before we add the index to the model, we have to add the collection metadata for this 806 813 CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + index.getID()); 807 814 metadatum.setValue(name); 808 // Finally add index. 815 816 // Finally, add the index 809 817 addIndex(index, metadatum); 810 818 index_list.setSelectedValue(index, true); 811 metadatum = null; 812 index = null; 813 } 814 name = null; 815 } 816 } 819 } 820 } 821 } 822 817 823 818 824 /** Listens for selections within the list on the IndexManager controls, and if a change is detected enables, or disables, controls appropriately. */ 819 825 private class IndexListListener 820 implements ListSelectionListener { 826 implements ListSelectionListener 827 { 821 828 /** This method is called whenever the source list selection changes. When it does we need to fill in the various parts of the list description panel 822 829 * @param event A <strong>ListSelectionEvent</strong> containing further information about the list selection. … … 837 844 return; 838 845 } 839 // enable the buttons appropriately 846 847 // Enable the buttons appropriately 840 848 remove_button.setEnabled(true); 841 849 set_default_button.setEnabled(default_index == null || !default_index.equals(value)); … … 844 852 if (i > 0) { 845 853 move_up_button.setEnabled(true); 846 } else { 854 } 855 else { 847 856 move_up_button.setEnabled(false); 848 857 } 849 if (i <size-1){858 if (i < size-1){ 850 859 move_down_button.setEnabled(true); 851 } else { 860 } 861 else { 852 862 move_down_button.setEnabled(false); 853 863 } 854 864 855 // need to fill in the rest of the bits865 // Need to fill in the rest of the bits 856 866 updateControlsWithSelectedIndex(); 857 867 } … … 904 914 } 905 915 906 /** Listens for actions apon the 'remove' button in the IndexManager controls, and if detected calls the remove method of the manager with the index selected for removal. */ 916 917 /** Listens for key presses within the name field, and enabled or disables controls as appropriate. */ 918 private class NameListener 919 implements DocumentListener 920 { 921 public void changedUpdate(DocumentEvent e) 922 { 923 validateAddButton(); 924 } 925 926 public void insertUpdate(DocumentEvent e) 927 { 928 validateAddButton(); 929 } 930 931 public void removeUpdate(DocumentEvent e) 932 { 933 validateAddButton(); 934 } 935 } 936 937 907 938 private class RemoveListener 908 implements ActionListener { 909 /** If called when an action occurs on a registered component, we remove the currently selected index, if there is one. 910 * @param event An <strong>ActionEvent</strong> containing extra information about the action that occured. 911 * @see org.greenstone.gatherer.cdm.Index 912 */ 913 public void actionPerformed(ActionEvent event) { 939 implements ActionListener 940 { 941 public void actionPerformed(ActionEvent event) 942 { 914 943 int i = index_list.getSelectedIndex(); 915 if(i != -1) { 916 removeIndex((Index)index_list.getSelectedValue()); 917 } 944 if (i != -1) { 945 removeIndex((Index) index_list.getSelectedValue()); 946 } 947 918 948 int size = index_list.getModel().getSize(); 919 949 if (i == size) { 920 950 i--; 921 951 } 922 923 952 index_list.setSelectedIndex(i); 924 // this will produce an event on the list, updating the other buttons 953 954 // This will produce an event on the list, updating the other buttons 925 955 if (size == 0) { 926 // we have removed the last index, should be able to add whats filled in currently, if valid956 // We have removed the last index, should be able to add what's filled in currently, if valid 927 957 validateAddButton(); 928 } 929 } 930 } 931 932 /** Listens for actions apon the 'remove' button in the IndexManager controls, and if detected calls the remove method of the manager with the index selected for removal. */ 958 } 959 } 960 } 961 962 933 963 private class ReplaceListener 934 implements ActionListener { 935 /** If called when an action occurs on a registered component, we replace the currently selected index, with the new details 936 * @param event An <strong>ActionEvent</strong> containing extra information about the action that occured. 937 * @see org.greenstone.gatherer.cdm.Index 938 */ 939 public void actionPerformed(ActionEvent event) { 940 if(index_list.isSelectionEmpty()) { 941 // this should never happen, but just in case.. 964 implements ActionListener 965 { 966 public void actionPerformed(ActionEvent event) 967 { 968 if (index_list.isSelectionEmpty()) { 969 // This should never happen, but just in case... 942 970 replace_button.setEnabled(false); 943 971 return; 944 972 } 945 // we'll just remove the old one and add the new one 946 removeIndex((Index)index_list.getSelectedValue()); 973 974 // We'll just remove the old one and add the new one 975 removeIndex((Index) index_list.getSelectedValue()); 947 976 replace_button.setEnabled(false); 948 977 add_button.setEnabled(true); … … 951 980 } 952 981 } 982 953 983 954 984 private class SetDefaultListener … … 966 996 } 967 997 968 /** Listens for selections within the list on the IndexManager controls, and if a change is detected enables, or disables, controls appropriately. */ 998 969 999 private class SourceListListener 970 implements ListSelectionListener { 971 /** This method is called whenever the source list selection changes. When it does we need to check if the add button should now be enabled. 972 * @param event A <strong>ListSelectionEvent</strong> containing further information about the list selection. 973 */ 974 public void valueChanged(ListSelectionEvent event) { 975 validateAddButton(); 976 } 977 } 978 979 /** Listens for key presses within the name field, and enabled or disables controls as appropriate. */ 980 private class NameListener 981 implements DocumentListener { 982 /** Gives notification that an attribute or set of attributes changed. */ 983 public void changedUpdate(DocumentEvent e) { 984 validateAddButton(); 985 } 986 987 /** Gives notification that there was an insert into the document. */ 988 public void insertUpdate(DocumentEvent e) { 989 validateAddButton(); 990 } 991 992 /** Gives notification that a portion of the document has been removed. */ 993 public void removeUpdate(DocumentEvent e) { 1000 implements ListSelectionListener 1001 { 1002 public void valueChanged(ListSelectionEvent event) 1003 { 994 1004 validateAddButton(); 995 1005 } -
trunk/gli/src/org/greenstone/gatherer/cdm/Subcollection.java
r8313 r9161 97 97 * @return an int which is >0, 0, or <0 if this subcollection is before, equal to, or after the target object respectively. 98 98 */ 99 public int compareTo(Object object) { 100 if(object == null) { 99 public int compareTo(Object object) 100 { 101 if (object == null) { 101 102 return -1; 102 103 } 103 return getName().compareTo(((Subcollection)object).getName()); 104 } 104 105 // Object may be a String 106 if (object instanceof String) { 107 return getName().compareTo(object); 108 } 109 110 // Otherwise assume it is a Subcollection object 111 return getName().compareTo(((Subcollection) object).getName()); 112 } 113 105 114 106 115 public DOMProxyListEntry create(Element element) { -
trunk/gli/src/org/greenstone/gatherer/cdm/SubcollectionIndex.java
r8243 r9161 81 81 */ 82 82 public int compareTo(Object object) { 83 return id.compareTo(((SubcollectionIndex)object).getID());83 return getID().compareTo(((SubcollectionIndex)object).getID()); 84 84 } 85 85 … … 168 168 this.sources = sources; 169 169 } 170 else {171 DebugStream.println("Error! Called setSource() of index other than the default.");172 }173 170 } 174 171 -
trunk/gli/src/org/greenstone/gatherer/cdm/SubcollectionIndexManager.java
r8243 r9161 32 32 import javax.swing.*; 33 33 import javax.swing.event.*; 34 import org.greenstone.gatherer.Configuration;35 34 import org.greenstone.gatherer.DebugStream; 36 35 import org.greenstone.gatherer.Dictionary; 37 36 import org.greenstone.gatherer.Gatherer; 38 37 import org.greenstone.gatherer.gui.GLIButton; 39 import org.greenstone.gatherer.util.ExclusiveListSelectionListener; 40 import org.greenstone.gatherer.util.StaticStrings; 38 import org.greenstone.gatherer.util.CheckList; 41 39 import org.greenstone.gatherer.util.Utility; 42 40 import org.w3c.dom.*; 41 42 43 43 /** This class maintains a list of indexes partitions for the purpose of defining subcollections. 44 44 * @author John Thompson, Greenstone Digital Library, University of Waikato … … 46 46 */ 47 47 public class SubcollectionIndexManager 48 extends DOMProxyListModel { 48 extends DOMProxyListModel 49 { 50 static final private Dimension FIELD_SIZE = new Dimension(200, 30); 49 51 50 52 private Control controls; … … 52 54 private SubcollectionIndex default_index; 53 55 56 54 57 /** Constructor. */ 55 public SubcollectionIndexManager(Element subindexes) { 58 public SubcollectionIndexManager(Element subindexes) 59 { 56 60 super(subindexes, CollectionConfiguration.INDEX_ELEMENT, new SubcollectionIndex()); 57 61 DebugStream.println("SubcollectionIndexManager: " + getSize() + " subcollection indexes parsed."); 58 62 model = this; 63 59 64 // Parse and retrieve the default index 60 65 NodeList default_index_elements = CollectionDesignManager.collect_config.getDocumentElement().getElementsByTagName(CollectionConfiguration.SUBCOLLECTION_DEFAULT_INDEX_ELEMENT); 61 if(default_index_elements.getLength() > 0) { 62 default_index = new SubcollectionIndex((Element)default_index_elements.item(0)); 63 } 64 } 66 if (default_index_elements.getLength() > 0) { 67 default_index = new SubcollectionIndex((Element) default_index_elements.item(0)); 68 } 69 } 70 65 71 66 72 /** Method to add a subindex. … … 69 75 * @see org.greenstone.gatherer.collection.CollectionManager 70 76 */ 71 private void addSubcollectionIndex(SubcollectionIndex subindex) { 72 if(!contains(subindex)) { 73 add(getSize(), subindex); 77 private void addSubcollectionIndex(SubcollectionIndex subcollection_index) 78 { 79 if (!contains(subcollection_index)) { 80 add(getSize(), subcollection_index); 74 81 Gatherer.c_man.configurationChanged(); 75 82 } 76 83 } 77 84 78 public void destroy() { 79 if(controls != null) { 85 86 public void destroy() 87 { 88 if (controls != null) { 80 89 controls.destroy(); 81 90 controls = null; … … 85 94 } 86 95 87 public Control getControls() { 88 if(controls == null) { 89 controls = new SubcollectionIndexControl(); 96 97 public Control getControls() 98 { 99 if (controls == null) { 100 controls = new SubcollectionIndexControls(); 90 101 } 91 102 return controls; 92 103 } 93 104 94 /** Method to retrieve the default index.95 * @return the default Index, or null if no such index assigned96 */97 /* private SubcollectionIndex getDefaultSubcollectionIndex() {98 if(default_index != null && default_index.isAssigned()) {99 return default_index;100 }101 else {102 return null;103 }104 } */105 106 /** Retrieve a certain subindex given its name.107 * @param id the String identifier of a subcollectionindex108 * @return the SubcollectionIndex requested or null if no such subindex109 */110 private SubcollectionIndex getSubcollectionIndex(String id) {111 int size = getSize();112 for(int i = 0; i < size; i++) {113 SubcollectionIndex subindex = (SubcollectionIndex) getElementAt(i);114 if(subindex.getID().equals(id)) {115 return subindex;116 }117 }118 return null;119 }120 105 121 106 /** Method to get all of the subindexes set. 122 107 * @return an ArrayList containing all the defined indexes 123 108 */ 124 public ArrayList getSubcollectionIndexes() { 109 public ArrayList getSubcollectionIndexes() 110 { 125 111 return children(); 126 112 } 127 113 128 /** Method to remove a certain subindex. 129 * @param subindex the Index you wish to remove 130 * @see org.greenstone.gatherer.Gatherer 131 * @see org.greenstone.gatherer.collection.CollectionManager 132 */ 133 private void removeSubcollectionIndex(SubcollectionIndex subindex) { 134 if(subindex != null) { 114 115 private int moveSubcollectionIndex(SubcollectionIndex subcollection_index, boolean move_up) 116 { 117 // Determine the current position of the subcollection index 118 int position = indexOf(subcollection_index); 119 int new_position; 120 121 // Attempt to move the subcollection index up 122 if (move_up) { 123 // Check it's not already at the top 124 if (position == 0) { 125 return position; 126 } 127 128 // This automatically removes the index first, as an Element can only exist once in a particular document 129 new_position = position - 1; 130 addBefore(subcollection_index, (SubcollectionIndex) getElementAt(new_position)); 131 } 132 133 // Attempt to move the subcollection index down 134 else { 135 // Check it's not already at the bottom 136 if (position == (getSize()) - 1) { 137 return position; 138 } 139 140 // This automatically removes the index first, as an Element can only exist once in a particular document 141 new_position = position + 1; 142 addAfter(subcollection_index, (SubcollectionIndex) getElementAt(new_position)); 143 } 144 145 // Schedule the collection for saving 146 Gatherer.c_man.configurationChanged(); 147 return new_position; 148 } 149 150 151 /** Method to remove a certain subcollection index. */ 152 private void removeSubcollectionIndex(SubcollectionIndex subcollection_index) 153 { 154 if (subcollection_index != null) { 135 155 // Remove any current metadata from this index 136 CollectionDesignManager.collectionmeta_manager.removeMetadata(StaticStrings.STOP_CHARACTER + subindex.getID()); 156 CollectionDesignManager.collectionmeta_manager.removeMetadata("." + subcollection_index.getID()); 157 137 158 // Check if the index removed happens to be the default index 138 if(default_index != null && default_index.equals(subindex)) { 139 default_index.setAssigned(false); 140 ((SubcollectionIndexControl)controls).clearDefaultIndex(); 141 } 159 if (default_index != null && default_index.equals(subcollection_index)) { 160 // If so our first solution is to set the first subcollection index to be the default 161 if (getSize() > 0) { 162 setDefaultSubcollectionIndex((SubcollectionIndex) getElementAt(0)); 163 } 164 else { 165 default_index.setAssigned(false); 166 } 167 } 168 142 169 // Remove the index 143 remove(sub index);170 remove(subcollection_index); 144 171 Gatherer.c_man.configurationChanged(); 145 172 } 146 173 } 174 147 175 148 176 /** Method to remove all of the subindexes that contain a certain subcollection. … … 151 179 * @see org.greenstone.gatherer.cdm.SubcollectionIndex 152 180 */ 153 public void removeSubcollectionIndexes(Subcollection subcollection) { 181 public void removeSubcollectionIndexes(Subcollection subcollection) 182 { 154 183 String subcollection_name = subcollection.getName(); 155 184 int size = getSize(); 156 185 for(int i = size - 1; i >= 0; i--) { 157 SubcollectionIndex subindex = (SubcollectionIndex)getElementAt(i); 158 if(subindex.getSources().contains(subcollection_name)) { 159 removeSubcollectionIndex(subindex); 160 } 161 subindex = null; 162 } 163 subcollection_name = null; 164 } 186 SubcollectionIndex subcollection_index = (SubcollectionIndex) getElementAt(i); 187 if (subcollection_index.getSources().contains(subcollection_name)) { 188 removeSubcollectionIndex(subcollection_index); 189 } 190 } 191 } 192 165 193 166 194 /** Method to set the default subcollection index. … … 170 198 * @see org.greenstone.gatherer.cdm.SubcollectionIndex 171 199 */ 172 private void setDefaultSubcollectionIndex(SubcollectionIndex index) { 173 if(index != null) { 174 if(default_index == null) { 200 private void setDefaultSubcollectionIndex(SubcollectionIndex subcollection_index) 201 { 202 if (subcollection_index != null) { 203 if (default_index == null) { 175 204 // Create the default index element, and place immediately after indexes element. 176 205 Element default_index_element = root.getOwnerDocument().createElement(CollectionConfiguration.SUBCOLLECTION_DEFAULT_INDEX_ELEMENT); 177 206 default_index = new SubcollectionIndex(default_index_element); 178 207 Node target_node = CollectionConfiguration.findInsertionPoint(default_index_element); 179 if (target_node != null) {208 if (target_node != null) { 180 209 root.getOwnerDocument().getDocumentElement().insertBefore(default_index_element, target_node); 181 210 } … … 183 212 root.getOwnerDocument().getDocumentElement().appendChild(default_index_element); 184 213 } 185 } 186 default_index.setAssigned(true); 187 default_index.setSources(index.getSources()); 188 } 189 else { 190 if(default_index != null) { 191 default_index.setAssigned(false); 192 } 193 } 194 Gatherer.c_man.configurationChanged(); 195 } 196 197 private class SubcollectionIndexControl 214 } 215 default_index.setAssigned(true); 216 default_index.setSources(subcollection_index.getSources()); 217 } 218 else { 219 if (default_index != null) { 220 default_index.setAssigned(false); 221 } 222 } 223 Gatherer.c_man.configurationChanged(); 224 } 225 226 227 /** This class creates a set of controls for editing the indexes. */ 228 private class SubcollectionIndexControls 198 229 extends JPanel 199 implements Control { 200 201 private JButton add_index_button; 202 private JButton clear_default_button; 203 private JButton remove_index_button; 230 implements Control 231 { 232 private CheckList source_list; 233 private JButton add_button; 234 private JButton move_down_button; 235 private JButton move_up_button; 236 private JButton remove_button; 237 private JButton replace_button; 204 238 private JButton set_default_button; 205 private JList subcollection_list; 206 private JList subcollectionindexes_list; 207 private JTextField default_value_field; 208 private JTextField subcollectionindex_name_field; 209 210 public SubcollectionIndexControl() { 239 private JList subcollection_index_list; 240 private JTextField subcollection_index_name_textfield; 241 242 243 /** Constructor. 244 */ 245 public SubcollectionIndexControls() 246 { 211 247 super(); 248 249 ArrayList sources = new ArrayList(); 250 ListModel source_model = CollectionDesignManager.subcollection_manager; 251 for (int i = 0; i < source_model.getSize(); i++) { 252 sources.add(source_model.getElementAt(i)); 253 } 254 212 255 // Creation 213 JPanel subcollection_panel = new JPanel(); 214 JPanel subindex_name_panel = new JPanel(); 215 JLabel subindex_name_label = new JLabel(); 216 Dictionary.registerText(subindex_name_label, "CDM.SubcollectionIndexManager.PartitionName"); 217 subcollectionindex_name_field = new JTextField(); 218 subcollectionindex_name_field.setPreferredSize(Utility.LABEL_SIZE); 219 Dictionary.registerTooltip(subcollectionindex_name_field, "CDM.SubcollectionIndexManager.PartitionName_Tooltip"); 256 JPanel assigned_indexes_pane = new JPanel(); 257 JLabel index_label = new JLabel(); 258 Dictionary.registerText(index_label, "CDM.SubcollectionIndexManager.Subindexes"); 259 subcollection_index_list = new JList(model); 260 subcollection_index_list.setCellRenderer(new SubcollectionIndexListCellRenderer()); 261 subcollection_index_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 262 subcollection_index_list.setVisibleRowCount(2); 263 264 JPanel movement_pane = new JPanel(); 265 move_up_button = new JButton("", Utility.getImage("arrow-up.gif")); 266 move_up_button.setEnabled(true); 267 move_up_button.setMnemonic(KeyEvent.VK_U); 268 Dictionary.registerBoth(move_up_button, "CDM.Move.Move_Up", "CDM.Move.Move_Up_Tooltip"); 269 270 move_down_button = new JButton("", Utility.getImage("arrow-down.gif")); 271 move_down_button.setEnabled(true); 272 move_down_button.setMnemonic(KeyEvent.VK_D); 273 Dictionary.registerBoth(move_down_button, "CDM.Move.Move_Down", "CDM.Move.Move_Down_Tooltip"); 274 275 set_default_button = new GLIButton(); 276 set_default_button.setEnabled(false); 277 set_default_button.setMnemonic(KeyEvent.VK_S); 278 Dictionary.registerBoth(set_default_button, "CDM.SubcollectionIndexManager.Set_Default_Subindex", "CDM.SubcollectionIndexManager.Set_Default_Subindex_Tooltip"); 279 280 JPanel index_pane = new JPanel(); 281 JPanel details_pane = new JPanel(); 282 JPanel labels_pane = new JPanel(); 283 JPanel boxes_pane = new JPanel(); 284 JPanel content_pane = new JPanel(); 285 286 JLabel name_label = new JLabel(); 287 Dictionary.registerText(name_label, "CDM.SubcollectionIndexManager.PartitionName"); 288 subcollection_index_name_textfield = new JTextField(); 289 subcollection_index_name_textfield.setPreferredSize(FIELD_SIZE); 290 Dictionary.registerTooltip(subcollection_index_name_textfield, "CDM.SubcollectionIndexManager.PartitionName_Tooltip"); 291 292 JLabel source_label = new JLabel(); 293 Dictionary.registerText(source_label, "CDM.SubcollectionIndexManager.Source"); 294 source_list = new CheckList(false); 295 source_list.setListData(sources); 296 Dictionary.registerTooltip(source_list, "CDM.SubcollectionIndexManager.Source_Tooltip"); 220 297 221 298 JPanel button_pane = new JPanel(); 222 223 add_index_button = new GLIButton(); 224 add_index_button.setMnemonic(KeyEvent.VK_A); 225 add_index_button.setEnabled(false); 226 Dictionary.registerBoth(add_index_button, "CDM.SubcollectionIndexManager.Add_Subindex", "CDM.SubcollectionIndexManager.Add_Subindex_Tooltip"); 227 228 clear_default_button = new GLIButton(); 229 clear_default_button.setMnemonic(KeyEvent.VK_C); 230 clear_default_button.setEnabled(default_index != null); 231 Dictionary.registerBoth(clear_default_button, "CDM.SubcollectionIndexManager.Clear_Default_Subindex", "CDM.SubcollectionIndexManager.Clear_Default_Subindex_Tooltip"); 232 233 JLabel default_label = new JLabel(); 234 Dictionary.registerText(default_label, "CDM.SubcollectionIndexManager.Default_Subindex"); 235 236 JPanel default_pane = new JPanel(); 237 if(default_index == null) { 238 default_value_field = new JTextField(); 239 } 240 else { 241 default_value_field = new JTextField(default_index.toString()); 242 } 243 default_value_field.setPreferredSize(Utility.LABEL_SIZE); 244 default_value_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false)); 245 default_value_field.setEditable(false); 246 247 remove_index_button = new GLIButton(); 248 remove_index_button.setMnemonic(KeyEvent.VK_R); 249 remove_index_button.setEnabled(false); 250 Dictionary.registerBoth(remove_index_button, "CDM.SubcollectionIndexManager.Remove_Subindex", "CDM.SubcollectionIndexManager.Remove_Subindex_Tooltip"); 251 252 set_default_button = new GLIButton(); 253 set_default_button.setMnemonic(KeyEvent.VK_S); 254 set_default_button.setEnabled(false); 255 Dictionary.registerBoth(set_default_button, "CDM.SubcollectionIndexManager.Set_Default_Subindex", "CDM.SubcollectionIndexManager.Set_Default_Subindex_Tooltip"); 256 257 JLabel subcollection_label = new JLabel(); 258 Dictionary.registerText(subcollection_label, "CDM.SubcollectionIndexManager.Subcollection"); 259 subcollection_list = new JList(CollectionDesignManager.subcollection_manager); 260 JPanel list_pane = new JPanel(); 261 JLabel subindexes_label = new JLabel(); 262 Dictionary.registerText(subcollection_label, "CDM.SubcollectionIndexManager.Subindexes"); 263 subcollectionindexes_list = new JList(model); 264 subcollectionindexes_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 265 JPanel subindexes_pane = new JPanel(); 266 267 // Add listeners 268 ExclusiveListSelectionListener ell = new ExclusiveListSelectionListener(); 269 ell.add(subcollection_list); 270 ell.add(subcollectionindexes_list); 271 add_index_button.addActionListener(new AddSubIndexListener()); 272 clear_default_button.addActionListener(new ClearDefaultSubIndexListener()); 273 remove_index_button.addActionListener(new RemoveSubIndexListener()); 274 set_default_button.addActionListener(new SetDefaultSubIndexListener()); 275 276 subcollectionindexes_list.addListSelectionListener(new SubcollectionListListener()); 277 278 subcollectionindex_name_field.getDocument().addDocumentListener(new SubcollectionIndexListener()); 279 subcollection_list.addListSelectionListener(new SubcollectionIndexListener()); 299 add_button = new GLIButton(); 300 add_button.setEnabled(false); 301 add_button.setMnemonic(KeyEvent.VK_A); 302 Dictionary.registerBoth(add_button, "CDM.SubcollectionIndexManager.Add_Subindex", "CDM.SubcollectionIndexManager.Add_Subindex_Tooltip"); 303 304 remove_button = new GLIButton(); 305 remove_button.setEnabled(false); 306 remove_button.setMnemonic(KeyEvent.VK_R); 307 Dictionary.registerBoth(remove_button, "CDM.SubcollectionIndexManager.Remove_Subindex", "CDM.SubcollectionIndexManager.Remove_Subindex_Tooltip"); 308 309 replace_button = new GLIButton(); 310 replace_button.setEnabled(false); 311 replace_button.setMnemonic(KeyEvent.VK_P); 312 Dictionary.registerBoth(replace_button, "CDM.SubcollectionIndexManager.Replace_Subindex", "CDM.SubcollectionIndexManager.Replace_Subindex_Tooltip"); 313 314 // Listeners 315 add_button.addActionListener(new AddListener()); 316 move_down_button.addActionListener(new MoveListener(false)); 317 move_up_button.addActionListener(new MoveListener(true)); 318 remove_button.addActionListener(new RemoveListener()); 319 replace_button.addActionListener(new ReplaceListener()); 320 set_default_button.addActionListener(new SetDefaultListener()); 321 subcollection_index_name_textfield.getDocument().addDocumentListener(new NameListener()); 322 subcollection_index_list.addListSelectionListener(new SubcollectionIndexListListener()); 323 source_list.addListSelectionListener(new SourceListListener()); 280 324 281 325 // Layout 282 default_label.setBorder(BorderFactory.createEmptyBorder(0,0,0,5)); 283 284 default_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(2,0,0,0), BorderFactory.createCompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createEmptyBorder(2,2,2,2)))); 285 default_pane.setLayout(new BorderLayout(5,0)); 286 default_pane.add(default_label, BorderLayout.WEST); 287 default_pane.add(default_value_field, BorderLayout.CENTER); 288 289 subindexes_pane.setLayout(new BorderLayout()); 290 subindexes_pane.add(subindexes_label, BorderLayout.NORTH); 291 subindexes_pane.add(new JScrollPane(subcollectionindexes_list), BorderLayout.CENTER); 292 subindexes_pane.add(default_pane, BorderLayout.SOUTH); 326 movement_pane.setBorder(BorderFactory.createEmptyBorder(0,2,0,0)); 327 movement_pane.setLayout(new GridLayout(3,1)); 328 movement_pane.add(move_up_button); 329 movement_pane.add(move_down_button); 330 movement_pane.add(set_default_button); 331 332 assigned_indexes_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0)); 333 assigned_indexes_pane.setLayout(new BorderLayout()); 334 assigned_indexes_pane.add(index_label, BorderLayout.NORTH); 335 assigned_indexes_pane.add(new JScrollPane(subcollection_index_list), BorderLayout.CENTER); 336 assigned_indexes_pane.add(movement_pane, BorderLayout.EAST); 337 338 labels_pane.setLayout(new BorderLayout()); 339 labels_pane.setBorder(BorderFactory.createEmptyBorder(5, 5, 10, 5)); 340 labels_pane.add(name_label, BorderLayout.NORTH); 341 labels_pane.add(source_label, BorderLayout.CENTER); 293 342 294 subindex_name_panel.setBorder(BorderFactory.createEmptyBorder(2,0,0,0)); 295 subindex_name_panel.setLayout(new BorderLayout(5,0)); 296 subindex_name_panel.add(subindex_name_label, BorderLayout.WEST); 297 subindex_name_panel.add(subcollectionindex_name_field, BorderLayout.CENTER); 298 299 list_pane.setBorder(BorderFactory.createEmptyBorder(5,0,2,0)); 300 list_pane.setLayout(new BorderLayout()); 301 list_pane.add(subcollection_label, BorderLayout.NORTH); 302 list_pane.add(new JScrollPane(subcollection_list), BorderLayout.CENTER); 303 list_pane.add(subindex_name_panel, BorderLayout.SOUTH); 304 305 button_pane.setLayout(new GridLayout(2,2)); 306 button_pane.add(add_index_button); 307 button_pane.add(remove_index_button); 308 button_pane.add(set_default_button); 309 button_pane.add(clear_default_button); 310 311 subcollection_panel.setLayout(new BorderLayout()); 312 //subcollection_panel.add(subindex_name_panel, BorderLayout.NORTH); 313 subcollection_panel.add(list_pane, BorderLayout.CENTER); 314 subcollection_panel.add(button_pane, BorderLayout.SOUTH); 343 boxes_pane.setLayout(new BorderLayout()); 344 boxes_pane.add(subcollection_index_name_textfield, BorderLayout.NORTH); 345 boxes_pane.add(new JScrollPane(source_list), BorderLayout.CENTER); 315 346 347 details_pane.setLayout(new BorderLayout()); 348 details_pane.add(labels_pane, BorderLayout.WEST); 349 details_pane.add(boxes_pane, BorderLayout.CENTER); 350 351 button_pane.setLayout(new GridLayout(1,3)); 352 button_pane.add(add_button); 353 button_pane.add(replace_button); 354 button_pane.add(remove_button); 355 356 index_pane.setLayout(new BorderLayout()); 357 index_pane.add(details_pane, BorderLayout.CENTER); 358 index_pane.add(button_pane, BorderLayout.SOUTH); 359 360 content_pane.setLayout(new BorderLayout()); 361 content_pane.add(assigned_indexes_pane, BorderLayout.NORTH); 362 content_pane.add(index_pane, BorderLayout.CENTER); 363 316 364 setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 317 365 setLayout(new BorderLayout()); 318 add(subindexes_pane, BorderLayout.CENTER); 319 add(subcollection_panel, BorderLayout.SOUTH); 320 } 321 322 public void clearDefaultIndex() { 323 clear_default_button.doClick(); 324 } 325 326 public void destroy() { 327 } 328 329 public void gainFocus() { 330 } 331 332 public void loseFocus() { 333 } 334 335 /** Listens for actions apon the 'add subindex' button in the SubcollectionManager controls, and if detected calls the addSubindex method of the manager with a newly created subindex. */ 336 private class AddSubIndexListener 337 implements ActionListener { 338 /** 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 series of subcollections selected, and if so build an new subindex based apon them. 339 * @param event An <strong>ActionEvent</strong> containing information about the event. 340 * @see org.greenstone.gatherer.cdm.SubcollectionIndex 366 add(content_pane, BorderLayout.CENTER); 367 } 368 369 370 public void destroy() 371 { 372 } 373 374 375 public void gainFocus() 376 { 377 // Reload the source list 378 ArrayList sources = new ArrayList(); 379 ListModel source_model = CollectionDesignManager.subcollection_manager; 380 for (int i = 0; i < source_model.getSize(); i++) { 381 sources.add(source_model.getElementAt(i)); 382 } 383 source_list.setListData(sources); 384 385 // Refresh the subcollection index list 386 subcollection_index_list.updateUI(); 387 388 // If there is one selected, fill in the controls 389 updateControlsWithSelectedIndex(); 390 } 391 392 393 public void loseFocus() 394 { 395 } 396 397 398 private void updateControlsWithSelectedIndex() 399 { 400 SubcollectionIndex selected_index = (SubcollectionIndex) subcollection_index_list.getSelectedValue(); 401 if (selected_index == null) { 402 return; 403 } 404 405 // Display the selected subcollection index's name 406 String id = selected_index.getID(); 407 String name = CollectionDesignManager.collectionmeta_manager.getMetadatum("." + id).getValue(true); 408 subcollection_index_name_textfield.setText(name); 409 410 // Display the selected subcollection index's sources 411 source_list.clearSelection(); 412 source_list.setSelectedObjects(selected_index.getSources().toArray()); 413 } 414 415 416 private void validateControls() 417 { 418 boolean add_enabled = false; 419 boolean replace_enabled = false; 420 421 // Indexes must have a name 422 if (subcollection_index_name_textfield.getText().length() == 0) { 423 add_enabled = false; 424 } 425 // Can't add a new index if no sources are selected 426 else if (source_list.getSelected().size() == 0) { 427 add_enabled = false; 428 } 429 // If we get this far, create a dummy index and see if it's already assigned in the collection 430 else { 431 ArrayList sources = source_list.getSelected(); 432 SubcollectionIndex subcollection_index = new SubcollectionIndex(sources.toArray()); 433 434 // Subcollection index already exists: can't add, but can replace if the name has changed 435 if (model.contains(subcollection_index)) { 436 add_enabled = false; 437 438 // Here we need to check if we have changed the name - if so, we can enable the replace button 439 if (subcollection_index_list.getSelectedIndex() != -1) { 440 String name = subcollection_index_name_textfield.getText(); 441 SubcollectionIndex selected_index = (SubcollectionIndex) subcollection_index_list.getSelectedValue(); 442 String selected_name = CollectionDesignManager.collectionmeta_manager.getMetadatum("." + selected_index.getID()).getValue(true); 443 if (!name.equals(selected_name)) { 444 replace_enabled = true; 445 } 446 } 447 } 448 449 // Subcollection index doesn't already exist: can add, or replace if there is something selected 450 else { 451 add_enabled = true; 452 if (subcollection_index_list.getSelectedIndex() != -1) { 453 replace_enabled = true; 454 } 455 } 456 } 457 458 // We should now know the add_button state 459 add_button.setEnabled(add_enabled); 460 replace_button.setEnabled(replace_enabled); 461 } 462 463 464 private class AddListener 465 implements ActionListener 466 { 467 public void actionPerformed(ActionEvent event) 468 { 469 String name = subcollection_index_name_textfield.getText(); 470 if (source_list.getSelected().size() > 0 && name.length() != 0) { 471 ArrayList sources = source_list.getSelected(); 472 SubcollectionIndex subcollection_index = new SubcollectionIndex(sources.toArray()); 473 474 // Before we add the index to the model, we have to add the collection metadata for this 475 CollectionMeta metadatum = new CollectionMeta("." + subcollection_index.getID()); 476 metadatum.setValue(name); 477 CollectionDesignManager.collectionmeta_manager.addMetadatum(metadatum); 478 479 // Finally, add the subcollection index 480 addSubcollectionIndex(subcollection_index); 481 subcollection_index_list.setSelectedIndex(model.getSize() - 1); 482 } 483 } 484 } 485 486 487 private class MoveListener 488 implements ActionListener 489 { 490 private boolean move_up; 491 492 public MoveListener(boolean move_up) 493 { 494 this.move_up = move_up; 495 } 496 497 public void actionPerformed(ActionEvent event) 498 { 499 // Retrieve the selected subcollection index 500 SubcollectionIndex subcollection_index = (SubcollectionIndex) subcollection_index_list.getSelectedValue(); 501 if (subcollection_index != null) { 502 int new_position = moveSubcollectionIndex(subcollection_index, move_up); 503 // Ensure the subcollection index that moved is still selected 504 subcollection_index_list.setSelectedIndex(new_position); 505 } 506 } 507 } 508 509 510 /** Listens for key presses within the name field, and enabled or disables controls as appropriate. */ 511 private class NameListener 512 implements DocumentListener 513 { 514 public void changedUpdate(DocumentEvent e) 515 { 516 validateControls(); 517 } 518 519 public void insertUpdate(DocumentEvent e) 520 { 521 validateControls(); 522 } 523 524 public void removeUpdate(DocumentEvent e) 525 { 526 validateControls(); 527 } 528 } 529 530 531 private class RemoveListener 532 implements ActionListener 533 { 534 public void actionPerformed(ActionEvent event) 535 { 536 int i = subcollection_index_list.getSelectedIndex(); 537 if (i != -1) { 538 removeSubcollectionIndex((SubcollectionIndex) subcollection_index_list.getSelectedValue()); 539 } 540 541 int size = subcollection_index_list.getModel().getSize(); 542 if (i == size) { 543 i--; 544 } 545 subcollection_index_list.setSelectedIndex(i); 546 validateControls(); 547 } 548 } 549 550 551 private class ReplaceListener 552 implements ActionListener 553 { 554 public void actionPerformed(ActionEvent event) 555 { 556 if (subcollection_index_list.isSelectionEmpty()) { 557 // This should never happen, but just in case... 558 replace_button.setEnabled(false); 559 return; 560 } 561 562 // We'll just remove the old one and add the new one 563 removeSubcollectionIndex((SubcollectionIndex) subcollection_index_list.getSelectedValue()); 564 replace_button.setEnabled(false); 565 add_button.setEnabled(true); 566 add_button.doClick(); 567 add_button.setEnabled(false); 568 } 569 } 570 571 572 private class SetDefaultListener 573 implements ActionListener 574 { 575 public void actionPerformed(ActionEvent event) 576 { 577 SubcollectionIndex subcollection_index = (SubcollectionIndex) subcollection_index_list.getSelectedValue(); 578 if (subcollection_index != null) { 579 setDefaultSubcollectionIndex(subcollection_index); 580 // This should cause a repaint of just the desired row 581 subcollection_index_list.setSelectedValue(subcollection_index, true); 582 } 583 set_default_button.setEnabled(false); 584 } 585 } 586 587 588 private class SourceListListener 589 implements ListSelectionListener 590 { 591 public void valueChanged(ListSelectionEvent event) 592 { 593 validateControls(); 594 } 595 } 596 597 598 /** Listens for selections within the list on the SubcollectionIndexManager controls, and if a change is detected enables, or disables, controls appropriately. */ 599 private class SubcollectionIndexListListener 600 implements ListSelectionListener 601 { 602 /** This method is called whenever the source list selection changes. When it does we need to fill in the various parts of the list description panel 603 * @param event A <strong>ListSelectionEvent</strong> containing further information about the list selection. 341 604 */ 342 public void actionPerformed(ActionEvent event) { 343 if(!subcollection_list.isSelectionEmpty() && subcollectionindex_name_field.getText().length() > 0) { 344 SubcollectionIndex subindex = new SubcollectionIndex(subcollection_list.getSelectedValues()); 345 addSubcollectionIndex(subindex); 346 // Add the subindexes name. 347 CollectionMeta metadatum = new CollectionMeta("." + subindex.getID()); 348 metadatum.setValue(subcollectionindex_name_field.getText()); 349 CollectionDesignManager.collectionmeta_manager.addMetadatum(metadatum); 350 } 351 } 352 } 353 354 /** Listens for actions apon the 'clear default subindex' button in the SubcollectionManager controls, and if detected calls the setDefaultSubcollectionIndex() method of the manager with <i>null</i>. */ 355 private class ClearDefaultSubIndexListener 356 implements ActionListener { 357 /** 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. 358 * @param event An <strong>ActionEvent</strong> containing information about the event. 359 */ 360 public void actionPerformed(ActionEvent event) { 361 setDefaultSubcollectionIndex(null); 362 default_value_field.setText(""); 363 clear_default_button.setEnabled(false); 364 set_default_button.setEnabled(!subcollectionindexes_list.isSelectionEmpty()); 365 } 366 } 367 368 /** Listens for actions apon the 'remove subindex' button in the SubcollectionManager controls, and if detected calls the removeSubcollectionIndex method of the manager with the SubcollectionIndex selected for removal. */ 369 private class RemoveSubIndexListener 370 implements ActionListener { 371 /** 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. 372 * @param event An <strong>ActionEvent</strong> containing information about the event. 373 * @see org.greenstone.gatherer.cdm.SubcollectionIndex 374 */ 375 public void actionPerformed(ActionEvent event) { 376 if(!subcollectionindexes_list.isSelectionEmpty()) { 377 removeSubcollectionIndex((SubcollectionIndex)subcollectionindexes_list.getSelectedValue()); 378 } 379 } 380 } 381 /** Listens for actions apon the 'set default subindex' button in the SubcollectionManager controls, and if detected calls the setDefaultSubcollectionIndex method of the manager with the SubIndex selected for default. */ 382 private class SetDefaultSubIndexListener 383 implements ActionListener { 384 /** 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. 385 * @param event An <strong>ActionEvent</strong> containing information about the event. 386 * @see org.greenstone.gatherer.cdm.SubcollectionIndex 387 */ 388 public void actionPerformed(ActionEvent event) { 389 if(!subcollectionindexes_list.isSelectionEmpty()) { 390 setDefaultSubcollectionIndex((SubcollectionIndex)subcollectionindexes_list.getSelectedValue()); 391 default_value_field.setText(default_index.toString()); 392 clear_default_button.setEnabled(true); 393 set_default_button.setEnabled(false); 394 } 395 } 396 } 397 398 private class SubcollectionIndexListener 399 implements DocumentListener, ListSelectionListener { 400 401 /** Gives notification that an attribute or set of attributes changed. */ 402 public void changedUpdate(DocumentEvent e) { 403 update(); 404 } 405 /** Gives notification that there was an insert into the document. */ 406 public void insertUpdate(DocumentEvent e) { 407 update(); 408 } 409 /** Gives notification that a portion of the document has been removed. */ 410 public void removeUpdate(DocumentEvent e) { 411 update(); 412 } 413 414 public void valueChanged(ListSelectionEvent event) { 415 if(!event.getValueIsAdjusting()) { 416 update(); 417 } 418 } 419 420 /** 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. */ 421 private void update() { 422 if(!subcollection_list.isSelectionEmpty() && subcollectionindex_name_field.getText().length() > 0) { 423 if (getSubcollectionIndex(subcollectionindex_name_field.getText()) == null) { 424 SubcollectionIndex subindex = new SubcollectionIndex(subcollection_list.getSelectedValues()); 425 add_index_button.setEnabled(!model.contains(subindex)); 426 } else { 427 add_index_button.setEnabled(false); 428 } 429 } 430 else { 431 add_index_button.setEnabled(false); 432 } 433 } 434 } 435 436 private class SubcollectionListListener 437 implements ListSelectionListener { 438 439 public void valueChanged(ListSelectionEvent event) { 440 if(!event.getValueIsAdjusting()) { 441 boolean enable = !subcollectionindexes_list.isSelectionEmpty(); 442 remove_index_button.setEnabled(enable); 443 set_default_button.setEnabled(enable); 444 } 605 public void valueChanged(ListSelectionEvent event) 606 { 607 if (event.getValueIsAdjusting()) { 608 return; 609 } 610 611 int i = subcollection_index_list.getSelectedIndex(); 612 int size = subcollection_index_list.getModel().getSize(); 613 if (i < 0 || i >= size) { 614 move_down_button.setEnabled(false); 615 move_up_button.setEnabled(false); 616 remove_button.setEnabled(false); 617 replace_button.setEnabled(false); 618 set_default_button.setEnabled(false); 619 return; 620 } 621 622 // Enable the buttons appropriately 623 remove_button.setEnabled(true); 624 SubcollectionIndex selected_index = (SubcollectionIndex) subcollection_index_list.getSelectedValue(); 625 set_default_button.setEnabled(default_index == null || !default_index.equals(selected_index)); 626 if (i > 0) { 627 move_up_button.setEnabled(true); 628 } 629 else { 630 move_up_button.setEnabled(false); 631 } 632 if (i < size-1){ 633 move_down_button.setEnabled(true); 634 } 635 else { 636 move_down_button.setEnabled(false); 637 } 638 639 // Need to fill in the rest of the bits 640 updateControlsWithSelectedIndex(); 641 } 642 } 643 644 645 private class SubcollectionIndexListCellRenderer 646 extends DefaultListCellRenderer 647 { 648 /** Return a component that has been configured to display the specified value. */ 649 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 650 JLabel component = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 651 if (default_index != null && default_index.equals(value)) { 652 component.setText(component.getText() + " " + Dictionary.get("CDM.SubcollectionIndexManager.Default_Partition_Indicator")); 653 } 654 return component; 445 655 } 446 656 } -
trunk/gli/src/org/greenstone/gatherer/cdm/SubcollectionManager.java
r8576 r9161 158 158 private class SubcollectionControl 159 159 extends JPanel 160 implements Control {161 160 implements Control, ChangeListener 161 { 162 162 private CardLayout card_layout; 163 163 private JButton add_button; … … 190 190 191 191 tabbed_pane = new JTabbedPane(); 192 tabbed_pane.addChangeListener(this); 192 193 JLabel title = new JLabel(); 193 194 title.setHorizontalAlignment(JLabel.CENTER); … … 380 381 else { 381 382 card_layout.show(border_pane, DISABLED_CONTROLS); 383 } 384 } 385 386 public void stateChanged(ChangeEvent event) 387 { 388 if (tabbed_pane.getSelectedIndex() == 1) { 389 CollectionDesignManager.subcollectionindex_manager.getControls().gainFocus(); 390 } 391 if (tabbed_pane.getSelectedIndex() == 2) { 392 CollectionDesignManager.language_manager.getControls().gainFocus(); 382 393 } 383 394 }
Note:
See TracChangeset
for help on using the changeset viewer.