[Issue 471] New - RFE: SwingProxyCalculation

View: New views
1 Messages — Rating Filter:   Alert me  

[Issue 471] New - RFE: SwingProxyCalculation

by BRANDS-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

https://glazedlists.dev.java.net/issues/show_bug.cgi?id=471
                 Issue #|471
                 Summary|RFE: SwingProxyCalculation
               Component|glazedlists
                 Version|current
                Platform|All
              OS/Version|All
                     URL|
                  Status|NEW
       Status whiteboard|
                Keywords|
              Resolution|
              Issue type|DEFECT
                Priority|P3
            Subcomponent|calculations
             Assigned to|jplemieux
             Reported by|brands






------- Additional comments from brands@... Sun Mar 22 11:33:33 +0000 2009 -------
A proposal from Kevin Day from the user list:

I recently ran into a deadlock problem where I had the results of a calculation
bound to the enabled state of an action.  The issue was that the calculation was
firing off of the EDT.  In the spirit of SwingThreadProxyEventList, I put
together the following code for calculations.
 
/*
 * Created on Mar 18, 2009
 *
 */
package com.trumpetinc.glazedlistsext;
import java.awt.EventQueue;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.SwingUtilities;
import ca.odell.glazedlists.calculation.AbstractCalculation;
import ca.odell.glazedlists.calculation.Calculation;
/**
 * @author kevin
 */
public class SwingProxyCalculation<E> extends AbstractCalculation<E> {
    private Calculation<? extends E> calc;
    private PCL pcl;
   
    public SwingProxyCalculation(Calculation<? extends E> calc) {
        super(calc.getValue());
        this.calc = calc;
        this.pcl = new PCL();
        calc.addPropertyChangeListener(pcl);
    }
    public void dispose() {
        calc.removePropertyChangeListener(pcl);
        calc = null;
    }
   
    public E getValue() {
        return calc.getValue();
    }
   
    private class PCL implements PropertyChangeListener{
        public void propertyChange(final PropertyChangeEvent evt) {
            if (EventQueue.isDispatchThread()){
                fireValueChange((E)evt.getOldValue(), (E)evt.getNewValue());
            } else {
                SwingUtilities.invokeLater(new Runnable(){
   
                    public void run() {
                        fireValueChange((E)evt.getOldValue(), (E)evt.getNewValue());
                    }
                   
                });
            }          
       }
       
    }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@...
For additional commands, e-mail: issues-help@...