Event System

A small simple event system that is easy to use and makes sure the events being send are kept separate from the listening to the objects.

The 2 min tutorial

1. Use EventSystemActivator.getDefault().createEventService();
2. Somehow make your model send events to this event service (for instance listen to your existing model and delegate to this event service OR change your model to do something like the following:

public class Book {
private String title;

public String getTitle() {
  return title;
}

public void setTitle(String title) {
  eventService.firePropertyChanged(new PropertyChangeEvent(this, "title", 
                                    this.title, this.title = title));
}
}

3. Now the event service is able to inform of changes using the java.beans.PropertyChangeEvent
4. You can listen for changes using the eventService like this:

public class MyUIClass {
private MyListener listener = new MyListener();

public void listenForChanges() {
  eventservice.addPropertyListener(listener, IBook.class, "title");
}

public void dispose() {
  eventservice.removePropertyListener(listener,  IBook.class, "title");
}

private class MyListener implements PropertyChangeListener{
  @Override
  public void propertyChange(PropertyChangeEvent event) {
    //do refresh of the UI here
  }
}
}

5. Or use any of the api calls:

public interface IEventService {
 addListener(PropertyChangeListener listener);
 removeListener(PropertyChangeListener listener);
 addClassListener(PropertyChangeListener listener, Class... item);
 removeClassListener(PropertyChangeListener listener, Class... item);
 addPropertyListener(PropertyChangeListener listener, Class item, String... property);
 removePropertyListener(PropertyChangeListener listener, Class item, String... property);
}