public interface

Mediator

org.eclipse.sisu.Mediator<Q extends java.lang.annotation.Annotation, T, W>

Class Overview

Implement this interface to Watch for Qualified bean implementations of T.

The Mediator is responsible for translating updates to whatever the watchers expect. Mediation only occurs when there are updates to qualified bindings and at least one live watcher instance. So if no-one requests or injects an instance of the watcher then the mediator will not be called.

 @Named
 public class MyTabbedPane
     extends JTabbedPane
 {
     // watcher
 }
 
 @Qualifier
 @Retention( RetentionPolicy.RUNTIME )
 public @interface Tab
 {
     String title();
 }
 
 @Tab( title = "Summary" )
 public class SummaryTab
     extends JPanel
 {
     // qualified bean
 }
 
 @Tab( title = "Notes" )
 public class NotesTab
     extends JPanel
 {
     // qualified bean
 }
 
 @Named
 public class SwingTabMediator
     implements Mediator<Tab, JPanel, MyTabbedPane>
 {
     public void add( BeanEntry<Tab, JPanel> entry, final MyTabbedPane watcher )
         throws Exception
     {
         final Tab tab = entry.getKey();
         final JPanel panel = entry.getValue();
 
         SwingUtilities.invokeLater( new Runnable()
         {
             public void run()
             {
                 watcher.addTab( tab.title(), panel );
             }
         } );
     }
 
     public void remove( BeanEntry<Tab, JPanel> entry, final MyTabbedPane watcher )
         throws Exception
     {
         final Tab tab = entry.getKey();
 
         SwingUtilities.invokeLater( new Runnable()
         {
             public void run()
             {
                 watcher.removeTabAt( watcher.indexOfTab( tab.title() ) );
             }
         } );
     }
 }
 
As soon as MyTabbedPane is instantiated Sisu uses the declared SwingTabMediator to send all known JPanels annotated with @Tab to the watching MyTabbedPane. Sisu will continue to send updates, which add or remove tabs as appropriate, until the MyTabbedPane instance becomes unreachable. Note how MyTabbedPane doesn't need to know about Sisu APIs and vice-versa, SwingTabMediator takes care of the necessary interaction.

Summary

Public Methods
abstract void add(BeanEntry<Q, T> entry, W watcher)
Processes the added BeanEntry and sends the necessary updates to the watcher.
abstract void remove(BeanEntry<Q, T> entry, W watcher)
Processes the removed BeanEntry and sends the necessary updates to the watcher.

Public Methods

public abstract void add (BeanEntry<Q, T> entry, W watcher)

Processes the added BeanEntry and sends the necessary updates to the watcher.

Parameters
entry The added bean entry
watcher The watching object
Throws
Exception

public abstract void remove (BeanEntry<Q, T> entry, W watcher)

Processes the removed BeanEntry and sends the necessary updates to the watcher.

Parameters
entry The removed bean entry
watcher The watching object
Throws
Exception