欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

dhtmlx的pojo

程序员文章站 2022-06-17 14:15:53
...

 

Grid

 

public class DhtmlxGridRow {
	Object id;
	Object data;
	public Object getId() {
		return id;
	}
	public void setId(Object id) {
		this.id = id;
	}
	public Object getData() {
		return data;
	}
	public void setData(Object data) {
		this.data = data;
	}
	
	
	
	
	
}

 

 

 

import java.util.ArrayList;
import java.util.List;

public class DhtmlxGridTable {
	List<DhtmlxGridRow> rows;
	int total_count;
	int pos;

	public int getPos() {
		return pos;
	}

	public void setPos(int pos) {
		this.pos = pos;
	}

	public int getTotal_count() {
		return total_count;
	}

	public void setTotal_count(int total_count) {
		this.total_count = total_count;
	}

	public List<DhtmlxGridRow> getRows() {
	  if(rows ==null){
	    rows = new ArrayList<DhtmlxGridRow>();
	  }
		return rows;
	}

	public void setRows(List<DhtmlxGridRow> rows) {
		this.rows = rows;
	}
}

 

 

Tree

 

import java.io.Serializable;
import java.util.List;

/**
 * @Description:DhtmlxTree节点类
 * 
 * 
 * @Version: 1.0
 * 
 */
public class DhtmlxTreeItem implements Serializable {
	/**
	 * 2011-8-2
	 */
	private static final long serialVersionUID = 1L;
	public static Long ROOTID = 0L;// 要求树的根的id为0
	public static final String[] INCLUDE_SIMPLE = { "id", "text", "item" };
	public static final String[] INCLUDE_CHECKED = { "id", "text", "item",
			"checked" };
	public static final String[] INCLUDE_OPEN = { "id", "text", "item", "open" };
	public static final String[] INCLUDE_OPEN_CHECKED = { "id", "text", "item",
			"open", "checked" };
	public static final String[] INCLUDE_ALL = { "id", "text", "item", "open",
			"checked", "child", "im0", "im1", "im2", "aCol", "sCol", "style",
			"select", "call", "tooltip", "nocheckbox", "radio", "imheight",
			"imwidth", "topoffset" };

	private String id;// id of the node
	private String text;// label of the node
	private String im0;// image for a node without child items (tree will get
						// images from the path specified in setImagePath()
						// method)
	private String im1;// image for an expanded node with child items
	private String im2;// image for a collapsed node with child items
	private String aCol;// colour of an item that is not selected
	private String sCol;// colour of a selected item
	private String style;// text style of a node
	private String open;// show a node opened (any value)
	private String select;// select a node on load (any value)
	private String call;// call function on select(any value)
	private String tooltip;// tooltip of the node
	private String checked;// check checkbox if exists (in case of 3-state
							// checkboxes values can be 1 - checked or -1 -
							// unsure)
	private String nocheckbox;// instruct component, to not render checkbox for
								// related item, optional
	private String child;// specifies whether a node has child items (1) or not
							// (0)
	private String radio;// if not empty, child items of this node will have
							// radio buttons
	private int imheight;// height of the icon
	private int imwidth;// width of the icon
	private int topoffset;// offset of the item from the node above

	private List<DhtmlxTreeItem> item;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getIm0() {
		return im0;
	}

	public void setIm0(String im0) {
		this.im0 = im0;
	}

	public String getIm1() {
		return im1;
	}

	public void setIm1(String im1) {
		this.im1 = im1;
	}

	public String getIm2() {
		return im2;
	}

	public void setIm2(String im2) {
		this.im2 = im2;
	}

	public List<DhtmlxTreeItem> getItem() {
		return item;
	}

	public void setItem(List<DhtmlxTreeItem> item) {
		this.item = item;
	}

	public String getOpen() {
		return open;
	}

	public void setOpen(String open) {
		this.open = open;
	}

	public String getSelect() {
		return select;
	}

	public void setSelect(String select) {
		this.select = select;
	}

	public String getCall() {
		return call;
	}

	public void setCall(String call) {
		this.call = call;
	}

	public String getTooltip() {
		return tooltip;
	}

	public void setTooltip(String tooltip) {
		this.tooltip = tooltip;
	}

	public String getaCol() {
		return aCol;
	}

