< prev index next >

modules/base/src/main/java/javafx/beans/property/ReadOnlyMapWrapper.java

Print this page
rev 9213 : 8089557: bindBidirection works for ReadOnly*Wrapper incorrectly


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javafx.beans.property;
  27 
  28 import javafx.beans.InvalidationListener;
  29 import javafx.beans.value.ChangeListener;
  30 import javafx.collections.ObservableMap;
  31 import javafx.collections.MapChangeListener;
  32 
  33 import static javafx.collections.MapChangeListener.Change;
  34 
  35 /**
  36  * This class provides a convenient class to define read-only properties. It
  37  * creates two properties that are synchronized. One property is read-only
  38  * and can be passed to external users. The other property is read- and
  39  * writable and should be used internally only.
  40  *
  41  * @since JavaFX 2.1
  42  */
  43 public class ReadOnlyMapWrapper<K, V> extends SimpleMapProperty<K, V> {
  44 
  45     private ReadOnlyPropertyImpl readOnlyProperty;
  46 
  47     /**
  48      * The constructor of {@code ReadOnlyMapWrapper}
  49      */
  50     public ReadOnlyMapWrapper() {
  51     }
  52 


  87         super(bean, name, initialValue);
  88     }
  89 
  90     /**
  91      * Returns the readonly property, that is synchronized with this
  92      * {@code ReadOnlyMapWrapper}.
  93      *
  94      * @return the readonly property
  95      */
  96     public ReadOnlyMapProperty<K, V> getReadOnlyProperty() {
  97         if (readOnlyProperty == null) {
  98             readOnlyProperty = new ReadOnlyPropertyImpl();
  99         }
 100         return readOnlyProperty;
 101     }
 102 
 103     /**
 104      * {@inheritDoc}
 105      */
 106     @Override
 107     public void addListener(InvalidationListener listener) {
 108         getReadOnlyProperty().addListener(listener);
 109     }
 110 
 111     /**
 112      * {@inheritDoc}
 113      */
 114     @Override
 115     public void removeListener(InvalidationListener listener) {
 116         if (readOnlyProperty != null) {
 117             readOnlyProperty.removeListener(listener);
 118         }
 119     }
 120 
 121     /**
 122      * {@inheritDoc}
 123      */
 124     @Override
 125     public void addListener(ChangeListener<? super ObservableMap<K, V>> listener) {
 126         getReadOnlyProperty().addListener(listener);
 127     }
 128 
 129     /**
 130      * {@inheritDoc}
 131      */
 132     @Override
 133     public void removeListener(ChangeListener<? super ObservableMap<K, V>> listener) {
 134         if (readOnlyProperty != null) {
 135             readOnlyProperty.removeListener(listener);
 136         }
 137     }
 138 
 139     /**
 140      * {@inheritDoc}
 141      */
 142     @Override
 143     public void addListener(MapChangeListener<? super K, ? super V> listener) {
 144         getReadOnlyProperty().addListener(listener);
 145     }
 146 
 147     /**
 148      * {@inheritDoc}
 149      */
 150     @Override
 151     public void removeListener(MapChangeListener<? super K, ? super V> listener) {
 152         if (readOnlyProperty != null) {
 153             readOnlyProperty.removeListener(listener);
 154         }
 155     }
 156 
 157     /**
 158      * {@inheritDoc}
 159      */
 160     @Override
 161     protected void fireValueChangedEvent() {

 162         if (readOnlyProperty != null) {
 163             readOnlyProperty.fireValueChangedEvent();
 164         }
 165     }
 166 
 167     /**
 168      * {@inheritDoc}
 169      */
 170     @Override
 171     protected void fireValueChangedEvent(Change<? extends K, ? extends V> change) {

 172         if (readOnlyProperty != null) {
 173             readOnlyProperty.fireValueChangedEvent(change);
 174         }
 175     }
 176 
 177     private class ReadOnlyPropertyImpl extends ReadOnlyMapPropertyBase<K, V> {
 178 
 179         @Override
 180         public ObservableMap<K, V> get() {
 181             return ReadOnlyMapWrapper.this.get();
 182         }
 183 
 184         @Override
 185         public Object getBean() {
 186             return ReadOnlyMapWrapper.this.getBean();
 187         }
 188 
 189         @Override
 190         public String getName() {
 191             return ReadOnlyMapWrapper.this.getName();


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javafx.beans.property;
  27 


  28 import javafx.collections.ObservableMap;


  29 import static javafx.collections.MapChangeListener.Change;
  30 
  31 /**
  32  * This class provides a convenient class to define read-only properties. It
  33  * creates two properties that are synchronized. One property is read-only
  34  * and can be passed to external users. The other property is read- and
  35  * writable and should be used internally only.
  36  *
  37  * @since JavaFX 2.1
  38  */
  39 public class ReadOnlyMapWrapper<K, V> extends SimpleMapProperty<K, V> {
  40 
  41     private ReadOnlyPropertyImpl readOnlyProperty;
  42 
  43     /**
  44      * The constructor of {@code ReadOnlyMapWrapper}
  45      */
  46     public ReadOnlyMapWrapper() {
  47     }
  48 


  83         super(bean, name, initialValue);
  84     }
  85 
  86     /**
  87      * Returns the readonly property, that is synchronized with this
  88      * {@code ReadOnlyMapWrapper}.
  89      *
  90      * @return the readonly property
  91      */
  92     public ReadOnlyMapProperty<K, V> getReadOnlyProperty() {
  93         if (readOnlyProperty == null) {
  94             readOnlyProperty = new ReadOnlyPropertyImpl();
  95         }
  96         return readOnlyProperty;
  97     }
  98 
  99     /**
 100      * {@inheritDoc}
 101      */
 102     @Override






















































 103     protected void fireValueChangedEvent() {
 104         super.fireValueChangedEvent();
 105         if (readOnlyProperty != null) {
 106             readOnlyProperty.fireValueChangedEvent();
 107         }
 108     }
 109 
 110     /**
 111      * {@inheritDoc}
 112      */
 113     @Override
 114     protected void fireValueChangedEvent(Change<? extends K, ? extends V> change) {
 115         super.fireValueChangedEvent(change);
 116         if (readOnlyProperty != null) {
 117             readOnlyProperty.fireValueChangedEvent(change);
 118         }
 119     }
 120 
 121     private class ReadOnlyPropertyImpl extends ReadOnlyMapPropertyBase<K, V> {
 122 
 123         @Override
 124         public ObservableMap<K, V> get() {
 125             return ReadOnlyMapWrapper.this.get();
 126         }
 127 
 128         @Override
 129         public Object getBean() {
 130             return ReadOnlyMapWrapper.this.getBean();
 131         }
 132 
 133         @Override
 134         public String getName() {
 135             return ReadOnlyMapWrapper.this.getName();
< prev index next >