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.SetExpressionHelper; 029import javafx.beans.InvalidationListener; 030import javafx.beans.value.ChangeListener; 031import javafx.collections.ObservableSet; 032import javafx.collections.SetChangeListener; 033 034/** 035 * Base class for all readonly properties wrapping an {@link javafx.collections.ObservableSet}. 036 * This class provides a default implementation to attach listener. 037 * 038 * @see ReadOnlySetProperty 039 * 040 * @param <E> the type of the {@code Set} elements 041 */ 042public abstract class ReadOnlySetPropertyBase<E> extends ReadOnlySetProperty<E> { 043 044 private SetExpressionHelper<E> helper; 045 046 @Override 047 public void addListener(InvalidationListener listener) { 048 helper = SetExpressionHelper.addListener(helper, this, listener); 049 } 050 051 @Override 052 public void removeListener(InvalidationListener listener) { 053 helper = SetExpressionHelper.removeListener(helper, listener); 054 } 055 056 @Override 057 public void addListener(ChangeListener<? super ObservableSet<E>> listener) { 058 helper = SetExpressionHelper.addListener(helper, this, listener); 059 } 060 061 @Override 062 public void removeListener(ChangeListener<? super ObservableSet<E>> listener) { 063 helper = SetExpressionHelper.removeListener(helper, listener); 064 } 065 066 @Override 067 public void addListener(SetChangeListener<? super E> listener) { 068 helper = SetExpressionHelper.addListener(helper, this, listener); 069 } 070 071 @Override 072 public void removeListener(SetChangeListener<? super E> listener) { 073 helper = SetExpressionHelper.removeListener(helper, listener); 074 } 075 076 /** 077 * This method needs to be called if the reference to the 078 * {@link javafx.collections.ObservableSet} changes. 079 * 080 * It sends notifications to all attached 081 * {@link javafx.beans.InvalidationListener InvalidationListeners}, 082 * {@link javafx.beans.value.ChangeListener ChangeListeners}, and 083 * {@link javafx.collections.SetChangeListener}. 084 * 085 * This method needs to be called, if the value of this property changes. 086 */ 087 protected void fireValueChangedEvent() { 088 SetExpressionHelper.fireValueChangedEvent(helper); 089 } 090 091 /** 092 * This method needs to be called if the content of the referenced 093 * {@link javafx.collections.ObservableSet} changes. 094 * 095 * Sends notifications to all attached 096 * {@link javafx.beans.InvalidationListener InvalidationListeners}, 097 * {@link javafx.beans.value.ChangeListener ChangeListeners}, and 098 * {@link javafx.collections.SetChangeListener}. 099 * 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(SetChangeListener.Change<? extends E> change) { 105 SetExpressionHelper.fireValueChangedEvent(helper, change); 106 } 107 108 109 110}