Changeset 5037
- Timestamp:
- 2003-07-25T16:35:22+12:00 (21 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/ClassifierManager.java
r4960 r5037 536 536 537 537 classifier = new GComboBox(library.toArray()); 538 classifier.setBackgroundNonSelectionColor(Gatherer.config.getColor("coloring.editable ", false));538 classifier.setBackgroundNonSelectionColor(Gatherer.config.getColor("coloring.editable_background", false)); 539 539 classifier.setBackgroundSelectionColor(Gatherer.config.getColor("coloring.collection_selection_background", false)); 540 540 classifier.setEditable(true); -
trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfiguration.java
r4967 r5037 404 404 Element collect_config_element = document.getDocumentElement(); 405 405 NodeList command_elements = collect_config_element.getChildNodes(); 406 boolean just_wrote_newline = false; // Prevent two or more newlines in a row 406 407 for(int i = 0; i < command_elements.getLength(); i++) { 407 408 Node command_node = command_elements.item(i); … … 409 410 Element command_element = (Element) command_node; 410 411 // The only thing left are NewLine elements 411 if(command_element.getNodeName().equals(NEWLINE_ELEMENT) ) {412 if(command_element.getNodeName().equals(NEWLINE_ELEMENT) && !just_wrote_newline) { 412 413 buffered_writer.newLine(); 414 just_wrote_newline = true; 413 415 } 414 // Anything else we write to file, but only if it has been assigned 415 else if(!command_element.getAttribute(ASSIGNED_ATTRIBUTE).equals(FALSE_STR) ){416 // Anything else we write to file, but only if it has been assigned, the exception being the Indexes element which just get commented if unassigned (a side effect of MG && MGPP compatibility) 417 else if(!command_element.getAttribute(ASSIGNED_ATTRIBUTE).equals(FALSE_STR) || command_element.getNodeName().equals(INDEXES_ELEMENT)){ 416 418 String command = toString(command_element, false); 417 419 if(command != null && command.length() > 0) { 418 420 write(buffered_writer, command); 419 421 buffered_writer.newLine(); 422 just_wrote_newline = false; 420 423 } 421 424 } … … 532 535 533 536 private String indexesToString(Element command_element, boolean show_extracted_namespace) { 537 boolean comment_only = false; 534 538 StringBuffer text = new StringBuffer(""); 535 539 if(command_element.getAttribute(ASSIGNED_ATTRIBUTE).equals(FALSE_STR)) { 536 540 text.append("#"); 541 comment_only = true; 537 542 } 538 543 text.append(INDEX_STR); 539 544 text.append(TAB_CHARACTER); 540 text.append(TAB_CHARACTER); 545 if(!comment_only) { 546 text.append(TAB_CHARACTER); 547 } 541 548 NodeList index_elements = command_element.getElementsByTagName(INDEX_ELEMENT); 542 549 // For each index, write its level, a colon, then concatenate its child content elements into a single comma separated list … … 551 558 NodeList content_elements = index_element.getElementsByTagName(CONTENT_ELEMENT); 552 559 int content_elements_length = content_elements.getLength(); 560 // Don't output anything if no indexes are set 561 if(content_elements_length == 0) { 562 return null; 563 } 553 564 for(int k = 0; k < content_elements_length; k++) { 554 565 Element content_element = (Element) content_elements.item(k); … … 575 586 576 587 private String indexDefaultToString(Element command_element, boolean show_extracted_namespace) { 577 StringBuffer text = new StringBuffer(INDEX_DEFAULT_STR); 588 boolean comment_only = false; 589 StringBuffer text = new StringBuffer(""); 590 if(command_element.getAttribute(ASSIGNED_ATTRIBUTE).equals(FALSE_STR)) { 591 text.append("#"); 592 comment_only = true; 593 } 594 text.append(INDEX_DEFAULT_STR); 578 595 text.append(TAB_CHARACTER); 579 596 text.append(command_element.getAttribute(LEVEL_ATTRIBUTE)); … … 625 642 626 643 private String levelsToString(Element command_element) { 627 if(command_element.getAttribute(ASSIGNED_ATTRIBUTE).equals(TRUE_STR)) { 628 StringBuffer text = new StringBuffer(LEVELS_STR); 629 text.append(TAB_CHARACTER); 630 text.append(TAB_CHARACTER); 631 NodeList content_elements = command_element.getElementsByTagName(CONTENT_ELEMENT); 632 int content_elements_length = content_elements.getLength(); 633 for(int i = 0; i < content_elements_length; i++) { 634 Element content_element = (Element) content_elements.item(i); 635 text.append(content_element.getAttribute(NAME_ATTRIBUTE)); 636 text.append(SPACE_CHARACTER); 637 } 638 return text.substring(0, text.length() - 1); 639 } 640 else { 644 StringBuffer text = new StringBuffer(""); 645 if(!command_element.getAttribute(ASSIGNED_ATTRIBUTE).equals(TRUE_STR)) { 646 text.append("#"); 647 } 648 text.append(LEVELS_STR); 649 text.append(TAB_CHARACTER); 650 text.append(TAB_CHARACTER); 651 NodeList content_elements = command_element.getElementsByTagName(CONTENT_ELEMENT); 652 int content_elements_length = content_elements.getLength(); 653 // Don't output anything if no levels are set. 654 if(content_elements_length == 0) { 641 655 return null; 642 656 } 657 for(int i = 0; i < content_elements_length; i++) { 658 Element content_element = (Element) content_elements.item(i); 659 text.append(content_element.getAttribute(NAME_ATTRIBUTE)); 660 text.append(SPACE_CHARACTER); 661 } 662 return text.substring(0, text.length() - 1); 643 663 } 644 664 -
trunk/gli/src/org/greenstone/gatherer/cdm/DOMProxyListModel.java
r4967 r5037 91 91 else { 92 92 // Retrieve the currently last entry 93 Node sibling = children.item(children.getLength() - 1); 94 Node parent_node = sibling.getParentNode(); 95 sibling = sibling.getNextSibling(); 96 if(sibling != null) { 93 index = children.getLength() - 1; 94 Node sibling = null; 95 Node parent_node = null; 96 if(index >= 0) { 97 sibling = children.item(index); 98 parent_node = sibling.getParentNode(); 99 sibling = sibling.getNextSibling(); 100 } 101 if(sibling != null && parent_node != null) { 97 102 parent_node.insertBefore(element, sibling); 98 103 } 99 104 // Add to the root node 100 105 else { 106 index = 0; 101 107 root.appendChild(element); 102 108 } -
trunk/gli/src/org/greenstone/gatherer/cdm/FormatManager.java
r4960 r5037 227 227 control_pane = new JPanel(); 228 228 editor = new JTextArea(); 229 editor.setBackground(Gatherer.config.getColor("coloring.editable ", false));229 editor.setBackground(Gatherer.config.getColor("coloring.editable_background", false)); 230 230 editor.setCaretPosition(0); 231 231 editor.setLineWrap(true); -
trunk/gli/src/org/greenstone/gatherer/cdm/Index.java
r4967 r5037 76 76 Object source_object = sources.get(i); 77 77 if(source_object instanceof ElementWrapper) { 78 System.err.println("Found ElementWrapper as source: " + ((ElementWrapper)source_object).getName()); 78 79 content_element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, ((ElementWrapper)source_object).getName()); 79 80 } 80 81 else { 82 System.err.println("Found String as source: " + source_object.toString()); 81 83 content_element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, source_object.toString()); 82 84 } … … 110 112 */ 111 113 public int compareTo(Object object) { 114 if(object == null) { 115 return -1; 116 } 117 String id = getID(); 112 118 return id.compareTo(((Index)object).getID()); 113 119 } … … 159 165 for(int i = 0; i < sources_size; i++) { 160 166 Object source_object = sources.get(i); 167 // If its an element wrapper use the unique name rather than the 161 168 if(source_object instanceof ElementWrapper) { 162 id_buffer.append(((ElementWrapper)source_object).getName()); 169 String full_element_name = ((ElementWrapper)source_object).getName(); 170 if(full_element_name.startsWith(Utility.EXTRACTED_METADATA_NAMESPACE)) { 171 id_buffer.append(full_element_name.substring(Utility.EXTRACTED_METADATA_NAMESPACE.length())); 172 } 173 else { 174 id_buffer.append(full_element_name); 175 } 163 176 } 164 177 else { … … 183 196 for(int i = 0; i < content_elements_length; i++) { 184 197 Element content_element = (Element) content_elements.item(i); 185 sources.add(content_element.getAttribute(CollectionConfiguration.NAME_ATTRIBUTE)); 198 String source_str = (String) content_element.getAttribute(CollectionConfiguration.NAME_ATTRIBUTE); 199 if(source_str.indexOf(MSMUtils.NS_SEP) != -1) { 200 ElementWrapper element_wrapper = Gatherer.c_man.getCollection().msm.getElement(source_str); 201 if(element_wrapper != null) { 202 sources.add(element_wrapper); 203 } 204 else { 205 sources.add(source_str); 206 } 207 } 208 else { 209 sources.add(source_str); 210 } 186 211 } 187 212 content_elements = null; … … 249 274 */ 250 275 public String toString() { 251 String id = getID(); 252 StringBuffer text = new StringBuffer(id); 253 CollectionMeta metadatum = CollectionDesignManager.collectionmeta_manager.getMetadatum(StaticStrings.STOP_CHARACTER + id, false); 276 StringBuffer text_buffer = new StringBuffer(""); 277 // Generate language dependant id (include extracted metadata namespace) 278 // Write level information, if any. 279 int level = getLevel(); 280 if(0 <= level && level < 3) { 281 text_buffer.append(LEVEL[level]); 282 text_buffer.append(StaticStrings.COLON_CHARACTER); 283 } 284 // Write data information. Retrieve each of the content sources and add them in a comma separated list. 285 ArrayList sources = getSources(); 286 int sources_size = sources.size(); 287 for(int i = 0; i < sources_size; i++) { 288 String source_name = (sources.get(i)).toString(); 289 // Sometimes I wish they'd asked me to give extracted metadata a namespace, way back before I programmed so much of GLI to expect "" for extracted metadata, any namespace for normal metadata. That way I could just say 'ex' and be done with it, not add all of these special tests whenever it may come to displaying an extracted element. 290 if(source_name.indexOf(MSMUtils.NS_SEP) == -1 && !source_name.equals(CollectionConfiguration.TEXT_STR) && !source_name.equals(CollectionConfiguration.ALLFIELDS_STR)) { 291 text_buffer.append(Utility.EXTRACTED_METADATA_NAMESPACE); 292 text_buffer.append(MSMUtils.NS_SEP); 293 } 294 text_buffer.append(source_name); 295 if(i < sources_size - 1) { 296 text_buffer.append(StaticStrings.COMMA_CHARACTER); 297 } 298 } 299 sources = null; 300 CollectionMeta metadatum = CollectionDesignManager.collectionmeta_manager.getMetadatum(StaticStrings.STOP_CHARACTER + getID(), false); 254 301 if(metadatum != null) { 255 text .append(" \"");256 text .append(metadatum.getValue());257 text .append("\"");258 } 259 return text .toString();302 text_buffer.append(" \""); 303 text_buffer.append(metadatum.getValue()); 304 text_buffer.append("\""); 305 } 306 return text_buffer.toString(); 260 307 } 261 308 } -
trunk/gli/src/org/greenstone/gatherer/cdm/IndexManager.java
r4967 r5037 37 37 import org.greenstone.gatherer.cdm.DOMProxyListModel; 38 38 import org.greenstone.gatherer.cdm.Index; 39 import org.greenstone.gatherer.gui.GComboBox; 39 40 import org.greenstone.gatherer.msm.ElementWrapper; 40 41 import org.greenstone.gatherer.msm.MSMUtils; 41 42 import org.greenstone.gatherer.util.ExclusiveListSelectionListener; 42 import org.greenstone.gatherer.util. StaticStrings;43 import org.greenstone.gatherer.util.Utility; 43 44 import org.w3c.dom.*; 44 45 /** This class is resposible for storing the indexes which have been assigned to this collection and the default index, and providing methods for interacting with both these data pools. It also knows how to turn itself into a String as it would be displayed in the collection configuration file. … … 48 49 public class IndexManager 49 50 extends DOMProxyListModel { 51 52 static final private Dimension LABEL_SIZE = new Dimension(150,30); 53 static final private String MGINDEXES = "mg indexes"; 54 static final private String MGPPINDEXES = "mgpp indexes"; 55 50 56 /** The controls for editing the indexes. */ 51 57 private Control controls = null; … … 56 62 /** The default index. */ 57 63 private Index default_index = null; 64 58 65 /** Constructor. */ 59 66 public IndexManager(Element indexes) { … … 81 88 CollectionDesignManager.collectionmeta_manager.addMetadatum(metadatum); 82 89 // Retrieve the currently last index 83 Index last_index = (Index)getElementAt(getSize() - 1); 84 addAfter(index, last_index); 90 if(getSize() > 0) { 91 Index last_index = (Index)getElementAt(getSize() - 1); 92 addAfter(index, last_index); 93 } 94 else { 95 add(index); 96 } 85 97 Gatherer.c_man.configurationChanged(); 86 98 } 87 99 else { 88 100 JOptionPane.showMessageDialog(Gatherer.g_man, get("CDM.IndexManager.Index_Exists"), get("General.Warning"), JOptionPane.WARNING_MESSAGE); 101 } 102 } 103 104 public void addLevel(Level level, CollectionMeta metadatum) { 105 if(!levels_model.contains(level)) { 106 CollectionDesignManager.collectionmeta_manager.addMetadatum(metadatum); 107 // Retrieve the currently last index 108 if(getSize() > 0) { 109 Level last_level = (Level)levels_model.getElementAt(levels_model.getSize() - 1); 110 levels_model.addAfter(level, last_level); 111 } 112 else { 113 add(level); 114 } 115 Gatherer.c_man.configurationChanged(); 116 } 117 else { 118 JOptionPane.showMessageDialog(Gatherer.g_man, get("CDM.IndexManager.Level_Exists"), get("General.Warning"), JOptionPane.WARNING_MESSAGE); 89 119 } 90 120 } … … 152 182 } 153 183 184 public Level getLevel(String name) { 185 int levels_model_size = levels_model.getSize(); 186 for(int i = 0; i < levels_model_size; i++) { 187 Level level = (Level) levels_model.getElementAt(i); 188 if(level.getName().equals(name)) { 189 return level; 190 } 191 } 192 return null; 193 } 194 195 public void moveIndex(Index index, boolean move_up) { 196 // Determine the indexes current position 197 int position = indexOf(index); 198 // 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. 199 if(position == -1) { 200 return; 201 } 202 if(position == 0 && move_up) { 203 return; 204 } 205 if(position == (getSize()) - 1 && !move_up) { 206 return; 207 } 208 // Ok, move the index 209 if(move_up) { 210 // Retrieve the index at position - 1 211 Index previous_index = (Index) getElementAt(position - 1); 212 // And add before. This will automatically remove the index first, as an Element can only exist once in a particular document 213 addBefore(index, previous_index); 214 } 215 else { 216 // Retrieve the index at position + 1 217 Index next_index = (Index) getElementAt(position + 1); 218 // And add after. This will automatically remove the index first, as an Element can only exist once in a particular document 219 addAfter(index, next_index); 220 } 221 // Schedule the collection for saving 222 Gatherer.c_man.configurationChanged(); 223 } 224 225 public void moveLevel(Level level, boolean move_up) { 226 // Determine the leveles current position 227 int position = levels_model.indexOf(level); 228 // 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. 229 if(position == -1) { 230 return; 231 } 232 if(position == 0 && move_up) { 233 return; 234 } 235 if(position == (levels_model.getSize()) - 1 && !move_up) { 236 return; 237 } 238 // Ok, move the level 239 if(move_up) { 240 // Retrieve the level at position - 1 241 Level previous_level = (Level) levels_model.getElementAt(position - 1); 242 // And add before. This will automatically remove the level first, as an Element can only exist once in a particular document 243 levels_model.addBefore(level, previous_level); 244 } 245 else { 246 // Retrieve the level at position + 1 247 Level next_level = (Level) levels_model.getElementAt(position + 1); 248 // And add after. This will automatically remove the level first, as an Element can only exist once in a particular document 249 levels_model.addAfter(level, next_level); 250 } 251 // Schedule the collection for saving 252 Gatherer.c_man.configurationChanged(); 253 } 254 154 255 /** Method to remove a certain index. 155 256 * @param index the Index to remove. … … 162 263 if(index != null) { 163 264 // Remove any current metadata from this index 164 CollectionDesignManager.collectionmeta_manager.removeMetadata( StaticStrings.STOP_CHARACTER + index.getID());265 CollectionDesignManager.collectionmeta_manager.removeMetadata(CollectionConfiguration.STOP_CHARACTER + index.getID()); 165 266 // Check if the index removed happens to be the default index 166 267 if(default_index != null && default_index.equals(index)) { … … 169 270 // Remove the index 170 271 remove(index); 272 Gatherer.c_man.configurationChanged(); 273 } 274 } 275 276 public void removeLevel(Level level) { 277 if(level != null) { 278 // Remove any current metadata from this level 279 CollectionDesignManager.collectionmeta_manager.removeMetadata(CollectionConfiguration.STOP_CHARACTER + level.getName()); 280 // Remove the level 281 levels_model.remove(level); 171 282 Gatherer.c_man.configurationChanged(); 172 283 } … … 268 379 source_object = null; 269 380 Index new_index = new Index(new_sources); 270 // Before we add the index to the model, we have to add the collection metadata for this. 271 CollectionMeta metadatum = new CollectionMeta(StaticStrings.STOP_CHARACTER + source_str); 272 metadatum.setValue(source_str); 381 // Try to retrieve existing metadatum 382 source_str = new_index.getID(); 383 CollectionMeta metadatum = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.STOP_CHARACTER + source_str, false); 384 // If no metadata was found, add new pseudo metadata using the id 385 if(metadatum == null) { 386 metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + source_str); 387 metadatum.setAssigned(true); 388 metadatum.setValue(source_str); 389 } 390 // If it was found, ensure it is assigned 391 else { 392 metadatum.setAssigned(true); 393 } 394 source_str = null; 273 395 addIndex(new_index, metadatum); 274 396 metadatum = null; … … 312 434 for(int i = 0; i < level_size; i++) { 313 435 Level level = (Level) levels_model.getElementAt(i); 314 Index new_index = new Index(level. toString(), index.getSources());436 Index new_index = new Index(level.getName(), index.getSources()); 315 437 // Try to retrieve existing metadatum 316 CollectionMeta metadatum = CollectionDesignManager.collectionmeta_manager.getMetadatum(new_index.getID(), false); 438 String source_str = new_index.getID(); 439 CollectionMeta metadatum = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.STOP_CHARACTER + source_str, false); 440 // If no metadata was found, add new pseudo metadata using the id 441 if(metadatum == null) { 442 metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + source_str); 443 metadatum.setAssigned(true); 444 metadatum.setValue(source_str); 445 } 446 // If it was found, ensure it is assigned 447 else { 448 metadatum.setAssigned(true); 449 } 450 source_str = null; 317 451 addIndex(new_index, metadatum); 318 452 new_index = null; … … 359 493 extends JPanel 360 494 implements Control { 495 496 private CardLayout card_layout; 497 361 498 /** The default size of a label on this control. */ 362 499 private Dimension LABEL_SIZE = new Dimension(125,25); … … 413 550 /** A text field for controlling the name of the new index. */ 414 551 private JTextField name = null; 415 /** A model containing all of the available index sources. */ 416 private Vector source_model = null; 552 553 private MGPPControl mgppindexes_control = null; 554 417 555 /** Constructor. 418 556 * @see org.greenstone.gatherer.Configuration … … 430 568 public IndexControl() { 431 569 super(); 432 source_model = new Vector();433 source_model.add("text");434 source_model.addAll(Gatherer.c_man.getCollection().msm.getAssignedElements());435 570 // Creation 571 JPanel mgindexes_panel = new JPanel(); 572 card_layout = new CardLayout(); 573 436 574 add = new JButton(get("Add")); 437 575 add.setEnabled(false); … … 485 623 set_default.setMnemonic(KeyEvent.VK_S); 486 624 source_label = new JLabel(get("Source")); 487 source_list = new JList( source_model);625 source_list = new JList(); 488 626 title = new JLabel(get("Title")); 489 627 title.setHorizontalAlignment(JLabel.CENTER); 628 629 // This class is getting a little crowded, so I'll generate the many mgpp controls in a inner class. 630 mgppindexes_control = new MGPPControl(); 490 631 491 632 // Listeners … … 563 704 button_pane.add(set_default); 564 705 565 setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 566 setLayout(new BorderLayout()); 567 add(header_pane, BorderLayout.NORTH); 568 add(central_pane, BorderLayout.CENTER); 569 add(button_pane, BorderLayout.SOUTH); 706 mgindexes_panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 707 mgindexes_panel.setLayout(new BorderLayout()); 708 mgindexes_panel.add(header_pane, BorderLayout.NORTH); 709 mgindexes_panel.add(central_pane, BorderLayout.CENTER); 710 mgindexes_panel.add(button_pane, BorderLayout.SOUTH); 711 712 setLayout(card_layout); 713 add(mgindexes_panel, MGINDEXES); 714 add(mgppindexes_control, MGPPINDEXES); 570 715 } 571 716 /* Destructor, removes persistant listeners from the Dictionary. 572 717 */ 573 718 public void destroy() { 719 mgppindexes_control.destroy(); 720 mgppindexes_control = null; 574 721 } 575 722 576 723 public void gainFocus() { 724 boolean mgpp_enabled = CollectionDesignManager.searchtype_manager.isMGPPEnabled(); 577 725 if(instructions != null) { 578 726 instructions.setCaretPosition(0); 579 727 } 580 // Reload the assigned indexes list. 581 if(source_model != null) { 582 source_model.clear(); 583 source_model.add("text"); 584 source_model.addAll(Gatherer.c_man.getCollection().msm.getAssignedElements()); 585 // reset the model in the list - needed if the model is larger than when it was first created, the list doesn't display 586 source_list.setListData(source_model); 587 728 if(mgpp_enabled) { 729 mgppindexes_control.gainFocus(); 730 } 731 else { 732 // Reload the assigned indexes list. 733 ArrayList new_data = new ArrayList(); 734 new_data.add(CollectionConfiguration.TEXT_STR); 735 new_data.addAll(Gatherer.c_man.getCollection().msm.getAssignedElements()); 736 // reset the model in the list and combobox 737 source_list.setListData(new_data.toArray()); 738 new_data = null; 739 } 740 // Bring the appropriate card to the front 741 if(mgpp_enabled) { 742 card_layout.show(this, MGPPINDEXES); 743 } 744 else { 745 card_layout.show(this, MGINDEXES); 588 746 } 589 747 } … … 615 773 sources = null; 616 774 // Before we add the index to the model, we have to add the collection metadata for this. 617 CollectionMeta metadatum = new CollectionMeta( StaticStrings.STOP_CHARACTER + index.getID());775 CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + index.getID()); 618 776 metadatum.setValue(name.getText()); 619 777 // Finally add index. … … 653 811 } 654 812 } 813 814 /** Listens for selections within the list on the IndexManager controls, and if a change is detected enables, or disables, controls appropriately. */ 815 private class ListListener 816 implements ListSelectionListener { 817 /** 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. 818 * @param event A <strong>ListSelectionEvent</strong> containing further information about the list selection. 819 */ 820 public void valueChanged(ListSelectionEvent event) { 821 if(source_list.isSelectionEmpty() || name.getText().length() == 0) { 822 add.setEnabled(false); 823 } 824 else { 825 add.setEnabled(true); 826 } 827 if(index_list.isSelectionEmpty()) { 828 remove.setEnabled(false); 829 set_default.setEnabled(false); 830 } 831 else { 832 remove.setEnabled(true); 833 set_default.setEnabled(true); 834 } 835 } 836 } 837 838 /** Listens for key presses within the name field, and enabled or disables controls as appropriate. */ 839 private class NameListener 840 extends KeyAdapter { 841 /** Called when a key is released, this is the perfect time to enable the add button if the fields are appropriately set. 842 * @param event A <strong>KeyEvent</strong> containing information about the key released. 843 */ 844 public void keyReleased(KeyEvent event) { 845 if(source_list.isSelectionEmpty() || name.getText().length() == 0) { 846 add.setEnabled(false); 847 } 848 else { 849 add.setEnabled(true); 850 } 851 if(index_list.isSelectionEmpty()) { 852 remove.setEnabled(false); 853 set_default.setEnabled(false); 854 } 855 else { 856 remove.setEnabled(true); 857 set_default.setEnabled(true); 858 } 859 } 860 } 861 655 862 /** Listens for actions apon the 'set default' button in the IndexManager controls, and if detected calls the setDefault method of the manager with the index selected for default. */ 656 863 private class SetDefaultListener … … 673 880 } 674 881 } 675 /** Listens for key presses within the name field, and enabled or disables controls as appropriate. */ 676 private class NameListener 677 extends KeyAdapter { 678 /** Called when a key is released, this is the perfect time to enable the add button if the fields are appropriately set. 679 * @param event A <strong>KeyEvent</strong> containing information about the key released. 680 */ 681 public void keyReleased(KeyEvent event) { 682 if(source_list.isSelectionEmpty() || name.getText().length() == 0) { 683 add.setEnabled(false); 882 } 883 884 private class MGPPControl 885 extends JPanel { 886 887 private GComboBox index_combobox; 888 private GComboBox level_combobox; 889 private JButton add_index_button; 890 private JButton add_level_button; 891 private JButton move_index_down_button; 892 private JButton move_level_down_button; 893 private JButton move_index_up_button; 894 private JButton move_level_up_button; 895 private JButton remove_index_button; 896 private JButton remove_level_button; 897 private JLabel current_levels_label; 898 private JLabel current_indexes_label; 899 private JLabel index_label; 900 private JLabel index_name_label; 901 private JLabel level_label; 902 private JLabel level_name_label; 903 private JLabel move_index_down_label; 904 private JLabel move_level_down_label; 905 private JLabel move_index_up_label; 906 private JLabel move_level_up_label; 907 private JLabel title_label; 908 private JList current_levels_list; 909 private JList current_indexes_list; 910 private JTabbedPane tabbed_pane; 911 private JTextArea instructions_textarea; 912 private JTextField index_name_field; 913 private JTextField level_name_field; 914 915 public MGPPControl() { 916 // Create Indexes 917 JPanel indexes_panel = new JPanel(); 918 919 JPanel current_indexes_panel = new JPanel(); 920 921 current_indexes_label = new JLabel("CDM.IndexManager.MGPP.Current_Indexes"); 922 923 current_indexes_list = new JList(model); 924 current_indexes_list.setVisibleRowCount(5); 925 926 JPanel index_movement_panel = new JPanel(); 927 928 ImageIcon move_index_up_icon = Utility.getImage("arrow-up.gif"); 929 move_index_up_button = new JButton(); 930 move_index_up_label = new JLabel("CDM.Move.Move_Up"); 931 move_index_up_label.setHorizontalAlignment(JLabel.CENTER); 932 move_index_up_label.setPreferredSize(LABEL_SIZE); 933 move_index_up_button.setLayout(new BorderLayout()); 934 move_index_up_button.add(new JLabel(move_index_up_icon), BorderLayout.WEST); 935 move_index_up_button.add(move_index_up_label, BorderLayout.CENTER); 936 move_index_up_button.add(new JLabel(move_index_up_icon), BorderLayout.EAST); 937 move_index_up_button.setMnemonic(KeyEvent.VK_U); 938 939 ImageIcon move_index_down_icon = Utility.getImage("arrow-down.gif"); 940 move_index_down_button = new JButton(); 941 move_index_down_label = new JLabel("CDM.Move.Move_Down"); 942 move_index_down_label.setHorizontalAlignment(JLabel.CENTER); 943 move_index_down_label.setPreferredSize(LABEL_SIZE); 944 move_index_down_button.setLayout(new BorderLayout()); 945 move_index_down_button.add(new JLabel(move_index_down_icon), BorderLayout.WEST); 946 move_index_down_button.add(move_index_down_label, BorderLayout.CENTER); 947 move_index_down_button.add(new JLabel(move_index_down_icon), BorderLayout.EAST); 948 move_index_down_button.setMnemonic(KeyEvent.VK_D); 949 950 JPanel index_spacer_panel = new JPanel(); 951 952 JPanel index_body_panel = new JPanel(); 953 954 JPanel index_details_panel = new JPanel(); 955 956 JPanel index_name_panel = new JPanel(); 957 958 index_name_label = new JLabel("CDM.IndexManager.MGPP.Index_Name"); 959 index_name_label.setPreferredSize(LABEL_SIZE); 960 961 index_name_field = new JTextField(); 962 963 JPanel index_panel = new JPanel(); 964 965 index_label = new JLabel("CDM.IndexManager.MGPP.Index"); 966 index_label.setPreferredSize(LABEL_SIZE); 967 968 index_combobox = new GComboBox(); 969 index_combobox.setBackgroundNonSelectionColor(Gatherer.config.getColor("coloring.editable_background", false)); 970 index_combobox.setBackgroundSelectionColor(Gatherer.config.getColor("coloring.collection_selection_background", false)); 971 index_combobox.setEditable(true); 972 index_combobox.setTextNonSelectionColor(Gatherer.config.getColor("coloring.workspace_tree_foreground", false)); 973 index_combobox.setTextSelectionColor(Gatherer.config.getColor("coloring.collection_selection_foreground", false)); 974 975 JPanel index_button_panel = new JPanel(); 976 977 add_index_button = new JButton("CDM.IndexManager.MGPP.Add_Index"); 978 add_index_button.setEnabled(false); 979 add_index_button.setMnemonic(KeyEvent.VK_A); 980 981 remove_index_button = new JButton("CDM.IndexManager.MGPP.Remove_Index"); 982 remove_index_button.setEnabled(false); 983 remove_index_button.setMnemonic(KeyEvent.VK_A); 984 985 JPanel index_empty_panel = new JPanel(); 986 987 // Connect Indexes 988 EnableAddIndexListener index_eal = new EnableAddIndexListener(); 989 add_index_button.addActionListener(new AddIndexActionListener()); 990 current_indexes_list.addListSelectionListener(new CurrentIndexesListSelectionListener()); 991 Gatherer.dictionary.register(add_index_button, null, false); 992 Gatherer.dictionary.register(current_indexes_label, null, false); 993 Gatherer.dictionary.register(index_label, null, false); 994 Gatherer.dictionary.register(index_name_label, null, false); 995 Gatherer.dictionary.register(move_index_down_label, null, false); 996 Gatherer.dictionary.register(move_index_up_label, null, false); 997 Gatherer.dictionary.register(remove_index_button, null, false); 998 index_combobox.addActionListener(index_eal); 999 ((JTextField)index_combobox.getEditor().getEditorComponent()).getDocument().addDocumentListener(index_eal); 1000 index_name_field.getDocument().addDocumentListener(index_eal); 1001 move_index_down_button.addActionListener(new MoveIndexDownListener()); 1002 move_index_up_button.addActionListener(new MoveIndexUpListener()); 1003 remove_index_button.addActionListener(new RemoveIndexActionListener(index_eal)); 1004 // Layout Indexes 1005 index_movement_panel.setLayout(new GridLayout(2,1)); 1006 index_movement_panel.add(move_index_up_button); 1007 index_movement_panel.add(move_index_down_button); 1008 1009 current_indexes_panel.setLayout(new BorderLayout()); 1010 current_indexes_panel.add(current_indexes_label, BorderLayout.NORTH); 1011 current_indexes_panel.add(new JScrollPane(current_indexes_list), BorderLayout.CENTER); 1012 current_indexes_panel.add(index_movement_panel, BorderLayout.EAST); 1013 1014 index_name_panel.setLayout(new BorderLayout()); 1015 index_name_panel.add(index_name_label, BorderLayout.WEST); 1016 index_name_panel.add(index_name_field, BorderLayout.CENTER); 1017 1018 index_panel.setLayout(new BorderLayout()); 1019 index_panel.add(index_label, BorderLayout.WEST); 1020 index_panel.add(index_combobox, BorderLayout.CENTER); 1021 1022 index_details_panel.setLayout(new GridLayout(2,1,0,5)); 1023 index_details_panel.add(index_name_panel); 1024 index_details_panel.add(index_panel); 1025 1026 index_button_panel.setBorder(BorderFactory.createEmptyBorder(5,0,0,0)); 1027 index_button_panel.setLayout(new GridLayout(1,2,5,0)); 1028 index_button_panel.add(add_index_button); 1029 index_button_panel.add(remove_index_button); 1030 1031 index_body_panel.setBorder(BorderFactory.createEmptyBorder(5,0,0,0)); 1032 index_body_panel.setLayout(new BorderLayout()); 1033 index_body_panel.add(index_details_panel, BorderLayout.CENTER); 1034 index_body_panel.add(index_button_panel, BorderLayout.SOUTH); 1035 1036 index_spacer_panel.setLayout(new BorderLayout()); 1037 index_spacer_panel.add(index_body_panel, BorderLayout.NORTH); 1038 index_spacer_panel.add(index_empty_panel, BorderLayout.CENTER); 1039 1040 indexes_panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 1041 indexes_panel.setLayout(new BorderLayout()); 1042 indexes_panel.add(current_indexes_panel, BorderLayout.NORTH); 1043 indexes_panel.add(index_spacer_panel, BorderLayout.CENTER); 1044 1045 // Create Levels 1046 JPanel levels_panel = new JPanel(); 1047 1048 JPanel current_levels_panel = new JPanel(); 1049 1050 current_levels_label = new JLabel("CDM.IndexManager.MGPP.Current_Levels"); 1051 1052 current_levels_list = new JList(levels_model); 1053 current_levels_list.setVisibleRowCount(5); 1054 1055 JPanel level_movement_panel = new JPanel(); 1056 1057 ImageIcon move_level_up_icon = Utility.getImage("arrow-up.gif"); 1058 move_level_up_button = new JButton(); 1059 move_level_up_label = new JLabel("CDM.Move.Move_Up"); 1060 move_level_up_label.setHorizontalAlignment(JLabel.CENTER); 1061 move_level_up_label.setPreferredSize(LABEL_SIZE); 1062 move_level_up_button.setLayout(new BorderLayout()); 1063 move_level_up_button.add(new JLabel(move_level_up_icon), BorderLayout.WEST); 1064 move_level_up_button.add(move_level_up_label, BorderLayout.CENTER); 1065 move_level_up_button.add(new JLabel(move_level_up_icon), BorderLayout.EAST); 1066 move_level_up_button.setMnemonic(KeyEvent.VK_U); 1067 1068 ImageIcon move_level_down_icon = Utility.getImage("arrow-down.gif"); 1069 move_level_down_button = new JButton(); 1070 move_level_down_label = new JLabel("CDM.Move.Move_Down"); 1071 move_level_down_label.setHorizontalAlignment(JLabel.CENTER); 1072 move_level_down_label.setPreferredSize(LABEL_SIZE); 1073 move_level_down_button.setLayout(new BorderLayout()); 1074 move_level_down_button.add(new JLabel(move_level_down_icon), BorderLayout.WEST); 1075 move_level_down_button.add(move_level_down_label, BorderLayout.CENTER); 1076 move_level_down_button.add(new JLabel(move_level_down_icon), BorderLayout.EAST); 1077 move_level_down_button.setMnemonic(KeyEvent.VK_D); 1078 1079 JPanel level_spacer_panel = new JPanel(); 1080 1081 JPanel level_body_panel = new JPanel(); 1082 1083 JPanel level_details_panel = new JPanel(); 1084 1085 JPanel level_name_panel = new JPanel(); 1086 1087 level_name_label = new JLabel("CDM.IndexManager.MGPP.Level_Name"); 1088 level_name_label.setPreferredSize(LABEL_SIZE); 1089 1090 level_name_field = new JTextField(); 1091 1092 JPanel level_panel = new JPanel(); 1093 1094 level_label = new JLabel("CDM.IndexManager.MGPP.Level"); 1095 level_label.setPreferredSize(LABEL_SIZE); 1096 1097 level_combobox = new GComboBox(Index.LEVEL); 1098 level_combobox.setBackgroundNonSelectionColor(Gatherer.config.getColor("coloring.editable_background", false)); 1099 level_combobox.setBackgroundSelectionColor(Gatherer.config.getColor("coloring.collection_selection_background", false)); 1100 level_combobox.setEditable(true); 1101 level_combobox.setTextNonSelectionColor(Gatherer.config.getColor("coloring.workspace_tree_foreground", false)); 1102 level_combobox.setTextSelectionColor(Gatherer.config.getColor("coloring.collection_selection_foreground", false)); 1103 1104 JPanel level_button_panel = new JPanel(); 1105 1106 add_level_button = new JButton("CDM.IndexManager.MGPP.Add_Level"); 1107 add_level_button.setEnabled(false); 1108 add_level_button.setMnemonic(KeyEvent.VK_A); 1109 1110 remove_level_button = new JButton("CDM.IndexManager.MGPP.Remove_Level"); 1111 remove_level_button.setEnabled(false); 1112 remove_level_button.setMnemonic(KeyEvent.VK_A); 1113 1114 JPanel level_empty_panel = new JPanel(); 1115 1116 // Connect Levels 1117 EnableAddLevelListener level_eal = new EnableAddLevelListener(); 1118 add_level_button.addActionListener(new AddLevelActionListener()); 1119 current_levels_list.addListSelectionListener(new CurrentLevelsListSelectionListener()); 1120 Gatherer.dictionary.register(add_level_button, null, false); 1121 Gatherer.dictionary.register(current_levels_label, null, false); 1122 Gatherer.dictionary.register(level_label, null, false); 1123 Gatherer.dictionary.register(level_name_label, null, false); 1124 Gatherer.dictionary.register(move_level_down_label, null, false); 1125 Gatherer.dictionary.register(move_level_up_label, null, false); 1126 Gatherer.dictionary.register(remove_level_button, null, false); 1127 level_combobox.addActionListener(level_eal); 1128 ((JTextField)level_combobox.getEditor().getEditorComponent()).getDocument().addDocumentListener(level_eal); 1129 level_name_field.getDocument().addDocumentListener(level_eal); 1130 move_level_down_button.addActionListener(new MoveLevelDownListener()); 1131 move_level_up_button.addActionListener(new MoveLevelUpListener()); 1132 remove_level_button.addActionListener(new RemoveLevelActionListener(level_eal)); 1133 // Layout Levels 1134 1135 level_movement_panel.setLayout(new GridLayout(2,1)); 1136 level_movement_panel.add(move_level_up_button); 1137 level_movement_panel.add(move_level_down_button); 1138 1139 current_levels_panel.setLayout(new BorderLayout()); 1140 current_levels_panel.add(current_levels_label, BorderLayout.NORTH); 1141 current_levels_panel.add(new JScrollPane(current_levels_list), BorderLayout.CENTER); 1142 current_levels_panel.add(level_movement_panel, BorderLayout.EAST); 1143 1144 level_name_panel.setLayout(new BorderLayout()); 1145 level_name_panel.add(level_name_label, BorderLayout.WEST); 1146 level_name_panel.add(level_name_field, BorderLayout.CENTER); 1147 1148 level_panel.setLayout(new BorderLayout()); 1149 level_panel.add(level_label, BorderLayout.WEST); 1150 level_panel.add(level_combobox, BorderLayout.CENTER); 1151 1152 level_details_panel.setLayout(new GridLayout(2,1,0,5)); 1153 level_details_panel.add(level_name_panel); 1154 level_details_panel.add(level_panel); 1155 1156 level_button_panel.setBorder(BorderFactory.createEmptyBorder(5,0,0,0)); 1157 level_button_panel.setLayout(new GridLayout(1,2,5,0)); 1158 level_button_panel.add(add_level_button); 1159 level_button_panel.add(remove_level_button); 1160 1161 level_body_panel.setBorder(BorderFactory.createEmptyBorder(5,0,0,0)); 1162 level_body_panel.setLayout(new BorderLayout()); 1163 level_body_panel.add(level_details_panel, BorderLayout.CENTER); 1164 level_body_panel.add(level_button_panel, BorderLayout.SOUTH); 1165 1166 level_spacer_panel.setLayout(new BorderLayout()); 1167 level_spacer_panel.add(level_body_panel, BorderLayout.NORTH); 1168 level_spacer_panel.add(level_empty_panel, BorderLayout.CENTER); 1169 1170 levels_panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 1171 levels_panel.setLayout(new BorderLayout()); 1172 levels_panel.add(current_levels_panel, BorderLayout.NORTH); 1173 levels_panel.add(level_spacer_panel, BorderLayout.CENTER); 1174 1175 // Create General 1176 JPanel header_panel = new JPanel(); 1177 1178 title_label = new JLabel("CDM.IndexManager.MGPP.Title"); 1179 1180 instructions_textarea = new JTextArea("CDM.IndexManager.MGPP.Instructions"); 1181 instructions_textarea.setEditable(false); 1182 instructions_textarea.setLineWrap(true); 1183 instructions_textarea.setRows(5); 1184 instructions_textarea.setWrapStyleWord(true); 1185 1186 tabbed_pane = new JTabbedPane(); 1187 1188 // Layout General 1189 header_panel.setBorder(BorderFactory.createEmptyBorder(0,0,2,0)); 1190 header_panel.setLayout(new BorderLayout()); 1191 header_panel.add(title_label, BorderLayout.NORTH); 1192 header_panel.add(new JScrollPane(instructions_textarea), BorderLayout.CENTER); 1193 1194 tabbed_pane.add("CDM.IndexManager.MGPP.Indexes", indexes_panel); 1195 tabbed_pane.add("CDM.IndexManager.MGPP.Levels", levels_panel); 1196 1197 setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 1198 setLayout(new BorderLayout()); 1199 add(header_panel, BorderLayout.NORTH); 1200 add(tabbed_pane, BorderLayout.CENTER); 1201 1202 // Connect General 1203 Gatherer.dictionary.register(instructions_textarea, null, false); 1204 Gatherer.dictionary.register(tabbed_pane, null, false); 1205 Gatherer.dictionary.register(title_label, null, false); 1206 } 1207 1208 public void destroy() { 1209 Gatherer.dictionary.deregister(add_index_button); 1210 Gatherer.dictionary.deregister(current_indexes_label); 1211 Gatherer.dictionary.deregister(index_label); 1212 Gatherer.dictionary.deregister(index_name_label); 1213 Gatherer.dictionary.deregister(move_index_down_label); 1214 Gatherer.dictionary.deregister(move_index_up_label); 1215 Gatherer.dictionary.deregister(remove_index_button); 1216 1217 Gatherer.dictionary.deregister(instructions_textarea); 1218 Gatherer.dictionary.deregister(tabbed_pane); 1219 Gatherer.dictionary.deregister(title_label); 1220 } 1221 1222 public void gainFocus() { 1223 // Reload the assigned indexes list. 1224 index_combobox.removeAllItems(); 1225 index_combobox.addItem(CollectionConfiguration.ALLFIELDS_STR); 1226 index_combobox.addItem(CollectionConfiguration.TEXT_STR); 1227 java.util.List assigned_elements = Gatherer.c_man.getCollection().msm.getAssignedElements(); 1228 int assigned_elements_size = assigned_elements.size(); 1229 for(int i = 0; i < assigned_elements_size; i++) { 1230 index_combobox.addItem(assigned_elements.get(i)); 1231 } 1232 assigned_elements = null; 1233 } 1234 1235 private class AddIndexActionListener 1236 implements ActionListener { 1237 public void actionPerformed(ActionEvent event) { 1238 // Retrieve the name 1239 String name = index_name_field.getText(); 1240 // Retrieve the source 1241 Object source = index_combobox.getSelectedItem(); 1242 // If this object isn't yet in the combobox add it. 1243 if(index_combobox.getSelectedIndex() == -1) { 1244 index_combobox.insertItemAt(source, index_combobox.getItemCount()); 1245 } 1246 // Create new index 1247 ArrayList sources = new ArrayList(); 1248 sources.add(source); 1249 Index index = new Index(sources); 1250 // Create new metadatum 1251 CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + index.getID()); 1252 metadatum.setValue(name); 1253 // Assign new index 1254 addIndex(index, metadatum); 1255 // Done. Disable add 1256 add_index_button.setEnabled(false); 1257 } 1258 } 1259 1260 private class AddLevelActionListener 1261 implements ActionListener { 1262 public void actionPerformed(ActionEvent event) { 1263 // Retrieve the name 1264 String name = level_name_field.getText(); 1265 // Retrieve the source 1266 String source = (String)level_combobox.getSelectedItem(); 1267 // If this object isn't yet in the combobox add it. 1268 if(level_combobox.getSelectedIndex() == -1) { 1269 level_combobox.insertItemAt(source, level_combobox.getItemCount()); 1270 } 1271 Level level = new Level(source); 1272 // Create new metadatum 1273 CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + source); 1274 metadatum.setValue(name); 1275 // Assign new level 1276 addLevel(level, metadatum); 1277 // Done. Disable add 1278 add_level_button.setEnabled(false); 1279 } 1280 } 1281 1282 private class CurrentIndexesListSelectionListener 1283 implements ListSelectionListener { 1284 public void valueChanged(ListSelectionEvent event) { 1285 if(!event.getValueIsAdjusting()) { 1286 Index index = (Index)current_indexes_list.getSelectedValue(); 1287 if(index != null) { 1288 move_index_down_button.setEnabled((model.indexOf(index) < model.getSize() - 1)); 1289 move_index_up_button.setEnabled((model.indexOf(index) > 0)); 1290 remove_index_button.setEnabled(true); 1291 } 1292 else { 1293 move_index_down_button.setEnabled(false); 1294 move_index_up_button.setEnabled(false); 1295 remove_index_button.setEnabled(false); 1296 } 1297 } 1298 } 1299 } 1300 1301 private class CurrentLevelsListSelectionListener 1302 implements ListSelectionListener { 1303 public void valueChanged(ListSelectionEvent event) { 1304 if(!event.getValueIsAdjusting()) { 1305 Level level = (Level)current_levels_list.getSelectedValue(); 1306 if(level != null) { 1307 move_level_down_button.setEnabled((levels_model.indexOf(level) < levels_model.getSize() - 1)); 1308 move_level_up_button.setEnabled((levels_model.indexOf(level) > 0)); 1309 remove_level_button.setEnabled(true); 1310 } 1311 else { 1312 move_level_down_button.setEnabled(false); 1313 move_level_up_button.setEnabled(false); 1314 remove_level_button.setEnabled(false); 1315 } 1316 } 1317 } 1318 } 1319 1320 private class EnableAddIndexListener 1321 implements ActionListener, DocumentListener { 1322 /** Called whenever a selection action occurs on the combobox. 1323 * @param event an ActionEvent containing information about the selection event 1324 */ 1325 public void actionPerformed(ActionEvent event) { 1326 validateAddButton(); 1327 } 1328 1329 /** Gives notification that an attribute or set of attributes changed. 1330 * @param event a DocumentEvent containing information about the text changed 1331 */ 1332 public void changedUpdate(DocumentEvent event) { 1333 validateAddButton(); 1334 } 1335 1336 /** Gives notification that there was an insert into the document. 1337 * @param event a DocumentEvent containing information about the text added 1338 */ 1339 public void insertUpdate(DocumentEvent event) { 1340 validateAddButton(); 1341 } 1342 1343 /** Gives notification that a portion of the document has been removed. 1344 * @param event a DocumentEvent containing information about the text removed 1345 */ 1346 public void removeUpdate(DocumentEvent e) { 1347 validateAddButton(); 1348 } 1349 1350 /** Change the enable state of the add button depending on the current value in the search type combobox. */ 1351 public void validateAddButton() { 1352 String name = index_name_field.getText(); 1353 Object selected_object = index_combobox.getSelectedItem(); 1354 if(name.length() > 0 && selected_object != null) { 1355 // Unfortunately we have to generate a valid id 1356 String id = null; 1357 if(selected_object instanceof ElementWrapper) { 1358 id = ((ElementWrapper)selected_object).getName(); 1359 } 1360 else { 1361 id = selected_object.toString(); 1362 } 1363 add_index_button.setEnabled(getIndex(id) == null); 684 1364 } 685 1365 else { 686 add.setEnabled(true); 687 } 688 if(index_list.isSelectionEmpty()) { 689 remove.setEnabled(false); 690 set_default.setEnabled(false); 1366 add_index_button.setEnabled(false); 1367 } 1368 } 1369 } 1370 1371 private class EnableAddLevelListener 1372 implements ActionListener, DocumentListener { 1373 /** Called whenever a selection action occurs on the combobox. 1374 * @param event an ActionEvent containing information about the selection event 1375 */ 1376 public void actionPerformed(ActionEvent event) { 1377 validateAddButton(); 1378 } 1379 1380 /** Gives notification that an attribute or set of attributes changed. 1381 * @param event a DocumentEvent containing information about the text changed 1382 */ 1383 public void changedUpdate(DocumentEvent event) { 1384 validateAddButton(); 1385 } 1386 1387 /** Gives notification that there was an insert into the document. 1388 * @param event a DocumentEvent containing information about the text added 1389 */ 1390 public void insertUpdate(DocumentEvent event) { 1391 validateAddButton(); 1392 } 1393 1394 /** Gives notification that a portion of the document has been removed. 1395 * @param event a DocumentEvent containing information about the text removed 1396 */ 1397 public void removeUpdate(DocumentEvent e) { 1398 validateAddButton(); 1399 } 1400 1401 /** Change the enable state of the add button depending on the current value in the search type combobox. */ 1402 public void validateAddButton() { 1403 String name = level_name_field.getText(); 1404 Object selected_object = level_combobox.getSelectedItem(); 1405 if(name.length() > 0 && selected_object != null) { 1406 add_level_button.setEnabled(getLevel((String)selected_object) == null); 691 1407 } 692 1408 else { 693 remove.setEnabled(true); 694 set_default.setEnabled(true); 695 } 696 } 697 } 698 /** Listens for selections within the list on the IndexManager controls, and if a change is detected enables, or disables, controls appropriately. */ 699 private class ListListener 700 implements ListSelectionListener { 701 /** 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. 702 * @param event A <strong>ListSelectionEvent</strong> containing further information about the list selection. 703 */ 704 public void valueChanged(ListSelectionEvent event) { 705 if(source_list.isSelectionEmpty() || name.getText().length() == 0) { 706 add.setEnabled(false); 707 } 708 else { 709 add.setEnabled(true); 710 } 711 if(index_list.isSelectionEmpty()) { 712 remove.setEnabled(false); 713 set_default.setEnabled(false); 714 } 715 else { 716 remove.setEnabled(true); 717 set_default.setEnabled(true); 718 } 1409 add_level_button.setEnabled(false); 1410 } 1411 } 1412 } 1413 1414 private class MoveIndexDownListener 1415 implements ActionListener { 1416 public void actionPerformed(ActionEvent event) { 1417 // Retrieve the first selected item 1418 Index index = (Index) current_indexes_list.getSelectedValue(); 1419 moveIndex(index, false); 1420 current_indexes_list.setSelectedValue(index, true); 1421 } 1422 } 1423 1424 private class MoveLevelDownListener 1425 implements ActionListener { 1426 public void actionPerformed(ActionEvent event) { 1427 // Retrieve the first selected item 1428 Level level = (Level) current_levels_list.getSelectedValue(); 1429 moveLevel(level, false); 1430 current_levels_list.setSelectedValue(level, true); 1431 } 1432 } 1433 1434 private class MoveIndexUpListener 1435 implements ActionListener { 1436 public void actionPerformed(ActionEvent event) { 1437 // Retrieve the first selected item 1438 Index index = (Index) current_indexes_list.getSelectedValue(); 1439 moveIndex(index, true); 1440 current_indexes_list.setSelectedValue(index, true); 1441 } 1442 } 1443 1444 private class MoveLevelUpListener 1445 implements ActionListener { 1446 public void actionPerformed(ActionEvent event) { 1447 // Retrieve the first selected item 1448 Level level = (Level) current_levels_list.getSelectedValue(); 1449 moveLevel(level, true); 1450 current_levels_list.setSelectedValue(level, true); 1451 } 1452 } 1453 1454 private class RemoveIndexActionListener 1455 implements ActionListener { 1456 1457 private EnableAddIndexListener eal = null; 1458 1459 public RemoveIndexActionListener(EnableAddIndexListener eal) { 1460 this.eal = eal; 1461 } 1462 1463 public void actionPerformed(ActionEvent event) { 1464 // Retrieve the selected items 1465 Object[] selected_objects = current_indexes_list.getSelectedValues(); 1466 // Clear selection 1467 current_indexes_list.clearSelection(); 1468 for(int i = 0; i < selected_objects.length; i++) { 1469 Index index = (Index) selected_objects[i]; 1470 // Remove any related metadata 1471 CollectionDesignManager.collectionmeta_manager.removeMetadata(CollectionConfiguration.STOP_CHARACTER + index.getID()); 1472 // Remove the index 1473 removeIndex(index); 1474 } 1475 // Disable remove button 1476 remove_index_button.setEnabled(false); 1477 // Check if add should be reenabled 1478 eal.validateAddButton(); 1479 } 1480 } 1481 1482 private class RemoveLevelActionListener 1483 implements ActionListener { 1484 1485 private EnableAddLevelListener eal = null; 1486 1487 public RemoveLevelActionListener(EnableAddLevelListener eal) { 1488 this.eal = eal; 1489 } 1490 1491 public void actionPerformed(ActionEvent event) { 1492 // Retrieve the selected items 1493 Object[] selected_objects = current_levels_list.getSelectedValues(); 1494 // Clear selection 1495 current_levels_list.clearSelection(); 1496 for(int i = 0; i < selected_objects.length; i++) { 1497 Level level = (Level) selected_objects[i]; 1498 // Remove any related metadata 1499 CollectionDesignManager.collectionmeta_manager.removeMetadata(CollectionConfiguration.STOP_CHARACTER + level.getName()); 1500 // Remove the index 1501 removeLevel(level); 1502 } 1503 // Disable remove button 1504 remove_level_button.setEnabled(false); 1505 // Check if add should be reenabled 1506 eal.validateAddButton(); 719 1507 } 720 1508 } -
trunk/gli/src/org/greenstone/gatherer/cdm/Level.java
r4963 r5037 62 62 */ 63 63 public Level(String name) { 64 64 element = CollectionDesignManager.collect_config.document.createElement(CollectionConfiguration.CONTENT_ELEMENT); 65 element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, name); 66 text = null; 65 67 } 66 68 … … 103 105 */ 104 106 public String getName() { 105 return toString();107 return element.getAttribute(CollectionConfiguration.NAME_ATTRIBUTE); 106 108 } 107 109 … … 109 111 * @return true if this command has been assigned, false otherwise 110 112 * @see org.greenstone.gatherer.cdm.CollectionConfiguration 111 * @see org.greenstone.gatherer.util.StaticStrings112 113 */ 113 114 public boolean isAssigned() { … … 118 119 * @param assigned the desired state of assigned as a boolean 119 120 * @see org.greenstone.gatherer.cdm.CollectionConfiguration 120 * @see org.greenstone.gatherer.util.StaticStrings121 121 */ 122 122 public void setAssigned(boolean assigned) { … … 137 137 * @param name the new name for this level, as a String 138 138 * @see org.greenstone.gatherer.cdm.CollectionConfiguration 139 * @see org.greenstone.gatherer.util.StaticStrings140 139 */ 141 140 public void setName(String name) { … … 149 148 * @return a String showing this level 150 149 * @see org.greenstone.gatherer.cdm.CollectionConfiguration 151 * @see org.greenstone.gatherer.util.StaticStrings152 150 */ 153 151 public String toString() { 154 if(text == null && element != null) { 155 text = element.getAttribute(CollectionConfiguration.NAME_ATTRIBUTE); 152 if(text == null) { 153 if(element == null) { 154 text = "#Error"; 155 } 156 else { 157 String name = getName(); 158 StringBuffer text_buffer = new StringBuffer(name); 159 CollectionMeta metadatum = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.STOP_CHARACTER + name, false); 160 if(metadatum != null) { 161 text_buffer.append(" \""); 162 text_buffer.append(metadatum.getValue()); 163 text_buffer.append("\""); 164 } 165 text = text_buffer.toString(); 166 text_buffer = null; 167 } 156 168 } 157 169 return text; -
trunk/gli/src/org/greenstone/gatherer/cdm/SearchType.java
r4963 r5037 62 62 */ 63 63 public SearchType(String name) { 64 64 element = CollectionDesignManager.collect_config.document.createElement(CollectionConfiguration.CONTENT_ELEMENT); 65 element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, name); 66 text = null; 65 67 } 66 68 -
trunk/gli/src/org/greenstone/gatherer/cdm/SearchTypeManager.java
r4963 r5037 164 164 move_down_button.add(move_down_label, BorderLayout.CENTER); 165 165 move_down_button.add(new JLabel(move_down_icon), BorderLayout.EAST); 166 move_down_button.setMnemonic(KeyEvent.VK_ U);166 move_down_button.setMnemonic(KeyEvent.VK_D); 167 167 168 168 JPanel search_type_panel = new JPanel(); … … 178 178 JPanel button_panel = new JPanel(); 179 179 add_button = new JButton("CDM.SearchTypeManager.Add"); 180 add_button.setEnabled(false); 181 add_button.setMnemonic(KeyEvent.VK_A); 182 180 183 remove_button = new JButton("CDM.SearchTypeManager.Remove"); 184 remove_button.setEnabled(false); 185 remove_button.setMnemonic(KeyEvent.VK_R); 181 186 182 187 // Connection … … 240 245 241 246 public void destroy() { 242 247 Gatherer.dictionary.deregister(add_button); 248 Gatherer.dictionary.deregister(current_search_types_label); 249 Gatherer.dictionary.deregister(enable_advanced_searches_checkbox); 250 Gatherer.dictionary.deregister(instructions_textarea); 251 Gatherer.dictionary.deregister(move_down_label); 252 Gatherer.dictionary.deregister(move_up_label); 253 Gatherer.dictionary.deregister(remove_button); 254 Gatherer.dictionary.deregister(search_type_label); 255 Gatherer.dictionary.deregister(title_label); 243 256 } 244 257 -
trunk/gli/src/org/greenstone/gatherer/cdm/SuperCollectionManager.java
r4932 r5037 48 48 static final public String SUPERCOLLECTION_COMMAND = "supercollection"; 49 49 static final public String CCS_COMMAND = "ccs"; 50 50 private ArrayList collection_checklist_model = null; // Model used to actually populate list 51 private Control controls = null; 52 private DOMProxyListModel model = null; 51 53 private String current_coll_name = null; 52 private Control controls = null; 53 private ArrayList collection_checklist_model = null; // Model used to actually populate list 54 54 55 55 56 public SuperCollectionManager(Element supercollections_element) { 56 57 super(supercollections_element, StaticStrings.COLLECTION_ELEMENT, new SuperCollection()); 57 58 Gatherer.println("SuperCollectionManager: " + getSize() + " supercollection members parsed."); 59 this.model = this; 58 60 } 59 61 … … 167 169 168 170 public void loseFocus() { 171 int super_collections_count = 0; 169 172 // Retrieve the current supercollections 170 173 ArrayList supercollections = children(); … … 187 190 } 188 191 supercollection.setAssigned(true); 192 super_collections_count++; 189 193 } 190 194 } … … 193 197 SuperCollection supercollection = (SuperCollection) supercollections.get(j - 1); 194 198 removeSuperCollection(supercollection); 195 } 199 } 200 // Now we only assign supercollections if more than one is selected 201 model.root.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, (super_collections_count > 1 ? StaticStrings.TRUE_STR : StaticStrings.FALSE_STR)); 196 202 } 197 203 -
trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java
r4933 r5037 696 696 Gatherer.println("CollectionManager.importCollection()"); 697 697 if(!saved()) { 698 import_monitor.saving(); 698 699 // Force save. 699 700 try {
Note:
See TracChangeset
for help on using the changeset viewer.