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