java - Trying to have a view reflect an editor's status -


i have view want react happens in editor. right have button want when clicked updates data in view new set of information. start, have selection event no idea on how communicate between two. i'm looking loose coupling solution.

i'm sure there many ways of doing this, i've used jface ipropertychangelistener interface in past simple event propagation.

make view implement ipropertychangelistener. create singleton class can register ipropertychangelistener with, , send propertychangeevent to. in constructor of view, register singleton.

now can hold of singleton in editor , fire off event picked in view.

example code singleton:

public class propertychangeeventbus {      private static propertychangeeventbus s_instance = new propertychangeeventbus();      public static propertychangeeventbus instance()     {         return s_instance;     }      private set<ipropertychangelistener> m_listeners;      private propertychangeeventbus()     {         // use copyonwritearrayset prevent concurrentmodificationexceptions         m_listeners = new copyonwritearrayset<ipropertychangelistener>();     }      public void addlistener(ipropertychangelistener listener)     {            m_listeners.add(listener);            }      public void removelistener(ipropertychangelistener listener)     {         m_listeners.remove(listener);     }      public void fire(final propertychangeevent event)     {            // run property change events in ui thread prevent having have lots of syncexecs in listener methods         viewutils.syncexec(new runnable()         {                        @override             public void run()             {                 (ipropertychangelistener listener : m_listeners)                  {                     try                     {                         listener.propertychange(event);                     }                     catch(exception e)                     {                                                //log it, present error message                     }                 }             }         });          } } 

example code view:

//the constructor public myview()  {     propertychangeeventbus.instance().addlistener(this); }  @override public void propertychange(propertychangeevent event) {     if(event.getproperty().equals(some_constant))     {                    // refresh view              } } 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -