- Timestamp:
- 2004-10-13T14:48:20+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/ArgumentConfiguration.java
r8243 r8313 39 39 import org.greenstone.gatherer.gui.ModalDialog; 40 40 import org.greenstone.gatherer.gui.SimpleMenuBar; 41 import org.greenstone.gatherer.msm.ElementWrapper; 41 import org.greenstone.gatherer.metadata.MetadataElement; 42 import org.greenstone.gatherer.metadata.MetadataSetManager; 42 43 import org.greenstone.gatherer.util.StaticStrings; 43 44 import org.greenstone.gatherer.util.Utility; … … 321 322 String existing_value = argument.getValue(); 322 323 String default_value = argument.getDefaultValue(); 324 323 325 switch(argument.getType()) { 324 326 case Argument.ENUM: … … 333 335 Collections.sort(options_model); 334 336 value = new GComboBox(options_model.toArray(), false); 335 //((JComboBox)value).setEditable(false);336 337 ((JComboBox)value).addActionListener(new ToolTipUpdater()); 337 338 if(existing_value != null && existing_value.length() > 0) { … … 345 346 } 346 347 break; 348 347 349 case Argument.FLAG: 348 350 // Only need the check box. 349 351 break; 352 350 353 case Argument.HIERARCHY: 351 value = new GComboBox(Gatherer.c_man.getCollection().msm.getAssignedElements(true), false); 352 /** @TODO - figure out a smarter way of allowing Greenstone extracted metadata to be selected. */ 353 //((JComboBox)value).setEditable(false); 354 ((JComboBox)value).addItemListener(new HierarchyListener()); 355 // Now ensure we have the existing value or default value selected if either exist. 356 if(existing_value != null && existing_value.length() > 0) { 357 selectValue((JComboBox)value, existing_value); 358 } 359 else if(default_value != null) { 360 selectValue((JComboBox)value, default_value); 361 } 354 // I don't think these are used any more... 362 355 break; 356 363 357 case Argument.INTEGER: 364 358 // Build a spinner … … 393 387 value = spinner; 394 388 break; 389 395 390 case Argument.REGEXP: 396 391 case Argument.STRING: 397 // Use a standard text field398 if (existing_value != null && existing_value.length() > 0) {392 // If there is already a value set for this argument, use it 393 if (existing_value != null && !existing_value.equals("")) { 399 394 value = new JTextField(existing_value); 400 } 401 else { 402 if(default_value != null) { 403 value = new JTextField(default_value); 404 } 405 // Special test just for the hfile field. 406 else if(argument.getName().equals("hfile")) { 407 // Work through previous controls looking for the metadata one. 408 for(int i = 0; i < central_pane.getComponentCount(); i++) { 409 Object object = central_pane.getComponent(i); 410 if(object instanceof ArgumentControl) { 411 ArgumentControl control = (ArgumentControl) object; 412 if(control.toString().equals("metadata")) { 413 Object temp = control.getValue(); 414 if(temp != null) { 415 value = new JTextField(temp.toString() + ".txt"); 416 } 417 } 418 419 } 420 } 421 } 422 else { 423 value = new JTextField(); 424 } 425 } 395 break; 396 } 397 398 // Use the default value, if there is one 399 if (default_value != null && !default_value.equals("")) { 400 value = new JTextField(default_value); 401 break; 402 } 403 404 // // Special test just for the hfile field. 405 // if (argument.getName().equals("hfile")) { 406 // // Work through previous controls looking for the metadata one. 407 // for (int i = 0; i < central_pane.getComponentCount(); i++) { 408 // Object object = central_pane.getComponent(i); 409 // if (object instanceof ArgumentControl) { 410 // ArgumentControl control = (ArgumentControl) object; 411 // if (control.toString().equals("metadata")) { 412 // Object temp = control.getValue(); 413 // if (temp != null) { 414 // value = new JTextField(temp.toString() + ".txt"); 415 // break; 416 // } 417 // } 418 // } 419 // } 420 // } 421 422 // Blank field 423 value = new JTextField(); 426 424 break; 425 427 426 case Argument.LANGUAGE: 428 427 value = new GComboBox(CollectionDesignManager.language_manager.getLanguageCodes().toArray(), false); 429 //((JComboBox)value).setEditable(false); 428 430 429 // Now ensure we have the existing value or default value selected if either exist. 431 430 Language selected = null; … … 440 439 } 441 440 break; 441 442 442 case Argument.METADATUM: 443 443 case Argument.METADATA: 444 value = new GComboBox( Gatherer.c_man.getCollection().msm.getAssignedElements(), false);444 value = new GComboBox(MetadataSetManager.getEveryMetadataSetElement(), false); 445 445 446 446 // Editable for advanced modes (allows things like dc.Title,ex.Title) … … 450 450 451 451 // Now ensure we have the existing value or default value selected if either exist. 452 if(existing_value != null && existing_value.length() > 0) { 453 boolean found = selectValue((JComboBox)value, existing_value); 454 // Its possible that this is a custom value and so doesn't exist in the combobox. If so add it and then select it 455 if(!found) { 456 ((JComboBox)value).addItem(existing_value); 457 ((JComboBox)value).setSelectedItem(existing_value); 458 } 459 } 460 else if(default_value != null) { 461 selectValue((JComboBox)value, default_value); 452 if (existing_value != null && existing_value.length() > 0) { 453 boolean found = selectValue((JComboBox) value, existing_value); 454 // It's possible that this is a custom value and so doesn't exist in the combobox 455 if (!found) { 456 // If so, add it then select it 457 ((JComboBox) value).addItem(existing_value); 458 ((JComboBox) value).setSelectedItem(existing_value); 459 } 460 } 461 else if (default_value != null) { 462 selectValue((JComboBox) value, default_value); 462 463 } 463 464 break; 465 464 466 // ---- Special interface for adding and ordering multiple metadata items ---- 465 467 // Turned off at Ian's request! … … 467 469 // // Comma separated metadata values. 468 470 // ArrayList values = argument.getValues(); 469 // value = new GComboBox( Gatherer.c_man.getCollection().msm.getAssignedElements(), false);471 // value = new GComboBox(MetadataSetManager.getEveryMetadataSetElement(), false); 470 472 // //((JComboBox)value).setEditable(false); 471 473 // DefaultListModel model = new DefaultListModel(); … … 680 682 case Argument.METADATUM: 681 683 case Argument.METADATA: 682 Object new_value_raw = ((JComboBox)value).getSelectedItem(); 683 if(new_value_raw instanceof ElementWrapper) { 684 // Element wrappers are guaranteed to be non-zero length 685 argument.setValue(((ElementWrapper)new_value_raw).getName()); 684 Object new_value_raw = ((JComboBox) value).getSelectedItem(); 685 if (new_value_raw instanceof MetadataElement) { 686 argument.setValue(((MetadataElement) new_value_raw).getFullName()); 686 687 } 687 688 else { … … 719 720 // return true; 720 721 case Argument.HIERARCHY: 721 argument.setValue(((JComboBox)value).getSelectedItem().toString());722 // Kinda lucked out here. Its impossible not to choose an entry from these comboboxes as they are restricted.723 argument.setAssigned(true);722 // argument.setValue(((JComboBox)value).getSelectedItem().toString()); 723 // // Kinda lucked out here. Its impossible not to choose an entry from these comboboxes as they are restricted. 724 // argument.setAssigned(true); 724 725 return true; 725 726 case Argument.REGEXP: … … 777 778 */ 778 779 } 779 else if (object instanceof ElementWrapper) {780 else if (object instanceof MetadataElement) { 780 781 if(object.toString().equals(target)) { 781 782 combobox.setSelectedIndex(i); … … 796 797 ((JTextField)value).setText(value_str); 797 798 } 798 /** Listener which adds entries to a list from a combobox when fired. */799 private class AddListener800 implements ActionListener {801 /** The model behind the target list. */802 private DefaultListModel model = null;803 /** The source for data to be added to the list. */804 private JComboBox source = null;805 /** The list to add data to. */806 private JList target = null;807 /** Constructor.808 * @param source A <strong>JComboBox</strong> which serves as the source for data.809 * @param target A <strong>JList</strong> which serves as the target for data.810 */811 public AddListener(JComboBox source, JList target) {812 this.model = (DefaultListModel) target.getModel();813 this.source = source;814 this.target = target;815 }816 /** When the add button is clicked, we attempt to add the selected metadata from the source into the target.817 * @param event An <strong>ActionEvent</strong> containing information about the event.818 */819 public void actionPerformed(ActionEvent event) {820 ElementWrapper element = (ElementWrapper) source.getSelectedItem();821 String name = element.toString();822 if (!model.contains(name)) {823 model.addElement(name);824 }825 }826 }799 // /** Listener which adds entries to a list from a combobox when fired. */ 800 // private class AddListener 801 // implements ActionListener { 802 // /** The model behind the target list. */ 803 // private DefaultListModel model = null; 804 // /** The source for data to be added to the list. */ 805 // private JComboBox source = null; 806 // /** The list to add data to. */ 807 // private JList target = null; 808 // /** Constructor. 809 // * @param source A <strong>JComboBox</strong> which serves as the source for data. 810 // * @param target A <strong>JList</strong> which serves as the target for data. 811 // */ 812 // public AddListener(JComboBox source, JList target) { 813 // this.model = (DefaultListModel) target.getModel(); 814 // this.source = source; 815 // this.target = target; 816 // } 817 // /** When the add button is clicked, we attempt to add the selected metadata from the source into the target. 818 // * @param event An <strong>ActionEvent</strong> containing information about the event. 819 // */ 820 // public void actionPerformed(ActionEvent event) { 821 // ElementWrapper element = (ElementWrapper) source.getSelectedItem(); 822 // String name = element.toString(); 823 // if (!model.contains(name)) { 824 // model.addElement(name); 825 // } 826 // } 827 // } 827 828 /** Listens for actions apon the enable checkbox, and if detected enables or diables control appropriately. */ 828 829 private class EnabledListener … … 896 897 } 897 898 /** If a metadata element is selected that requires an hfile, then this listener defaults that hfile. */ 898 private class HierarchyListener899 implements ItemListener {900 /** Any implementation of ItemListener must include this method so that we can be informed when an item from the list is selected, and generate a predetermined hfile for that selection.901 * @param event An <strong>ItemEvent</strong> containing information about the selection.902 * @see org.greenstone.gatherer.cdm.ArgumentConfiguration.ArgumentControl903 */904 public void itemStateChanged(ItemEvent event) {905 // Determine if the selected element represents a hierarchy.906 Object temp = ((JComboBox)value).getSelectedItem();907 String filename = temp.toString();908 // Search for a argument control called hfile and enable and set value.909 for(int i = 0; i < central_pane.getComponentCount(); i++) {910 Object object = central_pane.getComponent(i);911 if(object instanceof ArgumentControl) {912 ArgumentControl control = (ArgumentControl) object;913 if(control.toString().equals("hfile")) {914 control.setValue(filename + ".txt");915 control.setEnabled(true);916 }917 }918 }919 }920 }899 // private class HierarchyListener 900 // implements ItemListener { 901 // /** Any implementation of ItemListener must include this method so that we can be informed when an item from the list is selected, and generate a predetermined hfile for that selection. 902 // * @param event An <strong>ItemEvent</strong> containing information about the selection. 903 // * @see org.greenstone.gatherer.cdm.ArgumentConfiguration.ArgumentControl 904 // */ 905 // public void itemStateChanged(ItemEvent event) { 906 // // Determine if the selected element represents a hierarchy. 907 // Object temp = ((JComboBox)value).getSelectedItem(); 908 // String filename = temp.toString(); 909 // // Search for a argument control called hfile and enable and set value. 910 // for(int i = 0; i < central_pane.getComponentCount(); i++) { 911 // Object object = central_pane.getComponent(i); 912 // if(object instanceof ArgumentControl) { 913 // ArgumentControl control = (ArgumentControl) object; 914 // if(control.toString().equals("hfile")) { 915 // control.setValue(filename + ".txt"); 916 // control.setEnabled(true); 917 // } 918 // } 919 // } 920 // } 921 // } 921 922 /** A ListOption is a compound item which is constructed from several Strings. That magic part is that the length of screen real-estate used by the text version of this item is limited. */ 922 923 private class ListOption
Note:
See TracChangeset
for help on using the changeset viewer.