Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Cell editing using a TreePickerItem

    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

    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();
    	}
    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

    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);
    	}
    
    }
    Thanks in advance for every help
    Kind regards
    Rod

    #2
    Still trying to wrap up my SmartGWT evaluation, and while I've been able to find a handful of threads where people were trying to do this, I haven't seen anyone actually say they were able to make it work...

    Is it safe to assume that for some reason, it doesn't work, or are we all just doing it wrong? :-)


    Thanks in advance.

    Comment


      #3
      This appears to be due to an interaction with the modalEditing feature of the grid.
      You should be able to work around it by calling 'setModalEditing(false)' on your editable ListGrid.

      Our engineering team is scheduled to look at the underlying issue in the near future.

      Comment

      Working...
      X