Develop > Presentation layer > Customize IBM Sales Center > Data model


Add change notification to the data model

The data model is used to cache business objects on the client. This section explains how to add change notification to the data model.

To be notified of changes to the data model, :


Procedure

  1. Create an implementation of IModelListener and register the listener to the model object that to listen to, for example:

    package extensions; 
    import java.text.DateFormat; import java.util.Date; 
    import com.ibm.commerce.telesales.model.IModelListener; import com.ibm.commerce.telesales.model.ModelObjectChangedEvent; import com.ibm.commerce.telesales.model.ModelRoot; import com.ibm.commerce.telesales.model.Store; 
    public class ExtendedModelListener implements IModelListener {
    
            public void modelChanged(ModelObjectChangedEvent event) {
                    String propertyName = event.getPropertyName();                 if (propertyName != null && propertyName.startsWith(ModelRoot.PROP_OPEN_STORES)) {
                            if (event.getNewData() instanceof Store) {
                                    Store store =
    (Store)event.getNewData();                                 store.setData("storeOpenedTime", DateFormat.getDateTimeInstance().format(new Date()));                         }
                    }
                    else if ("storeOpenedTime".equals(propertyName)) {
                            Store store = (Store)
    event.getParentModelObject();                         System.out.println(store.getDescription() +
    " was opened at " + store.getData("storeOpenedTime"));                 }
    
            }
    
    }
    

  2. Create an extension to the org.eclipse.ui.startup extension point. For example, in the extensions plug-in:

    <?xml version="1.0" encoding="UTF-8"?>
    <?eclipse version="3.0"?>
    <plugin>   
    <extension point="org.eclipse.ui.startup">      
    <startup />   
    </extension>
    </plugin>
    

  3. To hear about all changes to the model, add the listener to the ModelRoot object. For example:

    package extensions; 
    import org.eclipse.ui.IStartup; 
    import com.ibm.commerce.telesales.model.TelesalesModelManager; 
    public class ExtendedStartup implements IStartup {
    
            public void earlyStartup() {
                   
    TelesalesModelManager.getInstance().getModelRoot().addModelListener(new
    ExtendedModelListener());         }
    
    }
    


Related concepts

Data model


Related tasks

Add a model object

Add properties to a model object


+

Search Tips   |   Advanced Search