Changeset 8364
- Timestamp:
- 2004-10-18T15:44:09+13:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/gui/EnrichPane.java
r8359 r8364 500 500 501 501 // Update the metadata value table (and consequently, the metadata value tree) 502 metadata_value_table.rebuild(); 502 MetadataValue previously_selected_metadata_value = metadata_value_table.getSelectedMetadataValueTableEntry(); 503 metadata_value_table.rebuildAndSelectRowWithValueClosestTo(previously_selected_metadata_value); 503 504 504 505 // // Update the meta-audit view to show the current selection, if any. … … 539 540 // Update the metadata value table and tree 540 541 metadata_edit_event = true; 541 metadata_value_table.rebuild ();542 metadata_value_table.rebuildAndSelectRowWithValueClosestTo(metadata_value); 542 543 metadata_edit_event = false; 543 544 } … … 568 569 // Update the metadata value table and tree 569 570 metadata_edit_event = true; 570 metadata_value_table.rebuild ();571 metadata_value_table.rebuildAndSelectRowWithValueClosestTo(metadata_value); 571 572 metadata_edit_event = false; 572 573 } … … 589 590 // Update the metadata value table and tree 590 591 metadata_edit_event = true; 591 metadata_value_table.rebuild ();592 metadata_value_table.rebuildAndSelectRowWithValueClosestTo(selected_metadata_value_table_entry); 592 593 metadata_edit_event = false; 593 594 } … … 673 674 674 675 675 public void rebuild() 676 { 677 // Remember the current metadata element selection so we can select it again later 678 MetadataValueTableEntry previously_selected_metadata_value_table_entry = selected_metadata_value_table_entry; 679 676 public void moveSelectionDown() 677 { 678 int new_row_to_select = getSelectedRow() + 1; 679 if (new_row_to_select < metadata_value_table_model.getRowCount()) { 680 changeSelection(new_row_to_select, 1, false, false); 681 } 682 } 683 684 685 public void moveSelectionUp() 686 { 687 int new_row_to_select = getSelectedRow() - 1; 688 if (new_row_to_select >= 0) { 689 changeSelection(new_row_to_select, 1, false, false); 690 } 691 } 692 693 694 public void rebuildAndSelectRowWithValueClosestTo(MetadataValue optimal_metadata_value_to_select_when_building_complete) 695 { 680 696 // We don't want a lot of ListSelectionEvents while the table is rebuilding 681 697 clearSelection(); … … 696 712 metadata_value_table_card_layout.show(table_card_pane, TABLE_CARD); 697 713 698 // If there was no previous selection thenwe're done699 if ( previously_selected_metadata_value_table_entry== null) {714 // If we don't need to select a row in the table after rebuilding, we're done 715 if (optimal_metadata_value_to_select_when_building_complete == null) { 700 716 return; 701 717 } 702 718 703 // Look for an exact match 719 MetadataElement optimal_metadata_element = optimal_metadata_value_to_select_when_building_complete.getMetadataElement(); 720 721 // Find the row containing the closest value to the optimal value 722 int optimal_row_to_select = 0; 704 723 for (int i = 0; i < metadata_value_table_model.getRowCount(); i++) { 705 724 MetadataValueTableEntry metadata_value_table_entry = metadata_value_table_model.getMetadataValueTableEntry(i); 706 int c = metadata_value_table_entry.compareTo(previously_selected_metadata_value_table_entry); 707 708 if (c == 0) { 709 // Select this row and we're done 710 addRowSelectionInterval(i, i); 711 return; 712 } 713 714 if (c < 0) { 715 // Not in the list 716 break; 717 } 718 } 719 720 // Select the first entry with the same metadata element 721 MetadataElement previously_selected_metadata_element = previously_selected_metadata_value_table_entry.getMetadataElement(); 722 for (int i = 0; i < metadata_value_table_model.getRowCount(); i++) { 723 MetadataElement metadata_element = metadata_value_table_model.getMetadataValueTableEntry(i).getMetadataElement(); 724 if (metadata_element.equals(previously_selected_metadata_element)) { 725 // Select this row and we're done 726 addRowSelectionInterval(i, i); 727 return; 728 } 729 } 730 731 // All else has failed, so just select the first row in the table 732 addRowSelectionInterval(0, 0); 725 MetadataElement metadata_element = metadata_value_table_entry.getMetadataElement(); 726 if (metadata_element.equals(optimal_metadata_element)) { 727 // This row will be the optimal row, unless the next row matches better 728 optimal_row_to_select = i; 729 } 730 731 int c = metadata_value_table_entry.compareTo(optimal_metadata_value_to_select_when_building_complete); 732 if (c >= 0) { 733 // We've either found an exact match, or there is no exact match, so stop here 734 break; 735 } 736 } 737 738 changeSelection(optimal_row_to_select, 1, false, false); 733 739 } 734 740 … … 1099 1105 if (metadata_element == null) { 1100 1106 if (metadata_edit_event == false) { 1101 System.err.println("Clearing selection...");1107 // System.err.println("Clearing selection..."); 1102 1108 selected_metadata_element = null; 1103 1109 validateDisplay(); … … 1223 1229 1224 1230 /** Gives notification of key events on the text field */ 1225 public void keyPressed(KeyEvent e) { 1231 public void keyPressed(KeyEvent e) 1232 { 1233 // Tab: Auto-complete 1226 1234 if (e.getKeyCode() == KeyEvent.VK_TAB) { 1227 // Tab: Auto-complete1228 1235 if (tree.getSelectionCount() != 0 && !getSelectedValue().equals("")) { 1229 1236 TreePath path = tree.getSelectionPath(); … … 1232 1239 } 1233 1240 } 1241 1242 // Enter: Append the metadata value, if we're allowed to 1234 1243 if (e.getKeyCode() == KeyEvent.VK_ENTER) { 1235 // Enter: Append the metadata value, if we're allowed to1236 1244 if (add.isEnabled()) { 1237 1245 add.doClick(); 1238 1246 } 1247 } 1248 1249 // Down: Change the metadata value table selection 1250 if (e.getKeyCode() == KeyEvent.VK_DOWN) { 1251 metadata_value_table.moveSelectionDown(); 1252 } 1253 1254 // Up: Change the metadata value table selection 1255 if (e.getKeyCode() == KeyEvent.VK_UP) { 1256 metadata_value_table.moveSelectionUp(); 1239 1257 } 1240 1258 }
Note:
See TracChangeset
for help on using the changeset viewer.