Dorado 5 : 4.Dorado5自定义Dataset的步骤 (T34)

注意:在实做时配置文件中的My字符串都应被替换成实际的Dataset的类型名,Custom、AutoSql都属于Dataset的类型名。
1. 定义Dataset
2. 部署
3. 配置Studio
4. 配置项目


定义Dataset

从com.bstek.dorado.view.data.CustomDataset继承,并给新的类添加一到多个Bean属性例如:

package sample;

import org.apache.commons.lang.StringUtils;

import com.bstek.dorado.utils.variant.DataType;
import com.bstek.dorado.view.ViewModel;
import com.bstek.dorado.view.data.CustomDataset;
import com.bstek.dorado.view.data.ViewField;

public class MyDataset extends CustomDataset {

private String xmlPath;

public String getXmlPath() {
return xmlPath;
}

public void setXmlPath(String xmlPath) {
this.xmlPath = xmlPath;
}

public MyDataset(ViewModel viewModel, String id) {
super(viewModel, id);
}

protected void doLoad(boolean createFields, boolean loadData)
throws Exception {
if (createFields) {
if (StringUtils.isNotEmpty(xmlPath)) {
// 创建Field
ViewField field;
field = (ViewField) addField("field1");

field = (ViewField) addField("field2");
field.setDataType(DataType.INT);

field = (ViewField) addField("field3");
field.setDataType(DataType.BOOLEAN);

field = (ViewField) addField("field4");
field.setDataType(DataType.DATE);
}
}
super.doLoad(createFields, loadData);
}

}

部署

将此Dataset打成jar包的,并将jar包复制到studio/lib中。jar包中可以有其他的class.

配置Studio

编辑studio/configs/user-view-rules.xml,(如无此文件则新建)

<?xml version="1.0" encoding="UTF-8"?>
<rules>
<rule name="Controls">
<children>
<child name="Control-MarmotQuery" insertable="true" defaultNamePrefix="marmotQuery"/>
</children>
<palette>
<item name="Control-MarmotQuery"/>
</palette>
</rule>
<rule name="Control-DataTable"
object="org.marmot.framework.dorado.MarmotDataTable" />
<rule name="Control-AutoForm"
object="org.marmot.framework.dorado.MarmotAutoForm" />
<rule name="Control-MarmotQuery" text="MarmotQuery" tagName="Control" object="org.marmot.framework.dorado.MarmotQuery" nameAttribute="id" editable="true" icon="view/item.png">
<properties>
<property name="type" visible="false" defaultValue="MarmotQuery"/>
<property name="id" required="true"/>
<property name="category" required="true"/>
<property name="conditionDataset" idRef="true" editor="com.bstek.designer.impl.view.DatasetEditor"/>
<property name="queryDataset" idRef="true" required="true" editor="com.bstek.designer.impl.view.DatasetEditor"/>
</properties>
</rule>

<rule name="Datasets" expanded="true" showDetail="false">
<children>
<child name="Dataset-My" insertable="true" defaultNamePrefix="dataset"/>
</children>
</rule>
<rule name="Dataset-My" text="CustomDataset" tagName="Dataset" object="sample.MyDataset" nameAttribute="id" editable="true" icon="view/dataset-custom.png" expanded="true" eventSet="Dataset">
<properties>
<property name="id" required="true"/>
<property name="listener"/>
<property name="state" visible="false"/>
<property name="type" visible="false" defaultValue="My"/>
<property name="objectClazz" type="java.lang.String"/>
</properties>
<children>
<child name="MasterLink" fixed="true"/>
<child name="Fields-Base" fixed="true"/>
<child name="Parameters" fixed="true"/>
<child name="Properties" fixed="true"/>
</children>
<functions>
<function text="Auto create fields" icon="module/list-field.png" clazz="com.bstek.designer.impl.view.DatasetListFieldFunction"/>
<function text="Open Listener" icon="java/java.png" clazz="com.bstek.designer.impl.module.ShowDatasetListenerClassFunction"/>
</functions>
</rule>
</rules>

<rule name="Controls" expanded="true" showDetail="false">
<children>
<child name="Control-JbpmAutoForm" insertable="true" defaultNamePrefix="autoform"/>
</children>
</rule>
<rule name="Control-JbpmAutoForm" text="AutoForm" tagName="Control" object="com.bstek.dorado.view.control.autoform.AutoForm" nameAttribute="id" editable="true" icon="view/autoform.png">
<properties>
<property name="type" visible="false" defaultValue="AutoForm"/>
<property name="id" required="true"/>
<property name="format" optionsFixed="false" options="#.##;#,###.##;yyyy-MM-dd;yyyy年MM月dd日;yyyy-MM-dd HH:mm:ss;HH:mm:ss"/>
<property name="layout" optionsFixed="true" options="horizontal;vertical"/>
<property name="groupType" optionsFixed="true" options="groupbox,subwindow"/>
</properties>
<children>
<child name="FormGroup" insertable="true" defaultNamePrefix="group"/>
</children>
<functions>
<function text="Auto create elements" icon="view/create-element.png" clazz="com.bstek.designer.impl.view.AutoFormCreateElementFunction"/>
</functions>
</rule>

配置项目

在home新增view-datasets.xml

<?xml version="1.0" encoding="UTF-8"?>
<datasets>
<dataset type="My" clazz="sample.MyDataset"/>
</datasets>