Changeset 14745


Ignore:
Timestamp:
2007-10-30T15:16:00+13:00 (16 years ago)
Author:
anna
Message:

When a format variable is set to empty string, recover to its default statement.

File:
1 edited

Legend:

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

    r14231 r14745  
    2929import java.awt.*;
    3030import java.awt.event.*;
     31import java.lang.reflect.Field;
    3132import java.util.*;
    3233import javax.swing.*;
     
    166167  }
    167168 
     169  public String getDefaultFormatString(String name){
     170    String default_str = "";
     171    try{
     172      String field_name = name.toUpperCase()+"_DEFAULT_FORMAT";   
     173      Field field = this.getClass().getDeclaredField(field_name);
     174      Class fieldType = field.getType();
     175      default_str = (String) field.get(fieldType);
     176    } catch (SecurityException e) {
     177      //System.err.println("Debug: "+e.getMessage());
     178      default_str = VLIST_DEFAULT_FORMAT;
     179    } catch (NoSuchFieldException e) {
     180      //System.err.println("Debug: "+e.getMessage());
     181      default_str = VLIST_DEFAULT_FORMAT;
     182    } catch (IllegalArgumentException e) {
     183      //System.err.println("Debug: "+e.getMessage());
     184      default_str = VLIST_DEFAULT_FORMAT;
     185    } catch (IllegalAccessException e) {
     186      //System.err.println("Debug: "+e.getMessage());       
     187      default_str = VLIST_DEFAULT_FORMAT;
     188    }
     189    return default_str;
     190  }
     191 
    168192  /** Method to retrieve this managers controls.
    169193   * @return the Control for this collection.
     
    225249    return part_model;
    226250  }
    227  
     251   
    228252  private ArrayList buildVariableModel() {
    229253    ArrayList variable_model = new ArrayList();
     
    555579     
    556580      public void update() {
    557        
     581   
    558582        // Determine if replace should be enabled
    559583        if(!format_list.isSelectionEmpty()) {
     
    563587          if (shouldSave){
    564588            String format_str = editor_textarea.getText().trim();
    565             format_str = (format_str.equals(""))? VLIST_DEFAULT_FORMAT : format_str;
     589            format_str = (format_str.equals(""))? getDefaultFormatString(format.getName()) : format_str;
    566590            format.setValue(format_str);
    567591            model.refresh((DOMProxyListEntry)format);
     
    608632          // Step one: reset part
    609633          if (entry.canHavePart()) {
     634            // update AffectedComponents according to current entry             
     635            part_model = entry.getPartModel();
     636            part_combobox.setModel(new DefaultComboBoxModel(part_model.toArray()));
     637            part_combobox.updateUI();           
     638           
    610639            part_combobox.setEnabled(true);
    611             part_combobox.setSelectedIndex(part_combobox.getModel().getSize()-1);
     640            part_combobox.setSelectedIndex(part_combobox.getModel().getSize()-1);                       
    612641           
    613642          } else {
     
    718747            Format format = (Format)format_list.getSelectedValue();
    719748            // Try to match the target, remembering the entries within are Entry's
    720             Entry an_entry = new Entry(format.getFeature());
    721             feature_combobox.setSelectedItem(an_entry);
     749            Entry an_entry = new Entry(format.getFeature());           
     750            feature_combobox.setSelectedItem(an_entry);           
    722751            // If we didn't match anything, add it and select it again
    723752            Entry result_entry = (Entry) feature_combobox.getSelectedItem();
     
    746775              if (format.canHavePart()) {
    747776                part_combobox.setEnabled(true);
     777               
     778                // Should update the part list and re-render the part ComboBox here
     779                part_model = result_entry.getPartModel();
     780                part_combobox.setModel(new DefaultComboBoxModel(part_model.toArray()));
     781                part_combobox.updateUI();     
     782               
    748783                // Try to match the part.
    749784                String part_entry = format.getPart();
     
    10811116    }
    10821117   
     1118    public ArrayList getPartModel(){
     1119      DebugStream.println("getPartModel(): get appopriate affected components of this classifier");
     1120      String classifier_name = classifier == null ? "" : classifier.toString();
     1121      if(!classifier_name.equals("")){
     1122        classifier_name = classifier_name.substring(0, classifier_name.indexOf("-")).trim();       
     1123      }     
     1124      ArrayList part_model = new ArrayList();
     1125      // DateList only has DateList component
     1126      if(classifier_name.equals("DateList")){
     1127        part_model.add(new Part(DATELIST, DATELIST_DEFAULT_FORMAT));
     1128      }
     1129      // Other Format Entries, display the default Affected Components
     1130      else if(classifier_name.equals("")){     
     1131        part_model = buildPartModel();     
     1132      }
     1133      // Other Classifiers have HList and VList as Affected Component
     1134      else {
     1135        part_model.add(new Part(HLIST, HLIST_DEFAULT_FORMAT));
     1136        part_model.add(new Part(VLIST, VLIST_DEFAULT_FORMAT));
     1137      }
     1138      return part_model;
     1139    }
     1140   
    10831141    public String toString() {
    10841142      if(classifier != null) {
Note: See TracChangeset for help on using the changeset viewer.