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.scene.control;
027
028import java.lang.ref.WeakReference;
029
030/**
031 * This class is used to represent a single row/column/cell in a TreeTableView.
032 * This is used throughout the TreeTableView API to represent which rows/columns/cells
033 * are currently selected, focused, being edited, etc. Note that this class is
034 * immutable once it is created.
035 *
036 * <p>Because the TreeTableView can have different
037 * {@link SelectionMode selection modes}, the row and column properties in
038 * TablePosition can be 'disabled' to represent an entire row or column. This is
039 * done by setting the unrequired property to -1 or null.
040 *
041 * @param <S> The type of the {@link TreeItem} instances contained within the 
042 *      TreeTableView.
043 * @param <T> The type of the items contained within the TreeTableColumn.
044 * @see TreeTableView
045 * @see TreeTableColumn
046 */
047public class TreeTablePosition<S,T> extends TablePositionBase<TreeTableColumn<S,T>> {
048    
049    /***************************************************************************
050     *                                                                         *
051     * Constructors                                                            *
052     *                                                                         *
053     **************************************************************************/  
054
055    /**
056     * Constructs a TreeTablePosition instance to represent the given row/column
057     * position in the given TreeTableView instance. Both the TreeTableView and 
058     * TreeTableColumn are referenced weakly in this class, so it is possible that
059     * they will be null when their respective getters are called.
060     * 
061     * @param treeTableView The TreeTableView that this position is related to.
062     * @param row The row that this TreeTablePosition is representing.
063     * @param tableColumn The TreeTableColumn instance that this TreeTablePosition represents.
064     */
065    public TreeTablePosition(TreeTableView<S> treeTableView, int row, TreeTableColumn<S,T> tableColumn) {
066        super(row, tableColumn);
067        this.controlRef = new WeakReference<TreeTableView<S>>(treeTableView);
068    }
069    
070    
071    
072    /***************************************************************************
073     *                                                                         *
074     * Instance Variables                                                      *
075     *                                                                         *
076     **************************************************************************/
077
078    private final WeakReference<TreeTableView<S>> controlRef;
079
080
081    /***************************************************************************
082     *                                                                         *
083     * Public API                                                              *
084     *                                                                         *
085     **************************************************************************/
086    
087    /**
088     * The column index that this TreeTablePosition represents in the TreeTableView. It
089     * is -1 if the TreeTableView or TreeTableColumn instances are null.
090     */
091    @Override public int getColumn() {
092        TreeTableView<S> tableView = getTreeTableView();
093        TreeTableColumn<S,T> tableColumn = getTableColumn();
094        return tableView == null || tableColumn == null ? -1 : 
095                tableView.getVisibleLeafIndex(tableColumn);
096    }
097    
098    /**
099     * The TreeTableView that this TreeTablePosition is related to.
100     */
101    public final TreeTableView<S> getTreeTableView() {
102        return controlRef.get();
103    }
104    
105    @Override public final TreeTableColumn<S,T> getTableColumn() {
106        // Forcing the return type to be TreeTableColumn<S,T>, not TableColumnBase<S,T>
107        return super.getTableColumn();
108    }
109}