Changeset 5936


Ignore:
Timestamp:
2003-11-24T11:44:03+13:00 (20 years ago)
Author:
jmt12
Message:

Metadata arguments can now successfully take, and display, custom element names. Even fixed the stupid 'dialog dismissed before combobox loses focus' problem.

File:
1 edited

Legend:

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

    r5864 r5936  
    170170    boolean cont = true;
    171171    if (event.getSource() == ok) {
     172        // Clear the current focus to ensure components such as combobox have correctly updated
     173        custom.requestFocus();
    172174        // Update the details stored in the data objects arguments.
    173175        data.setCustom(custom.getText());
     
    398400        case Argument.METADATUM:
    399401        value = new JComboBox(Gatherer.c_man.getCollection().msm.getAssignedElements());
    400         /** @TODO - figure out a smarter way of allowing Greenstone extracted metadata to be selected. */
    401402        ((JComboBox)value).setEditable(true);
    402403        // Now ensure we have the existing value or default value selected if either exist.
    403404        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            }
    405411        }
    406412        else if(default_value != null) {
     
    531537     */
    532538    public boolean updateArgument() {
    533        if(enabled.isSelected() || argument.isRequired()) {
    534           argument.setAssigned(false);
    535           String result = null;
    536           switch(argument.getType()) {
    537          case Argument.ENUM:
     539        if(enabled.isSelected() || argument.isRequired()) {
     540        argument.setAssigned(false);
     541        String result = null;
     542        switch(argument.getType()) {
     543        case Argument.ENUM:
    538544            ListOption option = (ListOption)((JComboBox)value).getSelectedItem();
    539             if(option != null && option.getValue().length() > 0) {
    540                argument.setValue(option.getValue());
     545            if(option != null && option.getValue().length() > 0) {
     546            argument.setValue(option.getValue());
    541547            }
    542548            else {
    543             String args[] = new String[1];
    544             args[0] = argument.getName();
    545             if(argument.isRequired()) {
    546                 JOptionPane.showMessageDialog(self, Dictionary.get("CDM.ArgumentConfiguration.Required_Argument", args), Dictionary.get("CDM.ArgumentConfiguration.Error_Title"), JOptionPane.ERROR_MESSAGE);
    547             }
    548             // They've left the field blank
    549             else {
    550                 JOptionPane.showMessageDialog(self, Dictionary.get("CDM.ArgumentConfiguration.No_Value", args), Dictionary.get("CDM.ArgumentConfiguration.Error_Title"), JOptionPane.ERROR_MESSAGE);
    551                 argument.setValue(null);
    552             }
    553             args = null;
    554             return false;
     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;
    555561            }
    556562            argument.setAssigned(true);
    557563            return true;
    558564        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);
    561567            return true;
    562568        case Argument.INTEGER:
     
    578584            }
    579585            else {
    580             String args[] = new String[1];
    581             args[0] = argument.getName();
     586            String args[] = new String[1];
     587            args[0] = argument.getName();
    582588            if(argument.isRequired()) {
    583589                JOptionPane.showMessageDialog(self, Dictionary.get("CDM.ArgumentConfiguration.Required_Argument", args), Dictionary.get("CDM.ArgumentConfiguration.Error_Title"), JOptionPane.ERROR_MESSAGE);
    584590            }
    585             // They've left the field blank
     591            // They've left the field blank
    586592            else {
    587                 JOptionPane.showMessageDialog(self, Dictionary.get("CDM.ArgumentConfiguration.No_Value", args), Dictionary.get("CDM.ArgumentConfiguration.Error_Title"), JOptionPane.ERROR_MESSAGE);
    588                 argument.setValue(null);
    589             }
    590             args = null;
    591             return false;
     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;
    592598            }
    593599            argument.setAssigned(true);
    594600            return true;
    595            case Argument.LANGUAGE:
    596               String language = (((JComboBox)value).getSelectedItem()).toString();
    597               argument.setValue(language);
    598               // Kinda lucked out here. Its impossible not to choose an entry from these comboboxes as they are restricted.
    599               argument.setAssigned(true);
    600               return true;
     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;
    601607        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            }
    604635            argument.setAssigned(true);
    605636            return true;
     
    624655            }
    625656            else {
    626             String args[] = new String[1];
    627             args[0] = argument.getName();
    628             if(argument.isRequired()) {
    629                 JOptionPane.showMessageDialog(self, Dictionary.get("CDM.ArgumentConfiguration.Required_Argument", args), Dictionary.get("CDM.ArgumentConfiguration.Error_Title"), JOptionPane.ERROR_MESSAGE);
    630             }
    631             // They've left the field blank
    632             else {
    633                 JOptionPane.showMessageDialog(self, Dictionary.get("CDM.ArgumentConfiguration.No_Value", args), Dictionary.get("CDM.ArgumentConfiguration.Error_Title"), JOptionPane.ERROR_MESSAGE);
    634                 argument.setValue(null);
    635             }
    636             args = null;
    637             return false;
    638             }
    639             argument.setAssigned(true);
     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);
    640671            return true;
    641672        }
     
    650681     * @param combobox The <strong>JComboBox</strong> whose selection we are trying to preset.
    651682     * @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
    652684     * @see org.greenstone.gatherer.cdm.ArgumentConfiguration.ArgumentControl.ListOption
    653685     * @see org.greenstone.gatherer.msm.ElementWrapper
    654686     */
    655     public void selectValue(JComboBox combobox, String target) {
     687    public boolean selectValue(JComboBox combobox, String target) {
    656688        for(int i = 0; i < combobox.getItemCount(); i++) {
    657689        Object object = combobox.getItemAt(i);
     
    660692            if(lo.getValue().equals(target)) {
    661693            combobox.setSelectedIndex(i);
    662             return;
     694            return true;
    663695            }
    664696        }
     
    666698            if(object.toString().equals(target)) {
    667699            combobox.setSelectedIndex(i);
    668             return;
    669             }
    670         }
    671         }
     700            return true;
     701            }
     702        }
     703        }
     704        return false;
    672705    }
    673706    /** Forces the control into an 'enabled' mode. */
Note: See TracChangeset for help on using the changeset viewer.