public interface Mediator<Q extends Annotation,T,W>
W
atch for Q
ualified 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.
Modifier and Type | Method and Description |
---|---|
void |
add(BeanEntry<Q,T> entry,
W watcher)
Processes the added
BeanEntry and sends the necessary updates to the watcher. |
void |
remove(BeanEntry<Q,T> entry,
W watcher)
Processes the removed
BeanEntry and sends the necessary updates to the watcher. |
Copyright © 2013. All rights reserved.