- Timestamp:
- 2022-05-09T12:19:56+12:00 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/cdm/SearchIndexManager.java
r36149 r36158 52 52 * @version 2.3 53 53 */ 54 public class SearchIndexManager 55 extends DOMProxyListModel 56 implements BuildTypeManager.BuildTypeListener { 57 58 /** A reference to ourselves so our inner methods have access. */ 59 private DOMProxyListModel index_model = null; 60 /** The default index. */ 61 private Index default_index = null; 62 63 private Control controls = null; 64 private String build_type = null; 65 54 public class SearchIndexManager extends BaseIndexManager { 55 66 56 static final private Dimension FIELD_SIZE = new Dimension(200,30); 67 57 static final private String ALLFIELDS = "allfields"; 68 58 69 static final private Dimension PROMPT_SIZE = new Dimension(400,400);70 59 public SearchIndexManager(Element indexes, String current_build_type) { 71 60 72 super(indexes, StaticStrings.INDEX_ELEMENT, (current_build_type.equals(BuildTypeManager.BUILD_TYPE_MG)?new MGIndex():new Index())); 73 DebugStream.println("SearchIndexManager: " + getSize() + " indexes parsed."); 74 index_model = this; 61 super(indexes, current_build_type, StaticStrings.INDEX_ELEMENT, StaticStrings.INDEX_DEFAULT_ELEMENT, (current_build_type.equals(BuildTypeManager.BUILD_TYPE_MG)?new MGIndex():new Index())); 62 63 this.controls_title_key = "CDM.IndexManager.Indexes"; 64 this.new_button_tooltip_key = "CDM.IndexManager.New_Button_Tooltip"; 65 this.edit_button_tooltip_key = "CDM.IndexManager.Edit_Button_Tooltip"; 66 this.remove_button_tooltip_key = "CDM.IndexManager.Remove_Button_Tooltip"; 67 this.nip_new_index_key = "CDM.IndexManager.New_Index"; 68 this.nip_edit_index_key = "CDM.IndexManager.Edit_Index"; 69 this.nip_source_label_key = "CDM.IndexManager.Source"; 70 this.nip_add_index_button_key = "CDM.IndexManager.Add_Index"; 71 this.nip_add_index_tooltip_key = "CDM.IndexManager.Add_Index_Tooltip"; 72 this.nip_replace_index_button_key = "CDM.IndexManager.Replace_Index"; 73 this.nip_replace_index_tooltip_key = "CDM.IndexManager.Replace_Index_Tooltip"; 75 74 76 // Parse and retrieve the default index 77 NodeList default_index_elements = CollectionConfiguration.getElementsByTagName(StaticStrings.INDEX_DEFAULT_ELEMENT); 78 if(default_index_elements.getLength() > 0) { 79 if (current_build_type.equals(BuildTypeManager.BUILD_TYPE_MG)) { 80 default_index = new MGIndex((Element)default_index_elements.item(0)); 81 } else { 82 default_index = new Index((Element)default_index_elements.item(0)); 83 } 84 } 85 build_type = current_build_type; 86 } 87 88 /** Method to add a new index. 89 * @param index The <strong>Index</strong> to add. 90 * @see org.greenstone.gatherer.Gatherer 91 * @see org.greenstone.gatherer.collection.CollectionManager 92 */ 93 private void addIndex(Index index, CollectionMeta metadatum) { 94 ///ystem.err.println("Adding an index: " + index.toString()); 95 if(!contains(index)) { 96 CollectionDesignManager.collectionmeta_manager.addMetadatum(metadatum); 97 // Retrieve the currently last index 98 if(getSize() > 0) { 99 Index last_index = (Index)getElementAt(getSize() - 1); 100 addAfter(index, last_index); 101 102 } 103 else { 104 add(index); 105 // Also set this index as the default one, 106 setDefault(index); 107 } 108 } 109 else { 110 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.IndexManager.Index_Exists"), Dictionary.get("General.Warning"), JOptionPane.WARNING_MESSAGE); 111 } 112 } 75 } 76 113 77 114 78 public void buildTypeChanged(String new_build_type) { … … 260 224 } 261 225 226 227 262 228 public Control getControls() { 263 229 if (controls == null) { 264 controls = new IndexControl();230 controls = new SearchIndexControl(); 265 231 } 266 232 return controls; 267 233 } 268 234 269 /** Method to retrieve a certain index, as referenced by an index number. 270 * @param index An <i>int</i> which indicates the position of the desired index. 271 * @return The <strong>Index</strong> at the given index, or <i>null</i> if no such index exists. 272 */ 273 public Index getIndex(int index) { 274 if(0 <= index && index < getSize()) { 275 return (Index)getElementAt(index); 276 } 277 return null; 278 } 279 280 /** Method to retrieve a certain index, given its id. 281 * @param id the id of the index as a String 282 * @return the Index that matches id, or null if no such index exists 283 */ 284 public Index getIndex(String id) { 285 int size = getSize(); 286 for(int i = 0; i < size; i++) { 287 Index index = (Index) getElementAt(i); 288 if(index.getID().equals(id)) { 289 return index; 290 } 291 } 292 return null; 293 } 294 295 public ArrayList getIndexes() { 296 return children(); 297 } 298 299 300 301 /** Called when the detail mode has changed which in turn may cause several design elements to be available/hidden 302 * @param mode the new mode as an int 303 */ 304 public void modeChanged(int mode) { 305 306 } 307 308 private void moveIndex(Index index, boolean move_up) 309 { 310 // Determine the current position of the index 311 int position = indexOf(index); 312 // 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. 313 if(position == -1) { 314 return; 315 } 316 if(position == 0 && move_up) { 317 return; 318 } 319 if(position == (getSize()) - 1 && !move_up) { 320 return; 321 } 322 323 // Ok, move up 324 if (move_up) { 325 position--; 326 remove(index); 327 add(position, index); 328 } 329 330 // Or move down 331 else { 332 position++; 333 remove(index); 334 add(position, index); 335 } 336 } 337 338 339 340 /** Method to remove a certain index. 341 * @param index the Index to remove. 342 * @see org.greenstone.gatherer.Gatherer 343 * @see org.greenstone.gatherer.cdm.CollectionDesignManager 344 * @see org.greenstone.gatherer.cdm.CollectionMetaManager 345 * @see org.greenstone.gatherer.collection.CollectionManager 346 */ 347 private void removeIndex(Index index) { 348 if(index != null) { 349 // Remove any current metadata from this index 350 CollectionDesignManager.collectionmeta_manager.removeMetadata(StaticStrings.STOP_CHARACTER + index.getID()); 351 // Remove the index 352 remove(index); 353 // Check if the index removed happens to be the default index 354 if(default_index != null && default_index.equals(index)) { 355 // If so our first solution is to set the first index to be default 356 if(getSize() > 0) { 357 Index another_index = (Index) getElementAt(0); 358 setDefault(another_index); 359 another_index = null; 360 } 361 else { 362 default_index.setAssigned(false); 363 } 364 } 365 } 366 } 367 368 369 /* replace an index in the list. new index may have the same sources but a 370 different name, or may be a new index altogether */ 371 private void replaceIndex(Index old_index, Index new_index, 372 CollectionMeta coll_meta) { 373 if (old_index == null || new_index == null || coll_meta == null) { 374 return; 375 } 376 if (!old_index.getID().equals(new_index.getID()) && contains(new_index)) { 377 // shoudl we output an error?? 378 return; 379 } 380 // Remove the old index coll meta 381 CollectionDesignManager.collectionmeta_manager.removeMetadata(StaticStrings.STOP_CHARACTER + old_index.getID()); 382 // Add the new coll meta 383 CollectionDesignManager.collectionmeta_manager.addMetadatum(coll_meta); 384 385 // get the position of the old one 386 int position = indexOf(old_index); 387 // remove it 388 remove(old_index); 389 // add the new one at that position 390 add(position, new_index); 391 } 235 392 236 393 237 … … 435 279 } 436 280 437 438 private class IndexControl439 extends JPanel440 implements Control {441 442 private JList index_list;443 private JButton move_down_button;444 private JButton move_up_button;445 private JButton set_default_button;446 447 private JButton new_button;448 private JButton edit_button;449 private JButton remove_button;450 451 public IndexControl() {452 super();453 this.setComponentOrientation(Dictionary.getOrientation());454 // Creation455 JPanel assigned_indexes_pane = new JPanel();456 assigned_indexes_pane.setComponentOrientation(Dictionary.getOrientation());457 458 JLabel index_label = new JLabel(Dictionary.get("CDM.IndexManager.Indexes"));459 index_label.setComponentOrientation(Dictionary.getOrientation());460 461 index_list = new JList(index_model);462 index_list.setCellRenderer(new IndexListRenderer());463 index_list.setVisibleRowCount(6);464 index_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);465 index_list.addMouseListener(new ClickListener());466 index_list.setComponentOrientation(Dictionary.getOrientation());467 468 JPanel movement_pane = new JPanel();469 movement_pane.setComponentOrientation(Dictionary.getOrientation());470 471 move_up_button = new GLIButton(Dictionary.get("CDM.Move.Move_Up"), JarTools.getImage("arrow-up.gif"), Dictionary.get("CDM.Move.Move_Up_Tooltip"));472 move_up_button.setEnabled(false);473 474 move_down_button = new GLIButton(Dictionary.get("CDM.Move.Move_Down"), JarTools.getImage("arrow-down.gif"), Dictionary.get("CDM.Move.Move_Down_Tooltip"));475 move_down_button.setEnabled(false);476 477 set_default_button = new GLIButton(Dictionary.get("CDM.IndexManager.Set_Default"), Dictionary.get("CDM.IndexManager.Set_Default_Tooltip"));478 set_default_button.setEnabled(false);479 480 JPanel button_pane = new JPanel();481 button_pane.setComponentOrientation(Dictionary.getOrientation());482 483 new_button = new GLIButton(Dictionary.get("CDM.IndexManager.New_Index")+StaticStrings.FURTHER_DIALOG_INDICATOR, Dictionary.get("CDM.IndexManager.New_Index_Tooltip"));484 new_button.setEnabled(true);485 486 edit_button = new GLIButton(Dictionary.get("CDM.IndexManager.Edit_Index")+StaticStrings.FURTHER_DIALOG_INDICATOR, Dictionary.get("CDM.IndexManager.Edit_Index_Tooltip"));487 edit_button.setEnabled(false);488 489 remove_button = new GLIButton(Dictionary.get("CDM.IndexManager.Remove_Index"), Dictionary.get("CDM.IndexManager.Remove_Index_Tooltip"));490 remove_button.setEnabled(false);491 492 // Listeners493 new_button.addActionListener(new NewIndexListener());494 edit_button.addActionListener(new EditIndexListener());495 remove_button.addActionListener(new RemoveIndexListener());496 remove_button.addActionListener(CollectionDesignManager.buildcol_change_listener);497 498 index_list.addListSelectionListener(new IndexListListener());499 500 move_down_button.addActionListener(new MoveListener(false));501 move_down_button.addActionListener(CollectionDesignManager.buildcol_change_listener);502 move_up_button.addActionListener(new MoveListener(true));503 move_up_button.addActionListener(CollectionDesignManager.buildcol_change_listener);504 505 set_default_button.addActionListener(new SetDefaultListener());506 // Layout507 movement_pane.setBorder(BorderFactory.createEmptyBorder(0,2,0,0));508 movement_pane.setLayout(new GridLayout(3,1));509 movement_pane.add(move_up_button);510 movement_pane.add(move_down_button);511 movement_pane.add(set_default_button);512 513 assigned_indexes_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));514 assigned_indexes_pane.setLayout(new BorderLayout());515 assigned_indexes_pane.add(index_label, BorderLayout.NORTH);516 assigned_indexes_pane.add(new JScrollPane(index_list), BorderLayout.CENTER);517 assigned_indexes_pane.add(movement_pane, BorderLayout.LINE_END);518 519 button_pane.setLayout(new GridLayout(1,3,5,0));520 button_pane.add(new_button);521 button_pane.add(edit_button);522 button_pane.add(remove_button);523 524 setBorder(BorderFactory.createEmptyBorder(0,5,0,0));525 setLayout(new BorderLayout());526 add(assigned_indexes_pane, BorderLayout.CENTER);527 add(button_pane, BorderLayout.SOUTH);528 529 }530 public void loseFocus() {}531 public void gainFocus() {}532 public void destroy() {}533 281 534 /** Listens for double clicks apon the list and react as if the configure button was pushed. */ 535 private class ClickListener 536 extends MouseAdapter { 537 /** Called whenever the mouse is clicked over a registered component, we use this to chain through to the configure prompt. 538 * @param event A <strong>MouseEvent</strong> containing information about the mouse click. 539 */ 540 public void mouseClicked(MouseEvent event) { 541 if(event.getClickCount() == 2 ) { 542 if(!index_list.isSelectionEmpty()) { 543 Index index = (Index) index_list.getSelectedValue(); 544 NewIndexPrompt nip = new NewIndexPrompt(build_type, index); 545 nip.destroy(); 546 } 547 } 548 } 549 } 550 551 552 private class IndexListListener 553 implements ListSelectionListener { 554 555 /** 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 556 * @param event A <strong>ListSelectionEvent</strong> containing further information about the list selection. 557 */ 558 public void valueChanged(ListSelectionEvent event) 559 { 560 if (event.getValueIsAdjusting()) { 561 return; 562 } 563 564 set_default_button.setEnabled(true); 565 Object value = index_list.getSelectedValue(); 566 if (value == null) { 567 move_down_button.setEnabled(false); 568 move_up_button.setEnabled(false); 569 remove_button.setEnabled(false); 570 edit_button.setEnabled(false); 571 set_default_button.setEnabled(false); 572 return; 573 } 574 575 // Enable the buttons appropriately 576 remove_button.setEnabled(true); 577 edit_button.setEnabled(true); 578 set_default_button.setEnabled(default_index == null || !default_index.equals(value)); 579 int i = index_list.getSelectedIndex(); 580 int size = index_list.getModel().getSize(); 581 move_up_button.setEnabled((i>0)); 582 move_down_button.setEnabled((i<size-1)); 583 } 584 } 585 586 private class IndexListRenderer 587 extends DefaultListCellRenderer { 588 589 /** Return a component that has been configured to display the specified value. */ 590 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 591 JLabel component = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 592 if(default_index != null && default_index.equals(value)) { 593 component.setText(component.getText() + " " + Dictionary.get("CDM.IndexManager.Default_Index_Indicator")); 594 } 595 return component; 596 } 597 598 } 599 600 private class NewIndexListener 601 implements ActionListener { 602 603 public void actionPerformed(ActionEvent event) { 604 NewIndexPrompt nip = new NewIndexPrompt(build_type, null); 605 nip.destroy(); 606 } 607 } 608 609 private class EditIndexListener 610 implements ActionListener { 611 612 public void actionPerformed(ActionEvent event) { 613 Index index = (Index) index_list.getSelectedValue(); 614 NewIndexPrompt nip = new NewIndexPrompt(build_type, index); 615 nip.destroy(); 616 } 617 } 618 619 private class RemoveIndexListener 620 implements ActionListener { 621 622 public void actionPerformed(ActionEvent event) { 623 624 int i = index_list.getSelectedIndex(); 625 if (i != -1) { 626 removeIndex((Index) index_list.getSelectedValue()); 627 } 628 int size = index_list.getModel().getSize(); 629 if (i == size) { 630 i--; 631 } 632 index_list.setSelectedIndex(i); 633 // This will produce an event on the list, updating the other buttons 634 } 635 } 636 637 private class MoveListener 638 implements ActionListener { 639 640 private boolean move_up; 641 642 public MoveListener(boolean move_up) { 643 this.move_up = move_up; 644 } 645 646 public void actionPerformed(ActionEvent event) { 647 // Retrieve the selected index 648 Index index = (Index) index_list.getSelectedValue(); 649 if(index != null) { 650 moveIndex(index, move_up); 651 // Ensure the index that moved is still selected 652 index_list.setSelectedValue(index, true); 653 index = null; 654 } 655 } 656 } 657 658 private class SetDefaultListener 659 implements ActionListener { 660 661 public void actionPerformed(ActionEvent event) { 662 Index index = (Index) index_list.getSelectedValue(); 663 if(index != null) { 664 setDefault(index); 665 // This should cause a repaint of just the desired row 666 index_list.setSelectedValue(index, true); 667 } 668 set_default_button.setEnabled(false); 669 } 670 } 671 672 673 674 private class NewIndexPrompt 675 extends ModalDialog { 676 677 NewIndexPrompt new_index_prompt = null; 678 679 private JCheckBox text_checkbox; 680 private CheckList source_list; 282 private class SearchIndexControl 283 extends IndexControl { 284 285 public SearchIndexControl() { 286 super(); 287 } 288 289 290 /** we want our own custom new index prompt for searhc indexes */ 291 protected NewIndexPrompt createNewIndexPrompt(String build_type, Index index) { 292 return new NewSearchIndexPrompt(build_type, index); 293 294 } 295 296 /** we customise this to add text box, allfields, and add all, select all buttons etc */ 297 protected class NewSearchIndexPrompt 298 extends NewIndexPrompt { 299 300 private JCheckBox text_checkbox; 681 301 // mg uses a level box 682 302 private JComboBox level_combobox; … … 684 304 private JCheckBox allfields_box; 685 305 686 private JButton add_or_replace_button; 687 private JButton select_all_button; 688 private JButton select_none_button; 689 private JButton add_all_button; 690 //private JButton select_all_button; 691 //private JButton replace_button; 692 private JButton cancel_button; 693 306 private JButton select_all_button; 307 private JButton select_none_button; 308 private JButton add_all_button; 309 694 310 private boolean mgpp_enabled = false; 695 311 private boolean editing = false; 696 312 697 public NewIndexPrompt(String build_type, Index existing_index) { 698 super(Gatherer.g_man, true); 699 this.setComponentOrientation(Dictionary.getOrientation()); 700 701 new_index_prompt = this; 702 703 setModal(true); 704 setSize(PROMPT_SIZE); 705 if (existing_index != null) { 706 setTitle (Dictionary.get("CDM.IndexManager.Edit_Index")); 707 editing = true; 708 } else { 709 setTitle(Dictionary.get("CDM.IndexManager.New_Index")); 710 } 711 712 setJMenuBar(new SimpleMenuBar("searchindexes")); 713 if (build_type.equals(BuildTypeManager.BUILD_TYPE_MGPP) || build_type.equals(BuildTypeManager.BUILD_TYPE_LUCENE)) { 714 mgpp_enabled = true; 715 } 716 JPanel content_pane = (JPanel)this.getContentPane(); 717 content_pane.setComponentOrientation(Dictionary.getOrientation()); 718 ArrayList new_data = new ArrayList(); 719 new_data.addAll(MetadataSetManager.getEveryMetadataSetElement()); 720 721 JPanel details_pane = new JPanel(); 722 details_pane.setComponentOrientation(Dictionary.getOrientation()); 723 724 text_checkbox = new JCheckBox(Dictionary.get("CDM.IndexManager.Text_Source")); 725 text_checkbox.setToolTipText(Dictionary.get("CDM.IndexManager.Text_Source_Tooltip")); 726 text_checkbox.setComponentOrientation(Dictionary.getOrientation()); 727 text_checkbox.addActionListener(new ActionListener() { 728 public void actionPerformed(ActionEvent event) { 729 validateAddOrReplaceButton(); 730 } 731 }); 732 JLabel source_label = new JLabel(Dictionary.get("CDM.IndexManager.Source")); 733 source_label.setComponentOrientation(Dictionary.getOrientation()); 734 source_list = new CheckList(false); 735 source_list.setListData(new_data); 736 source_list.setToolTipText(Dictionary.get("CDM.IndexManager.Source_Tooltip")); 737 source_list.addListSelectionListener(new SourceListListener()); 738 739 JPanel button_pane = new JPanel(); 740 button_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 741 button_pane.setComponentOrientation(Dictionary.getOrientation()); 742 743 if (existing_index == null && mgpp_enabled) { 744 button_pane.setLayout(new GridLayout(2,3,5,0)); 745 JPanel tmp = new JPanel(); 746 tmp.setComponentOrientation(Dictionary.getOrientation()); 747 button_pane.add(tmp); 748 } else { 749 button_pane.setLayout(new GridLayout(2,2,5,0)); 750 } 751 752 select_all_button = new GLIButton(Dictionary.get("CDM.IndexManager.Select_All"), Dictionary.get("CDM.IndexManager.Select_All_Tooltip")); 753 select_all_button.addActionListener(new ActionListener() { 754 755 public void actionPerformed(ActionEvent event) { 756 text_checkbox.setSelected(true); 757 source_list.setAllTicked(); 758 validateAddOrReplaceButton(); 759 } 760 }); 761 762 select_none_button = new GLIButton(Dictionary.get("CDM.IndexManager.Select_None"), Dictionary.get("CDM.IndexManager.Select_None_Tooltip")); 763 select_none_button.addActionListener(new ActionListener() { 764 765 public void actionPerformed(ActionEvent event) { 766 text_checkbox.setSelected(false); 767 source_list.clearTicked(); 768 validateAddOrReplaceButton(); 769 } 770 }); 771 772 773 button_pane.add(select_all_button); 774 button_pane.add(select_none_button); 775 776 if (existing_index != null) { 777 add_or_replace_button = new GLIButton(Dictionary.get("CDM.IndexManager.Replace_Index"), Dictionary.get("CDM.IndexManager.Replace_Index_Tooltip")); 778 add_or_replace_button.addActionListener(new ReplaceIndexListener()); 779 } else { 780 add_or_replace_button = new GLIButton(Dictionary.get("CDM.IndexManager.Add_Index"), Dictionary.get("CDM.IndexManager.Add_Index_Tooltip")); 781 add_or_replace_button.addActionListener(new AddIndexListener()); 782 } 783 784 add_or_replace_button.addActionListener(CollectionDesignManager.buildcol_change_listener); 785 add_or_replace_button.setEnabled(false); 786 button_pane.add(add_or_replace_button); 787 788 if (existing_index == null && mgpp_enabled) { 789 add_all_button = new GLIButton(Dictionary.get("CDM.IndexManager.Add_All"), Dictionary.get("CDM.IndexManager.Add_All_Tooltip")); 790 add_all_button.setEnabled(true); 791 add_all_button.addActionListener(new AddAllIndexActionListener()); 792 button_pane.add(add_all_button); 793 } 794 795 // always have a cancel button 796 cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Cancel")); 797 cancel_button.setEnabled(true); 798 cancel_button.addActionListener(new ActionListener() { 799 public void actionPerformed(ActionEvent event) { 800 new_index_prompt.dispose(); 801 } 802 }); 803 button_pane.add(cancel_button); 804 805 //Layout 806 details_pane.setLayout(new BorderLayout(10,10)); 807 details_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 808 details_pane.add(text_checkbox, BorderLayout.NORTH); 809 details_pane.add(new JScrollPane(source_list), BorderLayout.CENTER); 810 811 812 // do type specific stuff 813 if (mgpp_enabled) { 814 // allfields 815 allfields_box = new JCheckBox(Dictionary.get("CDM.IndexManager.Allfields_Index")); 816 allfields_box.addItemListener(new AllFieldsBoxListener()); 817 allfields_box.setComponentOrientation(Dictionary.getOrientation()); 818 //JLabel allfields_label = new JLabel(Dictionary.get("CDM.IndexManager.Allfields_Index")); 819 details_pane.add(allfields_box, BorderLayout.SOUTH); 313 public NewSearchIndexPrompt(String build_type, Index existing_index) { 314 super(build_type, existing_index); 315 } 316 317 /** inside here is where we customise our controls */ 318 protected void generateContents(String build_type, Index existing_index) { 319 if (build_type.equals(BuildTypeManager.BUILD_TYPE_MG)) { 320 mgpp_enabled = false; 321 } else { 322 mgpp_enabled = true; 323 } 324 super.generateContents(build_type, existing_index); 325 text_checkbox = new JCheckBox(Dictionary.get("CDM.IndexManager.Text_Source")); 326 text_checkbox.setToolTipText(Dictionary.get("CDM.IndexManager.Text_Source_Tooltip")); 327 text_checkbox.setComponentOrientation(Dictionary.getOrientation()); 328 text_checkbox.addActionListener(new ActionListener() { 329 public void actionPerformed(ActionEvent event) { 330 validateAddOrReplaceButton(); 331 } 332 }); 333 if (existing_index == null && mgpp_enabled) { 334 button_pane.setLayout(new GridLayout(2,3,5,0)); 335 JPanel tmp = new JPanel(); 336 tmp.setComponentOrientation(Dictionary.getOrientation()); 337 button_pane.add(tmp); 338 } else { 339 button_pane.setLayout(new GridLayout(2,2,5,0)); 340 } 341 342 select_all_button = new GLIButton(Dictionary.get("CDM.IndexManager.Select_All"), Dictionary.get("CDM.IndexManager.Select_All_Tooltip")); 343 select_all_button.addActionListener(new ActionListener() { 344 345 public void actionPerformed(ActionEvent event) { 346 text_checkbox.setSelected(true); 347 source_list.setAllTicked(); 348 validateAddOrReplaceButton(); 349 } 350 }); 351 352 select_none_button = new GLIButton(Dictionary.get("CDM.IndexManager.Select_None"), Dictionary.get("CDM.IndexManager.Select_None_Tooltip")); 353 select_none_button.addActionListener(new ActionListener() { 354 355 public void actionPerformed(ActionEvent event) { 356 text_checkbox.setSelected(false); 357 source_list.clearTicked(); 358 validateAddOrReplaceButton(); 359 } 360 }); 361 362 363 button_pane.add(select_all_button); 364 button_pane.add(select_none_button); 365 366 if (existing_index == null && mgpp_enabled) { 367 add_all_button = new GLIButton(Dictionary.get("CDM.IndexManager.Add_All"), Dictionary.get("CDM.IndexManager.Add_All_Tooltip")); 368 add_all_button.setEnabled(true); 369 add_all_button.addActionListener(new AddAllIndexActionListener()); 370 button_pane.add(add_all_button); 371 } 372 details_pane.add(text_checkbox, BorderLayout.NORTH); 373 // do type specific stuff 374 if (mgpp_enabled) { 375 // allfields 376 allfields_box = new JCheckBox(Dictionary.get("CDM.IndexManager.Allfields_Index")); 377 allfields_box.addItemListener(new AllFieldsBoxListener()); 378 allfields_box.setComponentOrientation(Dictionary.getOrientation()); 379 //JLabel allfields_label = new JLabel(Dictionary.get("CDM.IndexManager.Allfields_Index")); 380 details_pane.add(allfields_box, BorderLayout.SOUTH); 381 382 383 } else { 384 // index level 385 JLabel level_label = new JLabel(Dictionary.get("CDM.IndexManager.Level")); 386 level_label.setComponentOrientation(Dictionary.getOrientation()); 387 388 level_combobox = new JComboBox(); 389 level_combobox.setOpaque(false); 390 level_combobox.setPreferredSize(FIELD_SIZE); 391 // Note the order of these must be the same as the 392 // level order in Index 393 level_combobox.addItem(StaticStrings.DOCUMENT_STR);//Dictionary.get("CDM.LevelManager.Document")); 394 level_combobox.addItem(StaticStrings.SECTION_STR);//Dictionary.get("CDM.LevelManager.Section")); 395 level_combobox.addItem(StaticStrings.PARAGRAPH_STR);//Dictionary.get("CDM.LevelManager.Paragraph")); 396 level_combobox.setEditable(false); 397 level_combobox.setToolTipText(Dictionary.get("CDM.IndexManager.Level_Tooltip")); 398 level_combobox.setComponentOrientation(Dictionary.getOrientation()); 399 level_combobox.addActionListener(new ActionListener() { 400 public void actionPerformed(ActionEvent event) { 401 validateAddOrReplaceButton(); 402 } 403 }); 404 JPanel level_pane = new JPanel(); 405 level_pane.setComponentOrientation(Dictionary.getOrientation()); 406 level_pane.setLayout(new BorderLayout()); 407 level_pane.add(level_label, BorderLayout.LINE_START); 408 level_pane.add(level_combobox, BorderLayout.CENTER); 409 details_pane.add(level_pane, BorderLayout.SOUTH); 410 411 } 412 // if we are editing, fill in the controls 413 if (existing_index !=null) { 414 ArrayList sources = existing_index.getSources(); 415 if (mgpp_enabled && sources.get(0).equals(ALLFIELDS)) { 416 allfields_box.setSelected(true); 417 source_list.setEnabled(false); 418 } else { 419 source_list.setTickedObjects(sources.toArray()); 420 source_list.setEnabled(true); 421 if (sources.contains(StaticStrings.TEXT_STR)) { 422 text_checkbox.setSelected(true); 423 } 424 } 425 if (!mgpp_enabled && existing_index instanceof MGIndex) { 426 level_combobox.setSelectedIndex(((MGIndex)existing_index).getLevel()); 427 } 820 428 821 822 } else { 823 // index level 824 JLabel level_label = new JLabel(Dictionary.get("CDM.IndexManager.Level")); 825 level_label.setComponentOrientation(Dictionary.getOrientation()); 826 827 level_combobox = new JComboBox(); 828 level_combobox.setOpaque(false); 829 level_combobox.setPreferredSize(FIELD_SIZE); 830 // Note the order of these must be the same as the 831 // level order in Index 832 level_combobox.addItem(StaticStrings.DOCUMENT_STR);//Dictionary.get("CDM.LevelManager.Document")); 833 level_combobox.addItem(StaticStrings.SECTION_STR);//Dictionary.get("CDM.LevelManager.Section")); 834 level_combobox.addItem(StaticStrings.PARAGRAPH_STR);//Dictionary.get("CDM.LevelManager.Paragraph")); 835 level_combobox.setEditable(false); 836 level_combobox.setToolTipText(Dictionary.get("CDM.IndexManager.Level_Tooltip")); 837 level_combobox.setComponentOrientation(Dictionary.getOrientation()); 838 level_combobox.addActionListener(new ActionListener() { 839 public void actionPerformed(ActionEvent event) { 840 validateAddOrReplaceButton(); 841 } 842 }); 843 JPanel level_pane = new JPanel(); 844 level_pane.setComponentOrientation(Dictionary.getOrientation()); 845 level_pane.setLayout(new BorderLayout()); 846 level_pane.add(level_label, BorderLayout.LINE_START); 847 level_pane.add(level_combobox, BorderLayout.CENTER); 848 details_pane.add(level_pane, BorderLayout.SOUTH); 849 850 } 851 // if we are editing, fill in the controls 852 if (existing_index !=null) { 853 ArrayList sources = existing_index.getSources(); 854 if (mgpp_enabled && sources.get(0).equals(ALLFIELDS)) { 855 allfields_box.setSelected(true); 856 source_list.setEnabled(false); 857 } else { 858 source_list.setTickedObjects(sources.toArray()); 859 source_list.setEnabled(true); 860 if (sources.contains(StaticStrings.TEXT_STR)) { 861 text_checkbox.setSelected(true); 862 } 863 } 864 if (!mgpp_enabled && existing_index instanceof MGIndex) { 865 level_combobox.setSelectedIndex(((MGIndex)existing_index).getLevel()); 866 } 867 868 } 869 content_pane.setLayout(new BorderLayout()); 870 content_pane.add(source_label, BorderLayout.NORTH); 871 content_pane.add(details_pane, BorderLayout.CENTER); 872 content_pane.add(button_pane, BorderLayout.SOUTH); 873 874 // Display on screen. 875 Dimension screen_size = Configuration.screen_size; 876 setLocation((screen_size.width - PROMPT_SIZE.width) / 2, (screen_size.height - PROMPT_SIZE.height) / 2); 877 screen_size = null; 878 setVisible(true); 879 880 } 881 882 /** Method which actually forces the dialog to be shown on screen. 883 * @return <i>true</i> if the user completed configuration and pressed ok, <i>false</i> otherwise. 884 */ 885 public boolean display() { 886 setVisible(true); 887 return true; 888 // return success; 889 } 890 891 public void destroy() { 892 } 893 429 } 430 431 } 894 432 // Checks that specified index not already in the collection 895 pr ivatevoid validateAddOrReplaceButton() {433 protected void validateAddOrReplaceButton() { 896 434 Index index; 897 435 ArrayList sources; … … 928 466 } 929 467 930 pr ivateIndex generateNewIndex() {468 protected Index generateNewIndex() { 931 469 Index index = null; 932 470 ArrayList sources; … … 948 486 } 949 487 return index; 950 951 952 488 } 953 489 954 private CollectionMeta generateCollectionMeta(Index index) {955 CollectionMeta metadatum = new CollectionMeta(StaticStrings.STOP_CHARACTER + index.getID());956 if (use_macro_as_display_name(index.getID())) {957 metadatum.setValue(get_macro_name(index.getID()));958 } else {959 metadatum.setValue(index.getID());960 }961 return metadatum;962 }963 964 private class AddIndexListener965 implements ActionListener966 {967 public void actionPerformed(ActionEvent event)968 {969 Index index = generateNewIndex();970 if (index != null) {971 972 CollectionMeta metadatum = generateCollectionMeta(index);973 // Add the index974 addIndex(index, metadatum);975 index_list.setSelectedValue(index, true);976 }977 new_index_prompt.dispose();978 }979 }980 490 981 491 /** add all sources as separate indexes (fields). */ … … 1022 532 if (event.getStateChange() == ItemEvent.SELECTED) { 1023 533 source_list.setEnabled(false); 534 text_checkbox.setEnabled(false); 1024 535 } else if (event.getStateChange() == ItemEvent.DESELECTED) { 1025 536 source_list.setEnabled(true); 537 text_checkbox.setEnabled(true); 1026 538 } 1027 539 validateAddOrReplaceButton(); … … 1030 542 } 1031 543 1032 private class SourceListListener 1033 implements ListSelectionListener { 1034 1035 public void valueChanged(ListSelectionEvent event) { 1036 if (event.getValueIsAdjusting()) { 1037 return; 1038 } 1039 validateAddOrReplaceButton(); 1040 } 1041 } 1042 1043 1044 private class ReplaceIndexListener 1045 implements ActionListener { 1046 1047 public void actionPerformed(ActionEvent event) 1048 { 1049 Index index = generateNewIndex(); 1050 if (index != null) { 1051 CollectionMeta metadatum = generateCollectionMeta(index); 1052 // replace the index 1053 replaceIndex((Index) index_list.getSelectedValue(), index, metadatum); 1054 index_list.setSelectedValue(index, true); 1055 } 1056 new_index_prompt.dispose(); 1057 } 1058 } 1059 1060 /** 1061 * If the index is built with DC metadata, use macro variable as the display text, 1062 * so that translations of DC metadata can be displayed in the search field drop-down list 1063 * when interface language changes. 1064 * 1065 * @param index_id Current index id. 1066 * @return Whether macro variable should be used. 1067 */ 1068 private boolean use_macro_as_display_name(String index_id) { 1069 //String metaname = index_id; 1070 if (index_id.indexOf(":") != -1) { 1071 index_id = index_id.substring(index_id.indexOf(":") + 1); 1072 } 1073 1074 String field = null; 1075 String[] fields = index_id.split(","); 1076 for (int i = 0; i < fields.length; i++) { 1077 String s = fields[i]; 1078 if (s.indexOf(".") != -1) { 1079 s = s.substring(s.indexOf(".") + 1); 1080 } 1081 if (field == null) { 1082 field = s; 1083 } 1084 else if (!field.equals(s)) { 1085 return false; 1086 } 1087 } 1088 1089 field = field.toLowerCase(); 1090 if (field.equals("text") || field.equals("title") || field.equals("creator") || field.equals("subject") || 1091 field.equals("description") || field.equals("publisher") || field.equals("contributor") || field.equals("date") || 1092 field.equals("type") || field.equals("format") || field.equals("identifier") || field.equals("source") || 1093 field.equals("language") || field.equals("relation") || field.equals("coverage") || field.equals("rights")) { 1094 return true; 1095 } 1096 1097 return false; 1098 } 1099 1100 /** 1101 * Get the corresponding macro variable name, eg. _labelTitle_, _labelCreator_. 1102 * 1103 * @param index_id Current index id. 1104 * @return Name of the macro variable. 1105 */ 1106 private String get_macro_name(String index_id) { 1107 if (index_id.indexOf(":") != -1) { 1108 index_id = index_id.substring(index_id.indexOf(":") + 1); 1109 } 1110 if (index_id.indexOf(",") != -1) { 1111 index_id = index_id.substring(0, index_id.indexOf(",")); 1112 } 1113 if (index_id.indexOf(".") != -1) { 1114 index_id = index_id.substring(index_id.indexOf(".") + 1); 1115 } 1116 1117 return "_label" + index_id + "_"; 1118 } 1119 } 1120 } 1121 } 544 545 } // NewSearchIndexPrompt 546 }// SearchIndexControl 547 } // SearchIndexManager 548
Note:
See TracChangeset
for help on using the changeset viewer.