SmartGWT 3.1p-2012-11-23
SmartClient Version: v8.3p_2012-11-23/LGPL Development Only (built 2012-11-23)
Chrome 23, FF 6.0.2
However, if I add a second field to the tree:
Code:
final TreeGridField textField = new TreeGridField ("text", "Text", 200);
textField.setType (ListGridFieldType.TEXT);
...
treeGrid.setFields (nameField, textField);
1. The error does not present itself
2. The new column becomes editable, but not the first
So I changed the field name from "name" to "xname", and then F2 worked on column #1.
Full source:
Code:
import com.smartgwt.client.types.TreeModelType;
import com.smartgwt.client.types.ListGridFieldType;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.tree.Tree;
import com.smartgwt.client.widgets.tree.TreeGridField;
import com.smartgwt.client.widgets.tree.TreeGrid;
import com.smartgwt.client.widgets.tree.TreeNode;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
public class TreeGridEditOnF2Keypress implements EntryPoint {
// my attributes
int nextNodeId = 1;
/**
* The EntryPoint interface
* http://forums.smartclient.com/showthread.php?t=24124
*/
public void onModuleLoad () {
// configure Tree
final Tree tree = new Tree ();
tree.setModelType (TreeModelType.PARENT);
tree.setNameProperty ("name");
tree.setIdField ("nodeId");
tree.setParentIdField ("parentNodeId");
final TreeGridField nameField = new TreeGridField ("xname", "Name", 200);
nameField.setType (ListGridFieldType.TEXT);
final TreeGridField textField = new TreeGridField ("text", "Text", 200);
textField.setType (ListGridFieldType.TEXT);
// configure TreeGrid
final TreeGrid treeGrid = new TreeGrid ();
treeGrid.setWidth (500);
treeGrid.setHeight (300);
treeGrid.setCanEdit (true);
treeGrid.setEditOnF2Keypress (true);
treeGrid.setFields (nameField, textField);
treeGrid.setData (tree);
// add a few nodes, folders and nodes
addTreeNode (tree, true, "C");
addTreeNode (tree, true, "A");
addTreeNode (tree, false, "B");
addTreeNode (tree, false, "D");
// add abutton to specifically call startEditing () which seems to throw a different exceptions
final IButton startEditingButton = new IButton ("startEditing ()");
startEditingButton.addClickHandler (new ClickHandler () {
public void onClick (final ClickEvent event) {
final int rowNum = 1;
final int colNum = 0;
final Boolean suppressFocus = null;
GWT.log ("calling startEditing (" + rowNum + ", " + colNum + ", " + suppressFocus + ")");
treeGrid.startEditing (rowNum, colNum, suppressFocus);
}
});
// layout
final HLayout layout = new HLayout ();
layout.addMember (treeGrid);
layout.addMember (startEditingButton);
layout.show ();
}
/**
* Helper: uniformely adds the given TreeNode
* @param tree
* @param isFolder
* @param name
*/
private void addTreeNode (
final Tree tree,
final boolean isFolder,
final String name) {
nextNodeId ++;
final TreeNode treeNode = new TreeNode ();
treeNode.setAttribute ("nodeId", nextNodeId);
treeNode.setAttribute ("parentNodeId", 1); // hard-coded
treeNode.setAttribute ("xname", name);
treeNode.setAttribute ("text", "Text - " + name);
treeNode.setIsFolder (isFolder);
final TreeNode rootTreeNode = tree.getRoot ();
tree.add (treeNode, rootTreeNode);
}
}
Leave a comment: