Wednesday, February 4, 2009

GlazedLists is not "GUI-Lists"!

This is a post in Praise of GlazedLists - at least the concepts it embodies!

It took some time before I "got" GlazedLists.

I had read several articles about GL, and went to a JavaOne 2008 talk about it, but I still didn't actually grasp it: I feel that GL's presentations always centers around GUI aspects, in particular list-views and other boring stuff. This was not a good way to sell it to me: I weren't a particularly huge fan of "binding frameworks" and the like. However, I did see something through that GUI-haze, and when I finally did get down into GL, I pretty much immediately rewrote my current project to use it from the core outward! GL's concepts have nothing to do with GUI in themselves! It is just that the concepts are really very handy when it comes to several GUI aspects. I now believe GL have utility for any system which have a state consisting of a dynamic set of entities - not only for the "last mile", the actual display to the user, but as a core tool to build ones entity handling on.

The main concept of GL is actually not very "big" as such. I'll try to formulate a phrase that would have had me get the concept:

 " GL is at its core a modifiable List of objects, where sorting (reordering), selections (filtering) and transformations can be applied in a chain, resulting in new list views of the parent list, and the entire chain of lists is kept updated no matter where modification methods are invoked on that chain, by propagating the incremental change events internal to the chain, not needing an external event structure. "

Was that understandable?

Think about a system that has a List-of-Customers in the base. You then sort that list based on the customers' last name, getting a new list. Then you filter the list, for example selecting all the customers of age 40 or more. Yes? This resulting list is used often, so you keep a reference to it, "caching" it so to speak.

But then you get a new customer.

If you don't know GlazedLists, you now immediately think about some "NewCustomerEvent" that the container of the base list fires, on which the cache-holder listens, and upon receiving such events, it does the filtering, then sticks it into the list at the correct sorted position. Then you start thinking about customers that want to leave, and realize that you need a "CustomerDeletedEvent". And then, what if the customer was entered with the wrong name or age?

If you do know GlazedLists, you just smile! :-)

The base EventList gets the customer inserted, and sends an internal event up to the listeners, and first hits the SortedList. Here it is inserted at the correct position, but the sortedlist propagates the change further, up to the FilterList, which applies the filter, and now both the intermediate list and the age-40-filtered list is updated, "just like that". You may even change the sort-order, or the filter, and things are always correct.

You may also hook onto the event fire system at any point.

Now, this happens to be exceptionally useful for GUIs where it can keep different views "magically updated" when the internal state of the system changes, and GL also have lots of such utility classes that handle common "binding cases", but the main concept is useful for pretty much any stateful system that have dynamic set of entities as its state.

So, yes: Everyone should check out GlazedLists, not only the die-hard Swing/SWT GUI developers! It is definitely a tool that should be in any serious coder's tool chest blah blah..!

1 comment:

  1. Collagen là loại protein chiếm khoảng 30% tổng lượng protein trong cơ thể người, những thực phẩm bổ sung collagen cho da có chức năng chính là kết nối các mô trong cơ thể lại với nhau. Các nhà khoa học thường ví collagen giống như một chất keo dính các bộ phận trong cơ thể nhằm tạo thành một khối hoàn chỉnh.bổ sung collagen cho da bằng cách nào, sức khỏe và làm đẹp, bổ sung collagen bằng cách nào, Collagen là nguyên tố quan trọng giúp duy trì sự căng mịn và độ đàn hồi của da. Da mặt chúng ta có thể giãn ra và co lại theo hoạt động của các bộ phận trên mặt, là do sự chuyển động của cơ và độ đàn hồi của da. cách bổ sung collagen cho da, bao nhiêu tuổi thì cần bổ sung collagen, bổ sung collagen cho da bằng thực phẩm Da mặt có thể căng mịn, trắng sáng khi còn trẻ và chùng nhão, nhiều nếp nhăn, nám sạm khi về già là do sự thay đổi về chất và lượng của collagen, các loại thực phẩm bổ sung collagen, có nên uống thuốc bổ sung collagen, những thực phẩm bổ sung collagen cho da vì thế cần duy trì lượng collagen cần thiết bằng cách bổ sung kịp thời lượng thiếu hụt chính là nhân tố quan trọng nhất giúp duy trì sự trẻ trung, tươi sáng cho da.