changeset 5281:70b8c27e00e0

Ensemble8: Guarded XYDataVisualizer against NPEs.
author Alexander Kouznetsov
date Mon, 07 Oct 2013 13:14:33 +0400
parents b275a99ef7f5
children 77c02e6ffbe6
files apps/samples/Ensemble8/src/app/java/ensemble/samplepage/XYDataVisualizer.java
diffstat 1 files changed, 21 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/apps/samples/Ensemble8/src/app/java/ensemble/samplepage/XYDataVisualizer.java	Mon Oct 07 13:10:06 2013 +0400
+++ b/apps/samples/Ensemble8/src/app/java/ensemble/samplepage/XYDataVisualizer.java	Mon Oct 07 13:14:33 2013 +0400
@@ -101,7 +101,11 @@
 
             @Override
             public ObservableValue<String> call(CellDataFeatures<XYChartItem<X, Y>, String> p) {
-                return p.getValue().getValue().nameProperty();
+                if (p.getValue() != null) {
+                    return p.getValue().getValue().nameProperty();
+                } else {
+                    return null;
+                }
             }
         });
         nameColumn.setEditable(true);
@@ -113,7 +117,11 @@
 
             @Override
             public ObservableValue<X> call(CellDataFeatures<XYChartItem<X, Y>, X> p) {
-                return p.getValue().getValue().xValueProperty();
+                if (p.getValue() != null) {
+                    return p.getValue().getValue().xValueProperty();
+                } else {
+                    return null;
+                }
             }
         });
         xValueColumn.setCellFactory(new Callback<TreeTableColumn<XYChartItem<X, Y>, X>, TreeTableCell<XYChartItem<X, Y>, X>>() {
@@ -147,7 +155,11 @@
 
             @Override
             public ObservableValue<Y> call(CellDataFeatures<XYChartItem<X, Y>, Y> p) {
-                return p.getValue().getValue().yValueProperty();
+                if (p.getValue() != null) {
+                    return p.getValue().getValue().yValueProperty();
+                } else {
+                    return null;
+                }
             }
         });
         yValueColumn.setCellFactory(new Callback<TreeTableColumn<XYChartItem<X, Y>, Y>, TreeTableCell<XYChartItem<X, Y>, Y>>() {
@@ -176,17 +188,20 @@
         yValueColumn.setSortable(false);
         yValueColumn.setMinWidth(50);
         
-        Class<XYChartItem<X, Y>> clz = (Class<XYChartItem<X, Y>>) root.getClass();
         TreeTableColumn<XYChartItem<X, Y>, Object> extraValueColumn = new TreeTableColumn<>("Extra Value");
         extraValueColumn.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<XYChartItem<X, Y>, Object>, ObservableValue<Object>>() {
             @Override
             public ObservableValue<Object> call(CellDataFeatures<XYChartItem<X, Y>, Object> p) {
-                return p.getValue().getValue().extraValueProperty();
+                if (p.getValue() != null) {
+                    return p.getValue().getValue().extraValueProperty();
+                } else {
+                    return null;
+                }
             }
         });
         extraValueColumn.setMinWidth(100);
         extraValueColumn.setSortable(false);
-
+        
         getColumns().setAll(nameColumn, xValueColumn, yValueColumn, extraValueColumn);
         
         setOnContextMenuRequested(new EventHandler<ContextMenuEvent>() {