Revision: 1706
          http://svn.sourceforge.net/spring-rich-c/?rev=1706&view=rev
Author:   mathiasbr
Date:     2007-02-02 14:58:51 -0800 (Fri, 02 Feb 2007)

Log Message:
-----------
fixed app lock

Modified Paths:
--------------
    
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/table/support/AbstractObjectTable.java

Modified: 
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/table/support/AbstractObjectTable.java
===================================================================
--- 
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/table/support/AbstractObjectTable.java
 2007-02-02 08:10:16 UTC (rev 1705)
+++ 
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/table/support/AbstractObjectTable.java
 2007-02-02 22:58:51 UTC (rev 1706)
@@ -26,15 +26,6 @@
 import javax.swing.event.ListSelectionEvent;
 import javax.swing.event.ListSelectionListener;
 
-import ca.odell.glazedlists.EventList;
-import ca.odell.glazedlists.GlazedLists;
-import ca.odell.glazedlists.SortedList;
-import ca.odell.glazedlists.event.ListEvent;
-import ca.odell.glazedlists.event.ListEventListener;
-import ca.odell.glazedlists.gui.AbstractTableComparatorChooser;
-import ca.odell.glazedlists.gui.TableFormat;
-import ca.odell.glazedlists.swing.EventSelectionModel;
-import ca.odell.glazedlists.swing.TableComparatorChooser;
 import org.springframework.beans.support.PropertyComparator;
 import org.springframework.context.ApplicationEvent;
 import org.springframework.context.ApplicationListener;
@@ -47,6 +38,17 @@
 import org.springframework.richclient.util.PopupMenuMouseListener;
 import org.springframework.util.Assert;
 
+import ca.odell.glazedlists.EventList;
+import ca.odell.glazedlists.GlazedLists;
+import ca.odell.glazedlists.SortedList;
+import ca.odell.glazedlists.event.ListEvent;
+import ca.odell.glazedlists.event.ListEventListener;
+import ca.odell.glazedlists.gui.AbstractTableComparatorChooser;
+import ca.odell.glazedlists.gui.TableFormat;
+import ca.odell.glazedlists.swing.EventSelectionModel;
+import ca.odell.glazedlists.swing.TableComparatorChooser;
+import ca.odell.glazedlists.util.concurrent.Lock;
+
 /**
  * This class provides a standard table representation for a set of objects 
with properties of the objects presented in
  * the columns of the table. The table created offers the following features:
@@ -448,34 +450,82 @@
        }
 
        /**
+        * Executes the runnable with a write lock on the event list.
+        * 
+        * @param runnable its run method is executed while holding a write 
lock for
+        * the event list.
+        * 
+        * @see #getFinalEventList()
+        */
+       protected void runWithWriteLock(Runnable runnable) {
+               runWithLock(runnable, 
getFinalEventList().getReadWriteLock().writeLock());
+       }
+
+       /**
+        * Executes the runnable with a read lock on the event list.
+        * 
+        * @param runnable its run method is executed while holding a read lock 
for
+        * the event list.
+        * 
+        * @see #getFinalEventList()
+        */
+       protected void runWithReadLock(Runnable runnable) {
+               runWithLock(runnable, 
getFinalEventList().getReadWriteLock().readLock());
+       }
+
+       private void runWithLock(Runnable runnable, Lock lock) {
+               Assert.notNull(runnable);
+               Assert.notNull(lock);
+               lock.lock();
+               try {
+                       runnable.run();
+               }
+               finally {
+                       lock.unlock();
+               }
+       }
+
+       /**
         * Handle the creation of a new object.
         * @param object New object to handle
         */
-       protected void handleNewObject(Object object) {
-               getFinalEventList().add(object);
+       protected void handleNewObject(final Object object) {
+               runWithWriteLock(new Runnable() {
+                       public void run() {
+                               getFinalEventList().add(object);
+                       }
+               });
        }
-
+       
        /**
         * Handle an updated object in this table. Locate the existing entry 
(by equals) and replace it in the underlying
         * list.
         * @param object Updated object to handle
         */
-       protected void handleUpdatedObject(Object object) {
-               int index = baseList.indexOf(object);
-               if (index >= 0) {
-                       baseList.set(index, object);
-               }
+       protected void handleUpdatedObject(final Object object) {               
+               runWithWriteLock(new Runnable() {
+                       public void run() {
+                               int index = getFinalEventList().indexOf(object);
+                               if (index >= 0) {
+                                       getFinalEventList().set(index, object);
+                               }
+                       }
+               });
        }
 
        /**
         * Handle the deletion of an object in this table. Locate this entry 
(by equals) and delete it.
         * @param object Updated object being deleted
         */
-       protected void handleDeletedObject(Object object) {
-               int index = baseList.indexOf(object);
-               if (index >= 0) {
-                       baseList.remove(index);
-               }
+       protected void handleDeletedObject(final Object object) {
+               runWithWriteLock(new Runnable() {
+                       public void run() {
+                               int index = getFinalEventList().indexOf(object);
+                               if (index >= 0) {
+                                       getFinalEventList().remove(index);
+                               }
+                       }
+               });
        }
 
        /**


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
spring-rich-c-cvs mailing list
spring-rich-c-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs

Reply via email to