/*
 * HtmlComboBoxEditor.java
 *
 * Created on October 18, 2000, 4:23 PM
 */

package ovt.servlet;

import ovt.beans.*;

/**
 *
 * @author  ko
 * @version 
 */
public class HtmlComboBoxEditor extends HtmlPropertyEditor {
  
    /** Creates new HtmlComboBoxEditor */
    public HtmlComboBoxEditor(BasicPropertyDescriptor desc) {
        super(desc);
    }

    public String toString() {
        String res="<SELECT NAME=\"" + getName() + "\""; 
        if (submitOnChange()) 
            res += " ONCHANGE=\"document."+ getForm().getName() +".submit()\" ONBLUR=\"return\"";
        res += ">\n";
        
        String[] tags = getEd().getTags();
        for (int i=0; i<tags.length; i++) {
            
            res+= "<OPTION VALUE=\"" + tags[i] +"\" " +
                ( isChecked(tags[i]) ? "SELECTED" : "") + " >" + 
                tags[i] + "\n";
        }
        res+= "</SELECT>\n";
        return res;
    }
    
    public boolean isChecked(String item) {
      return getEd().getAsText().equals(item);
    }
}