public abstract class IlvManagerSelectionDispatcher extends Object implements ManagerSelectionListener, Serializable
The typical use case is when a graphic object must react when it got selected. It is far too expensive to register each single graphic object as selection listener on the manager. Instead, a manager selection dispatcher is registered which distributes the events to the selected objects.
The example below shows a sketch how this class can be used:
public class IlvMyGraphic extends IlvGraphic implements ManagerSelectionListener { // acts as template, to know how to create similar dispatchers static MyManagerSelectionDispatcher templateDisp = new MyManagerSelectionDispatcher(); public void setGraphicBag(IlvGraphicBag bag) { IlvGraphicBag oldBag = getGraphicBag(); if (bag != oldBag) { if (oldBag != null) { IlvManagerSelectionDispatcher dispatcher = IlvManagerSelectionDispatcher.Get(oldBag, false, templateDisp); if (dispatcher != null) dispatcher.notifyRemove(); } if (bag != null) { IlvManagerSelectionDispatcher dispatcher = IlvManagerSelectionDispatcher.Get(bag, true, templateDisp); if (dispatcher != null) dispatcher.notifyAdd(); } } super.setGraphicBag(bag); } public void selectionChanged(ManagerSelectionChangedEvent event) { ... here are the operations to do when the object got selected ... } // inner class of the specific dispatcher static class MyManagerSelectionDispatcher extends IlvManagerSelectionDispatcher { protected String getID() { return "MyManagerSelectionDispatcher".intern(); } protected IlvManagerSelectionDispatcher create() { return new MyManagerSelectionDispatcher(); } protected void selectionChanged(IlvGraphic g, ManagerSelectionChangedEvent event) { if (g instanceof IlvMyGraphic) { ((IlvMyGraphic)g).selectionChanged(event); } } } }
Constructor and Description |
---|
IlvManagerSelectionDispatcher()
Creates a new manager selection dispatcher.
|
Modifier and Type | Method and Description |
---|---|
protected abstract IlvManagerSelectionDispatcher |
create()
Creates an instance of the manager selection dispatcher.
|
static IlvManagerSelectionDispatcher |
Get(IlvGraphicBag bag,
boolean addIfNecessary,
IlvManagerSelectionDispatcher 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 selection event. |
void |
notifyRemove()
Must be called whenever a
IlvGraphic is removed from
the related manager that wanted to receive the selection event. |
protected void |
selectionChanged(IlvGraphic g,
ManagerSelectionChangedEvent event)
Reacts for the input graphic on selection events.
|
void |
selectionChanged(ManagerSelectionChangedEvent event)
Reacts on selection events.
|
public IlvManagerSelectionDispatcher()
protected abstract String getID()
protected abstract IlvManagerSelectionDispatcher create()
public static IlvManagerSelectionDispatcher Get(IlvGraphicBag bag, boolean addIfNecessary, IlvManagerSelectionDispatcher 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 selection event.public void notifyRemove()
IlvGraphic
is removed from
the related manager that wanted to receive the selection event.public void selectionChanged(ManagerSelectionChangedEvent event)
selectionChanged
in interface ManagerSelectionListener
event
- The selection event.IlvManager.addManagerSelectionListener(ilog.views.event.ManagerSelectionListener)
,
IlvManager.removeManagerSelectionListener(ilog.views.event.ManagerSelectionListener)
,
IlvManager.addManagerTreeSelectionListener(ilog.views.event.ManagerSelectionListener)
,
IlvManager.removeManagerTreeSelectionListener(ilog.views.event.ManagerSelectionListener)
,
IlvManager.selectionChanged(ilog.views.IlvGraphic)
protected void selectionChanged(IlvGraphic g, ManagerSelectionChangedEvent event)
g
- The object that was selected or deselected.event
- The selection event.© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.