	public void setaCol(String aCol) {
		this.aCol = aCol;
	}

	public String getsCol() {
		return sCol;
	}

	public void setsCol(String sCol) {
		this.sCol = sCol;
	}

	public String getStyle() {
		return style;
	}

	public void setStyle(String style) {
		this.style = style;
	}

	public String getChecked() {
		return checked;
	}

	public void setChecked(String checked) {
		this.checked = checked;
	}

	public String getNocheckbox() {
		return nocheckbox;
	}

	public void setNocheckbox(String nocheckbox) {
		this.nocheckbox = nocheckbox;
	}

	public String getChild() {
		return child;
	}

	public void setChild(String child) {
		this.child = child;
	}

	public String getRadio() {
		return radio;
	}

	public void setRadio(String radio) {
		this.radio = radio;
	}

	public int getImheight() {
		return imheight;
	}

	public void setImheight(int imheight) {
		this.imheight = imheight;
	}

	public int getImwidth() {
		return imwidth;
	}

	public void setImwidth(int imwidth) {
		this.imwidth = imwidth;
	}

	public int getTopoffset() {
		return topoffset;
	}

	public void setTopoffset(int topoffset) {
		this.topoffset = topoffset;
	}

}
 

 

import java.util.ArrayList;
import java.util.List;

public class DhtmlxTreeGridRow {
  Object id;
  Object data;
  String xmlkids;
  List<DhtmlxTreeGridRow> rows;
  public Object getId() {
      return id;
  }
  public void setId(Object id) {
      this.id = id;
  }
  public Object getData() {
      return data;
  }
  public void setData(Object data) {
      this.data = data;
  }
  public List<DhtmlxTreeGridRow> getRows() {
    if(rows==null){
      rows = new ArrayList<DhtmlxTreeGridRow>();
    }
    return rows;
  }
  public void setRows(List<DhtmlxTreeGridRow> rows) {
    this.rows = rows;
  }
  public String getXmlkids() {
    return xmlkids;
  }
  public void setXmlkids(String xmlkids) {
    this.xmlkids = xmlkids;
  }
  
}
 

 

 

 

import java.util.ArrayList;
import java.util.List;

public class DhtmlxTreeGridTable {
  int total_count;
  int pos;
  List<DhtmlxTreeGridRow> rows;
  
  
  public int getTotal_count() {
    return total_count;
  }
  public void setTotal_count(int total_count) {
    this.total_count = total_count;
  }
  public int getPos() {
    return pos;
  }
  public void setPos(int pos) {
    this.pos = pos;
  }
  public List<DhtmlxTreeGridRow> getRows() {
    if(rows==null){
      rows = new ArrayList<DhtmlxTreeGridRow>();
    }
    return rows;
  }
  public void setRows(List<DhtmlxTreeGridRow> rows) {
    this.rows = rows;
  }
  
}
 

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

import org.apache.commons.lang.StringUtils;

import com.mogenesis.mobileadplatform.web.util.ArrayUtil;

/**
 * 
 * @Description: dhtmxTree JSON输出构建类,使用方法见
 *               
 * 
 * @Date: 2011-8-3 下午10:57:19
 * @Version: 1.0
 * 
 */
