net.refractions.udig.ui.operations
Class LazyOpFilter

java.lang.Object
  extended by net.refractions.udig.ui.operations.LazyOpFilter
All Implemented Interfaces:
OpFilter

public class LazyOpFilter
extends java.lang.Object
implements OpFilter

A non-blocking version of the LazyOpFilter. Returns false first then calculates whether it is in fact false or true in a seperate thread and notifies the listeners of the actual state.

Since:
1.1.0
Author:
Jesse

Field Summary
static boolean DEFAULT_RETURN_VALUE
           
 
Fields inherited from interface net.refractions.udig.ui.operations.OpFilter
FALSE, TRUE
 
Constructor Summary
LazyOpFilter(ILazyOpListener listener, OpFilter opFilter)
           
 
Method Summary
 boolean accept(java.lang.Object object)
          Returns true if the object is accepted by the filter
 void addListener(IOpFilterListener listener)
          Adds a listener to listen for events indicating the value has changed.
 boolean canCacheResult()
          Returns true if the results can be cached.
 void disable()
           
 boolean isBlocking()
          Returns true if processing this filter may block when OpFilter.accept(Object) is called or takes a large amount of time to execute.
 void removeListener(IOpFilterListener listener)
          Removes a listeners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_RETURN_VALUE

public static final boolean DEFAULT_RETURN_VALUE
See Also:
Constant Field Values
Constructor Detail

LazyOpFilter

public LazyOpFilter(ILazyOpListener listener,
                    OpFilter opFilter)
Method Detail

accept

public boolean accept(java.lang.Object object)
Description copied from interface: OpFilter
Returns true if the object is accepted by the filter

Specified by:
accept in interface OpFilter
Parameters:
object - object to test
Returns:
true if the object is accepted by the filter

addListener

public void addListener(IOpFilterListener listener)
Description copied from interface: OpFilter
Adds a listener to listen for events indicating the value has changed. Listeners should only be added if OpFilter.canCacheResult() returns true.

Specified by:
addListener in interface OpFilter
Parameters:
listener - listener to add

canCacheResult

public boolean canCacheResult()
Description copied from interface: OpFilter
Returns true if the results can be cached.

A result can be cached if

  1. The value will never change
  2. It is possible for the filter to listen for changes and update listeners added via the OpFilter.addListener(IOpFilterListener) method

Therefore this method only returns false if it must be calculated each time because there is no way to listen for state changes. If it is non-blocking that is fine, if it is blocking then try to do this rarely.

WARNING: If this returns true then the listeners must be notified for the new value to be recognized

Specified by:
canCacheResult in interface OpFilter
Returns:
true if the results can be cached.

isBlocking

public boolean isBlocking()
Description copied from interface: OpFilter
Returns true if processing this filter may block when OpFilter.accept(Object) is called or takes a large amount of time to execute.

Specified by:
isBlocking in interface OpFilter
Returns:
true if processing this filter may block when OpFilter.accept(Object) is called.

removeListener

public void removeListener(IOpFilterListener listener)
Description copied from interface: OpFilter
Removes a listeners

Specified by:
removeListener in interface OpFilter
Parameters:
listener - listener to remove

disable

public void disable()