Hi all,
I'm trying to define a custom cell editor on a ListGrid. The custom editor type should be a "PickTreeItem". after i set the editor type, the cell doesn't more edit.
Here is My Code
Notice that i call this method from method EntryPoint#onModuleLoad().
I'm using the tree from the show case here is the class for it
Thanks in advance for every help
Kind regards
Rod
I'm trying to define a custom cell editor on a ListGrid. The custom editor type should be a "PickTreeItem". after i set the editor type, the cell doesn't more edit.
Here is My Code
Code:
private void testCustomEditor() { VLayout main = new VLayout(3); main.setWidth(500); main.setHeight(500); main.setLayoutMargin(20); Button addButton = new Button("Add"); Button removeButton = new Button("Remove"); HLayout buttonsPanel = new HLayout(3); buttonsPanel.setAlign(Alignment.RIGHT); buttonsPanel.setMembers(addButton, removeButton); buttonsPanel.setWidth100(); buttonsPanel.setHeight(20); main.addMember(buttonsPanel); final PickTreeItem pickerTreeItem = new PickTreeItem(); final Tree tree = new Tree(); tree.setRoot(DepartmentTreeNode.departmentRoot); pickerTreeItem.setValueTree(tree); final ListGrid listGrid = new ListGrid(); ListGridField nameField = new ListGridField(FIELD_NAME, "Name"); nameField.setType(ListGridFieldType.TEXT); nameField.setHidden(false); nameField.setEditorType(pickerTreeItem); listGrid.setFields(nameField); listGrid.setWidth100(); main.addMember(listGrid); // DynamicForm form = new DynamicForm(); // form.setItems(pickerTreeItem); // main.addMember(form); nameField.addEditorEnterHandler(new EditorEnterHandler() { @Override public void onEditorEnter(EditorEnterEvent event) { GWT.log(" record: " + event.getRecord(), null); } }); nameField.setCellFormatter(new CellFormatter() { @Override public String format(Object value, ListGridRecord record, int rowNum, int colNum) { GWT.log("value: " + value + " record: " + record, null); if (record != null) { GWT.log("record.name: " + record.getAttributeAsString(FIELD_NAME), null); } int index = value.toString().lastIndexOf("/"); if (index < 0) return value.toString(); return value.toString().substring(index + 1); // return value.toString() + "1"; // return ((TreeNode) value).getName(); } }); addButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { Map<String, Object> defaultValues = new HashMap<String, Object>(); defaultValues.put(FIELD_NAME, "root/Marketing"); // pickerTreeItem.setValue("root/Marketing"); // GWT.log("value: " + pickerTreeItem.getValue(), null); // defaultValues.put(FIELD_NAME, tree.getPath(DepartmentTreeNode.departmentRoot)); try { listGrid.startEditingNew(defaultValues); }catch (Exception e) { GWT.log("daaf", e); } } }); removeButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { listGrid.removeSelectedData(); } }); main.draw(); }
I'm using the tree from the show case here is the class for it
Code:
public class DepartmentTreeNode extends TreeNode { public static final TreeNode departmentRoot = new DepartmentTreeNode( "root", new DepartmentTreeNode("Marketing", new DepartmentTreeNode( "Advertising"), new DepartmentTreeNode( "Community Relations")), new DepartmentTreeNode("Sales", new DepartmentTreeNode("Channel Sales"), new DepartmentTreeNode("Direct Sales")), new DepartmentTreeNode("Manufacturing", new DepartmentTreeNode( "Design"), new DepartmentTreeNode("Development"), new DepartmentTreeNode("QA")), new DepartmentTreeNode( "Services", new DepartmentTreeNode("Support"), new DepartmentTreeNode("Consulting"))); public DepartmentTreeNode(String name) { setName(name); } public DepartmentTreeNode(String name, DepartmentTreeNode... children) { setName(name); setChildren(children); } }
Kind regards
Rod
Comment