public class DhtmlxTreeBuilder {
	/**
	 * 递归构建json字符串
	 * 
	 * @param <T>
	 * @param root
	 * @param cb
	 * @return
	 */
	public static <T> String buildRecursiveJson(T root,
			DhtmlxTreeBuildCallback<T> cb) {
		DhtmlxTreeItem d = buildRecursive(root, cb);
		if (d == null) {
			return "{}";
		}
		String[] includeProperties = cb.includeProperties();
		String[] excludeProperties = cb.excludeProperties();
		Set<String> includes = null;
		if ((includeProperties != null) && (includeProperties.length > 0)) {
			includes = new TreeSet<String>();
			for (String property : includeProperties) {
				if (StringUtils.isNotEmpty(property)) {
					includes.add(property);
				}
			}
			if (includes.size() == 0)
				includes = null;
		}
		Set<String> excludes = null;
		if ((excludeProperties != null) && (excludeProperties.length > 0)) {
			excludes = new TreeSet<String>();
			for (String property : excludeProperties) {
				if (StringUtils.isNotEmpty(property)) {
					excludes.add(property);
				}
			}
			if (excludes.size() == 0) {
				excludes = null;
			}
		}
		JsonConfig config = null;
		if ((excludes == null) && (includes == null)) {
			return JSONObject.fromObject(d).toString();
		}
		Set<String> ex;
		if (includes != null) {
			ex = new HashSet<String>();
			for (String s : DhtmlxTreeItem.INCLUDE_ALL) {
				if (!(includes.contains(s)))
					ex.add(s);
			}
			if (ex.size() > 0) {
				config = new JsonConfig();
				config.setExcludes((String[]) ArrayUtil.toArray(ex));
			}
		}
		if (excludes != null) {
			config = new JsonConfig();
			config.setExcludes((String[]) ArrayUtil.toArray(excludes));
		}
		if ((excludes != null) && (includes != null)) {
			ex = new HashSet<String>();
			for (String s : DhtmlxTreeItem.INCLUDE_ALL) {
				if (excludes.contains(s))
					ex.add(s);
				else if (!(includes.contains(s)))
					ex.add(s);
			}
			if (ex.size() > 0) {
				config = new JsonConfig();
				config.setExcludes((String[]) ArrayUtil.toArray(ex));
			}
		}
		return ((String) JSONObject.fromObject(d, config).toString());
	}

	public static <T> DhtmlxTreeItem buildRecursive(T root,
			DhtmlxTreeBuildCallback<T> cb) {
		if ((root == null) || (cb == null)) {
			return null;
		}
		DhtmlxTreeItem dRoot = cb.getDhtmlxTreeItem(root);
		if (dRoot != null)
			buildRecursiveJson(root, dRoot, cb);
		return dRoot;
	}

	private static <T> void buildRecursiveJson(T t, DhtmlxTreeItem dT,
			DhtmlxTreeBuildCallback<T> cb) {
		T[] nodes = cb.getChildren(t);
		if ((nodes == null) || (nodes.length == 0))
			return;
		List<DhtmlxTreeItem> children = dT.getItem();
		if (children == null) {
			children = new ArrayList<DhtmlxTreeItem>();
			dT.setItem(children);
		}
		for (int i = 0; i < nodes.length; ++i) {
			T node = nodes[i];
			if (node == null) {
				continue;
			}
			DhtmlxTreeItem o = cb.getDhtmlxTreeItem(node);
			buildRecursiveJson(node, o, cb);

			children.add(o);
		}
	}
}
 

 

 

import java.io.StringWriter;
import java.text.SimpleDateFormat;

import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
import org.codehaus.jackson.map.annotate.JsonSerialize;

public class PojoMapper {
	private static final ObjectMapper objectMapper = new ObjectMapper();
	private static final JsonFactory jsonFactory = new JsonFactory();
	private static final String JSON_DATE_FROMATE = "yyyy-MM-dd HH:mm:ss";
	static{
		SimpleDateFormat dateFormate = new SimpleDateFormat(JSON_DATE_FROMATE);
		objectMapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
		objectMapper.getSerializationConfig().setDateFormat(dateFormate);//the withDateFormate method can not effect
		objectMapper.getDeserializationConfig().setDateFormat(dateFormate);
		objectMapper.getSerializationConfig().set(SerializationConfig.Feature.WRITE_ENUMS_USING_TO_STRING, true);
	}
    /**
     * deserializea a json string  to an object
     *  
     * @param <T>
     * @param jsonAsString
     * @param pojoClass
     * @return
     * @throws Exception
     */
	public static <T> T fromJson(String jsonAsString, Class<T> pojoClass)
			throws Exception {
		return (T)objectMapper.readValue(jsonAsString, pojoClass);
	}
	/**
	 * serializea an object  to  a json string
	 * @param pojo
	 * @param prettyPrint  if true,enabling pretty-printing using the default pretty printer
	 * @return
	 * @throws Exception
	 */
	public static String toJson(Object pojo, boolean prettyPrint)
			throws Exception {
		StringWriter sw = new StringWriter();
		JsonGenerator jg = jsonFactory.createJsonGenerator(sw);
		if (prettyPrint) {
			jg.useDefaultPrettyPrinter();
		}
		objectMapper.writeValue(jg, pojo);
		return sw.toString();
	}
	
	
	public static String toJson(Object pojo) throws Exception{
	  return toJson(pojo, false);
	}

}