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 javafx.beans.binding.Bindings; 029import javafx.beans.value.WritableListValue; 030import javafx.beans.value.WritableSetValue; 031import javafx.collections.ObservableList; 032import javafx.collections.ObservableSet; 033 034/** 035 * This class provides a full implementation of a {@link Property} wrapping a 036 * {@link javafx.collections.ObservableSet}. 037 * 038 * The value of a {@code SetProperty} can be get and set with {@link #get()}, 039 * {@link #getValue()}, {@link #set(Object)}, and {@link #setValue(ObservableSet)}. 040 * 041 * A property can be bound and unbound unidirectional with 042 * {@link #bind(javafx.beans.value.ObservableValue)} and {@link #unbind()}. Bidirectional bindings 043 * can be created and removed with {@link #bindBidirectional(Property)} and 044 * {@link #unbindBidirectional(Property)}. 045 * 046 * The context of a {@code SetProperty} can be read with {@link #getBean()} 047 * and {@link #getName()}. 048 * 049 * @see javafx.collections.ObservableSet 050 * @see javafx.beans.value.ObservableSetValue 051 * @see javafx.beans.value.WritableSetValue 052 * @see ReadOnlySetProperty 053 * @see Property 054 * 055 * @param <E> the type of the {@code Set} elements 056 */ 057public abstract class SetProperty<E> extends ReadOnlySetProperty<E> implements 058 Property<ObservableSet<E>>, WritableSetValue<E> { 059 /** 060 * {@inheritDoc} 061 */ 062 @Override 063 public void setValue(ObservableSet<E> v) { 064 set(v); 065 } 066 067 /** 068 * {@inheritDoc} 069 */ 070 @Override 071 public void bindBidirectional(Property<ObservableSet<E>> other) { 072 Bindings.bindBidirectional(this, other); 073 } 074 075 /** 076 * {@inheritDoc} 077 */ 078 @Override 079 public void unbindBidirectional(Property<ObservableSet<E>> other) { 080 Bindings.unbindBidirectional(this, other); 081 } 082 083 /** 084 * Returns a string representation of this {@code SetProperty} object. 085 * @return a string representation of this {@code SetProperty} object. 086 */ 087 @Override 088 public String toString() { 089 final Object bean = getBean(); 090 final String name = getName(); 091 final StringBuilder result = new StringBuilder( 092 "SetProperty ["); 093 if (bean != null) { 094 result.append("bean: ").append(bean).append(", "); 095 } 096 if ((name != null) && (!name.equals(""))) { 097 result.append("name: ").append(name).append(", "); 098 } 099 result.append("value: ").append(get()).append("]"); 100 return result.toString(); 101 } 102}