ListBox.java 5.04 KB
Newer Older
Naung1 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
package com.csc.library.components;

import com.csc.library.utilities.ThaiUtilities;

  /**
   *  <strong>Edit 2008/09/15 by James </strong><br />
   *  <p>
   *  -  option ҧ listbox 㹡óշҧҨҡ systemcode <br/>
   *     default  false
   *    <p><ul><u>ҹ</u>
   *    <li> <code>&lt;BLANKOPTION&gt; true&lt;/BLANKOPTION&gt;</code>  protable
   *   ǹͧ component ͧŴ</li>
   *   <li> setBlank</li>
   *   </ul>
   *   </p>
   *    <blockquote><u>ŷ</u><br />&lt;select name='com_name' size='1'&gt;<br />&lt;option value=''&gt;   &lt;/option&gt;<br /> 
   *     ...<br />...<br />&lt;/select&gt;</blockquote>
   *   </p>
   */

public class ListBox extends MyTag {

	private static final long serialVersionUID = 1L;
	static final String BLANK_OPTION = "<option value=\"\">   </option>";
	String tagInput = "";
	String hspace = "";
	String checked = "";
	String sizel = "";
	String multiple = "";
	boolean blank = false;

	public ListBox() {
		this.type = "list";
	}

	public ListBox(ComponentManager cm) {
		super(cm); 
		this.setValidCode(cm.getProperty("validCode"));
		this.setMultiple(cm.getProperty("multiple"));
		this.setSizel(cm.getProperty("sizel"));
		this.setTable(cm.getProperty("table"));
		if(!cm.getString().trim().equals("")){
			this.setChecked(cm.getString().trim());
		} else {
			this.setChecked(cm.getProperty("defaultvalue").trim());
		}
		
		String blankOpt = cm.getProperty("blankoption");
		if(blankOpt !=null && "true".equalsIgnoreCase(blankOpt)) {
			setBlank(true);
		}
		this.ini();
	}
	
	/**
	 * Edit by : james <br/>
	 * Edit date: 2008-09-12 <br/>
	 *  tag options ҧ 1 ѹ <br/>
	 * <code>&lt;option value=&quot;&quot;&gt;   &lt;/option&gt;<code>
	 */
	public void ini() {
		ThaiUtilities ethai = new ThaiUtilities();
		String label2;
		String tmpV;
		String tmpL="";
		//String input2 = "";
		
		tagInput = label2 = "";
		
		StringBuilder tag = new StringBuilder();
		StringBuilder options = new StringBuilder();
		
		if (sysCode != null) {
			
			if( blank && useValidCode) {
				options.append(BLANK_OPTION);
			}
			
			for (int point = 0; point < sysCode.length; point++) {
				tmpV = sysCode[point][0];
				
				if((sysCode[point][1]==null)){
					break;
				}
				tmpL = this.spilltLang(sysCode[point][1]);	
				
				// edit ͵ͧʴ
				tmpL = ethai.ASCII2Unicode(tmpL);   
				
				if ((tmpV != null) && (tmpL != null) && (!tmpV.equals("")) && (!tmpL.equals("")) && (!tmpV.equals("null"))) {
					
					options.append("<option ");
					options.append(" value=\"").append(tmpV).append("\" ");
					
					if ((this.checked != null) && (this.checked.equalsIgnoreCase(tmpV))) {
						options.append("selected");
					}
					options.append(" >");
					options.append(tmpL).append("</option>");

				}
			}
		
			tag.append("<select name=\"").append(this.name).append("\" ");
			tag.append("size=\"").append(this.sizel).append("\" ");
			
			if("true".equalsIgnoreCase(this.disable)) {
				tag.append(" disabled ");
			}
			if( this.onClick != null && !this.onClick.equals("") ){
				tag.append("onClick=\"").append( this.onClick ).append("\" ");
		    }
		    if( this.onChange != null && !this.onChange.equals("") ){
		    	tag.append("onChange=\"").append( this.onChange ).append("sysIsEdit();").append("\" ");
		    }
			if( this.onBlur != null && !this.onBlur.equals("") ){
				tag.append("onBlur=\"").append( this.onBlur ).append("\" ");
		    }
			if( this.onKeyUp != null && !this.onKeyUp.equals("") ){
				tag.append("onKeyUp=\"").append( this.onKeyUp ).append("\" ");
		    }
			if( this.onMouseOver!= null && !this.onMouseOver.equals("") ){
				tag.append("onMouseOver=\"").append( this.onMouseOver ).append("\" ");
		    }
			if( this.onMouseOut != null && !this.onMouseOut.equals("") ){
				tag.append("onMouseOut=\"").append( this.onMouseOut ).append("\" ");
		    }
			
			if( com != null && com.getDescription() != null && com.getDescription().equals("")){
				tag.append("alt=\"").append( com.getDescription()).append("\" ");
		    }
			
			tag.append(multiple);

			tag.append(" >");
			tag.append(options.toString());
			tag.append("</select>").append(label2);
			
			this.tagInput = tag.toString();
		}
	}
	public String process() {
		this.ini();
		if ((this.point != null) && (this.point.equalsIgnoreCase("l"))) {
			return this.tagInput + this.hspace + this.label;
		} else {
			return this.label + this.hspace + this.tagInput;
		}
	}
	public void setSpace(int space) {
		for (int i = 0; i < space; i++) {
			hspace = hspace + "&nbsp;";
		}
	}
	public void setSelect(String[][] code) {
		sysCode = code;
	}
	public void setSelect(String value, String label) {
		int i = 0;
		if (this.sysCode.length != 0) {
			i = this.sysCode.length;
		}
		sysCode[i][0] = value;
		sysCode[i][1] = label;
	}
	public String getInput() {
		return this.tagInput;
	}
	public void setChecked(String check) {
		this.checked = check;
	}
	public void setSizel(String sizel) {
		this.sizel = sizel;
	}
	public void setMultiple(String multiple) {
		this.multiple = multiple;
	}
	public void setBlank(boolean blank){
		this.blank = blank;
	}
}