自定义dorado7控件

来自ling
跳转至: 导航搜索

通过java自定义

 ${acomp.id('buttonClearSelectIrisArea')}


 self.dataProvider="${acomp.prop('dataProvider')}";
 self.PRIVATE_ATTRIBUTES.dataProvider.setter = function(dataProvider) {
	 self.dataProvider=dataProvider;
 };

 view.get("#${acomp.id('SingleUserSelect')}").selectdata();
	<bean parent="dorado.assembledComponentTypeRegister">
		<property name="name" value="IrisAreaSingleSelect" />
		<property name="category" value="ling.iris" />
		<property name="src" value="com.deloitte.iris.define.area.view.component.IrisAreaSingleSelect#DropDownIrisAreaSingleSelect" />
		<d:virtual-property name="dataProvider" avialableAt="both" />
		<d:virtual-property name="parameter" avialableAt="both" />
	</bean>

研究本示例前建议您先了解一下“配置型组装控件”示例。对象型组装控件允许您通过Java代码来定义组装控件具体形式,相对于配置型组装控件具有更大的灵活性和自由度。

对象型组装控件和配置型组装控件这两种定义方法并不是相斥,您也可以同时利用这两种方法来定义一个组装控件。例如首先通过配置信息大致的生成组装控件,然后再利用Java代码对其进行进一步的定制。

本例试做了一个名为QuickForm的组装控件,该控件可以根据用户指定的一个items字符串快速的生成一个表单。

package com.bstek.dorado.sample.widget.customize;

import org.apache.commons.lang.StringUtils;

import com.bstek.dorado.config.definition.DefinitionPostProcessor;
import com.bstek.dorado.view.widget.AssembledComponent;
import com.bstek.dorado.view.widget.form.autoform.AutoForm;
import com.bstek.dorado.view.widget.form.autoform.AutoFormElement;

public class QuickForm extends AutoForm implements AssembledComponent,
		DefinitionPostProcessor {
	private String items;

	public QuickForm() {
		setCols("*");
	}

	public String getItems() {
		return items;
	}

	public void setItems(String items) {
		this.items = items;
	}

	public void onInit() throws Exception {
		if (items != null) {
			for (String item : StringUtils.split(items, ',')) {
				if (StringUtils.isEmpty(item)) {
					continue;
				}
				AutoFormElement element = new AutoFormElement();
				element.setProperty(item);
				addElement(element);
			}
		}
	}

}

package com.bstek.dorado.sample.process;

import java.util.HashMap;
import java.util.Map;

import com.bstek.dorado.config.definition.DefinitionPostProcessor;
import com.bstek.dorado.config.definition.ObjectDefinition;
import com.bstek.dorado.config.text.DispatchableTextParser;
import com.bstek.dorado.view.annotation.Widget;
import com.bstek.dorado.view.widget.AssembledComponent;
import com.bstek.dorado.view.widget.HtmlContainer;
import com.bstek.dorado.view.widget.base.Panel;
import com.bstek.dorado.view.widget.layout.CommonLayoutConstraint;
import com.bstek.dorado.view.widget.layout.FormLayout;
import com.ling2.core.commons.utils.AssertHelper;

@Widget(name = "CalendarForm", category = "deloitte",
dependsPackage = "tree-grid")
public class CalendarForm extends Panel implements AssembledComponent,DefinitionPostProcessor{
	
	public CalendarForm(){
		FormLayout layout=new FormLayout();
		layout.setCols("*,*,*,*");
		this.setLayout(layout);	
		
		HtmlContainer htmlContainer1=new HtmlContainer();

//		ObjectDefinition layoutDefinition = new ObjectDefinition();
//		layoutDefinition.setImplType(CommonLayoutConstraint.class);
//		
//		layoutDefinition.setProperty("colSpan", 2);
//		htmlContainer1.setLayoutConstraint(layoutDefinition);
		htmlContainer1.setLayoutConstraint("type:left;colSpan:2;rowSpan:2");
//		htmlContainer1.setContent("colSpan: 4");		
		String style="background:#FDFEDA; border:1px #DBB74A solid; padding:4px; display:block; height: 100%; overflow: hidden";
		htmlContainer1.setStyle(getStyle(style));
		
		getChildren().add(htmlContainer1);		
	}
	@Override
	public void onInit() throws Exception {
			
	}
	private Map<String, Object> getStyle(String style){
		Map<String, Object> result=new HashMap<String, Object>();
		String[] contents=style.split(";");
		for(String content:contents){
			String[] keyandvalue=content.split(":");
			if(keyandvalue.length>1&&AssertHelper.notEmpty(keyandvalue[0])&&AssertHelper.notEmpty(keyandvalue[1])){
				result.put(keyandvalue[0].trim(), keyandvalue[1].trim());
			}
		}
		return result;
	}
}
	<bean parent="dorado.assembledComponentTypeRegister">
		<property name="name" value="QuickForm" />
		<property name="classType" value="com.bstek.dorado.sample.widget.customize.QuickForm" />
	</bean>
	<bean parent="dorado.assembledComponentTypeRegister">
		<property name="name" value="CalendarForm" />
		<property name="classType" value="com.bstek.dorado.sample.process.CalendarForm" />
	</bean>

组装型控件

	<bean parent="dorado.assembledComponentTypeRegister">
		<property name="name" value="DualListSelection" />
		<property name="src" value="com.bstek.dorado.sample.widget.customize.DualListSelectionComponent#DualListSelection" />
		<d:virtual-property name="dataSetLeft" referenceComponentType="DataSet" />
		<d:virtual-property name="dataPathLeft" />
		<d:virtual-property name="dataSetRight" referenceComponentType="DataSet" />
		<d:virtual-property name="dataPathRight" />
		<d:virtual-property name="captionLeft" />
		<d:virtual-property name="captionRight" />
		<d:virtual-property name="added" avialableAt="client" />
		<d:virtual-property name="removed" avialableAt="client" />
		<d:virtual-property name="selection" avialableAt="client" />
		<d:virtual-event name="onSelectionChange" />
	</bean>