⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formfield.java

📁 OBPM是一个开源
💻 JAVA
字号:
// Source file:
// C:\\Java\\workspace\\SmartWeb3\\src\\com\\cyberway\\dynaform\\form\\ejb\\FormField.java

package cn.myapps.core.dynaform.form.ejb;

import java.io.Serializable;
import java.sql.Date;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import cn.myapps.base.action.ParamsTable;
import cn.myapps.core.dynaform.PermissionType;
import cn.myapps.core.dynaform.document.ejb.Document;
import cn.myapps.core.dynaform.document.ejb.Item;
import cn.myapps.core.macro.runner.JavaScriptRunner;
import cn.myapps.core.user.action.WebUser;
import cn.myapps.util.Debug;
import cn.myapps.util.StringUtil;

public abstract class FormField implements FormElement, Cloneable, Serializable {
	public final static String SCRIPT_TYPE_STATICTEXT = "STATICTEXT";

	public final static String SCRIPT_TYPE_JAVASCRIPT = "JAVASCRIPT";

	private Map _otherprops = new HashMap();

	/**
	 * @return Returns the id.
	 */
	public String getId() {
		return id;
	}

	/**
	 * @param id
	 *            The id to set.
	 */
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * 表示该“Field”将在变化时刷新文档
	 */
	private boolean refreshOnChanged;

	/**
	 * 表示该“Field”将在文档刷新时重新计算
	 */
	private boolean calculateOnRefresh;

	private String id;

	/**
	 * @return Returns the refreshOnChanged.
	 */
	public boolean isRefreshOnChanged() {
		return refreshOnChanged;
	}

	/**
	 * @param refreshOnChanged
	 *            The refreshOnChanged to set.
	 */
	public void setRefreshOnChanged(boolean refreshOnChanged) {
		this.refreshOnChanged = refreshOnChanged;
	}

	/**
	 * @return Returns the validateRule.
	 */
	public String getValidateRule() {
		return validateRule;
	}

	/**
	 * @param validateRule
	 *            The validateRule to set.
	 */
	public void setValidateRule(String validateRule) {
		this.validateRule = validateRule;
	}

	/**
	 * @return Returns the valueScript.
	 */
	public String getValueScript() {
		return valueScript;
	}

	/**
	 * @param valueScript
	 *            The valueScript to set.
	 */
	public void setValueScript(String valueScript) {
		this.valueScript = valueScript;
	}

	/**
	 * Form的主键
	 */
	private long formid;

	/**
	 * Field名称
	 */
	private String name;

	/**
	 * 计算值
	 */
	private String fieldtype;

	/**
	 * 文本框类型
	 */
	private String textType;

	/**
	 * 字段描述
	 */
	private String discript;

	/**
	 * 计算隐藏条件
	 */
	private String hiddenScript;

	/**
	 * 计算只读条件
	 */
	private String readonlyScript;

	/**
	 * 计算值
	 */
	private String valueScript;

	/**
	 * 打印文档时是否打印该字段,默认为“打印”
	 */
	private String hiddenPrintScript;

	/**
	 * 校验规则
	 */
	private String validateRule;

	private String isbrief;

	private int orderno;

	private String islist;

	private int seq;

	public Form _form;

	private boolean issubformvalue;

	/*
	 * 别名
	 */
	private String alias;

	/*
	 * 字段长度
	 */
	private int fieldWidth;

	/*
	 * 列表显示宽度(可为px或百分比如20px、20%)
	 */
	private String showWidth;

	/*
	 * 排列方式 horizontal/vertical
	 */
	private String layout;

	/**
	 * @roseuid 41ECB66C0055
	 */

	private int displayType = PermissionType.MODIFY;

	public FormField() {

	}

	/**
	 * 校验输入知是否合法,如不合法时返回错误信息,合法时返回为空。
	 * 
	 * @return boolean
	 * @roseuid 41DB56C5017C
	 */
	public abstract ValidateMessage validate(JavaScriptRunner runner,
			Document doc) throws Exception;

