Go Back   SmartClient Forums > Smart GWT Technical Q&A
Wiki Register Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 2nd May 2012, 20:08
ls3674 ls3674 is offline
Registered Developer
 
Join Date: Sep 2011
Posts: 129
Default Accessing Record Components in a ListGrid

SmartClient Version: v8.2p_2012-04-26/PowerEdition Deployment (built 2012-04-26)

I have a ListGrid with a custom component of a form with three controls. When an update occurs, the new record is pushed to the datasource cache, and the ListGrid component is redrawn.

When this redraw occurs, the state of the checkbox and the colorpicker in the ListGridField are lost. These fields are not part of the datasource. They are meant for manipulating information that is only relevant on the client, and need not be persisted.

I started to search for a way to traverse the components in the the listgrid, but I couldn't seem to find anything in the documentation that was made for such a thing (basically a for in loop that would allow me to access ListGridFields and their children, e.g. checkboxitem and reset its state).

It appeared that using the recordPoolingMode of RECYCLE might help me accomplish this. However, when implementing that setting, strange behavior occurs in the ListGrid fields. Sometimes the checkboxitem is checked and sometimes it is not.

What would you recommend doing to either keep state even through an update/redraw or traverse the ListGridFields and get access to their children so that I can set the sate of those items? The second option is more preferable, if possible, because it will assist for similar use cases in the application.

Code:
@Override
    protected Canvas createRecordComponent(final ListGridRecord record, Integer colNum)
    {
        String fieldName = this.getFieldName(colNum);
        String creator = record.getAttribute("creatorName");
        setRecordComponentPoolingMode(RecordComponentPoolingMode.RECYCLE);

        if(fieldName.equals("viewField"))
        {
            HLayout recordCanvas = new HLayout();
            recordCanvas.setWidth100();
            recordCanvas.setHeight(22);
            recordCanvas.setAlign(Alignment.CENTER);

            DynamicForm dfOptions = new DynamicForm();
            dfOptions.setWidth("80%");
            dfOptions.setHeight(22);
            dfOptions.setNumCols(8);

            ButtonItem biDelete = new ButtonItem();
            biDelete.setWidth(22);
            biDelete.setHeight(22);
            biDelete.setColSpan(2);
            biDelete.setIcon("[SKIN]/actions/remove.png");
            biDelete.setEndRow(false);
            biDelete.setStartRow(false);
            if(!GSUI.getUserInfo().getPrincipal().equals(record.getAttributeAsString("creatorName")))
            {
                biDelete.setDisabled(true);
            }
            else
            {
                biDelete.addClickHandler(new com.smartgwt.client.widgets.form.fields.events.ClickHandler()
                {
                    @Override
                    public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent clickEvent)
                    {
                        if(listener != null)
                        {
                            listener.onDeleteStream(record.getAttributeAsInt("id"));
                        }
                    }
                });
            }

            CheckboxItem cbiShow = new CheckboxItem();
            cbiShow.setTitle("");
            cbiShow.setWidth(22);
            cbiShow.setHeight(22);
            cbiShow.setColSpan(2);
            cbiShow.setEndRow(false);
            cbiShow.setStartRow(false);
            cbiShow.addChangedHandler(new ChangedHandler()
            {
                @Override
                public void onChanged(ChangedEvent changedEvent)
                {
                    if(listener != null)
                    {
                        CheckboxItem cbi = (CheckboxItem) changedEvent.getSource();
                        listener.onDisplayCheckChange(cbi.getValueAsBoolean(), record);
                    }
                }
            });

            ColorPickerItem cpiRectangleColor = new ColorPickerItem();
            cpiRectangleColor.setTitle("");
            cpiRectangleColor.setWidth(22);
            cpiRectangleColor.setHeight(22);
            cpiRectangleColor.setColSpan(2);
            cpiRectangleColor.setTextBoxStyle("");
            cpiRectangleColor.setEndRow(false);
            cpiRectangleColor.setStartRow(false);
            cpiRectangleColor.addChangedHandler(new ChangedHandler()
            {
                @Override
                public void onChanged(ChangedEvent changedEvent)
                {
                    ColorPickerItem cpi = (ColorPickerItem) changedEvent.getSource();
                    int id           = record.getAttributeAsInt("id");
                    String hex       = RegexHelper.stripNonAlphaNumericChars(cpi.getValueAsString());
                    long fillColor   = Integer.valueOf(hex,16).intValue() * 256 + 127;  //convert to rgba with .5 opacity
                    long borderColor = Integer.valueOf("000000",16).intValue() * 256 + 255; //rgb black
                    int borderWidth  = 2;
                    listener.onRectangleColorSwatchChanged(id,fillColor,borderColor,borderWidth);
                }
            });

            dfOptions.setItems(cbiShow, cpiRectangleColor, biDelete);
            
            recordCanvas.addMember(dfOptions);
            return recordCanvas;
        }
        else
        {
            return null;
        }
    }
Reply With Quote
  #2  
Old 3rd May 2012, 13:17
Isomorphic Isomorphic is online now
Administrator
 
Join Date: May 2006
Posts: 30,595
Default

See the docs for RECYCLE mode - if you aren't updating the component properly when updateRecordComponent is called, strange behavior would occur.

As far as accessing recordComponents, you can keep track of them in a simple Map keyed by the rowNum - just update it whenever you return a recordComponent from createRecordComponent or updateRecordComponent.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads
Thread Thread Starter Forum Replies Last Post
CanvasItem value management markok Smart GWT Technical Q&A 60 13th Apr 2013 12:59
ListGrid record components jpappalardo Smart GWT Technical Q&A 14 12th Apr 2012 05:43
ListGrid: record components and new record in grid martintaal Technical Q&A 1 25th Jan 2011 16:17
ListGrid add operation that affects more than one record RHelgeson Technical Q&A 3 22nd Apr 2009 19:52
Add a record to a listgrid with out saving into DB the moment addData() is called. srividhya_v@infosys.com Technical Q&A 7 5th Mar 2008 10:36

© 2010,2011 Isomorphic Software. All Rights Reserved