Backing an actionscript DataGrid - actionscript-3

I am trying to implement the model for a DataGrid. The documentation:
http://help.adobe.com/en_US/flex/using/WS0ab2a460655f2dc3-427f401412c60d04dca-8000.html#WS0ab2a460655f2dc3-427f401412c60d04dca-7fff
indicates that I need to use an implementation of IList which contains rows. What the docs do not indicate however is what interface I need to use to implement a row class. The examples are all in XML, which suggests static content.
What I need is a row implementation that can receive changes from the underlying model and provide them to the DataGrid, and likewise, receive changes from the DataGrid and provide them to the underlying model.

The documentation you cite suggests using an ArrayList class as one of the possible implementations of IList as a data provider. And the ArrayList manual states that the row class is plain Object, and all the property change handling and notification is done within ArrayList instance using its methods for add, update, delete and set index operations. So, either use this class, or ArrayCollection, or write your own IList implementation that will handle data update notification process in itself, without referring to row class.
I also think that making row class update its container list is rather pointless, because rows are designed to be just data, without any "sanity", and lists are what actively process that data, including reordering, sorting, filtering and so on. Thus, adding such a functionality to row class overturns this (working) model, thus is not needed.

Related

Symfony/Doctrine - Query to Set/Change the Value for a Field when Selecting an Entity

[Usage: Doctrine 2.6, Symfony 2.7]
Using Doctrine queryBuilder or straight DQL, how can I set a value for a field of an entity that is selected, or otherwise change or manipulate the value of a field that is returned BEFORE the postLoad event listener is called?
Background
As a simplified description of my context, I have an entity view that can be associated with a ton of different "Content Type" entities, so it doesn't (can't) have a direct doctrine association. But I usually want that other entity to be loaded and attached to view->content property. So I have a postLoad listener that automatically checks what type of content it is, and loads it from the right entity if content hasn't been loaded already.
I usually want this to happen automatically, but if I get an array of views this lazy loading is too inefficient (too many database calls), so in those cases I want to fetch the content separately in a more efficient way after I get the results back (not in the postLoad listener one entity at a time). Which means I need to tell the listener to ignore it's usual automatic loading. I can do this easily if I am able to pre-populate that field with a TRUE value (so the listener thinks it's already loaded and doesn't try to fetch it automatically.
Pseudo Idea for Solution
So what if when I create my query that fetches a list of views I make doctrine fill that field with a default value of 1. In MySQL that is easy, just:
SELECT *, 1 AS `content` FROM `view`;
NOTE: This unfortunately doesn't actually set the value of view.content, it just appends an alias called content...
While content is a property in the view entity, it is not a persisted property, so there is no database field for that property. But I could make it persists (just as a placeholder). Let's say I do that, I still can't figure out how to manipulate the value that gets returned (always empty in the database) and pre-fill it with a 1 whenever I want to notify the postLoad Listener to ignore the auto loading.

AS3 Custom Event Best Practices Questions (Opinions)

I'm just curious how a lot of you handle custom events.
My custom event/s that I will be creating pertain to creating and displaying views. I want to have two separate events dispatched, one to create the view and then one to display the view. I'd like the create a view using an ID that corresponds to the type of view to create and when displaying the view would like to pass the handler a view object to add to the stage.
I see three ways of doing this:
Create a single ViewEvent class with two event types CREATE_VIEW and DISPLAY_VIEW. The problem with a single event class is that I would like if possible to use strongly typed parameters. When using CREATE_VIEW though, I want to pass an ID that corresponds to the view to create and when I dispatch DISPLAY_VIEW I'd like to pass the view object to display. So to get them strongly typed I'd have to two optional parameters, one for viewId of type int and one for view of type DisplayObject and then test for which one exists which I don't like.
Same as number 1 except use a single generic parameter and check for it's type to see what the event's payload is which I don't like generic parameters either.
Create two separate event classes, a CreateViewEvent and a DisplayViewEvent. This would allow me to use the proper typed parameters, but it seems a little weird since both event actions are so closely related that I feel they should be within the same event class.
So the question is... in general what are everyone's views on handling a situation like this? Is there a better way to handle this?
I've run into this situation before too with other types of events, my view example is just a simple example of what I'm currently running into.

LINQ to Entity Cross Tab

