ARoad0.Gui2
Class GraphicViewBaseListenerImpl

java.lang.Object
  extended by ARoad0.Gui2.GraphicViewBaseListenerImpl
All Implemented Interfaces:
BaseListener, MVC_Controller, java.awt.event.ActionListener, java.beans.PropertyChangeListener, java.util.EventListener

public class GraphicViewBaseListenerImpl
extends java.lang.Object
implements BaseListener, java.awt.event.ActionListener

This important class manages the GraphicView associated in the GUI to a ViewInBase, and it is the main manager of a specialized thread to update the view and its rights at every relevant base changing. It is created by ViewModel. Its structure is derived from ViewTreeBaseListenerImpl, but it is more complex. It is responsible for listening the events:

- fired after any relevant change in a ViewInBase object or in its ACS, through the ViewInBase or directly,

- fired by the RightsNetworkObserver associated to the view, and this includes the listening of the specific events from any AcsAddon ACS or any of its objects.

Each event source is registered only one time. EPRviewInBase and NoThanViewInBase are handled for a dedicated listening. The ViewInBase updatings activate all the changings in the GraphicView. The opening and closing of views are managed only by ActionClose. This class does not listen the relevant events, and it is finalized indirectly by ActionClose through ViewModel. To avoid an useless processing of view rights, ActionSave calls setListenEvents(false) before any saving. It restores the listening after the saving.

The thread management for the views is described hereinafter.

Using the view threads, the first aim is to update quickly the access paths of a view when a property has changed in a view node. This is why it is done outside the event dispatch thread and the main thread, in a pool of worker threads managed by Gui2.ViewModel. The worker thread works also at the view creation or opening. In all cases, after the paths search, the graphic view updating is done in the event dispatch thread. All the worker threads have the same priority.

The second aim of the thread management is to process the paths search only once, while a database editing may generate several property changes for the same user action. A TIMER_DELAY of 150 ms is set to not process immediatly the first property change. After the TIMER_DELAY, even if several change events have been fired, the access path search reads the current state of the base. The maximal number of worker threads is set to 3 in Gui2.ViewModel.

This class is running under the event dispatch thread (EVT), and the calling sequence is:

- calls to propertyChange() one or several times, by one or several objects in gBase or gWork, and updates the relevant listeners in the base for each base change

- propertyChange() updates the 2 booleans toChange_ and toUpdated_, starts a timer at the first firing, and restarts it at each firing,

- the timer calls actionPerformed() when the TIMER_DELAY is expired, after 150 milliseconds,

- actionPerformed() reads toChange_ and toUpdate_, and it calls changeFrameView(), changeTabView() or updateFrameViewRights(); then it stops the timer,

- changeTabView() and sometimes actionPerformed() calls GraphicViewPropertyEditor.PropertyChangeEvent() if the view is in a JTabbedPane, which uses a worker thread to update the view, then run a task in the EVT to terminate the GUI updating through a call to repaint(),

- changeFrameView() and updateFrameViewRights() use also a worker thread to update the view, then to run a task in the EVT; this task terminates the GUI updating by the way of a call to repaint(),

- actionPerformed() resets the instance for the next firings on propertyChange().

In all cases after the view creation, the worker thread is run to call GraphicView.resetRights() or resetGraphicView(), and there is a call to GraphicView.setWhyText() in the EVT. The task in the worker thread is then ended. Since the worker thread is in a pool which is provided by ViewModel, the same thread is able to process a new task for another GraphicViewBaseListenerImpl instance, or for the same instance.


Field Summary
private  boolean listenEvents_
           
private  RightsMediator rightsNetworkObserver_
           
private  javax.swing.Timer timer_
           
private static int TIMER_DELAY
           
private  boolean toChange_
           
private  boolean toUpdate_
           
private  ViewInBase view_
           
private  ImmutableName viewName_
           
private  java.lang.Thread worker_
          This is used by propertyChange to create a worker thread which resets the view.
 
Constructor Summary
GraphicViewBaseListenerImpl()
          Public constructor.
GraphicViewBaseListenerImpl(ViewInBase _source)
          With this constructor, the GraphicViewBaseListenerImpl is registered as a listener for the view and a RightsNetworkObserver.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent _evt)
          Receives the event from timer_ when the last event has been received by propertyChange() at TIMER_DELAY, and calls an updating method for the view.
private  void changeFrameView()
          Resets the graphic view which has a different set of nodes, and the 'See why' frame if it is open, but not the explorer.
private  void changeTabView()
          Updates the RightsMediator and the view tab (GraphicView and 'See why').
 void finalizeForUser()
          Unregisters the instance as a listener for all registered sources.
 ImmutableName getEorMainEventSource()
          Get the main event source associated to the instance in its construction.
 void propertyChange(java.beans.PropertyChangeEvent _evt)
          Receives all the events about the view property changes, adds and removes this instance as property listener in the changing base objects, and calls actionPerformed() after a delay to avoid multiple unuseful calls for the same basic event.
 boolean setListenEvents(boolean _listen)
          To listen or not the events in propertyChange().
 java.lang.String toString()
           
