modules/controls/src/main/java/javafx/scene/control/TableView.java

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization


   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.scene.control;
  27 
  28 import java.lang.ref.WeakReference;
  29 import java.util.*;








  30 
  31 import com.sun.javafx.scene.control.Logging;

  32 import com.sun.javafx.scene.control.SelectedCellsMap;
  33 import com.sun.javafx.scene.control.behavior.TableCellBehavior;
  34 import com.sun.javafx.scene.control.behavior.TableCellBehaviorBase;
  35 import javafx.beans.*;
  36 import javafx.beans.Observable;
  37 import javafx.beans.property.BooleanProperty;
  38 import javafx.beans.property.DoubleProperty;
  39 import javafx.beans.property.ObjectProperty;
  40 import javafx.beans.property.ObjectPropertyBase;
  41 import javafx.beans.property.Property;
  42 import javafx.beans.property.ReadOnlyObjectProperty;
  43 import javafx.beans.property.ReadOnlyObjectWrapper;
  44 import javafx.beans.property.SimpleBooleanProperty;
  45 import javafx.beans.property.SimpleObjectProperty;
  46 import javafx.beans.value.ChangeListener;
  47 import javafx.beans.value.ObservableValue;
  48 import javafx.collections.FXCollections;
  49 import javafx.collections.ListChangeListener;
  50 import javafx.collections.MapChangeListener;
  51 import javafx.collections.ObservableList;
  52 import javafx.collections.WeakListChangeListener;
  53 import javafx.collections.transformation.SortedList;
  54 import javafx.css.CssMetaData;
  55 import javafx.css.PseudoClass;
  56 import javafx.css.Styleable;
  57 import javafx.css.StyleableDoubleProperty;
  58 import javafx.css.StyleableProperty;
  59 import javafx.event.EventHandler;
  60 import javafx.event.EventType;
  61 import javafx.scene.AccessibleAttribute;
  62 import javafx.scene.AccessibleRole;
  63 import javafx.scene.Node;
  64 import javafx.scene.layout.Region;
  65 import javafx.util.Callback;
  66 
  67 import com.sun.javafx.collections.MappingChange;
  68 import com.sun.javafx.collections.NonIterableChange;
  69 import com.sun.javafx.collections.annotations.ReturnsUnmodifiableCollection;
  70 import com.sun.javafx.css.converters.SizeConverter;
  71 import com.sun.javafx.scene.control.ReadOnlyUnbackedObservableList;
  72 import com.sun.javafx.scene.control.TableColumnComparatorBase.TableColumnComparator;
  73 import com.sun.javafx.scene.control.skin.TableViewSkin;
  74 import com.sun.javafx.scene.control.skin.TableViewSkinBase;
  75 
  76 /**
  77  * The TableView control is designed to visualize an unlimited number of rows
  78  * of data, broken out into columns. A TableView is therefore very similar to the
  79  * {@link ListView} control, with the addition of support for columns. For an
  80  * example on how to create a TableView, refer to the 'Creating a TableView'
  81  * control section below.
  82  *
  83  * <p>The TableView control has a number of features, including:
  84  * <ul>
  85  * <li>Powerful {@link TableColumn} API:
  86  *   <ul>
  87  *   <li>Support for {@link TableColumn#cellFactoryProperty() cell factories} to
  88  *      easily customize {@link Cell cell} contents in both rendering and editing
  89  *      states.
  90  *   <li>Specification of {@link TableColumn#minWidthProperty() minWidth}/
  91  *      {@link TableColumn#prefWidthProperty() prefWidth}/
  92  *      {@link TableColumn#maxWidthProperty() maxWidth},
  93  *      and also {@link TableColumn#resizableProperty() fixed width columns}.
  94  *   <li>Width resizing by the user at runtime.


1566                     // TablePosition's changing (which may reside in the same list
1567                     // position before and after the sort). Therefore, we need to fire
1568                     // a single add/remove event to cover the added and removed positions.
1569                     ListChangeListener.Change<TablePosition<S, ?>> c = new NonIterableChange.GenericAddRemoveChange<>(0, itemCount, removed, newState);
1570                     sm.handleSelectedCellsListChangeEvent(c);
1571                 }
1572             }
1573         }
1574     }
1575 
1576     /**
1577      * Calling {@code refresh()} forces the TableView control to recreate and
1578      * repopulate the cells necessary to populate the visual bounds of the control.
1579      * In other words, this forces the TableView to update what it is showing to
1580      * the user. This is useful in cases where the underlying data source has
1581      * changed in a way that is not observed by the TableView itself.
1582      *
1583      * @since JavaFX 8u60
1584      */
1585     public void refresh() {
1586         getProperties().put(TableViewSkinBase.RECREATE, Boolean.TRUE);
1587     }
1588     
1589     
1590 
1591     /***************************************************************************
1592      *                                                                         *
1593      * Private Implementation                                                  *
1594      *                                                                         *
1595      **************************************************************************/
1596     
1597     private boolean sortLock = false;
1598     private TableUtil.SortEventType lastSortEventType = null;
1599     private Object[] lastSortEventSupportInfo = null;
1600     
1601     private void doSort(final TableUtil.SortEventType sortEventType, final Object... supportInfo) {
1602         if (sortLock) {
1603             return;
1604         }
1605         
1606         this.lastSortEventType = sortEventType;




   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.scene.control;
  27 
  28 import java.lang.ref.WeakReference;
  29 import java.util.ArrayList;
  30 import java.util.Collection;
  31 import java.util.Collections;
  32 import java.util.Comparator;
  33 import java.util.HashMap;
  34 import java.util.LinkedHashSet;
  35 import java.util.List;
  36 import java.util.Set;
  37 import java.util.WeakHashMap;
  38 
  39 import com.sun.javafx.scene.control.Logging;
  40 import com.sun.javafx.scene.control.Properties;
  41 import com.sun.javafx.scene.control.SelectedCellsMap;
  42 import com.sun.javafx.scene.control.behavior.TableCellBehavior;
  43 import com.sun.javafx.scene.control.behavior.TableCellBehaviorBase;
  44 import javafx.beans.*;
  45 import javafx.beans.Observable;
  46 import javafx.beans.property.BooleanProperty;
  47 import javafx.beans.property.DoubleProperty;
  48 import javafx.beans.property.ObjectProperty;
  49 import javafx.beans.property.ObjectPropertyBase;
  50 import javafx.beans.property.Property;
  51 import javafx.beans.property.ReadOnlyObjectProperty;
  52 import javafx.beans.property.ReadOnlyObjectWrapper;
  53 import javafx.beans.property.SimpleBooleanProperty;
  54 import javafx.beans.property.SimpleObjectProperty;


  55 import javafx.collections.FXCollections;
  56 import javafx.collections.ListChangeListener;
  57 import javafx.collections.MapChangeListener;
  58 import javafx.collections.ObservableList;
  59 import javafx.collections.WeakListChangeListener;
  60 import javafx.collections.transformation.SortedList;
  61 import javafx.css.CssMetaData;
  62 import javafx.css.PseudoClass;
  63 import javafx.css.Styleable;
  64 import javafx.css.StyleableDoubleProperty;
  65 import javafx.css.StyleableProperty;
  66 import javafx.event.EventHandler;
  67 import javafx.event.EventType;
  68 import javafx.scene.AccessibleAttribute;
  69 import javafx.scene.AccessibleRole;
  70 import javafx.scene.Node;
  71 import javafx.scene.layout.Region;
  72 import javafx.util.Callback;
  73 
  74 import com.sun.javafx.collections.MappingChange;
  75 import com.sun.javafx.collections.NonIterableChange;
  76 import com.sun.javafx.collections.annotations.ReturnsUnmodifiableCollection;
  77 import javafx.css.converter.SizeConverter;
  78 import com.sun.javafx.scene.control.ReadOnlyUnbackedObservableList;
  79 import com.sun.javafx.scene.control.TableColumnComparatorBase.TableColumnComparator;
  80 import javafx.scene.control.skin.TableViewSkin;

  81 
  82 /**
  83  * The TableView control is designed to visualize an unlimited number of rows
  84  * of data, broken out into columns. A TableView is therefore very similar to the
  85  * {@link ListView} control, with the addition of support for columns. For an
  86  * example on how to create a TableView, refer to the 'Creating a TableView'
  87  * control section below.
  88  *
  89  * <p>The TableView control has a number of features, including:
  90  * <ul>
  91  * <li>Powerful {@link TableColumn} API:
  92  *   <ul>
  93  *   <li>Support for {@link TableColumn#cellFactoryProperty() cell factories} to
  94  *      easily customize {@link Cell cell} contents in both rendering and editing
  95  *      states.
  96  *   <li>Specification of {@link TableColumn#minWidthProperty() minWidth}/
  97  *      {@link TableColumn#prefWidthProperty() prefWidth}/
  98  *      {@link TableColumn#maxWidthProperty() maxWidth},
  99  *      and also {@link TableColumn#resizableProperty() fixed width columns}.
 100  *   <li>Width resizing by the user at runtime.


1572                     // TablePosition's changing (which may reside in the same list
1573                     // position before and after the sort). Therefore, we need to fire
1574                     // a single add/remove event to cover the added and removed positions.
1575                     ListChangeListener.Change<TablePosition<S, ?>> c = new NonIterableChange.GenericAddRemoveChange<>(0, itemCount, removed, newState);
1576                     sm.handleSelectedCellsListChangeEvent(c);
1577                 }
1578             }
1579         }
1580     }
1581 
1582     /**
1583      * Calling {@code refresh()} forces the TableView control to recreate and
1584      * repopulate the cells necessary to populate the visual bounds of the control.
1585      * In other words, this forces the TableView to update what it is showing to
1586      * the user. This is useful in cases where the underlying data source has
1587      * changed in a way that is not observed by the TableView itself.
1588      *
1589      * @since JavaFX 8u60
1590      */
1591     public void refresh() {
1592         getProperties().put(Properties.RECREATE, Boolean.TRUE);
1593     }
1594     
1595     
1596 
1597     /***************************************************************************
1598      *                                                                         *
1599      * Private Implementation                                                  *
1600      *                                                                         *
1601      **************************************************************************/
1602     
1603     private boolean sortLock = false;
1604     private TableUtil.SortEventType lastSortEventType = null;
1605     private Object[] lastSortEventSupportInfo = null;
1606     
1607     private void doSort(final TableUtil.SortEventType sortEventType, final Object... supportInfo) {
1608         if (sortLock) {
1609             return;
1610         }
1611         
1612         this.lastSortEventType = sortEventType;