Announcement

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

    SimpleType on TreeGrid first column

    Hi,

    v8.3d_2012-11-11/Pro Deployment (built 2012-11-11)

    It seems the value passed for the first column (where the tree connectors are) is passed differently than the other columns to the SimpleType.
    The display fomatter is hit, but the incoming value isn't a JSO anymore.
    The screenshot might make things clear. I would expect the same text in "name" as in "anotherName".


    Simple repro:
    Two fields (NAME, ANOTHERNAME) of the same SimpleType and same value. The 2nd field is correct.

    Code:
    private class MyType extends SimpleType {
    	//1. Test without JavaScriptObject as value for FIELD_NAME, FIELD_OTHER
    	//   OK: the TreeGrid name column uses the setShortDisplayFormatter
    	//2. Test with JavaScriptObject as value for FIELD_NAME, FIELD_OTHER
    	//   NOK: the TreeGrid name column shows [object Object]
    	
    	public static final String FIELD_REF = "ref";
    	public static final String FIELD_DESC = "desc";
    	
    	
    	public MyType() {
    		super("mine", FieldType.ANY);
    
    		setShortDisplayFormatter(new SimpleTypeFormatter() {
    			
    			public String format(Object value, DataClass field, DataBoundComponent component, Record record) {
    				if (value == null) return null;
    				
    				if (value instanceof JavaScriptObject) {
    					JavaScriptObject jso = (JavaScriptObject)value;
    					String ref = JSOHelper.getAttribute(jso, FIELD_REF);
    					if (ref != null && ref.length() > 0) return "Product ref# " + String.valueOf(ref);
    					String desc = JSOHelper.getAttribute(jso, FIELD_DESC);
    					return desc;
    				}
    				// an else should never happen
    				
    				return "NOT A JSO: " + String.valueOf(value);
    			}
    		});
    	}
    }
    
    private static final String FIELD_SELECTED = "_selectMe";
    private static final String FIELD_ID = "id";
    private static final String FIELD_NAME = "name";
    private static final String FIELD_OTHER = "anotherName";
    private static final String FIELD_PARENT = "parent";
    
    public Canvas getViewPanel() {
    	new MyType().register();
    	
    	TreeGrid grid = new TreeGrid();
    	grid.setCanSort(false);
    	grid.setCanEdit(false);
    	grid.setHeight(300);
    	grid.setShowPartialSelection(true);
    	grid.setCascadeSelection(true);
    	grid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
    	grid.setSelectionProperty(FIELD_SELECTED);
    	grid.setShowSelectedStyle(false);
    	grid.setFixedRecordHeights(false);
    	grid.setWrapCells(true);	
    	
    	ListGridField field1 = new ListGridField(FIELD_ID);
    	ListGridField field2 = new ListGridField(FIELD_NAME);
    	field2.setAttribute("type", "mine");
    	ListGridField field3 = new ListGridField(FIELD_OTHER);
    	field3.setAttribute("type", "mine");
    	ListGridField field4 = new ListGridField(FIELD_PARENT);
    	field4.setHidden(true);
    	grid.setFields(field2, field3, field1, field4);
    	
    	TreeNode rootNode = new TreeNode();
    	int rootNodeID = 0;
    	rootNode.setAttribute(FIELD_ID, rootNodeID);
    	rootNode.setAttribute(FIELD_NAME, "root");
    
    	TreeNode [] records = new TreeNode[13];
    	for (int i=0; i<records.length; i++) {
    		records[i] = new TreeNode();
    		records[i].setAttribute(FIELD_ID, (i+1));
    		JavaScriptObject jso = JSOHelper.createObject();
    		JSOHelper.setAttribute(jso, MyType.FIELD_DESC, "This is sample #" + (i+1));
    		JSOHelper.setAttribute(jso, MyType.FIELD_REF, "CAT " +   (10000 + (i+1))  );
    		records[i].setAttribute(FIELD_NAME, jso);
    		
    		jso = JSOHelper.createObject();
    		JSOHelper.setAttribute(jso, MyType.FIELD_DESC, "rec " + (i+1));
    		JSOHelper.setAttribute(jso, MyType.FIELD_REF, "CAT " +   (10000 + (i+1))  );
    		records[i].setAttribute(FIELD_OTHER, jso);
    		
    		records[i].setAttribute(FIELD_SELECTED, i % 3 == 0 ? true : false);
    		records[i].setAttribute(FIELD_PARENT, i/2);
    	}
    	
    	Tree dataTree = new Tree();
    	dataTree.setModelType(TreeModelType.PARENT);
    	dataTree.setIdField(FIELD_ID);
    	dataTree.setParentIdField(FIELD_PARENT);
    	dataTree.setNameProperty(null); //no name, built in fallback is ID
    	dataTree.setAutoOpenRoot(true);
    	dataTree.setReportCollisions(false);
    	dataTree.setShowRoot(false);
    	dataTree.setAutoOpenRoot(true);
    	dataTree.setRoot(rootNode);
    	dataTree.setData(records);
    	grid.setData(dataTree);
    	
    	VLayout layout = new VLayout();
    	layout.setWidth100();
    	layout.setMembers(grid);
    	return layout;
    }

    tia,
    Attached Files

    #2
    Just a quick update to let you know we have a developer looking at this

    Regards
    Isomorphic Software

    Comment


      #3
      This issue is now resolved. Please try the next nightly build (3.1p and 4.0d branches)

      Regards
      Isomorphic Software

      Comment


        #4
        Thanks for fixing,
        verified OK in v8.3p_2012-11-30/Pro Deployment (built 2012-11-30)

        Comment

        Working...
        X