org.viewaframework.controller
Class AbstractViewControllerWorker<EL extends EventListener,EO extends EventObject,T,V>

java.lang.Object
  extended by javax.swing.SwingWorker<T,V>
      extended by org.viewaframework.controller.AbstractViewControllerWorker<EL,EO,T,V>
Type Parameters:
EL - EventListener the controller is going to represent
EO - EventObject the controller is going to handle
T - Object the method doInBackground is going to return (It will always return null)
V - Object the method handleViewPublising is going to receive from publish(...) calls
All Implemented Interfaces:
InvocationHandler, Runnable, Future<T>, RunnableFuture<T>, ListenerProxy<EL,EO>, ViewController<EL,EO>, ViewContainerLocatorAware

public abstract class AbstractViewControllerWorker<EL extends EventListener,EO extends EventObject,T,V>
extends SwingWorker<T,V>
implements ViewController<EL,EO>, ViewContainerLocatorAware

Since:
1.0
Author:
Mario Garcia This class is an abstract controller using the functionality of a . It would be very useful for those actions that need progress information, or need to be cancel at a given time. This implementation is a workaround of what a real reusable SwingWorker should be. It creates copies of the source controller and launches these copies.

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.SwingWorker
SwingWorker.StateValue
 
Constructor Summary
AbstractViewControllerWorker()
           
 
Method Summary
protected  T doInBackground()
           
protected  void done()
           
 void executeHandler(ViewContainer view, EO eventObject)
          Its the callback method.
 EO getEventObject()
           
 ViewController<EL,EO> getTargetController()
          Returns the listener the proxy is carrying.
 ViewContainer getView()
          This method (together with setView()) is here for being copied for subsequent cloned workers.
 ViewManager getViewManager()
          Returns the application's current view manager
 void handleView(ViewContainer view, EO eventObject)
          This is the method where the logical handling of the data should be called.
abstract  void handleViewProgress(ViewContainer view, EO eventObject, Integer progress)
           
abstract  void handleViewPublising(ViewContainer view2, EO eventObject2, List<V> chunks)
           
 Object invoke(Object proxy, Method method, Object[] args)
           
<U extends ViewContainer>
ViewContainerLocator<U>
locate(Class<U> clazz)
          This method should return a ViewContainerLocator
 ViewContainer locate(String name)
          This method should return a ViewContainer with the name passed as parameter
 ViewContainerFrame locateRootView()
          This method should return the current root view
 void postHandlingView(ViewContainer view, EO eventObject)
          Used for some UI updating before the logical code has been called.
 void preHandlingView(ViewContainer view, EO eventObject)
          Used for some UI updating once the logical code has been called.
protected  void process(List<V> chunks)
           
 void setEventObject(EO eventObject)
           
 void setView(ViewContainer view)
           
 void setViewManager(ViewManager viewManager)
          This method (together with getView()) is here for copying ViewManager for subsequent cloned workers.
 
Methods inherited from class javax.swing.SwingWorker
addPropertyChangeListener, cancel, execute, firePropertyChange, get, get, getProgress, getPropertyChangeSupport, getState, isCancelled, isDone, publish, removePropertyChangeListener, run, setProgress
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.viewaframework.controller.ViewController
getSupportedClass
 

Constructor Detail

AbstractViewControllerWorker

public AbstractViewControllerWorker()
Method Detail

doInBackground

protected T doInBackground()
                    throws Exception
Specified by:
doInBackground in class SwingWorker<T,V>
Throws:
Exception

process

protected void process(List<V> chunks)
Overrides:
process in class SwingWorker<T,V>

handleViewPublising

public abstract void handleViewPublising(ViewContainer view2,
                                         EO eventObject2,
                                         List<V> chunks)
Parameters:
view2 -
eventObject2 -
chunks -

done

protected void done()
Overrides:
done in class SwingWorker<T,V>

executeHandler

public void executeHandler(ViewContainer view,
                           EO eventObject)
Description copied from interface: ViewController
Its the callback method. It is called from a given component of the view in order to perform some action. It should call first to preHandlingView() for cleaning up some information data then it calls to handleView(..) and finally calls to postHandlingView(...).

Notice that depending on the listener proxied the EventObject should be casted in order to get the desired information from it.

Specified by:
executeHandler in interface ViewController<EL extends EventListener,EO extends EventObject>
Parameters:
view - The view where this listener belongs
eventObject - The event fired by the proxied listener.

getViewManager

public ViewManager getViewManager()
Description copied from interface: ViewController
Returns the application's current view manager

Specified by:
getViewManager in interface ViewController<EL extends EventListener,EO extends EventObject>
Returns:
The current view manager

getView

public ViewContainer getView()
This method (together with setView()) is here for being copied for subsequent cloned workers.

Returns:
The current controller view

getEventObject

public EO getEventObject()
Returns:

getTargetController

public ViewController<EL,EO> getTargetController()
Description copied from interface: ListenerProxy
Returns the listener the proxy is carrying.

Specified by:
getTargetController in interface ListenerProxy<EL extends EventListener,EO extends EventObject>
Returns:

locate

public <U extends ViewContainer> ViewContainerLocator<U> locate(Class<U> clazz)
Description copied from interface: ViewContainerLocatorAware
This method should return a ViewContainerLocator

Specified by:
locate in interface ViewContainerLocatorAware
Returns:

locate

public ViewContainer locate(String name)
Description copied from interface: ViewContainerLocatorAware
This method should return a ViewContainer with the name passed as parameter

Specified by:
locate in interface ViewContainerLocatorAware
Returns:

locateRootView

public ViewContainerFrame locateRootView()
Description copied from interface: ViewContainerLocatorAware
This method should return the current root view

Specified by:
locateRootView in interface ViewContainerLocatorAware
Returns:

handleView

public void handleView(ViewContainer view,
                       EO eventObject)
Description copied from interface: ViewController
This is the method where the logical handling of the data should be called. Any UI call should be done in post/pre-handling methods. It is important to notice that the code executed within this method should be running in other thread than EventDispathThread.

Specified by:
handleView in interface ViewController<EL extends EventListener,EO extends EventObject>

handleViewProgress

public abstract void handleViewProgress(ViewContainer view,
                                        EO eventObject,
                                        Integer progress)
Parameters:
view -
eventObject -

invoke

public Object invoke(Object proxy,
                     Method method,
                     Object[] args)
Specified by:
invoke in interface InvocationHandler

postHandlingView

public void postHandlingView(ViewContainer view,
                             EO eventObject)
Description copied from interface: ViewController
Used for some UI updating before the logical code has been called.

Specified by:
postHandlingView in interface ViewController<EL extends EventListener,EO extends EventObject>

preHandlingView

public void preHandlingView(ViewContainer view,
                            EO eventObject)
Description copied from interface: ViewController
Used for some UI updating once the logical code has been called.

Specified by:
preHandlingView in interface ViewController<EL extends EventListener,EO extends EventObject>

setEventObject

public void setEventObject(EO eventObject)
Parameters:
eventObject -

setView

public void setView(ViewContainer view)
Parameters:
view -

setViewManager

public void setViewManager(ViewManager viewManager)
This method (together with getView()) is here for copying ViewManager for subsequent cloned workers.

Parameters:
viewManager -


Copyright © 2010. All Rights Reserved.