Spec-Zone .ru
спецификации, руководства, описания, API
|
001/* 002 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. Oracle designates this 008 * particular file as subject to the "Classpath" exception as provided 009 * by Oracle in the LICENSE file that accompanied this code. 010 * 011 * This code is distributed in the hope that it will be useful, but WITHOUT 012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 014 * version 2 for more details (a copy is included in the LICENSE file that 015 * accompanied this code). 016 * 017 * You should have received a copy of the GNU General Public License version 018 * 2 along with this work; if not, write to the Free Software Foundation, 019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 020 * 021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 022 * or visit www.oracle.com if you need additional information or have any 023 * questions. 024 */ 025 026package javafx.beans.property; 027 028import com.sun.javafx.binding.ListExpressionHelper; 029import javafx.beans.InvalidationListener; 030import javafx.beans.value.ChangeListener; 031import javafx.collections.ListChangeListener; 032import javafx.collections.ObservableList; 033 034/** 035 * Base class for all readonly properties wrapping a {@link javafx.collections.ObservableList}. 036 * This class provides a default implementation to attach listener. 037 * 038 * @see ReadOnlyListProperty 039 */ 040public abstract class ReadOnlyListPropertyBase<E> extends ReadOnlyListProperty<E> { 041 042 private ListExpressionHelper<E> helper; 043 044 @Override 045 public void addListener(InvalidationListener listener) { 046 helper = ListExpressionHelper.addListener(helper, this, listener); 047 } 048 049 @Override 050 public void removeListener(InvalidationListener listener) { 051 helper = ListExpressionHelper.removeListener(helper, listener); 052 } 053 054 @Override 055 public void addListener(ChangeListener<? super ObservableList<E>> listener) { 056 helper = ListExpressionHelper.addListener(helper, this, listener); 057 } 058 059 @Override 060 public void removeListener(ChangeListener<? super ObservableList<E>> listener) { 061 helper = ListExpressionHelper.removeListener(helper, listener); 062 } 063 064 @Override 065 public void addListener(ListChangeListener<? super E> listener) { 066 helper = ListExpressionHelper.addListener(helper, this, listener); 067 } 068 069 @Override 070 public void removeListener(ListChangeListener<? super E> listener) { 071 helper = ListExpressionHelper.removeListener(helper, listener); 072 } 073 074 /** 075 * This method needs to be called if the reference to the 076 * {@link javafx.collections.ObservableList} changes. 077 * 078 * It sends notifications to all attached 079 * {@link javafx.beans.InvalidationListener InvalidationListeners}, 080 * {@link javafx.beans.value.ChangeListener ChangeListeners}, and 081 * {@link javafx.collections.ListChangeListener}. 082 * 083 * This method needs to be called, if the value of this property changes. 084 */ 085 protected void fireValueChangedEvent() { 086 ListExpressionHelper.fireValueChangedEvent(helper); 087 } 088 089 /** 090 * This method needs to be called if the content of the referenced 091 * {@link javafx.collections.ObservableList} changes. 092 * 093 * Sends notifications to all attached 094 * {@link javafx.beans.InvalidationListener InvalidationListeners}, 095 * {@link javafx.beans.value.ChangeListener ChangeListeners}, and 096 * {@link javafx.collections.ListChangeListener}. 097 * 098 * This method is called when the content of the list changes. 099 * 100 * @param change the change that needs to be propagated 101 */ 102 protected void fireValueChangedEvent(ListChangeListener.Change<? extends E> change) { 103 ListExpressionHelper.fireValueChangedEvent(helper, change); 104 } 105 106 107 108}