changeset 6954:60ec7824be54

[TOY ONLY] Clean up HelloTableView to use proper CheckBoxTableCell.
author jgiles
date Thu, 01 May 2014 11:37:32 +1200
parents 54010afd2dcb
children 1c2d5be06d1c
files apps/toys/Hello/src/main/java/hello/HelloTableView.java
diffstat 1 files changed, 3 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/apps/toys/Hello/src/main/java/hello/HelloTableView.java	Tue Apr 29 14:28:02 2014 -0600
+++ b/apps/toys/Hello/src/main/java/hello/HelloTableView.java	Thu May 01 11:37:32 2014 +1200
@@ -68,6 +68,7 @@
 import javafx.scene.control.TextField;
 import javafx.scene.control.ToggleButton;
 import javafx.scene.control.ToggleGroup;
+import javafx.scene.control.cell.CheckBoxTableCell;
 import javafx.scene.control.cell.PropertyValueFactory;
 import javafx.scene.image.Image;
 import javafx.scene.image.ImageView;
@@ -294,6 +295,7 @@
         invitedCol.setMaxWidth(50);
         invitedCol.setCellValueFactory(new PropertyValueFactory("invited"));
         invitedCol.setCellFactory(p -> new CheckBoxTableCell<Person, Boolean>());
+        invitedCol.setEditable(true);
         /*
         ContextMenu ctx = new ContextMenu();
         final MenuItem cutMI    = new MenuItem("Cut");
@@ -389,6 +391,7 @@
 //        tableView.getColumns().addAll(nameCol, emailCol);
         tableView.getColumns().addAll(invitedCol, nameCol, emailCol, countryCol);
         tableView.setPrefSize(485, 300);
+        tableView.setEditable(true);
 
 
         ContextMenu ctx = new ContextMenu();
@@ -904,42 +907,4 @@
         Label label = new Label(text);
         return label;
     }
-
-
-
-    public static class CheckBoxTableCell<S,T> extends TableCell<S,T> {
-        private final CheckBox checkBox;
-
-        private ObservableValue<T> ov;
-
-        public CheckBoxTableCell() {
-            this.checkBox = new CheckBox();
-            this.checkBox.setAlignment(Pos.CENTER);
-
-            setAlignment(Pos.CENTER);
-            setGraphic(checkBox);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void updateItem(T item, boolean empty) {
-            super.updateItem(item, empty);
-
-            if (empty) {
-                setText(null);
-                setGraphic(null);
-            } else {
-                setGraphic(checkBox);
-
-                if (ov instanceof BooleanProperty) {
-                    checkBox.selectedProperty().unbindBidirectional((BooleanProperty)ov);
-                }
-
-                ov = getTableColumn().getCellObservableValue(getIndex());
-
-                if (ov instanceof BooleanProperty) {
-                    checkBox.selectedProperty().bindBidirectional((BooleanProperty)ov);
-                }
-            }
-        }
-    }
 }