001    package com.google.gwt.maps.client.mvc;
002    
003    import java.util.HashMap;
004    
005    import com.google.gwt.core.client.JavaScriptObject;
006    
007    /**
008     * Base class implementing KVO.
009     * <br><br>
010     * See <a href="https://developers.google.com/maps/documentation/javascript/reference#MVCObject">MVCObject API Doc</a>
011     */
012    public class MVCObject<T extends JavaScriptObject> extends JavaScriptObject {
013      
014      /**
015       * Base class implementing KVO.
016       * use newInstance();
017       */
018      protected MVCObject() {}
019      
020      /**
021       * (Main purpose is for internal use only)
022       * <br>
023       * create instance of MVCObject (inherited class)
024       */
025      public final static <T extends JavaScriptObject> MVCObject<T> createInstanceOfMVCObject() {
026        return createJsoMvcObject().cast();
027      }
028    
029      /**
030       * Binds a View to a Model.
031       */
032      private final static native JavaScriptObject createJsoMvcObject() /*-{
033        return $wnd.google.maps.MVCObject();
034      }-*/;
035    
036      /**
037       * Binds a View to a Model.
038       * @param key
039       * @param target
040       */
041      public final native void bindTo(String key, MVCObject<T> target) /*-{
042        this.bindTo(key, target); 
043      }-*/;
044      
045      /**
046       * Binds a View to a Model.
047       * @param key
048       * @param target
049       * @param targetKey
050       */
051      public final native void bindTo(String key, MVCObject<T> target, String targetKey) /*-{
052        this.bindTo(key, target, targetKey); 
053      }-*/;
054      
055      /**
056       * Binds a View to a Model.
057       * @param key
058       * @param target
059       * @param targetKey
060       * @param noNotify
061       */
062      public final native void bindTo(String key, MVCObject<T> target, String targetKey, boolean noNotify) /*-{
063        this.bindTo(key, target, targetKey, noNotify); 
064      }-*/;
065      
066      /**
067       * Generic handler for state changes. Override this in derived classes to handle arbitrary state changes.
068       * @param key
069       */
070      public final native void changed(String key) /*-{
071        this.changed(key);
072      }-*/;
073      
074      /**
075       * Gets a value.
076       * @param key
077       */
078      public final native T get(String key) /*-{
079        return this.get(key);
080      }-*/;
081      
082      /**
083       * Notify all observers of a change on this property. This notifies both objects that are bound to the object's property as well as the object that it is bound to.
084       * @param key
085       */
086      public final native void notify(String key) /*-{
087        this.notify(key);
088      }-*/;
089      
090      /**
091       * Sets a value.
092       * @param key
093       * @param value
094       */
095      public final native void set(String key, T value) /*-{
096        this.set(key, value);
097      }-*/;
098      
099      /**
100       * Sets a collection of key-value pairs.
101       * @param values
102       */
103      public final native void setValues(HashMap<String, String> values) /*-{
104        this.setValues(values);
105      }-*/;
106      
107      /**
108       * Removes a binding. Unbinding will set the unbound property to the current value. The object will not be notified, as the value has not changed.
109       * @param key
110       */
111      public final native void unbind(String key) /*-{
112        this.unbind(key);
113      }-*/;
114      
115      /**
116       * Removes all bindings.
117       */
118      public final native void unbindAll() /*-{
119        this.unbindAll();
120      }-*/;
121    }