Is it possible with LINQ to do a cross tab query to add new columns? These columns come from a second and third table and need to be converted to JSON to be displayed in a Telerik table.
One table contains the name of the columns that need to be displayed and the other contains the value for the rows of each column, and this relates to the first table, which has the main related data.
I have investigated dynamically creating the extra columns, but also come unstuck as they need to go through JSON serialization, as well as the difficulties of creating new properties within any class dynamically.
Any ideas would be helpful.
Regards
Mark
I hope this helps, although I'm not sure I understand completely what you're asking ...
Since you're serializing to JSON anyway (and so presumably are not overly concerned with schema/type info), I would suggest just using a Dictionary and populating your data that way. It sounds like you could run some kind of nested loop, cycling through the column names from the one table, and pulling the values from each column from the second table.
EDIT
BTW, it is possible to do dynamic properties using System.ComponentModel, although this seems like overkill from how you described your scenario (you don't require data binding, for instance). Here's a good post on SO, if you're interested: Data binding dynamic data

JTable Madness?

I've been reading the Swing tutorial "How to Use Tables", and although it has been very informative for the JTable newbie, I am instantly hitting roadblocks the second I try to veer away from the examples and strike out on my own.
So, if you want your Swing app to have a nifty, custom table, it looks like their are several core classes you'll be working with at the very least:
JTable
TableModel
TableModelListener
TableModelEvent
TableColumnModel
TableColumnModelListener
TableColumnModelEvent
Just from reading the tutorials and JavaDocs, it is not obvious to me what the difference is between a TableModel and a TableColumnModel, and how they relate to each other. Obviously, the column model pertains just to a single column or all the columns (?), whereas the table model is more general. But how do they relate to one another? What areas of responsibility does each one handle? Does TableModel manage, control or somehow contain the TableColumnModel?
Closely related to the first question, in which model do I specify cell editors and renderers?
I assume that, for each of these objects I should subclass/implement them so I can customize them for my project. Is that the generally-accepted way of customizing tables (subclassing the JTable "core" classes), or are these powerful enough to support any kind of table creation?
Usually, you just define a TableModel (by subclassing AbstractTableModel), and construct a JTable instance with this table model as argument.
If you implement getColumnClass() correctly in your table model, JTable will automatically choose an appropriate renderer for each of your column. If some cells are editable (you tell by overriding isCellEditable() in the table model), the appropriate cell editor will also be associated with the column. You'll have to trigger events (using one of the fireXxx methods in AbstractTableModel) when the model changes.
Of course, if you have special objects in your cells (i.e. something other than String, Boolean, Integer, etc.), you'll have to associate a renderer to a column (and an editor if the cells in these cells are editable). This is done by setting the renderer/editor on the column of the column model. The column model is automatically created by the JTable from the table model, though. You usually don't have to creat one by youself.
So, to answer your specific questions:
TableModel is used to hold the data displayed in the JTable. You must implement it yourself. TableColumnModel is automatically created by the JTable and is typically used to associate a renderer and editor to specific columns.
If you want a specific renderer for the nth column, you get the nth column from the column model of the JTable, and you set a renderer on this column.
Usually subclassing AbstractTableModel is sufficient.

How do I use LINQ to SQL with stored procedures returning multiple result sets without ORM?

http://blogs.msdn.com/b/dditweb/archive/2008/05/06/linq-to-sql-and-multiple-result-sets-in-stored-procedures.aspx
Similar to this link however the project I'm working on doesn't use the ORM component of LINQ to SQL (we use it more for quickly generating the ADO.Net interface to the db).
Currently, the pattern we follow is:
var result = myDataContext.GetAllCustomersAndOrders();
And the stored procedure looks like this:
Are there extra steps I need to take? Do I need to extend the generated dbml or the data context partial class file?
Hopefully this makes sense... It's a bit difficult to explain and all the examples I've found use the ORM piece of the dbml (dragging and dropping tables onto the dbml designer surface).
Yes, you can do this, but i will require creating a partial class for your dbml.
So, if your dbml file is MyLinqToSQL.dbml
open the dbml designer
drag the SP onto the design surface
save
and then press F7.
This will create a partial class of MyLinqToSQL.cs.
Now...
open the auto-generated MyLinqToSQL.designer.cs
copy the access method with the same name as the SP (the one you want to return multiple sets from.)
Insert this into the body of the partial class in MyLinqToSQL.cs you just created.
change the name of the method to something at least slightly different
change the return type from ISingleResult to IMultipleResult.
decorate your new class with System.Data.Linq.Mapping.ResultType attributes to define your return set types.
All of the resultsets will be returned in a single collection of IQueryable.
You can then use reflection to determine the type of each collection item and then cast them for use.
See http://kishor-naik-dotnet.blogspot.com/2011/12/linq-multiple-result-set-of-procedure.html