< prev index next >

apps/samples/Ensemble8/src/app/java/ensemble/samplepage/XYDataVisualizer.java

Print this page
rev 9364 : 8088078: [Chart] "Insert Series" can not work as expected after we remove all data
summary: Fixed error while adding new series to empty table or when no series selected.

@@ -196,11 +196,13 @@
         setOnContextMenuRequested((ContextMenuEvent t) -> {
             Node node = t.getPickResult().getIntersectedNode();
             while (node != null && !(node instanceof TreeTableRow) && !(node instanceof TreeTableCell)) {
                 node = node.getParent();
             }
-            if (node instanceof TreeTableCell) {
+            if (node == null) {
+                getSelectionModel().clearSelection();
+            } else if (node instanceof TreeTableCell) {
                 TreeTableCell tc = (TreeTableCell) node;
                 if (tc.getItem() == null) {
                     getSelectionModel().clearSelection();
                 } else {
                     getSelectionModel().select(tc.getIndex());

@@ -235,14 +237,12 @@
 
         MenuItem insertSeriesMenuitem = new MenuItem("Insert Series");
         insertSeriesMenuitem.setDisable(!isEditable());
         insertSeriesMenuitem.setOnAction((ActionEvent t) -> {
             TreeItem<XYChartItem<X, Y>> selectedItem = getSelectionModel().getSelectedItem();
-            if (selectedItem == null) {
-                return;
-            }
-            Object value = selectedItem.getValue().getValue();
+            Object value = selectedItem == null ? chart.getData()
+                    : selectedItem.getValue().getValue();
             if (value instanceof ObservableList) {
                 ObservableList parentList = (ObservableList) value;
                 insertSeries(parentList.size(), parentList);
             } else {
                 Object parentValue = selectedItem.getParent().getValue().getValue();
< prev index next >