Ignore:
Timestamp:
2004-10-13T14:48:20+13:00 (20 years ago)
Author:
mdewsnip
Message:

Finally committing the (many) changes to the GLI to use the new metadata code... I hope this doesn't have too many bugs in it and committing it now doesn't stuff anyone up! (Katherine said I could commit it, so blame her if anything goes wrong).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/cdm/ArgumentConfiguration.java

    r8243 r8313  
    3939import org.greenstone.gatherer.gui.ModalDialog;
    4040import org.greenstone.gatherer.gui.SimpleMenuBar;
    41 import org.greenstone.gatherer.msm.ElementWrapper;
     41import org.greenstone.gatherer.metadata.MetadataElement;
     42import org.greenstone.gatherer.metadata.MetadataSetManager;
    4243import org.greenstone.gatherer.util.StaticStrings;
    4344import org.greenstone.gatherer.util.Utility;
     
    321322        String existing_value = argument.getValue();
    322323        String default_value = argument.getDefaultValue();
     324
    323325        switch(argument.getType()) {
    324326        case Argument.ENUM:
     
    333335        Collections.sort(options_model);
    334336        value = new GComboBox(options_model.toArray(), false);
    335         //((JComboBox)value).setEditable(false);
    336337        ((JComboBox)value).addActionListener(new ToolTipUpdater());
    337338        if(existing_value != null && existing_value.length() > 0) {
     
    345346        }
    346347        break;
     348
    347349        case Argument.FLAG:
    348350        // Only need the check box.
    349351        break;
     352
    350353        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...
    362355        break;
     356
    363357        case Argument.INTEGER:
    364358        // Build a spinner
     
    393387        value = spinner;
    394388        break;
     389
    395390        case Argument.REGEXP:
    396391        case Argument.STRING:
    397         // Use a standard text field
    398         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("")) {
    399394            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();
    426424        break;
     425
    427426        case Argument.LANGUAGE:
    428427        value = new GComboBox(CollectionDesignManager.language_manager.getLanguageCodes().toArray(), false);
    429         //((JComboBox)value).setEditable(false);
     428
    430429        // Now ensure we have the existing value or default value selected if either exist.
    431430        Language selected = null;
     
    440439        }
    441440        break;
     441
    442442        case Argument.METADATUM:
    443443        case Argument.METADATA:
    444         value = new GComboBox(Gatherer.c_man.getCollection().msm.getAssignedElements(), false);
     444        value = new GComboBox(MetadataSetManager.getEveryMetadataSetElement(), false);
    445445
    446446        // Editable for advanced modes (allows things like dc.Title,ex.Title)
     
    450450
    451451        // 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);
    462463        }
    463464        break;
     465
    464466// ---- Special interface for adding and ordering multiple metadata items ----
    465467// Turned off at Ian's request!
     
    467469//          // Comma separated metadata values.
    468470//          ArrayList values = argument.getValues();
    469 //          value = new GComboBox(Gatherer.c_man.getCollection().msm.getAssignedElements(), false);
     471//          value = new GComboBox(MetadataSetManager.getEveryMetadataSetElement(), false);
    470472//          //((JComboBox)value).setEditable(false);
    471473//          DefaultListModel model = new DefaultListModel();
     
    680682        case Argument.METADATUM:
    681683        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());
    686687            }
    687688            else {
     
    719720//              return true;
    720721        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);
    724725            return true;
    725726        case Argument.REGEXP:
     
    777778            */
    778779        }
    779         else if(object instanceof ElementWrapper) {
     780        else if (object instanceof MetadataElement) {
    780781            if(object.toString().equals(target)) {
    781782            combobox.setSelectedIndex(i);
     
    796797        ((JTextField)value).setText(value_str);
    797798    }
    798     /** Listener which adds entries to a list from a combobox when fired. */
    799     private class AddListener
    800         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// }
    827828    /** Listens for actions apon the enable checkbox, and if detected enables or diables control appropriately. */
    828829    private class EnabledListener
     
    896897    }
    897898    /** If a metadata element is selected that requires an hfile, then this listener defaults that hfile. */
    898     private class HierarchyListener
    899         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.ArgumentControl
    903          */
    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// }
    921922    /** 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. */
    922923    private class ListOption
Note: See TracChangeset for help on using the changeset viewer.