	/**
	 * 获取html显示文本
	 * 
	 * @param doc
	 * @return java.lang.String
	 * @roseuid 41DB66D000EB
	 */
	// public abstract String toHtml(JavaScriptRunner runner, Document doc);
	/**
	 * 重新计算
	 * 
	 * @roseuid 41DB89D700F9
	 */
	public void recalculate(JavaScriptRunner runner, Document doc)
			throws Exception {
		Debug.println("FormField.recalculate");
	}

	/**
	 * 2种状态:true|不显示;false|显示;用于受控字段
	 * 
	 * @return java.lang.String
	 * @roseuid 41DB8A7E03D4
	 */
	public boolean runHiddenScript(JavaScriptRunner runner, Document doc)
			throws Exception {
		Object result = null;

		if (getHiddenScript() != null && getHiddenScript().trim().length() > 0) {
			/*
			 * Debug.println("JavaScript->" +
			 * StringUtil.dencodeHTML(getHiddenScript()));
			 */
			result = runner.run(StringUtil.dencodeHTML(getHiddenScript()));

			if (result != null) {
				if (result instanceof Boolean) {
					return ((Boolean) result).booleanValue();
				} else if (result instanceof String) {
					return ((String) result).equals("true") ? true : false;
				}
			}
		}
		return false;
	}

	/**
	 * 2种状态:true|只读;false|原属性;用于受控字段
	 * 
	 * @param runner
	 * @param doc
	 * @return
	 * @throws Exception
	 */
	public boolean runReadonlyScript(JavaScriptRunner runner, Document doc)
			throws Exception {
		Object result = null;

		if (getReadonlyScript() != null
				&& getReadonlyScript().trim().length() > 0) {
			/*
			 * Debug.println("JavaScript->" +
			 * StringUtil.dencodeHTML(getHiddenScript()));
			 */
			result = runner.run(StringUtil.dencodeHTML(getReadonlyScript()));

			if (result != null) {
				if (result instanceof Boolean) {
					return ((Boolean) result).booleanValue();
				} else if (result instanceof String) {
					return ((String) result).equals("true") ? true : false;
				}
			}
		}
		return false;
	}

	/**
	 * 打印文档时是否打印该字段,当返回值为false时不打印,默认为“打印”
	 * 
	 * @return java.lang.String
	 * @roseuid 41EBCA2B01DD
	 */
	public boolean runHiddenPrintScript(JavaScriptRunner runner, Document doc)
			throws Exception {
		Object result = null;

		if (getHiddenPrintScript() != null
				&& getHiddenPrintScript().trim().length() > 0) {
			Debug.println("JavaScript->"
					+ StringUtil.dencodeHTML(getHiddenPrintScript()));
			result = runner.run(StringUtil.dencodeHTML(getHiddenPrintScript()));

			if (result == null && result instanceof Object) {
				return false;
			}

		}
		return true;
	}

	/**
	 * 返回模板描述文本
	 * 
	 * @return java.lang.String
	 * @roseuid 41E7917A033F
	 */
	public abstract String toTemplate();

	public abstract String toHtmlTxt(ParamsTable params, WebUser user,
			JavaScriptRunner runner, Document doc) throws Exception;

	public String toHtmlTxt(ParamsTable params, WebUser user,
			JavaScriptRunner runner) throws Exception {// 空实现
		return "";
	}

