I have just started using GlazedLists in a Java project which uses beansbinding extensively (MVVM pattern).
PluggableList is allowing me to bind a source list to a table, and then change the source list at runtime. In order to make this happen every source list must share the same ListEventPublisher and ReadWriteLock, since PluggableList must share a lock and plublisher with it's source. I accomplish this by creating a static publisher and lock in my class that owns the potential source lists, use those static values to create the list in every instantiation of the class as well as the PluggableList, as shown in the pseudo code below:
public class ModelClass
{
final static EventList LIST = new BasicEventList();
final static ListEventPublisher LISTEVENTPUBLISHER = LIST.getPublisher();
final static ReadWriteLock READWRITELOCK = LIST.getReadWriteLock();
final EventList sourceList =
new BasicEventList(LISTEVENTPUBLISHER, READWRITELOCK);
}
public class UiControllerClass
{
final PluggableList pluggableList =
new PluggableList(ModelClass.LISTEVENTPUBLISHER, ModelClass.READWRITELOCK);
// ... call pluggableList.setSource(someSourceList)
}
I have two concerns with this:
(1) I have to make a decision in the Model because of a specific requirement of a component in the UiController. This seems to violate the MVVM pattern.
(2) The shared lock potentially impacts the performance of the lists if there are very many and they are accessed frequently, since they all share the same lock. Each of these lists should otherwise be able to operate independently without caring about each other.
Am I going about this incorrectly? Is there a better way to make PluggableLists work without the ModelClass having to know about a special UiControllerClass requirement and without the potential performance hit?