Changeset 5936
- Timestamp:
- 2003-11-24T11:44:03+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/ArgumentConfiguration.java
r5864 r5936 170 170 boolean cont = true; 171 171 if (event.getSource() == ok) { 172 // Clear the current focus to ensure components such as combobox have correctly updated 173 custom.requestFocus(); 172 174 // Update the details stored in the data objects arguments. 173 175 data.setCustom(custom.getText()); … … 398 400 case Argument.METADATUM: 399 401 value = new JComboBox(Gatherer.c_man.getCollection().msm.getAssignedElements()); 400 /** @TODO - figure out a smarter way of allowing Greenstone extracted metadata to be selected. */401 402 ((JComboBox)value).setEditable(true); 402 403 // Now ensure we have the existing value or default value selected if either exist. 403 404 if(existing_value != null) { 404 selectValue((JComboBox)value, existing_value); 405 boolean found = selectValue((JComboBox)value, existing_value); 406 // Its possible that this is a custom value and so doesn't exist in the combobox. If so add it and then select it 407 if(!found) { 408 ((JComboBox)value).addItem(existing_value); 409 ((JComboBox)value).setSelectedItem(existing_value); 410 } 405 411 } 406 412 else if(default_value != null) { … … 531 537 */ 532 538 public boolean updateArgument() { 533 if(enabled.isSelected() || argument.isRequired()) {534 535 536 537 539 if(enabled.isSelected() || argument.isRequired()) { 540 argument.setAssigned(false); 541 String result = null; 542 switch(argument.getType()) { 543 case Argument.ENUM: 538 544 ListOption option = (ListOption)((JComboBox)value).getSelectedItem(); 539 540 545 if(option != null && option.getValue().length() > 0) { 546 argument.setValue(option.getValue()); 541 547 } 542 548 else { 543 544 545 546 547 548 549 550 551 552 553 554 549 String args[] = new String[1]; 550 args[0] = argument.getName(); 551 if(argument.isRequired()) { 552 JOptionPane.showMessageDialog(self, Dictionary.get("CDM.ArgumentConfiguration.Required_Argument", args), Dictionary.get("CDM.ArgumentConfiguration.Error_Title"), JOptionPane.ERROR_MESSAGE); 553 } 554 // They've left the field blank 555 else { 556 JOptionPane.showMessageDialog(self, Dictionary.get("CDM.ArgumentConfiguration.No_Value", args), Dictionary.get("CDM.ArgumentConfiguration.Error_Title"), JOptionPane.ERROR_MESSAGE); 557 argument.setValue(null); 558 } 559 args = null; 560 return false; 555 561 } 556 562 argument.setAssigned(true); 557 563 return true; 558 564 case Argument.FLAG: 559 // Should have already been handled above.560 argument.setAssigned(true);565 // Should have already been handled above. 566 argument.setAssigned(true); 561 567 return true; 562 568 case Argument.INTEGER: … … 578 584 } 579 585 else { 580 581 586 String args[] = new String[1]; 587 args[0] = argument.getName(); 582 588 if(argument.isRequired()) { 583 589 JOptionPane.showMessageDialog(self, Dictionary.get("CDM.ArgumentConfiguration.Required_Argument", args), Dictionary.get("CDM.ArgumentConfiguration.Error_Title"), JOptionPane.ERROR_MESSAGE); 584 590 } 585 591 // They've left the field blank 586 592 else { 587 588 589 590 591 593 JOptionPane.showMessageDialog(self, Dictionary.get("CDM.ArgumentConfiguration.No_Value", args), Dictionary.get("CDM.ArgumentConfiguration.Error_Title"), JOptionPane.ERROR_MESSAGE); 594 argument.setValue(null); 595 } 596 args = null; 597 return false; 592 598 } 593 599 argument.setAssigned(true); 594 600 return true; 595 596 597 598 599 600 601 case Argument.LANGUAGE: 602 String language = (((JComboBox)value).getSelectedItem()).toString(); 603 argument.setValue(language); 604 // Kinda lucked out here. Its impossible not to choose an entry from these comboboxes as they are restricted. 605 argument.setAssigned(true); 606 return true; 601 607 case Argument.METADATUM: 602 argument.setValue(((ElementWrapper)((JComboBox)value).getSelectedItem()).getName()); 603 // Kinda lucked out here. Its impossible not to choose an entry from these comboboxes as they are restricted. 608 Object new_value_raw = ((JComboBox)value).getSelectedItem(); 609 if(new_value_raw instanceof ElementWrapper) { 610 // Element wrappers are guaranteed to be non-zero length 611 argument.setValue(((ElementWrapper)new_value_raw).getName()); 612 } 613 else { 614 // But we have to be careful as an arbitary string object could be zero length 615 String new_value = new_value_raw.toString(); 616 System.err.println("The current value is: " + new_value); 617 if(new_value.length() > 0) { 618 argument.setValue(new_value); 619 } 620 else { 621 String args[] = new String[1]; 622 args[0] = argument.getName(); 623 if(argument.isRequired()) { 624 JOptionPane.showMessageDialog(self, Dictionary.get("CDM.ArgumentConfiguration.Required_Argument", args), Dictionary.get("CDM.ArgumentConfiguration.Error_Title"), JOptionPane.ERROR_MESSAGE); 625 } 626 // They've left the field blank 627 else { 628 JOptionPane.showMessageDialog(self, Dictionary.get("CDM.ArgumentConfiguration.No_Value", args), Dictionary.get("CDM.ArgumentConfiguration.Error_Title"), JOptionPane.ERROR_MESSAGE); 629 argument.setValue(null); 630 } 631 args = null; 632 return false; 633 } 634 } 604 635 argument.setAssigned(true); 605 636 return true; … … 624 655 } 625 656 else { 626 627 628 629 630 631 632 633 634 635 636 637 638 639 657 String args[] = new String[1]; 658 args[0] = argument.getName(); 659 if(argument.isRequired()) { 660 JOptionPane.showMessageDialog(self, Dictionary.get("CDM.ArgumentConfiguration.Required_Argument", args), Dictionary.get("CDM.ArgumentConfiguration.Error_Title"), JOptionPane.ERROR_MESSAGE); 661 } 662 // They've left the field blank 663 else { 664 JOptionPane.showMessageDialog(self, Dictionary.get("CDM.ArgumentConfiguration.No_Value", args), Dictionary.get("CDM.ArgumentConfiguration.Error_Title"), JOptionPane.ERROR_MESSAGE); 665 argument.setValue(null); 666 } 667 args = null; 668 return false; 669 } 670 argument.setAssigned(true); 640 671 return true; 641 672 } … … 650 681 * @param combobox The <strong>JComboBox</strong> whose selection we are trying to preset. 651 682 * @param target The desired value of the selection as a <strong>String</strong>. 683 * @return true if the item was found and selected, false otherwise 652 684 * @see org.greenstone.gatherer.cdm.ArgumentConfiguration.ArgumentControl.ListOption 653 685 * @see org.greenstone.gatherer.msm.ElementWrapper 654 686 */ 655 public voidselectValue(JComboBox combobox, String target) {687 public boolean selectValue(JComboBox combobox, String target) { 656 688 for(int i = 0; i < combobox.getItemCount(); i++) { 657 689 Object object = combobox.getItemAt(i); … … 660 692 if(lo.getValue().equals(target)) { 661 693 combobox.setSelectedIndex(i); 662 return ;694 return true; 663 695 } 664 696 } … … 666 698 if(object.toString().equals(target)) { 667 699 combobox.setSelectedIndex(i); 668 return; 669 } 670 } 671 } 700 return true; 701 } 702 } 703 } 704 return false; 672 705 } 673 706 /** Forces the control into an 'enabled' mode. */
Note:
See TracChangeset
for help on using the changeset viewer.