1 /* 2 * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 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 com.sun.javafx.binding.ListExpressionHelper; 29 import javafx.beans.InvalidationListener; 30 import javafx.beans.value.ChangeListener; 31 import javafx.collections.ListChangeListener; 32 import javafx.collections.ObservableList; 33 34 /** 35 * Base class for all readonly properties wrapping an 36 * {@link javafx.collections.ObservableList}. 37 * This class provides a default implementation to attach listener. 38 * 39 * @see ReadOnlyListProperty 40 * @since JavaFX 2.1 41 */ 42 public abstract class ReadOnlyListPropertyBase<E> extends ReadOnlyListProperty<E> { 43 44 private ListExpressionHelper<E> helper; 45 46 @Override 47 public void addListener(InvalidationListener listener) { 48 helper = ListExpressionHelper.addListener(helper, this, listener); 49 } 50 51 @Override 52 public void removeListener(InvalidationListener listener) { 53 helper = ListExpressionHelper.removeListener(helper, listener); 54 } 55 56 @Override 57 public void addListener(ChangeListener<? super ObservableList<E>> listener) { 58 helper = ListExpressionHelper.addListener(helper, this, listener); 59 } 60 61 @Override 62 public void removeListener(ChangeListener<? super ObservableList<E>> listener) { 63 helper = ListExpressionHelper.removeListener(helper, listener); 64 } 65 66 @Override 67 public void addListener(ListChangeListener<? super E> listener) { 68 helper = ListExpressionHelper.addListener(helper, this, listener); 69 } 70 71 @Override 72 public void removeListener(ListChangeListener<? super E> listener) { 73 helper = ListExpressionHelper.removeListener(helper, listener); 74 } 75 76 /** 77 * This method needs to be called if the reference to the 78 * {@link javafx.collections.ObservableList} changes. 79 * 80 * It sends notifications to all attached 81 * {@link javafx.beans.InvalidationListener InvalidationListeners}, 82 * {@link javafx.beans.value.ChangeListener ChangeListeners}, and 83 * {@link javafx.collections.ListChangeListener}. 84 * 85 * This method needs to be called, if the value of this property changes. 86 */ 87 protected void fireValueChangedEvent() { 88 ListExpressionHelper.fireValueChangedEvent(helper); 89 } 90 91 /** 92 * This method needs to be called if the content of the referenced 93 * {@link javafx.collections.ObservableList} changes. 94 * 95 * Sends notifications to all attached 96 * {@link javafx.beans.InvalidationListener InvalidationListeners}, 97 * {@link javafx.beans.value.ChangeListener ChangeListeners}, and 98 * {@link javafx.collections.ListChangeListener}. 99 * 100 * This method is called when the content of the list changes. 101 * 102 * @param change the change that needs to be propagated 103 */ 104 protected void fireValueChangedEvent(ListChangeListener.Change<? extends E> change) { 105 ListExpressionHelper.fireValueChangedEvent(helper, change); 106 } 107 108 109 110 }