This Question is Assumed Answered

1 "correct" answer available (5 pts) 15 "helpful" answers available (3 pts)
7 Replies Last post: Sep 4, 2008 6:07 PM by carl

Regarding RecordGridCell

Sep 3, 2008 6:38 AM

Click to view varshuj's profile Level 3 varshuj 44 posts since
Mar 6, 2008

Hi,

Can i add image in a RecordGridCell without using cell-spec for that particular RecordGridColumn?

Thanks

varsha

Click to view Duke's profile Curl Duke 154 posts since
Oct 17, 2007
1. Re: Regarding RecordGridCell Sep 3, 2008 5:31 PM
The answer is no. You can use cell-spec as in the FlagCell example given in the RecordGrid documentation.
Click to view carl's profile Curl carl 74 posts since
Oct 17, 2007
2. Re: Regarding RecordGridCell Sep 3, 2008 5:33 PM
No. None of the standard cells would allow you to directly add an image. They're mostly designed for editing purposes.

It's not hard to do, though. The RecordGrid chapter in the documentation has an example; see Creating a Custom Cell.
Click to view URPradhan's profile Level 7 URPradhan 141 posts since
Mar 6, 2008
3. Re: Regarding RecordGridCell Sep 3, 2008 10:09 PM
I think you can not add an image to a cell with out cell-spec. But why you need an another way ? Can you plz explain what is your requirement ?
Click to view varshuj's profile Level 3 varshuj 44 posts since
Mar 6, 2008
4. Re: Regarding RecordGridCell Sep 3, 2008 11:32 PM
in response to: URPradhan
In my recordgrid I need 2 columns with images.
From these 2 columns one column image NEVER changes and
another column image MAY change depending upon the need and on PointerPress event.

So when I'm implementing cell-spec in both cases the method "refresh-data" is getting called for ALL records in the grid.
Hence "refresh-data" call for the STATIC (which image will not change) column for all records is an OVERHEAD and unnecessary.

because I run the profiler and found that 60% time is consumed by refresh-data
So how to prevent the "refresh-data" function call for the STATIC column and for all records ?


Thanks
varsha

Click to view carl's profile Curl carl 74 posts since
Oct 17, 2007
5. Re: Regarding RecordGridCell Sep 4, 2008 1:01 AM
in response to: varshuj
Even if your column is "static", the cells in it aren't. If you have more records than fit in the displayed area, then when you scroll, the same cells are reused to display the content of the new records now in view. If you don't refresh, the cell content will not be in sync with the record data anymore.

Now, refresh-data doesn't have to do anything if it doesn't need to. It's a notification method that's going to get called a lot, and if you have a custom cell you can decide when to actually have it do work. If your cell is totally static, as in every cell displays the same image for that column, you don't have to do anything in refresh-data; you could just immediately return on every call after the first.

If performance is really an issue in your case, perhaps there are operations that you could cache or optimize within the refresh-data? For example, the cell could cache the image displayed and its generating data, and only regenerate the image when the data meaningfully changes. An external cache could be used to share resources and avoid needless regeneration, etc. Those answers depend on your particular cell's goals.
Click to view varshuj's profile Level 3 varshuj 44 posts since
Mar 6, 2008
6. Re: Regarding RecordGridCell Sep 4, 2008 6:31 AM
in response to: carl

hi,

Thanks for reply :)

Would you please elaborate from your previeous reply,

+ the cell could cache the image displayed and its generating data, and
only regenerate the image when the data meaningfully changes. An
external cache could be used to share resources and avoid needless
regeneration,
+

My final goal is to optimize the code,

On PointerPress event and on CommandButtonClick RecordGridCell image should be changed,

But it should not be unnecessarily called for ALL records in the grid.


Thanks

varsha :)

Click to view carl's profile Curl carl 74 posts since
Oct 17, 2007
7. Re: Regarding RecordGridCell Sep 4, 2008 6:07 PM
in response to: varshuj
Well, it depends a great deal on your particular data and display purposes.

For example, let's say the record data associated with a given cell is a string, and that string looks up one of a limited number of images that are generated on or downloaded to the client. You could keep a {HashTable-of String, Pixmap} and all the cells displaying these images could look up the image by its String in this one table. Something along these lines (not a real code sample):

{method public open {refresh-data}:void
    {super.refresh-data}
    let constant (str:String, valid?:bool) = {self.get-formatted-data}
    {if not valid? then
        {self.remove-the-pixmap}
        {return}
    }
    let constant (pixmap:Pixmap, valid?:bool) = {the-cache.get-if-exists str}
    {if valid? then
        {if pixmap == self.displayed-pixmap then
            {return}
         else
            {self.display-the-pixmap pixmap}
        }
     else
        {self.make-and-display-pixmap str}
    }
}

Now, it sounds like you have two displayed modes for the cell, one normally and another for when it's clicked on. So you would want to have a list of cells in the alternate display mode, and that list should use a record-based identifier, not point to the exact cell(s), so that it will be valid if the RecordGridUI changes something. On a click, you can just change the cell's contents with some custom method, but you'll need to check the list on every refresh-data, because again, the cell may end up displaying another record, and you probably don't want to keep the alternate display for the new record.

So, modifying the above example and assuming that the alternate display mode shows a different Pixmap:


{method public open {refresh-data}:void
    {super.refresh-data}
    let constant (str:String, valid?:bool) = {self.get-formatted-data}
    {if not valid? then
        {self.remove-the-pixmap}
        {return}
    }
    let constant id:int =
        {if-non-null record = self.record then
            {record.get "unqiue-index-field"} asa int
         else
            -1
        }
    let constant the-cache:{HashTable-of String, Pixmap} =
        {if {the-list-of-alt-records.find id} == -1 then
            main-pixmap-cache
         else
            alternate-pixmap-cache
        }
    let constant (pixmap:Pixmap, valid?:bool) = {the-cache.get-if-exists str}
    {if valid? then
        {if pixmap == self.displayed-pixmap then
            {return}
         else
            {self.display-the-pixmap pixmap}
        }
     else
        {self.make-and-display-pixmap str, the-cache}
    }
}


But again, it really depends on your data, and there are a number of possible solutions. This is just one general way of going about it.