ilog.views.event.adapter
Class IlvManagerSelectionDispatcher

java.lang.Object
  extended by ilog.views.event.adapter.IlvManagerSelectionDispatcher
All Implemented Interfaces:
ManagerSelectionListener, EventListener

public abstract class IlvManagerSelectionDispatcher
extends Object
implements ManagerSelectionListener

An abstract dispatcher class for receiving manager selection events and dispatching them to the graphic objects whose selection changed. This class exists as convenience for creating listener objects.

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);
        }
      }
   }
 }
 

Since:
JViews 8.1
See Also:
ManagerSelectionListener, IlvManager.addManagerSelectionListener(ilog.views.event.ManagerSelectionListener), IlvManager.removeManagerSelectionListener(ilog.views.event.ManagerSelectionListener)

Constructor Summary
IlvManagerSelectionDispatcher()
          Creates a new manager selection dispatcher.
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IlvManagerSelectionDispatcher

public IlvManagerSelectionDispatcher()
Creates a new manager selection dispatcher.

Method Detail

getID

protected abstract String getID()
Returns the unique ID of the dispatcher. The string should be internalized for faster testing. If a manager needs a manager selection dispatcher, it is registered on the manager under this ID. Each manager has only exactly one shared listener for each ID.


create

protected abstract IlvManagerSelectionDispatcher create()
Creates an instance of the manager selection dispatcher. A subclass should return an new instance of the same subclass.


Get

public static IlvManagerSelectionDispatcher Get(IlvGraphicBag bag,
                                                boolean addIfNecessary,
                                                IlvManagerSelectionDispatcher tmplate)
Returns the listener for a manager.

Parameters:
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.

notifyAdd

public void notifyAdd()
Must be called whenever an IlvGraphic object is added to the related manager that wants to receive the selection event.


notifyRemove

public void notifyRemove()
Must be called whenever a IlvGraphic is removed from the related manager that wanted to receive the selection event.


selectionChanged

public void selectionChanged(ManagerSelectionChangedEvent event)
Reacts on selection events.

Specified by:
selectionChanged in interface ManagerSelectionListener
Parameters:
event - The selection event.
See Also:
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)

selectionChanged

protected void selectionChanged(IlvGraphic g,
                                ManagerSelectionChangedEvent event)
Reacts for the input graphic on selection events.

Parameters:
g - The object that was selected or deselected.
event - The selection event.


Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.