Announcement

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

    TreeNode title disappearing

    Using 5.0-p20150731 PowerEdition/Browser: Chrome

    We have a Treenode that shows the Title and a SelectItem (or TextItem) on the children.
    When we change the SelectItem and click anywhere outside, the title of this node disappears. However, the title does not disappear when we fill the TextItem.
    We found the problem when we are trying to create a simple text by removing the following line:
    selectItem.setAddUnknownValues(false);

    Code:
     
    
    	private VLayout mainLayout = new VLayout();
    	private Canvas canvas = new Canvas();
    
    	private TreeNode createNode(String name, String id, String parentId, int type) {
    		TreeNode node = new TreeNode();
    		node.setID(id);
    		node.setAttribute("Name", name);
    		node.setAttribute("VehicleBehaviorId", id);
    		node.setAttribute("ActionType", type);
    		node.setAttribute("ParentId", parentId);
    		node.setEnabled(true);
    		return node;
    	}
    
    
    	public Form() {
    		Map<String, String> codeValueMap = new LinkedHashMap<String, String>();
    		codeValueMap.put("0", "Select...");
    		codeValueMap.put("1", "Option 1");
    		codeValueMap.put("2", "Option 2");
    		
    		Tree tree = new Tree();
    		tree.setModelType(TreeModelType.PARENT);
    		tree.setNameProperty("Name");
    		tree.setIdField("VehicleBehaviorId");
    		tree.setParentIdField("ParentId");
    		tree.setData(new TreeNode[] {
    				// Motor
    				createNode("Parent", "id", "1", 0),
    				createNode("Select an option here ->", "id1", "id", 1),
    				createNode("Then, click here ->", "id2", "id", 2)  });
    
    		TreeGrid treeGrid = new TreeGrid();
    		treeGrid.setWidth100();
    		treeGrid.setHeight100();
    		treeGrid.setEditOnFocus(true);
    
    		TreeGridField nameField = new TreeGridField("Name");
    		nameField.setWidth("60%");
    		
    		final TreeGridField actionField = new TreeGridField("Value");
    		actionField.setWidth("40%");
    		actionField.setCanEdit(true);
    		actionField.setValueMap(codeValueMap);
    
    		treeGrid.setData(tree);
    		treeGrid.getTree().openAll();
    		treeGrid.setFields(nameField, actionField);
    		treeGrid.setEditorCustomizer(new ListGridEditorCustomizer() {
    			@Override
    			public FormItem getEditor(ListGridEditorContext context) {
    				Record rec = context.getEditedRecord();
    				int type = rec.getAttributeAsInt("ActionType");
    				switch (type) {
    				case 0:
    					return null;
    				case 1:
    					SelectItem selectItem = new SelectItem();
    					selectItem.setAddUnknownValues(false);
    					return selectItem;
    				default:
    					return new TextItem();
    				}
    			}
    		});
    
    		canvas.setHeight100();
    		canvas.addChild(treeGrid);
    
    		mainLayout.setWidth100();
    		mainLayout.setHeight100();
    		mainLayout.addMember(canvas);
    
    		this.addChild(mainLayout);
    	}

    #2
    This is an expected consequence of your code, which doesn't make sense: you've created a SelectItem for editing the node title, but it has not been given a valueMap and it disallows any items not in the valueMap. So any attempt to interact with the SelectItem will necessarily force the value to null, thus causing the node's title to disappear.

    Comment


      #3
      The valueMap is set when we call: actionField.setValueMap(codeValueMap);

      Actually we've created a node with 2 fields: The name and the action (SelectItem):
      treeGrid.setFields(nameField, actionField);

      Changing the SelectItem is clearing the Name field.

      Comment


        #4
        Yes, you provided a valueMap on the field. You did not provide a valueMap for the SelectItem - it needs one.

        Comment

        Working...
        X