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..!

2 comments:

  1. Khi dành phần đời còn lại của mình bằng việc mang niềm vui đến cho mọi người thì những con người ấy đã tìm thấy niềm vui thật sự của cuộc sống, thuốc fucoidan họ nhận ra niềm vui và hạnh phúc đến một cách tự nhiên khi mình mang niềm vui đến những người khác, tác dụng của thuốc Fucoidan và thật kì diệu khi gần đến những ngày cuối cùng của số mệnh đã định trước họ chợt thấy mình vẫn khỏe mạnh chẳng có dấu hiệu gì là sắp chết, thuốc Fucoidan có tốt không rồi họ nhận ra cuộc sống đã cho mình một cơ hội nữa để làm lại cuộc đời sống những phút giây ý nghĩa mang lại niềm vui cho mình và tha nhân. các loại thuốc Fucoidan Nhật Bản và Mỹ Fucoidan kích thích khả năng miễn dịch của cơ thể, ngăn ngừa sự hình thành của khối u, đồng thời có tác dụng làm chậm quá trình oxy hóa, thuốc Fucoidan là gì có tốt không ức chế quá trình sự phát triển mạch máu mới của tế bào ung thư, từ đó loại bỏ nguồn cung cấp chất dinh dưỡng cho các tế bào ung thư.

    ReplyDelete
  2. Very informative Blog! There is so much information here that can help thank you for sharing.
    Data Science Training in Chandigarh

    ReplyDelete