TreeGrid treeGrid = null;
TreeNode rootNode = null;
private TreeGrid getTree() {
// EmployeeXmlDS employeesDS = EmployeeXmlDS.getInstance();
rootNode = new TreeNode();
rootNode.setAttribute(Name, "Root");
rootNode.setAttribute(Name1, "Root1");
rootNode.setAttribute(Type, Sequence);
rootNode.setAttribute(Min, 1);
rootNode.setAttribute(Max, 1);
Tree tree = new Tree();
tree.setModelType(TreeModelType.PARENT);
tree.setRootValue(1);
tree.setNameProperty("Name1");
tree.setOpenProperty("isOpen");
tree.setData(new TreeNode[] { rootNode });
treeGrid = new TreeGrid();
treeGrid.setData(tree);
treeGrid.setCanReorderRecords(true);
treeGrid.setCanAcceptDroppedRecords(true);
// treeGrid.setCanDragResize(true);
treeGrid.setCanEdit(true);
treeGrid.setLoadDataOnDemand(false);
treeGrid.setWidth(handleHorizontal(870));
treeGrid.setHeight(handleVertical(290));
// treeGrid.setDataSource(employeesDS);
treeGrid.setNodeIcon("http://xml-it.appspot.com/icons/16/person.png");
treeGrid.setFolderIcon("http://xml-it.appspot.com/icons/16/person.png");
treeGrid.setShowOpenIcons(false);
treeGrid.setShowDropIcons(false);
treeGrid.setClosedIconSuffix("");
// treeGrid.setAutoFetchData(true);
TreeGridField nameField = new TreeGridField("Name", handleHorizontal(
650, 900));
nameField.setCanSort(false);
RegExpValidator elementName = new RegExpValidator();
elementName.setErrorMessage("Invalid name for XML element");
elementName.setExpression("^([a-zA-Z])+([a-zA-Z0-9\\-_\\.])*");
nameField.setValidators(elementName);
TreeGridField typeField = new TreeGridField(Type, 60);
typeField.setCanSort(false);
TreeGridField minField = new TreeGridField(Min, 30);
minField.setCanSort(false);
TreeGridField maxField = new TreeGridField(Max, 30);
maxField.setCanSort(false);
maxField.setType(ListGridFieldType.INTEGER);
minField.setType(ListGridFieldType.INTEGER);
TreeGridField prefix = new TreeGridField(Prefix, 40);
prefix.setCanSort(false);
TreeGridField suffix = new TreeGridField(Suffix, 40);
suffix.setCanSort(false);
typeField.setValueMap(Sequence, Choice, Simple);
treeGrid.setFields(nameField, typeField, minField, maxField, prefix,
suffix);
treeGrid.addSelectionChangedHandler(new SelectionChangedHandler() {
@Override
public void onSelectionChanged(SelectionEvent event) {
TreeNode selection = (TreeNode) treeGrid.getSelectedRecord();
if (selection == null)
return;
handleSelection(selection);
}