46
47 import javafx.scene.control.TableColumn.CellEditEvent;
48
49
50 /**
51 * Represents a single row/column intersection in a {@link TableView}. To
52 * represent this intersection, a TableCell contains an
53 * {@link #indexProperty() index} property, as well as a
54 * {@link #tableColumnProperty() tableColumn} property. In addition, a TableCell
55 * instance knows what {@link TableRow} it exists in.
56 *
57 * <p><strong>A note about selection:</strong> A TableCell visually shows it is
58 * selected when two conditions are met:
59 * <ol>
60 * <li>The {@link TableSelectionModel#isSelected(int, TableColumnBase)} method
61 * returns true for the row / column that this cell represents, and</li>
62 * <li>The {@link javafx.scene.control.TableSelectionModel#cellSelectionEnabledProperty() cell selection mode}
63 * property is set to true (to represent that it is allowable to select
64 * individual cells (and not just rows of cells)).</li>
65 * </ol>
66 * </p>
67 *
68 * @see TableView
69 * @see TableColumn
70 * @see Cell
71 * @see IndexedCell
72 * @see TableRow
73 * @param <S> The type of the TableView generic type (i.e. S == TableView<S>).
74 * This should also match with the first generic type in TableColumn.
75 * @param <T> The type of the item contained within the Cell.
76 * @since JavaFX 2.0
77 */
78 public class TableCell<S,T> extends IndexedCell<T> {
79
80 /***************************************************************************
81 * *
82 * Constructors *
83 * *
84 **************************************************************************/
85
86 /**
193 * Properties *
194 * *
195 **************************************************************************/
196
197 // --- TableColumn
198 private ReadOnlyObjectWrapper<TableColumn<S,T>> tableColumn = new ReadOnlyObjectWrapper<TableColumn<S,T>>() {
199 @Override protected void invalidated() {
200 updateColumnIndex();
201 }
202
203 @Override public Object getBean() {
204 return TableCell.this;
205 }
206
207 @Override public String getName() {
208 return "tableColumn";
209 }
210 };
211 /**
212 * The TableColumn instance that backs this TableCell.
213 */
214 public final ReadOnlyObjectProperty<TableColumn<S,T>> tableColumnProperty() { return tableColumn.getReadOnlyProperty(); }
215 private void setTableColumn(TableColumn<S,T> value) { tableColumn.set(value); }
216 public final TableColumn<S,T> getTableColumn() { return tableColumn.get(); }
217
218
219 // --- TableView
220 private ReadOnlyObjectWrapper<TableView<S>> tableView;
221 private void setTableView(TableView<S> value) {
222 tableViewPropertyImpl().set(value);
223 }
224 public final TableView<S> getTableView() {
225 return tableView == null ? null : tableView.get();
226 }
227
228 /**
229 * The TableView associated with this TableCell.
230 */
231 public final ReadOnlyObjectProperty<TableView<S>> tableViewProperty() {
232 return tableViewPropertyImpl().getReadOnlyProperty();
233 }
234
235 private ReadOnlyObjectWrapper<TableView<S>> tableViewPropertyImpl() {
236 if (tableView == null) {
237 tableView = new ReadOnlyObjectWrapper<TableView<S>>() {
238 private WeakReference<TableView<S>> weakTableViewRef;
239 @Override protected void invalidated() {
240 TableView.TableViewSelectionModel<S> sm;
241 TableViewFocusModel<S> fm;
242
243 if (weakTableViewRef != null) {
244 cleanUpTableViewListeners(weakTableViewRef.get());
245 }
246
247 if (get() != null) {
248 sm = get().getSelectionModel();
249 if (sm != null) {
678 if (itemDirty) {
679 updateItem(-1);
680 itemDirty = false;
681 }
682 super.layoutChildren();
683 }
684
685
686
687
688 /***************************************************************************
689 * *
690 * Expert API *
691 * *
692 **************************************************************************/
693
694 /**
695 * Updates the TableView associated with this TableCell. This is typically
696 * only done once when the TableCell is first added to the TableView.
697 *
698 * @expert This function is intended to be used by experts, primarily
699 * by those implementing new Skins. It is not common
700 * for developers or designers to access this function directly.
701 */
702 public final void updateTableView(TableView tv) {
703 setTableView(tv);
704 }
705
706 /**
707 * Updates the TableRow associated with this TableCell.
708 *
709 * @expert This function is intended to be used by experts, primarily
710 * by those implementing new Skins. It is not common
711 * for developers or designers to access this function directly.
712 */
713 public final void updateTableRow(TableRow tableRow) {
714 this.setTableRow(tableRow);
715 }
716
717 /**
718 * Updates the TableColumn associated with this TableCell.
719 *
720 * @expert This function is intended to be used by experts, primarily
721 * by those implementing new Skins. It is not common
722 * for developers or designers to access this function directly.
723 */
724 public final void updateTableColumn(TableColumn col) {
725 // remove style class of existing table column, if it is non-null
726 TableColumn<S,T> oldCol = getTableColumn();
727 if (oldCol != null) {
728 oldCol.getStyleClass().removeListener(weakColumnStyleClassListener);
729 getStyleClass().removeAll(oldCol.getStyleClass());
730
731 oldCol.idProperty().removeListener(weakColumnIdListener);
732 oldCol.styleProperty().removeListener(weakColumnStyleListener);
733
734 String id = getId();
735 String style = getStyle();
736 if (id != null && id.equals(oldCol.getId())) {
737 setId(null);
738 }
739 if (style != null && style.equals(oldCol.getStyle())) {
740 setStyle("");
741 }
742 }
|
46
47 import javafx.scene.control.TableColumn.CellEditEvent;
48
49
50 /**
51 * Represents a single row/column intersection in a {@link TableView}. To
52 * represent this intersection, a TableCell contains an
53 * {@link #indexProperty() index} property, as well as a
54 * {@link #tableColumnProperty() tableColumn} property. In addition, a TableCell
55 * instance knows what {@link TableRow} it exists in.
56 *
57 * <p><strong>A note about selection:</strong> A TableCell visually shows it is
58 * selected when two conditions are met:
59 * <ol>
60 * <li>The {@link TableSelectionModel#isSelected(int, TableColumnBase)} method
61 * returns true for the row / column that this cell represents, and</li>
62 * <li>The {@link javafx.scene.control.TableSelectionModel#cellSelectionEnabledProperty() cell selection mode}
63 * property is set to true (to represent that it is allowable to select
64 * individual cells (and not just rows of cells)).</li>
65 * </ol>
66 *
67 * @see TableView
68 * @see TableColumn
69 * @see Cell
70 * @see IndexedCell
71 * @see TableRow
72 * @param <S> The type of the TableView generic type (i.e. S == TableView<S>).
73 * This should also match with the first generic type in TableColumn.
74 * @param <T> The type of the item contained within the Cell.
75 * @since JavaFX 2.0
76 */
77 public class TableCell<S,T> extends IndexedCell<T> {
78
79 /***************************************************************************
80 * *
81 * Constructors *
82 * *
83 **************************************************************************/
84
85 /**
192 * Properties *
193 * *
194 **************************************************************************/
195
196 // --- TableColumn
197 private ReadOnlyObjectWrapper<TableColumn<S,T>> tableColumn = new ReadOnlyObjectWrapper<TableColumn<S,T>>() {
198 @Override protected void invalidated() {
199 updateColumnIndex();
200 }
201
202 @Override public Object getBean() {
203 return TableCell.this;
204 }
205
206 @Override public String getName() {
207 return "tableColumn";
208 }
209 };
210 /**
211 * The TableColumn instance that backs this TableCell.
212 * @return the TableColumn instance that backs this TableCell
213 */
214 public final ReadOnlyObjectProperty<TableColumn<S,T>> tableColumnProperty() { return tableColumn.getReadOnlyProperty(); }
215 private void setTableColumn(TableColumn<S,T> value) { tableColumn.set(value); }
216 public final TableColumn<S,T> getTableColumn() { return tableColumn.get(); }
217
218
219 // --- TableView
220 private ReadOnlyObjectWrapper<TableView<S>> tableView;
221 private void setTableView(TableView<S> value) {
222 tableViewPropertyImpl().set(value);
223 }
224 public final TableView<S> getTableView() {
225 return tableView == null ? null : tableView.get();
226 }
227
228 /**
229 * The TableView associated with this TableCell.
230 * @return the TableView associated with this TableCell
231 */
232 public final ReadOnlyObjectProperty<TableView<S>> tableViewProperty() {
233 return tableViewPropertyImpl().getReadOnlyProperty();
234 }
235
236 private ReadOnlyObjectWrapper<TableView<S>> tableViewPropertyImpl() {
237 if (tableView == null) {
238 tableView = new ReadOnlyObjectWrapper<TableView<S>>() {
239 private WeakReference<TableView<S>> weakTableViewRef;
240 @Override protected void invalidated() {
241 TableView.TableViewSelectionModel<S> sm;
242 TableViewFocusModel<S> fm;
243
244 if (weakTableViewRef != null) {
245 cleanUpTableViewListeners(weakTableViewRef.get());
246 }
247
248 if (get() != null) {
249 sm = get().getSelectionModel();
250 if (sm != null) {
679 if (itemDirty) {
680 updateItem(-1);
681 itemDirty = false;
682 }
683 super.layoutChildren();
684 }
685
686
687
688
689 /***************************************************************************
690 * *
691 * Expert API *
692 * *
693 **************************************************************************/
694
695 /**
696 * Updates the TableView associated with this TableCell. This is typically
697 * only done once when the TableCell is first added to the TableView.
698 *
699 * Note: This function is intended to be used by experts, primarily
700 * by those implementing new Skins. It is not common
701 * for developers or designers to access this function directly.
702 * @param tv the TableView associated with this TableCell
703 */
704 public final void updateTableView(TableView tv) {
705 setTableView(tv);
706 }
707
708 /**
709 * Updates the TableRow associated with this TableCell.
710 *
711 * Note: This function is intended to be used by experts, primarily
712 * by those implementing new Skins. It is not common
713 * for developers or designers to access this function directly.
714 * @param tableRow the TableRow associated with this TableCell
715 */
716 public final void updateTableRow(TableRow tableRow) {
717 this.setTableRow(tableRow);
718 }
719
720 /**
721 * Updates the TableColumn associated with this TableCell.
722 *
723 * Note: This function is intended to be used by experts, primarily
724 * by those implementing new Skins. It is not common
725 * for developers or designers to access this function directly.
726 * @param col the TableColumn associated with this TableCell
727 */
728 public final void updateTableColumn(TableColumn col) {
729 // remove style class of existing table column, if it is non-null
730 TableColumn<S,T> oldCol = getTableColumn();
731 if (oldCol != null) {
732 oldCol.getStyleClass().removeListener(weakColumnStyleClassListener);
733 getStyleClass().removeAll(oldCol.getStyleClass());
734
735 oldCol.idProperty().removeListener(weakColumnIdListener);
736 oldCol.styleProperty().removeListener(weakColumnStyleListener);
737
738 String id = getId();
739 String style = getStyle();
740 if (id != null && id.equals(oldCol.getId())) {
741 setId(null);
742 }
743 if (style != null && style.equals(oldCol.getStyle())) {
744 setStyle("");
745 }
746 }
|