	public String toHtml(ParamsTable params, WebUser user,
			JavaScriptRunner runner, Document doc) throws Exception {
		try {
			if (runHiddenScript(runner, doc)) {
				return toHtmlTxt(params, user, runner, doc);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "";
	}

	public String toPrintHtml(ParamsTable params, WebUser user,
			JavaScriptRunner runner, Document doc) {
		try {
			if (runHiddenPrintScript(runner, doc)) {
				return toPrintHtmlTxt(params, user, runner, doc);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "";
	}

	/**
	 * 打印模式
	 * 
	 * @param params
	 * @param user
	 * @param runner
	 * @param doc
	 * @return
	 * @throws Exception
	 */
	public abstract String toPrintHtmlTxt(ParamsTable params, WebUser user,
			JavaScriptRunner runner, Document doc) throws Exception;

	/**
	 * 根据FormField创建Item实例
	 * 
	 * @return cn.myapps.core.dynaform.document.ejb.Item
	 * @roseuid 41EBD62F00BE
	 */

	public Item createItem(Document doc, Object value) {
		Item item = new Item();
		item.setName(getName());
		item.setOrderno(this.getOrderno());
		item.setType(this.getFieldtype());

		item.setValue(value);

		item.setLastModified(new Date(System.currentTimeMillis()));
		return item;
	}

	/**
	 * @return Returns the discript.
	 */
	public String getDiscript() {
		return discript;
	}

	/**
	 * @param discript
	 *            The discript to set.
	 */
	public void setDiscript(String discript) {
		this.discript = discript;
	}

	/**
	 * @return Returns the formid.
	 */
	public long getFormid() {
		return formid;
	}

	/**
	 * @param formid
	 *            The formid to set.
	 */
	public void setFormid(long formid) {
		this.formid = formid;
	}

	/**
	 * @return Returns the hiddenPrintScript.
	 */
	public String getHiddenPrintScript() {
		return hiddenPrintScript;
	}

	/**
	 * @param hiddenPrintScript
	 *            The hiddenPrintScript to set.
	 */
	public void setHiddenPrintScript(String hiddenPrintScript) {
		this.hiddenPrintScript = hiddenPrintScript;
	}

	/**
	 * @return Returns the hiddenScript.
	 */
	public String getHiddenScript() {
		return hiddenScript;
	}

	/**
	 * @param hiddenScript
	 *            The hiddenScript to set.
	 */
	public void setHiddenScript(String hiddenScript) {
		this.hiddenScript = hiddenScript;
	}

	/**
	 * @return Returns the name.
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            The name to set.
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return Returns the _form.
	 */
	public Form get_form() {
		return _form;
	}

	/**
	 * @param _form
	 *            The _form to set.
	 */
	public void set_form(Form form) {
		this._form = form;
	}

	/**
	 * @return Returns the fieldType.
	 */
	public String getFieldtype() {
		return fieldtype;
	}

	/*
	 * @return Returns the textType
	 */
	public String getTextType() {
		return textType;
	}

	/**
	 * @param fieldType
	 *            The fieldType to set.
	 */
	public void setFieldtype(String fieldtype) {
		this.fieldtype = fieldtype;
	}

	/**
	 * 
	 * @param textType
	 *            The textType to set.
	 */
	public void setTextType(String textType) {
		this.textType = textType;
	}

	public void addOtherProps(String key, String value) {
		if (key != null && value != null)
			_otherprops.put(key, value);
	}

	public String getOtherProp(String key) {
		String value = (String) _otherprops.get(key);
		return value;
	}

	public Map getOtherPropsAsMap() {
		return _otherprops;
	}

	public Collection getOtherPropsAsCollection() {
		return _otherprops.values();
	}

	protected String toOtherpropsHtml() {
		StringBuffer buffer = new StringBuffer();
		Map coll = getOtherPropsAsMap();
		Collection keys = coll.keySet();
		Iterator iter = keys.iterator();
		while (iter.hasNext()) {
			String key = (String) iter.next();
			buffer.append(key);
			buffer.append("=");
			String value = (String) coll.get(key);
			int pos1 = value.indexOf("'");
			int pos2 = value.indexOf("\"");
			if (pos1 > pos2) {
				buffer.append("'");
				buffer.append(value);
				buffer.append("'");
			} else {
				buffer.append("'");
				buffer.append(value);
				buffer.append("' ");
			}

		}
		return buffer.toString();
	}

	/**
	 * @return Returns the isbrief.
	 */
	public String getIsbrief() {
		return isbrief;
	}

	/**
	 * @param isbrief
	 *            The isbrief to set.
	 */
	public void setIsbrief(String isbrief) {
		this.isbrief = isbrief;
	}

	/**
	 * @return Returns the orderno.
	 */
	public int getOrderno() {
		return orderno;
	}

	/**
	 * @param orderno
	 *            The orderno to set.
	 */
	public void setOrderno(int orderno) {
		this.orderno = orderno;
	}

	/**
	 * @return Returns the islist.
	 */
	public String getIslist() {
		return islist;
	}

	/**
	 * @param islist
	 *            The islist to set.
	 */
	public void setIslist(String islist) {
		this.islist = islist;
	}

	/**
	 * @return Returns the seq.
	 */
	public int getSeq() {
		return seq;
	}

	/**
	 * @param seq
	 *            The seq to set.
	 */
	public void setSeq(int seq) {
		this.seq = seq;
	}

	/**
	 * @return Returns the issubformvalue.
	 */
	public boolean getIssubformvalue() {
		return issubformvalue;
	}

	/**
	 * @param issubformvalue
	 *            The issubformvalue to set.
	 */
	public void setIssubformvalue(boolean issubformvalue) {
		this.issubformvalue = issubformvalue;
	}

	// public int compareTo(Object o) {
	// int rtn = -1;
	// if (o instanceof FormField) {
	// FormField f = (FormField)o;
	// if (f.getSeq()<getSeq()) {
	// rtn = 1;
	// }
	// else if (f.getSeq()==getSeq()) {
	// return 0;
	// }
	// else {
	// return -1;
	// }
	// }
	// return rtn;
	// }

	/**
	 * @return Returns the alias.
	 */
	public String getAlias() {
		return alias;
	}

	/**
	 * @param alias
	 *            The alias to set.
	 */
	public void setAlias(String alias) {
		this.alias = alias;
	}

	/**
	 * @return Returns the fieldWidth.
	 */
	public int getFieldWidth() {
		return fieldWidth;
	}

	/**
	 * @param fieldWidth
	 *            The fieldWidth to set.
	 */
	public void setFieldWidth(int fieldWidth) {
		this.fieldWidth = fieldWidth;
	}

	/**
	 * @return Returns the showWidth.
	 */
	public String getShowWidth() {
		return showWidth;
	}

	/**
	 * @param showWidth
	 *            The showWidth to set.
	 */
	public void setShowWidth(String showWidth) {
		this.showWidth = showWidth;
	}

	public String getLayout() {
		return layout;
	}

	public void setLayout(String layout) {
		this.layout = layout;
	}

	public boolean isCalculateOnRefresh() {
		return calculateOnRefresh;
	}

	public void setCalculateOnRefresh(boolean calculateOnRefresh) {
		this.calculateOnRefresh = calculateOnRefresh;
	}

	public String getReadonlyScript() {
		return readonlyScript;
	}

	public void setReadonlyScript(String readonlyScript) {
		this.readonlyScript = readonlyScript;
	}

	protected boolean isDisable(int displayType) {
		if ((this.getTextType() != null && this.getTextType().equalsIgnoreCase(
				"READONLY"))
				|| (displayType == PermissionType.DISABLED)
				|| (displayType == PermissionType.READONLY)) {
			return true;
		} else {
			return false;
		}
	}

	public int getDisplayType(JavaScriptRunner runner, Document doc)
			throws Exception {
		if (doc != null) {
			if (displayType != PermissionType.DISABLED) {
				if (runReadonlyScript(runner, doc)) {
					displayType = PermissionType.READONLY;
				}

				if (doc.getFieldPermList() != null) {
					displayType = doc.getFieldPermList().checkPermission(this);
				}
			}
		}
		return displayType;
	}

	public int getPrintDisplayType(JavaScriptRunner runner, Document doc)
			throws Exception {
		if (doc != null) {
			if (runHiddenPrintScript(runner, doc)) {
				displayType = PermissionType.READONLY;
			}
		}
		return displayType;
	}

	public void setDisplayType(int displayType) {
		this.displayType = displayType;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -