public abstract class IlvManagerContentChangedDispatcher extends Object implements ManagerContentChangedListener
The typical use case is when a graphic object must react when a related object changed. It is far too expensive to register each single graphic object as content listener on the manager. Instead, a manager content change dispatcher is registered which distributes the events to the changed objects.
The example below shows a sketch how this class can be used:
public class IlvMyGraphic extends IlvGraphic implements ManagerContentChangedListener { // acts as template, to know how to create similar dispatchers static MyManagerContentChangedDispatcher templateDisp = new MyManagerContentChangedDispatcher(); public void setGraphicBag(IlvGraphicBag bag) { IlvGraphicBag oldBag = getGraphicBag(); if (bag != oldBag) { if (oldBag != null) { IlvManagerContentChangedDispatcher dispatcher = IlvManagerContentChangedDispatcher.Get(oldBag, false, templateDisp); if (dispatcher != null) dispatcher.notifyRemove(); } if (bag != null) { IlvManagerContentChangedDispatcher dispatcher = IlvManagerContentChangedDispatcher.Get(bag, true, templateDisp); if (dispatcher != null) dispatcher.notifyAdd(); } } super.setGraphicBag(bag); } public void contentsChanged(ManagerContentChangedEvent event) { ... here are the operations to do when the object changed ... } // inner class of the specific dispatcher static class MyManagerContentChangedDispatcher extends IlvManagerContentChangedDispatcher { protected String getID() { return "MyManagerContentChangedDispatcher".intern(); } protected IlvManagerContentChangedDispatcher create() { return new MyManagerContentChangedDispatcher(); } protected void contentsChanged(IlvGraphic g, ManagerContentChangedEvent event) { if (g instanceof IlvMyGraphic) { ((IlvMyGraphic)g).contentsChanged(event); } } } }
Constructor and Description |
---|
IlvManagerContentChangedDispatcher()
Creates a new manager content change dispatcher.
|
Modifier and Type | Method and Description |
---|---|
protected void |
contentsChanged(IlvGraphic g,
ManagerContentChangedEvent event)
Reacts for the input graphic on content change events.
|
void |
contentsChanged(ManagerContentChangedEvent event)
Reacts on content change events.
|
protected abstract IlvManagerContentChangedDispatcher |
create()
Creates an instance of the manager content change dispatcher.
|
static IlvManagerContentChangedDispatcher |
Get(IlvGraphicBag bag,
boolean addIfNecessary,
IlvManagerContentChangedDispatcher tmplate)
Returns the listener for a manager.
|
protected abstract String |
getID()
Returns the unique ID of the dispatcher.
|
void |
notifyAdd()
Must be called whenever an
IlvGraphic object is added to
the related manager that wants to receive the content change event. |
void |
notifyRemove()
Must be called whenever a
IlvGraphic is removed from
the related manager that wanted to receive the content change event. |
public IlvManagerContentChangedDispatcher()
protected abstract String getID()
protected abstract IlvManagerContentChangedDispatcher create()
public static IlvManagerContentChangedDispatcher Get(IlvGraphicBag bag, boolean addIfNecessary, IlvManagerContentChangedDispatcher tmplate)
bag
- The manager that needs this type of listener.addIfNecessary
- If true
, it creates a new listener
if none is installed yet at the input manager.
If false
, it returns null
if no listener
with the same ID as the input template is installed.tmplate
- The template that is used to determined the ID and how
to create the listener.public void notifyAdd()
IlvGraphic
object is added to
the related manager that wants to receive the content change event.public void notifyRemove()
IlvGraphic
is removed from
the related manager that wanted to receive the content change event.public void contentsChanged(ManagerContentChangedEvent event)
contentsChanged
in interface ManagerContentChangedListener
event
- The content change event.IlvManager.addManagerContentChangedListener(ilog.views.event.ManagerContentChangedListener)
,
IlvManager.removeManagerContentChangedListener(ilog.views.event.ManagerContentChangedListener)
,
IlvManager.addManagerTreeContentChangedListener(ilog.views.event.ManagerContentChangedListener)
,
IlvManager.removeManagerTreeContentChangedListener(ilog.views.event.ManagerContentChangedListener)
protected void contentsChanged(IlvGraphic g, ManagerContentChangedEvent event)
g
- The object that was selected or deselected.event
- The content change event.© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.