Re: [SPAM] [flexcoders] Obtaining rendered text from a DataGrid
--- In flexcoders@yahoogroups.com, Mike msl...@... wrote: I must take the DataGrid as I find it. If no labelFunction is defined, that approach won't work; also each item in the dataProvider might be manifested in 0 or more columns. This approach probably won't be general enough. Do you have enough control in the project to ask that the Value Objects in the DataProvider implement a common interface? Then just have a getter defined by the interface that says what the rendered row should look like. I haven't had good luck instantiating renderers by hand, especially ones that fully implement IDropInListItemRenderer, and you're goingto run into several problems trying to do this: 1) Performance: Creating an object is usually the biggest processor hit. Multiply this across multiple columns, and you are likely to have a slowdown. 2) Timing: It's not like you can just create the renderers and immediately start reading through them for text. You'll need to wait until everthing is complete and all the properties are set, so you're going to have to pass things back and forth between multiple event handlers. 3) Depth: Since you have no control over the renderers, you don't have any way of knowing whether they're composed of containers within containers, etc. 4) Layout: Presumably, you want to have the text appear in the same order it appears in the columns, and then within the individual renderers. There's no guarantee that your iteration will go from top left to bottom right, so you'll have to record where the text was found and then arrange it in some way that tries to make sense (but may not, depending on what is going on in the renderers). 5) Random surprises from the renderer developers. If the renderer developer makes a reference to its parent, owner, or something else like that and you instantiate it in a way that doesn't involve a List of some sort, you may wind up with Null Pointer Exceptions. They may come up with other stuff that won't come up in your testing with reasonable renderers that you wrote, but it will be your fault when they do something stupid and YOUR logic errors out. In short, you have to work together with your other team members one way or another to make this work. Why not just shortcut to the most performant method? -Amy
Re: [SPAM] [flexcoders] Obtaining rendered text from a DataGrid
I have no control over the dataProvider at all. Performance is not an issue, because the data extraction only happens once, and it can be time-sliced it so the webapp does not appear to freeze. Passing through multiple event handlers, including EnterFrame would be perfectly acceptable. 3) Depth: Since you have no control over the renderers, you don't have any way of knowing whether they're composed of containers within containers, etc. True. The routine needs to deal with that. 4) Layout: Presumably, you want to have the text appear in the same order it appears in the columns, and then within the individual renderers. There's no guarantee that your iteration will go from top left to bottom right, so you'll have to record where the text was found and then arrange it in some way that tries to make sense (but may not, depending on what is going on in the renderers). Yes, doing this right will be a lot of work. 5) Random surprises from the renderer developers. If the renderer developer makes a reference to its parent, owner, or something else like that and you instantiate it in a way that doesn't involve a List of some sort, you may wind up with Null Pointer Exceptions. They may come up with other stuff that won't come up in your testing with reasonable renderers that you wrote, but it will be your fault when they do something stupid and YOUR logic errors out. Yep, that is true. In short, you have to work together with your other team members one way or another to make this work. There are no other team members. This is a library routine. I want this to be as general as possible, and am prepared to do what it takes to make it work properly. Why not just shortcut to the most performant method? Performance is not important, general utility is important. The library feature should just work, no excuses.
RE: [SPAM] Re: [SPAM] [flexcoders] Obtaining rendered text from a DataGrid
If you can get what you need easily from a rendered renderer, then it sounds like the hidden DG with all of the rows rendered might be the way to go. Tracy Spratt, Lariat Services, development services available _ From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf Of Mike Sent: Saturday, February 13, 2010 2:10 PM To: flexcoders@yahoogroups.com Subject: [SPAM] Re: [SPAM] [flexcoders] Obtaining rendered text from a DataGrid I have no control over the dataProvider at all. Performance is not an issue, because the data extraction only happens once, and it can be time-sliced it so the webapp does not appear to freeze. Passing through multiple event handlers, including EnterFrame would be perfectly acceptable. 3) Depth: Since you have no control over the renderers, you don't have any way of knowing whether they're composed of containers within containers, etc. True. The routine needs to deal with that. 4) Layout: Presumably, you want to have the text appear in the same order it appears in the columns, and then within the individual renderers. There's no guarantee that your iteration will go from top left to bottom right, so you'll have to record where the text was found and then arrange it in some way that tries to make sense (but may not, depending on what is going on in the renderers). Yes, doing this right will be a lot of work. 5) Random surprises from the renderer developers. If the renderer developer makes a reference to its parent, owner, or something else like that and you instantiate it in a way that doesn't involve a List of some sort, you may wind up with Null Pointer Exceptions. They may come up with other stuff that won't come up in your testing with reasonable renderers that you wrote, but it will be your fault when they do something stupid and YOUR logic errors out. Yep, that is true. In short, you have to work together with your other team members one way or another to make this work. There are no other team members. This is a library routine. I want this to be as general as possible, and am prepared to do what it takes to make it work properly. Why not just shortcut to the most performant method? Performance is not important, general utility is important. The library feature should just work, no excuses.
Re: [SPAM] Re: [SPAM] [flexcoders] Obtaining rendered text from a DataGrid
Except the memory implications of rendering every row must be considered. And I still haven’t figured out what you’d do for renderers that don’t display any text. And I’m pretty sure I could write a renderer that you could never figure out which children have text. But given all that, then start copying code from DataGridBase.as. CreateColumnItemRenderer, setupItemRenderer and some calls to validateNow should get the renderer in its “final state”, and code in FocusManager, addFocusables walks children in the two known ways of figuring out your children. If you run into TextFields, pull their text or htmlText and if you run into TextLines Not sure what you’ll do there. On 2/13/10 11:22 AM, Tracy Spratt tr...@nts3rd.com wrote: If you can get what you need easily from a “rendered” renderer, then it sounds like the hidden DG with all of the rows rendered might be the way to go. Tracy Spratt, Lariat Services, development services available From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf Of Mike Sent: Saturday, February 13, 2010 2:10 PM To: flexcoders@yahoogroups.com Subject: [SPAM] Re: [SPAM] [flexcoders] Obtaining rendered text from a DataGrid I have no control over the dataProvider at all. Performance is not an issue, because the data extraction only happens once, and it can be time-sliced it so the webapp does not appear to freeze. Passing through multiple event handlers, including EnterFrame would be perfectly acceptable. 3) Depth: Since you have no control over the renderers, you don't have any way of knowing whether they're composed of containers within containers, etc. True. The routine needs to deal with that. 4) Layout: Presumably, you want to have the text appear in the same order it appears in the columns, and then within the individual renderers. There's no guarantee that your iteration will go from top left to bottom right, so you'll have to record where the text was found and then arrange it in some way that tries to make sense (but may not, depending on what is going on in the renderers). Yes, doing this right will be a lot of work. 5) Random surprises from the renderer developers. If the renderer developer makes a reference to its parent, owner, or something else like that and you instantiate it in a way that doesn't involve a List of some sort, you may wind up with Null Pointer Exceptions. They may come up with other stuff that won't come up in your testing with reasonable renderers that you wrote, but it will be your fault when they do something stupid and YOUR logic errors out. Yep, that is true. In short, you have to work together with your other team members one way or another to make this work. There are no other team members. This is a library routine. I want this to be as general as possible, and am prepared to do what it takes to make it work properly. Why not just shortcut to the most performant method? Performance is not important, general utility is important. The library feature should just work, no excuses. -- Alex Harui Flex SDK Team Adobe System, Inc. http://blogs.adobe.com/aharui
[SPAM] Re: [SPAM] [flexcoders] Obtaining rendered text from a DataGrid
Because this is an library for exporting to other formats I only need to instantiate one renderer at a time. Memory requirements should therefore be modest. I have implemented a mechanism to export the display lists of non-text item renderers. The tricky part is learning how to instantiate any type of renderer on demand. Hopefully constructive suggestions will be forthcoming soon. Mike --- In flexcoders@yahoogroups.com, Alex Harui aha...@... wrote: Except the memory implications of rendering every row must be considered. And I still haven't figured out what you'd do for renderers that don't display any text. And I'm pretty sure I could write a renderer that you could never figure out which children have text. But given all that, then start copying code from DataGridBase.as. CreateColumnItemRenderer, setupItemRenderer and some calls to validateNow should get the renderer in its final state, and code in FocusManager, addFocusables walks children in the two known ways of figuring out your children. If you run into TextFields, pull their text or htmlText and if you run into TextLines Not sure what you'll do there.
Re: [SPAM] Re: [SPAM] [flexcoders] Obtaining rendered text from a DataGrid
My recommendation is to borrow code from DataGridBase On 2/13/10 5:21 PM, Mike msl...@mslinn.com wrote: Because this is an library for exporting to other formats I only need to instantiate one renderer at a time. Memory requirements should therefore be modest. I have implemented a mechanism to export the display lists of non-text item renderers. The tricky part is learning how to instantiate any type of renderer on demand. Hopefully constructive suggestions will be forthcoming soon. Mike --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com , Alex Harui aha...@... wrote: Except the memory implications of rendering every row must be considered. And I still haven't figured out what you'd do for renderers that don't display any text. And I'm pretty sure I could write a renderer that you could never figure out which children have text. But given all that, then start copying code from DataGridBase.as. CreateColumnItemRenderer, setupItemRenderer and some calls to validateNow should get the renderer in its final state, and code in FocusManager, addFocusables walks children in the two known ways of figuring out your children. If you run into TextFields, pull their text or htmlText and if you run into TextLines Not sure what you'll do there. -- Alex Harui Flex SDK Team Adobe System, Inc. http://blogs.adobe.com/aharui
RE: [SPAM] [flexcoders] Obtaining rendered text from a DataGrid
I will answer, but you probably won't like the answer. This is simply not possible. In order to optimize performance, DataGrid and the other list components only create(render) the visible elements. If a row is not visible, it does not exist. You can't look sideways into your tv screen and see beyond the edges. You must do wok like this using the dataProvider. What are you trying to do? Tracy Spratt, Lariat Services, development services available _ From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf Of Mike Sent: Friday, February 12, 2010 4:06 PM To: flexcoders@yahoogroups.com Subject: [SPAM] [flexcoders] Obtaining rendered text from a DataGrid I need extract the rendered text from all cells of a DataGrid, whether or not they are all displayed. The following code dies because renderer is null: public var dp:ArrayCollection = new ArrayCollection(); /** Obtain formatted text data from the DataGrid's dataProvider. * Other data generated by item renderers such as images are ignored. */ protected function extractData(originalComponent:*):void { var dg:DataGrid = DataGrid(originalComponent); for (var col:int=0; coldg.columnCount; col++) { var rowArray:Array = []; for (var row:int=0; rowdg.rowCount; row++) { var index:int = dg.indicesToIndex(row, col); var renderer:IListItemRenderer = dg.createItemRenderer(index); var value:* = renderer.data; rowArray.push(value); } dp.addItem(rowArray); } } Most of my posts to this group go unanswered. Hopefully this one won't suffer the same fate! :) Mike
Re: [SPAM] [flexcoders] Obtaining rendered text from a DataGrid
I need to post the displayed data to a server, complete with formatting. The dataProvider does not help much; I'd have to replicate the work that the datagrid does in determining the properties displayed by each column, and duplicate the job of the item renderers in order to extract the displayed property of each column. I see that itemRenderers can be created ad hoc, so it must be possible to shove data into them and obtain the displayed values. ... it is nice to get a response, and so quickly too :)
Re: [SPAM] [flexcoders] Obtaining rendered text from a DataGrid
If you don't have too many items in the dataProvider, you could create a second DataGrid, with the same DataProvider and itemRenderers, that does not have a height set and is not visible. The second DataGrid would render all of the items in the dataProvider, because the height isn't set. Then go about inspecting the itemRenderers like you proposed earlier; to get the data for your service call. Not the best solution, but this is an unusual use-case. -TH --- In flexcoders@yahoogroups.com, Mike msl...@... wrote: I need to post the displayed data to a server, complete with formatting. The dataProvider does not help much; I'd have to replicate the work that the datagrid does in determining the properties displayed by each column, and duplicate the job of the item renderers in order to extract the displayed property of each column. I see that itemRenderers can be created ad hoc, so it must be possible to shove data into them and obtain the displayed values. ... it is nice to get a response, and so quickly too :)
Re: [SPAM] [flexcoders] Obtaining rendered text from a DataGrid
--- In flexcoders@yahoogroups.com, turbo_vb timh...@... wrote: If you don't have too many items in the dataProvider, you could create a second DataGrid, with the same DataProvider and itemRenderers, that does not have a height set and is not visible. The second DataGrid would render all of the items in the dataProvider, because the height isn't set. Then go about inspecting the itemRenderers like you proposed earlier; to get the data for your service call. Not the best solution, but this is an unusual use-case. -TH Sounds like a workable suggestion, thanks. Mike
Re: [SPAM] [flexcoders] Obtaining rendered text from a DataGrid
--- In flexcoders@yahoogroups.com, Tracy Spratt tr...@... wrote: I will answer, but you probably won't like the answer. This is simply not possible. In order to optimize performance, DataGrid and the other list components only create(render) the visible elements. If a row is not visible, it does not exist. You can't look sideways into your tv screen and see beyond the edges. You should be able to do this by running the labelFunction on all items in the dataProvider. You'll need to change the method signature to allow for a null dataGridColumn, or pass in a dummy dataGridColumn. HTH; Amy
Re: [SPAM] [flexcoders] Obtaining rendered text from a DataGrid
I must take the DataGrid as I find it. If no labelFunction is defined, that approach won't work; also each item in the dataProvider might be manifested in 0 or more columns. This approach probably won't be general enough. Thanks, Mike You should be able to do this by running the labelFunction on all items in the dataProvider. You'll need to change the method signature to allow for a null dataGridColumn, or pass in a dummy dataGridColumn. HTH; Amy
Re: [SPAM] [flexcoders] Obtaining rendered text from a DataGrid
I’m still not sure what your goal is and what things are under your control. I can have a renderer that displays content not found in the data provider, or one that shows colors and no text. A renderer can have multiple text widgets inside it and be mixed with other controls. Is there some constraint on what kinds of renderers you want to grab text from? Usually, you own the renderers. Are folks supplying renderers for you to use? In the simplest case, you are using default or simple renderers that leverage the default text computation performed by the DataGrid. If that is true, while you could stuff each dataprovider item into a single renderer, that would be inefficient as the renderer will do lots of non-display work. It would be better to simply call the default text computaton methods and gather the text. Code for that might look like: Var s:String = “”; Var n:int = dg.dataProvider.length; Var m:int = dg.columns.length; For (var i:int = 0 ; I n; i++) { var item:Object = dg.dataProvider.getItemAt(i) for (var j:int = 0; j m; j++) { var dgc:DataGridColumn = dg.columns[j]; s += dgc.itemToLabel(item); } } This code would take into account labelFunction if there are any and the dataField, but not any other ways of deriving text content. On 2/12/10 6:41 PM, Mike msl...@mslinn.com wrote: I must take the DataGrid as I find it. If no labelFunction is defined, that approach won't work; also each item in the dataProvider might be manifested in 0 or more columns. This approach probably won't be general enough. Thanks, Mike You should be able to do this by running the labelFunction on all items in the dataProvider. You'll need to change the method signature to allow for a null dataGridColumn, or pass in a dummy dataGridColumn. HTH; Amy -- Alex Harui Flex SDK Team Adobe System, Inc. http://blogs.adobe.com/aharui
Re: [SPAM] [flexcoders] Obtaining rendered text from a DataGrid
Alex, Your code is very interesting, and quite instructive. Thank you. You said that your code handles labelFunction and dataField; however the asdoc for the itemToLabel() method reads: public function itemToLabel(data:Object):String Returns the string the renderer would display for the given data object based on the labelField and labelFunction properties. If the method cannot convert the parameter to a string, it returns a single space. ... no mention of dataField. Am I missing something? The goal is to export the text from any datagrid's displayed cells into a 2D array that is sent to a server. In the general case, one cannot assume anything about the dataProvider, or how the text in each DataGrid's cell is constructed. There are no constraints on the types of renderers that need to be supported. The export should handle any datagrid handed to it. This means that if item renderers are used, they need to be instantiated and the text values for each cell read out... and the export routine has to figure out how to do this without any clues beyond what it can discover from the dataGrid. Something to go 'hmm' about... Mike --- In flexcoders@yahoogroups.com, Alex Harui aha...@... wrote: I'm still not sure what your goal is and what things are under your control. I can have a renderer that displays content not found in the data provider, or one that shows colors and no text. A renderer can have multiple text widgets inside it and be mixed with other controls. Is there some constraint on what kinds of renderers you want to grab text from? Usually, you own the renderers. Are folks supplying renderers for you to use?