You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
175 lines
5.2 KiB
175 lines
5.2 KiB
package com.fr.plugin.demo.parameter.combo.grid.fun; |
|
|
|
import com.fr.base.TableData; |
|
import com.fr.data.impl.NameTableData; |
|
import com.fr.form.ui.DataControl; |
|
import com.fr.form.ui.WidgetValue; |
|
import com.fr.form.ui.WriteAbleRepeatEditor; |
|
import com.fr.general.data.DataModel; |
|
import com.fr.intelli.record.Focus; |
|
import com.fr.intelli.record.Original; |
|
import com.fr.json.JSON; |
|
import com.fr.json.JSONArray; |
|
import com.fr.json.JSONFactory; |
|
import com.fr.json.JSONObject; |
|
import com.fr.plugin.transform.ExecuteFunctionRecord; |
|
import com.fr.plugin.transform.FunctionRecorder; |
|
import com.fr.record.analyzer.EnableMetrics; |
|
import com.fr.script.Calculator; |
|
import com.fr.stable.xml.XMLPrintWriter; |
|
import com.fr.stable.xml.XMLableReader; |
|
import com.fr.web.core.TemplateSessionIDInfo; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
/** |
|
* @author richie |
|
* @date 2015-03-16 |
|
* @since 8.0 |
|
*/ |
|
@EnableMetrics |
|
public class ComboGrid extends WriteAbleRepeatEditor implements DataControl { |
|
|
|
private TableData tableData; |
|
private WidgetValue widgetValue; |
|
private int keyIndex; |
|
private int valueIndex; |
|
|
|
public ComboGrid() { |
|
|
|
} |
|
|
|
public TableData getTableData() { |
|
return tableData; |
|
} |
|
|
|
public void setTableData(TableData tableData) { |
|
this.tableData = tableData; |
|
} |
|
|
|
public int getKeyIndex() { |
|
return keyIndex; |
|
} |
|
|
|
public void setKeyIndex(int keyIndex) { |
|
this.keyIndex = keyIndex; |
|
} |
|
|
|
public int getValueIndex() { |
|
return valueIndex; |
|
} |
|
|
|
public void setValueIndex(int valueIndex) { |
|
this.valueIndex = valueIndex; |
|
} |
|
|
|
/** |
|
* 生成下拉框数据的JSONArray。这个方法用于生成控件数据,因为下拉框数据一般不需要在一开始就加载的, |
|
* 当点击下拉框的时候才加载数据,就要用到这个方法了。 |
|
* |
|
* @param sessionIDInfor 本次会话信息 |
|
* @param c 算子 |
|
* @param req http请求 |
|
* @return 返回数据对象 |
|
* @throws Exception 抛出异常 |
|
*/ |
|
@Focus(id="com.fr.plugin.demo.parameter.combo.grid", text = "", source = Original.PLUGIN) |
|
public JSONArray createJSONData(TemplateSessionIDInfo sessionIDInfor, Calculator c, HttpServletRequest req) throws Exception { |
|
JSONArray ja = JSONFactory.createJSON(JSON.ARRAY); |
|
|
|
JSONObject columnInfo = JSONFactory.createJSON(JSON.OBJECT); |
|
ja.put(columnInfo); |
|
|
|
JSONArray columnNames = JSONFactory.createJSON(JSON.ARRAY); |
|
columnInfo.put("columnNames", columnNames); |
|
|
|
JSONObject valueInfo = JSONFactory.createJSON(JSON.OBJECT); |
|
columnInfo.put("valueInfo", valueInfo); |
|
|
|
|
|
DataModel dataModel = tableData.createDataModel(c); |
|
|
|
for (int i = 0, col = dataModel.getColumnCount(); i < col; i ++) { |
|
String colName = dataModel.getColumnName(i); |
|
columnNames.put(colName); |
|
} |
|
valueInfo.put("valueColumnName", columnNames.length() > keyIndex ? columnNames.getString(keyIndex) : columnNames.getString(0)); |
|
valueInfo.put("textColumnName", columnNames.length() > valueIndex ? columnNames.getString(valueIndex) : columnNames.getString(0)); |
|
|
|
|
|
JSONArray valueArray = JSONFactory.createJSON(JSON.ARRAY); |
|
ja.put(valueArray); |
|
for (int j = 0, row = dataModel.getRowCount(); j < row; j ++) { |
|
JSONObject jo = JSONFactory.createJSON(JSON.OBJECT); |
|
valueArray.put(jo); |
|
for (int i = 0, col = dataModel.getColumnCount(); i < col; i ++) { |
|
jo.put(dataModel.getColumnName(i), dataModel.getValueAt(j, i)); |
|
} |
|
} |
|
|
|
return ja; |
|
} |
|
|
|
|
|
public String getXType() { |
|
return "combogrid"; |
|
} |
|
|
|
@Override |
|
public String getFormatText() { |
|
return null; |
|
} |
|
|
|
@Override |
|
public String getDataBindDefaultValue(Calculator calculator) { |
|
return null; |
|
} |
|
|
|
public void readXML(XMLableReader reader) { |
|
super.readXML(reader); |
|
if (reader.isChildNode()) { |
|
String nodeName = reader.getTagName(); |
|
if ("ComboGridAttr".equals(nodeName)) { |
|
tableData = new NameTableData(reader.getAttrAsString("tdname", "")); |
|
keyIndex = reader.getAttrAsInt("keyIndex", 0); |
|
valueIndex = reader.getAttrAsInt("valueIndex", 0); |
|
} |
|
} |
|
} |
|
|
|
public void writeXML(XMLPrintWriter writer) { |
|
super.writeXML(writer); |
|
writer.startTAG("ComboGridAttr"); |
|
if (tableData != null) { |
|
writer.attr("tdname", ((NameTableData) tableData).getName()); |
|
if (keyIndex != 0) { |
|
writer.attr("keyIndex", keyIndex); |
|
} |
|
if (valueIndex != 0) { |
|
writer.attr("valueindex", valueIndex); |
|
} |
|
} |
|
writer.end(); |
|
|
|
} |
|
|
|
@Override |
|
public int[] getValueType() { |
|
return new int[]{TYPE_STRING, TYPE_FORMULA}; |
|
} |
|
|
|
@Override |
|
public void setWidgetValue(WidgetValue value) { |
|
widgetValue = value; |
|
} |
|
|
|
@Override |
|
public WidgetValue getWidgetValue() { |
|
return widgetValue; |
|
} |
|
|
|
@Override |
|
public void createValueResult(DataControl widget, Calculator widgetCalculator, JSONObject widgetResult, JSONObject attrSourceCache) { |
|
|
|
} |
|
} |