Changeset 5758


Ignore:
Timestamp:
2003-10-29T12:22:18+13:00 (21 years ago)
Author:
jmt12
Message:

Started to fix the various ways to enter a null value for a plugin argument, including if you choose a language whereapon you'd throw an NPE an chaos would ensue. I'm sure there are still several ways to break it left

File:
1 edited

Legend:

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

    r5593 r5758  
    3838import org.greenstone.gatherer.cdm.CollectionDesignManager;
    3939import org.greenstone.gatherer.cdm.PlugIn;
     40import org.greenstone.gatherer.gui.ModalDialog;
     41import org.greenstone.gatherer.gui.SimpleMenuBar;
    4042import org.greenstone.gatherer.msm.ElementWrapper;
     43import org.greenstone.gatherer.util.StaticStrings;
    4144import org.greenstone.gatherer.util.Utility;
    4245import org.greenstone.gatherer.valuetree.GValueModel;
    43 import org.greenstone.gatherer.gui.SimpleMenuBar;
    44 import org.greenstone.gatherer.gui.ModalDialog;
    4546
    4647/** This class provides us with a dialog box which allows us to edit the arguments of either a PlugIn or a Classifier.
     
    175176        Component component = central_pane.getComponent(i);
    176177        if(component instanceof ArgumentControl) {
    177             // Once cont goes false it stays false
    178             cont = cont && ((ArgumentControl)component).updateArgument();
     178           cont = cont && ((ArgumentControl)component).updateArgument();
    179179        }
    180180        }
     
    503503    }
    504504
     505       public Argument getArgument() {
     506      return argument;
     507       }
     508       
    505509    public Object getValue() {
    506510        if(value instanceof JComboBox) {
     
    526530     */
    527531    public boolean updateArgument() {
    528         if(enabled.isSelected() || argument.isRequired()) {
    529         argument.setAssigned(true);
    530         String result = null;
    531         switch(argument.getType()) {
    532         case Argument.ENUM:
     532       if(enabled.isSelected() || argument.isRequired()) {
     533          argument.setAssigned(false);
     534          String result = null;
     535          switch(argument.getType()) {
     536         case Argument.ENUM:
    533537            ListOption option = (ListOption)((JComboBox)value).getSelectedItem();
     538            if(option == null || option.getValue().length() == 0) {
     539               String args[] = new String[1];
     540               args[0] = argument.getName();
     541               JOptionPane.showMessageDialog(self, Dictionary.get("CDM.ArgumentConfiguration.No_Value", args), Dictionary.get("CDM.ArgumentConfiguration.Error_Title"), JOptionPane.ERROR_MESSAGE);
     542               return false;
     543            }
    534544            result = option.getValue();
    535545            if(result.length() > 0) {
    536             argument.setValue(result);
     546               argument.setValue(result);
    537547            }
    538548            else {
    539             if(argument.isRequired()) {
    540                 String args[] = new String[1];
    541                 args[0] = argument.getName();
    542                 JOptionPane.showMessageDialog(self, Dictionary.get("CDM.ArgumentConfiguration.Required_Argument", args), Dictionary.get("CDM.ArgumentConfiguration.Error_Title"), JOptionPane.ERROR_MESSAGE);
    543                 args = null;
    544                 return false;
    545             }
    546             else {
    547                 argument.setValue(null);
    548             }
    549             }
     549               if(argument.isRequired()) {
     550              String args[] = new String[1];
     551              args[0] = argument.getName();
     552              JOptionPane.showMessageDialog(self, Dictionary.get("CDM.ArgumentConfiguration.Required_Argument", args), Dictionary.get("CDM.ArgumentConfiguration.Error_Title"), JOptionPane.ERROR_MESSAGE);
     553              args = null;
     554              return false;
     555               }
     556               else {
     557              argument.setValue(null);
     558               }
     559            }
     560            argument.setAssigned(true);
    550561            return true;
    551562        case Argument.FLAG:
    552             // Should have already been handled above.
     563           // Should have already been handled above.
     564           argument.setAssigned(true);
    553565            return true;
    554566        case Argument.INTEGER:
     
    581593            }
    582594            }
     595            argument.setAssigned(true);
    583596            return true;
    584         case Argument.LANGUAGE:
    585             Language language = (Language) ((JComboBox)value).getSelectedItem();
    586             argument.setValue(language.getCode());
    587             // Kinda lucked out here. Its impossible not to choose an entry from these comboboxes as they are restricted.
    588             return true;
     597           case Argument.LANGUAGE:
     598              String language = (((JComboBox)value).getSelectedItem()).toString();
     599              argument.setValue(language);
     600              // Kinda lucked out here. Its impossible not to choose an entry from these comboboxes as they are restricted.
     601              argument.setAssigned(true);
     602              return true;
    589603        case Argument.METADATUM:
    590604            argument.setValue(((ElementWrapper)((JComboBox)value).getSelectedItem()).getName());
    591605            // Kinda lucked out here. Its impossible not to choose an entry from these comboboxes as they are restricted.
     606            argument.setAssigned(true);
    592607            return true;
    593608        case Argument.HIERARCHY:
    594609            argument.setValue(((JComboBox)value).getSelectedItem().toString());
    595610            // Kinda lucked out here. Its impossible not to choose an entry from these comboboxes as they are restricted.
     611            argument.setAssigned(true);
    596612            return true;
    597613        case Argument.METADATA:
     
    602618            }
    603619            argument.setValues(values);
     620            argument.setAssigned(true);
    604621            return true;
    605622        case Argument.STRING:
     
    619636            }
    620637            }
     638            argument.setAssigned(true);
    621639            return true;
    622640        }
     
    785803        implements Comparable {
    786804        /** The maximum length of this String version of this item. */
    787         //private int MAX_DESC = 35;
     805        private int MAX_DESC = 65;
    788806        /** The description of the value for this item. */
    789807        private String description = null;
     
    832850        public String toString() {
    833851        if(text == null) {
    834             //if(description.length() >= MAX_DESC) {
    835             //  text = value + " - " + description.substring(0, MAX_DESC);
    836             //}
    837             //else {
    838             text = value + " - " + description;
    839             //}
     852            if(description.length() >= MAX_DESC) {
     853                text = value + StaticStrings.MINUS_CHARACTER + description.substring(0, MAX_DESC) + StaticStrings.TRUNCATED_STRING;
     854            }
     855            else {
     856               text = value + StaticStrings.MINUS_CHARACTER + description;
     857            }
    840858        }
    841859        return text;
     
    875893        JComboBox source = (JComboBox)event.getSource();
    876894        ListOption lo = (ListOption)source.getSelectedItem();
    877         String description = Utility.formatHTMLWidth(lo.getDesc(), 60);
    878         source.setToolTipText(description);
     895        if(lo != null) {
     896           String description = Utility.formatHTMLWidth(lo.getDesc(), 60);
     897           source.setToolTipText(description);
     898        }
     899        else {
     900           source.setToolTipText(StaticStrings.EMPTY_STR);
     901        }
    879902        }
    880903    }
Note: See TracChangeset for help on using the changeset viewer.