1 /* 2 * Copyright (c) 2011, 2013, 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 javafx.beans.binding.Bindings; 29 import javafx.beans.value.WritableListValue; 30 import javafx.beans.value.WritableSetValue; 31 import javafx.collections.ObservableList; 32 import javafx.collections.ObservableSet; 33 34 /** 35 * This class provides a full implementation of a {@link Property} wrapping an 36 * {@link javafx.collections.ObservableSet}. 37 * 38 * The value of a {@code SetProperty} can be get and set with {@link #get()}, 39 * {@link #getValue()}, {@link #set(Object)}, and {@link #setValue(ObservableSet)}. 40 * 41 * A property can be bound and unbound unidirectional with 42 * {@link #bind(javafx.beans.value.ObservableValue)} and {@link #unbind()}. Bidirectional bindings 43 * can be created and removed with {@link #bindBidirectional(Property)} and 44 * {@link #unbindBidirectional(Property)}. 45 * 46 * The context of a {@code SetProperty} can be read with {@link #getBean()} 47 * and {@link #getName()}. 48 * 49 * @see javafx.collections.ObservableSet 50 * @see javafx.beans.value.ObservableSetValue 51 * @see javafx.beans.value.WritableSetValue 52 * @see ReadOnlySetProperty 53 * @see Property 54 * 55 * @param <E> the type of the {@code Set} elements 56 * @since JavaFX 2.1 57 */ 58 public abstract class SetProperty<E> extends ReadOnlySetProperty<E> implements 59 Property<ObservableSet<E>>, WritableSetValue<E> { 60 /** 61 * {@inheritDoc} 62 */ 63 @Override 64 public void setValue(ObservableSet<E> v) { 65 set(v); 66 } 67 68 /** 69 * {@inheritDoc} 70 */ 71 @Override 72 public void bindBidirectional(Property<ObservableSet<E>> other) { 73 Bindings.bindBidirectional(this, other); 74 } 75 76 /** 77 * {@inheritDoc} 78 */ 79 @Override 80 public void unbindBidirectional(Property<ObservableSet<E>> other) { 81 Bindings.unbindBidirectional(this, other); 82 } 83 84 /** 85 * Returns a string representation of this {@code SetProperty} object. 86 * @return a string representation of this {@code SetProperty} object. 87 */ 88 @Override 89 public String toString() { 90 final Object bean = getBean(); 91 final String name = getName(); 92 final StringBuilder result = new StringBuilder( 93 "SetProperty ["); 94 if (bean != null) { 95 result.append("bean: ").append(bean).append(", "); 96 } 97 if ((name != null) && (!name.equals(""))) { 98 result.append("name: ").append(name).append(", "); 99 } 100 result.append("value: ").append(get()).append("]"); 101 return result.toString(); 102 } 103 }