Changeset 12283
- Timestamp:
- 2006-07-24T13:46:29+12:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/SubcollectionIndexManager.java
r12123 r12283 60 60 super(subindexes, CollectionConfiguration.INDEX_ELEMENT, new SubcollectionIndex()); 61 61 DebugStream.println("SubcollectionIndexManager: " + getSize() + " subcollection indexes parsed."); 62 model = this;62 this.model = this; 63 63 64 64 // Parse and retrieve the default index … … 78 78 { 79 79 if (!contains(subcollection_index)) { 80 // add a pseudo metadata 81 CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + subcollection_index.getID()); 82 metadatum.setValue(subcollection_index.getID()); 83 CollectionDesignManager.collectionmeta_manager.addMetadatum(metadatum); 80 84 add(getSize(), subcollection_index); 81 85 Gatherer.c_man.configurationChanged(); … … 112 116 } 113 117 118 /** Called when the detail mode has changed which in turn may cause several design elements to be available/hidden 119 * @param mode the new mode as an int 120 */ 121 public void modeChanged(int mode) { 122 123 } 114 124 115 125 private int moveSubcollectionIndex(SubcollectionIndex subcollection_index, boolean move_up) … … 154 164 if (subcollection_index != null) { 155 165 // Remove any current metadata from this index 156 CollectionDesignManager.collectionmeta_manager.removeMetadata( "."+ subcollection_index.getID());166 CollectionDesignManager.collectionmeta_manager.removeMetadata(CollectionConfiguration.STOP_CHARACTER + subcollection_index.getID()); 157 167 158 168 // Check if the index removed happens to be the default index 159 169 if (default_index != null && default_index.equals(subcollection_index)) { 160 // If so our first solution is to set the first subcollection index to be the default 161 if (getSize() > 0) { 162 setDefaultSubcollectionIndex((SubcollectionIndex) getElementAt(0)); 163 } 164 else { 165 default_index.setAssigned(false); 166 } 167 } 168 170 setDefault(null); 171 } 172 169 173 // Remove the index 170 174 remove(subcollection_index); … … 191 195 } 192 196 197 private void replaceSubcollectionIndex(SubcollectionIndex old_subcollection, SubcollectionIndex new_subcollection) { 198 // Remove old collection meta 199 CollectionDesignManager.collectionmeta_manager.removeMetadata(CollectionConfiguration.STOP_CHARACTER + old_subcollection.getID()); 200 // Add new one 201 CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + new_subcollection.getID()); 202 metadatum.setValue(new_subcollection.getID()); 203 CollectionDesignManager.collectionmeta_manager.addMetadatum(metadatum); 204 if(default_index != null && default_index.equals(old_subcollection)) { 205 setDefault(new_subcollection); 206 } 207 208 // get the position of the old one 209 int position = indexOf(old_subcollection); 210 remove(old_subcollection); 211 add(position, new_subcollection); 212 213 // Schedule the collection for saving 214 Gatherer.c_man.configurationChanged(); 215 216 } 193 217 194 218 /** Method to set the default subcollection index. … … 198 222 * @see org.greenstone.gatherer.cdm.SubcollectionIndex 199 223 */ 200 private void setDefault SubcollectionIndex(SubcollectionIndex subcollection_index)224 private void setDefault(SubcollectionIndex subcollection_index) 201 225 { 202 226 if (subcollection_index != null) { … … 306 330 set_default_button.addActionListener(new SetDefaultListener()); 307 331 set_default_button.addActionListener(CollectionDesignManager.buildcol_change_listener); 308 subcollection_index_list.addListSelectionListener(new SubcollectionIndexListListener());332 subcollection_index_list.addListSelectionListener(new AssignedListListener()); 309 333 source_list.addListSelectionListener(new SourceListListener()); 310 334 … … 370 394 subcollection_index_list.updateUI(); 371 395 372 // If there is one selected, fill in the controls 373 updateControlsWithSelectedIndex(); 374 } 375 376 377 public void loseFocus() 378 { 379 } 380 396 clearControls(); 397 398 } 399 400 401 public void loseFocus() { 402 } 403 404 private void clearControls() { 405 subcollection_index_list.clearSelection(); 406 source_list.clearTicked(); 407 add_button.setEnabled(false); 408 remove_button.setEnabled(false); 409 replace_button.setEnabled(false); 410 set_default_button.setEnabled(false); 411 move_down_button.setEnabled(false); 412 move_up_button.setEnabled(false); 413 414 } 381 415 382 416 private void updateControlsWithSelectedIndex() … … 384 418 SubcollectionIndex selected_index = (SubcollectionIndex) subcollection_index_list.getSelectedValue(); 385 419 if (selected_index == null) { 420 source_list.clearTicked(); 386 421 return; 387 422 } … … 393 428 394 429 395 private void validate Controls()396 {430 private void validateButtons() { 431 397 432 boolean add_enabled = false; 398 433 boolean replace_enabled = false; 399 434 400 435 // Can't add a new index if no sources are selected 401 if (source_list.isNothingTicked()) { 402 add_enabled = false; 403 } 404 // If we get this far, create a dummy index and see if it's already assigned in the collection 405 else { 406 ArrayList sources = source_list.getTicked(); 436 if (!source_list.isNothingTicked()) { 437 ArrayList sources = source_list.getTicked(); 407 438 SubcollectionIndex subcollection_index = new SubcollectionIndex(sources.toArray()); 408 439 409 440 // Subcollection index already exists: can't add, but can replace if the name has changed 410 if (model.contains(subcollection_index)) { 411 add_enabled = false; 412 413 // Here we need to check if we have changed the name - if so, we can enable the replace button 414 if (subcollection_index_list.getSelectedIndex() != -1) { 415 SubcollectionIndex selected_index = (SubcollectionIndex) subcollection_index_list.getSelectedValue(); 416 } 417 } 418 419 // Subcollection index doesn't already exist: can add, or replace if there is something selected 420 else { 441 if (!model.contains(subcollection_index)) { 421 442 add_enabled = true; 422 if ( subcollection_index_list.getSelectedIndex() != -1) {443 if (!subcollection_index_list.isSelectionEmpty()) { 423 444 replace_enabled = true; 424 445 } … … 433 454 434 455 private class AddListener 435 implements ActionListener 436 {456 implements ActionListener { 457 437 458 public void actionPerformed(ActionEvent event) 438 459 { 439 if (!source_list.isNothingTicked()) { // && name.length() != 0) {460 if (!source_list.isNothingTicked()) { 440 461 ArrayList sources = source_list.getTicked(); 441 462 SubcollectionIndex subcollection_index = new SubcollectionIndex(sources.toArray()); 442 443 // Before we add the index to the model, we have to add a default collection metadata for this444 CollectionMeta metadatum = new CollectionMeta("." + subcollection_index.getID());445 metadatum.setValue(subcollection_index.getID());446 CollectionDesignManager.collectionmeta_manager.addMetadatum(metadatum);447 448 // Finally, add the subcollection index449 463 addSubcollectionIndex(subcollection_index); 450 subcollection_index_list.setSelectedIndex(model.getSize() - 1);464 clearControls(); 451 465 } 452 466 } … … 476 490 } 477 491 478 479 /** Listens for key presses within the name field, and enabled or disables controls as appropriate. */480 private class NameListener481 implements DocumentListener482 {483 public void changedUpdate(DocumentEvent e)484 {485 validateControls();486 }487 488 public void insertUpdate(DocumentEvent e)489 {490 validateControls();491 }492 493 public void removeUpdate(DocumentEvent e)494 {495 validateControls();496 }497 }498 499 500 492 private class RemoveListener 501 493 implements ActionListener 502 494 { 503 public void actionPerformed(ActionEvent event) 504 { 505 int i = subcollection_index_list.getSelectedIndex(); 506 if (i != -1) { 507 removeSubcollectionIndex((SubcollectionIndex) subcollection_index_list.getSelectedValue()); 508 } 509 510 int size = subcollection_index_list.getModel().getSize(); 511 if (i == size) { 512 i--; 513 } 514 subcollection_index_list.setSelectedIndex(i); 515 validateControls(); 495 public void actionPerformed(ActionEvent event) { 496 497 SubcollectionIndex delete_me = (SubcollectionIndex) subcollection_index_list.getSelectedValue(); 498 if (delete_me != null) { 499 removeSubcollectionIndex(delete_me); 500 } 516 501 } 517 502 } … … 519 504 520 505 private class ReplaceListener 521 implements ActionListener 522 {523 public void actionPerformed(ActionEvent event) 524 {525 if (subcollection_index_list.isSelectionEmpty() ) {506 implements ActionListener { 507 508 public void actionPerformed(ActionEvent event) { 509 510 if (subcollection_index_list.isSelectionEmpty()|| source_list.isNothingTicked()) { 526 511 // This should never happen, but just in case... 527 512 replace_button.setEnabled(false); 528 513 return; 529 514 } 530 531 // We'll just remove the old one and add the new one 532 removeSubcollectionIndex((SubcollectionIndex) subcollection_index_list.getSelectedValue()); 533 replace_button.setEnabled(false); 534 add_button.setEnabled(true); 535 add_button.doClick(); 536 add_button.setEnabled(false); 515 SubcollectionIndex old_index = (SubcollectionIndex) subcollection_index_list.getSelectedValue(); 516 ArrayList sources = source_list.getTicked(); 517 SubcollectionIndex new_index = new SubcollectionIndex(sources.toArray()); 518 replaceSubcollectionIndex(old_index, new_index); 537 519 } 538 520 } … … 540 522 541 523 private class SetDefaultListener 542 implements ActionListener 543 {524 implements ActionListener { 525 544 526 public void actionPerformed(ActionEvent event) 545 527 { 546 528 SubcollectionIndex subcollection_index = (SubcollectionIndex) subcollection_index_list.getSelectedValue(); 547 529 if (subcollection_index != null) { 548 setDefault SubcollectionIndex(subcollection_index);530 setDefault(subcollection_index); 549 531 // This should cause a repaint of just the desired row 550 532 subcollection_index_list.setSelectedValue(subcollection_index, true); … … 556 538 557 539 private class SourceListListener 558 implements ListSelectionListener 559 { 560 public void valueChanged(ListSelectionEvent event) 561 { 562 validateControls(); 563 } 564 } 565 566 567 /** Listens for selections within the list on the SubcollectionIndexManager controls, and if a change is detected enables, or disables, controls appropriately. */ 568 private class SubcollectionIndexListListener 569 implements ListSelectionListener 570 { 571 /** 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 572 * @param event A <strong>ListSelectionEvent</strong> containing further information about the list selection. 573 */ 574 public void valueChanged(ListSelectionEvent event) 575 { 540 implements ListSelectionListener { 541 542 public void valueChanged(ListSelectionEvent event) { 576 543 if (event.getValueIsAdjusting()) { 577 544 return; 578 545 } 579 546 validateButtons(); 547 } 548 } 549 550 551 /** Listens for selections within the assigned subcollection indexes list */ 552 private class AssignedListListener 553 implements ListSelectionListener { 554 555 public void valueChanged(ListSelectionEvent event) { 556 557 if (event.getValueIsAdjusting()) { 558 return; 559 } 560 561 if (subcollection_index_list.isSelectionEmpty()) { 562 clearControls(); 563 return; 564 } 565 580 566 int i = subcollection_index_list.getSelectedIndex(); 581 567 int size = subcollection_index_list.getModel().getSize(); 582 if (i < 0 || i >= size) { 583 move_down_button.setEnabled(false); 584 move_up_button.setEnabled(false); 585 remove_button.setEnabled(false); 586 replace_button.setEnabled(false); 587 set_default_button.setEnabled(false); 588 return; 589 } 590 568 591 569 // Enable the buttons appropriately 592 570 remove_button.setEnabled(true); 571 replace_button.setEnabled(false); 572 add_button.setEnabled(false); 593 573 SubcollectionIndex selected_index = (SubcollectionIndex) subcollection_index_list.getSelectedValue(); 594 574 set_default_button.setEnabled(default_index == null || !default_index.equals(selected_index));
Note:
See TracChangeset
for help on using the changeset viewer.