private  void updateFrameViewRights()
          Resets the rights without node changing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ARoad0.Gui2.BaseListener
hashCode
 

Field Detail

TIMER_DELAY

private static int TIMER_DELAY

listenEvents_

private boolean listenEvents_

view_

private ViewInBase view_

viewName_

private ImmutableName viewName_

rightsNetworkObserver_

private RightsMediator rightsNetworkObserver_

worker_

private java.lang.Thread worker_
This is used by propertyChange to create a worker thread which resets the view.


timer_

private javax.swing.Timer timer_

toChange_

private boolean toChange_

toUpdate_

private boolean toUpdate_
Constructor Detail

GraphicViewBaseListenerImpl

public GraphicViewBaseListenerImpl()
Public constructor.


GraphicViewBaseListenerImpl

public GraphicViewBaseListenerImpl(ViewInBase _source)
With this constructor, the GraphicViewBaseListenerImpl is registered as a listener for the view and a RightsNetworkObserver. There is a specific listening if _source is a NoThanViewInBase.

Parameters:
_source - is the view to manage
Method Detail

getEorMainEventSource

public ImmutableName getEorMainEventSource()
Get the main event source associated to the instance in its construction.

Specified by:
getEorMainEventSource in interface BaseListener
Returns:
name of the main source for PropertyChangeEvents. May be null.

setListenEvents

public boolean setListenEvents(boolean _listen)
To listen or not the events in propertyChange(). Used to stop the listening before a saving of the relevant ACS, since the listening produces a reset of the view rights through a process which may be heavy.

Specified by:
setListenEvents in interface BaseListener
Parameters:
_listen - true to listen the events in this instance, through propertyChange()
Returns:
true if the previous value was different to this argument

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent _evt)
Receives the event from timer_ when the last event has been received by propertyChange() at TIMER_DELAY, and calls an updating method for the view. Calls GraphicViewPropertyEditor.propertyChange() with a null new value, RightsNetworkObserver.setRightsRelatedBaseObjects(), changeTabView(), updateFrameViewRights(), changeFrameView().

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
_evt - contains a null command

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent _evt)
Receives all the events about the view property changes, adds and removes this instance as property listener in the changing base objects, and calls actionPerformed() after a delay to avoid multiple unuseful calls for the same basic event. No processing if the property listenEvents_ is false. Listens 'OnePropertyInView' which is a wrapper for any property change event from an EPRViewInBase ACSObject or an AclEntry. Listens all the RightsNetworkObserver events for updating the view. Listens 'OneBaseObjectInView' (and not 'ConnectedACS') from the ViewInBase, 'OnePropertyInView' and 'AclConnectedResources' from the EPRViewInBase, and, from a NoThanViewInBase, 'FirstAccessTarget', 'OneMoreCriterion', 'OneLessCriterion', 'ObjectChangesInListeningPerimeter', 'OnePropertyInAListeningPerimeterObject'. Listens for the AclEntries, 'AclConnectedResources' (for EligibleParty), 'AclRights', 'ConditionSourceGroups' and 'AssociatedGroups'. 'OnePropertyInView' is in fact an event wrapper for any property change event from an EPRViewInBase ACSObject, so it is processed for each event where the declared source is a BaseObject. 'OnePropertyInAListeningPerimeterObject' is also an event wrapper for any property change event from the listening perimeter of a NoThanViewInBase. Calls actionPerformed() after TIMER_DELAY milliseconds.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
_evt - PropertyChangeEvent

changeFrameView

private void changeFrameView()
Resets the graphic view which has a different set of nodes, and the 'See why' frame if it is open, but not the explorer. Updates the RightsMediator. Runs a worker thread to call GraphicView.resetRights(), then calls GraphicView.setWhyText() in the Event Dispatch Thread. This method calls the worker thread pool returned by ViewModel.getViewsThreadsExecutor() which processes the calls in their calling order, as asynchronous tasks. Called by propertyChange().


updateFrameViewRights

private void updateFrameViewRights()
Resets the rights without node changing. When the 'all views' frame is closed and a right has been changed, reset the rights in the main frame and reset the 'See why' frame. Do not change the explorer. Reset the 'See why' frame, if it is open, to its initial position. Called by the RightsNetworkObserver. Used also for the 'Architecture' view. Run a worker thread to call GraphicView.resetRights(), then call GraphicView.setWhyText() in the Event Dispatch Thread. This method calls the worker thread pool returned by ViewModel.getViewsThreadsExecutor() which processes the calls in their calling order, as asynchronous tasks. Called by propertyChange().


changeTabView

private void changeTabView()
Updates the RightsMediator and the view tab (GraphicView and 'See why'). Does not change the explorer. On the contrary of changeFrameView(), no graphic view creation. Calls GraphicViewPropertyEditor.PropertyChangeEvent() which uses a worker thread to update the view Called by propertyChange().


finalizeForUser

public void finalizeForUser()
Unregisters the instance as a listener for all registered sources. Sets the variables to null. Called by ViewModel.removeViewMainObservers().

Specified by:
finalizeForUser in interface BaseListener

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
String