mercredi 18 juillet 2018

How do I unselect a selected CheckBoxTreeItem in a selectedProperty listener?

I have a program with a TreeView that has CheckBoxTreeItems and I want to limit the number of selected CheckBoxTreeItems to 24 (once 24 items are selected, other checkboxes that are selected will remain blank). The following code limits the number of items selected to 24, but any other check boxes that are selected after that are still displayed as selected even though I set the selected property to false. After setting the selected property to false, I believe it retains the change until the listener has finished, and then it just switches back to being selected.

 CheckBoxTreeItem<String> check = new CheckBoxTreeItem<>("Data " + Integer.toString(j + 1));
            check.selectedProperty().addListener((obs, oldVal, newVal) -> {

                XYChart.Series series1 = parsingData.graphPointOneStream(x, z);

                if(check.isSelected()){

                    MultiplePlots.setTotalSignalsSelected(MultiplePlots.getTotalSignalsSelected() + 1); 

                    if(MultiplePlots.getTotalSignalsSelected() <= 24){
                        graph.getData().add(series1); 
                        series1.setName("S" + Integer.toString(g + 1) + "D" + Integer.toString(x + 1));
                        channels.setSelectedOrNot(x, 1);   
                    }else{       
                        //Set the selected property of the CheckBox to false
                        check.selectedProperty().setValue(false);
                    }

                }else{

                    channels.setSelectedOrNot(x, 0);                         
                    MultiplePlots.setTotalSignalsSelected(MultiplePlots.getTotalSignalsSelected() - 1);
                    graph.getData().clear();

                    for(int d = 0; d < parsingData.getNumStreams(); ++d){
                        int e = sortMAC[d];
                        DataChannels ch = dataContainer[e];
                        int c = 0;                          
                        while (c < parsingData.getNumDataChannels()) {
                            if (ch.getSelectedOrNot(c) == 1) {
                                series1 = parsingData.graphPointOneStream(c, z);
                                graph.getData().add(series1);
                                series1.setName("S" + Integer.toString(d + 1) + "D" + Integer.toString(c + 1));
                            }                    
                            ++c;
                        }
                    }
                }
            });




Aucun commentaire:

Enregistrer un commentaire