2525import javafx .beans .binding .Bindings ;
2626import javafx .beans .property .SimpleBooleanProperty ;
2727import javafx .beans .property .SimpleObjectProperty ;
28- import javafx .beans .property .SimpleStringProperty ;
2928import javafx .collections .FXCollections ;
3029import javafx .collections .ObservableList ;
3130import javafx .concurrent .Task ;
3837import javafx .scene .control .CheckBox ;
3938import javafx .scene .control .ComboBox ;
4039import javafx .scene .control .ContextMenu ;
41- import javafx .scene .control .Label ;
4240import javafx .scene .control .ListCell ;
4341import javafx .scene .control .ListView ;
4442import javafx .scene .control .Menu ;
@@ -186,16 +184,12 @@ public class SaveAndRestoreController extends SaveAndRestoreBaseController
186184 @ FXML
187185 private VBox errorPane ;
188186
189- @ SuppressWarnings ("unused" )
190- @ FXML
191- private Label webSocketTrackerLabel ;
192-
193187 private final ObservableList <Node > searchResultNodes = FXCollections .observableArrayList ();
194-
195188 private final ObservableList <Filter > filtersList = FXCollections .observableArrayList ();
196189
197190 private final CountDownLatch treeInitializationCountDownLatch = new CountDownLatch (1 );
198191 private final ObservableList <Node > selectedItemsProperty = FXCollections .observableArrayList ();
192+ private final SimpleBooleanProperty serviceConnected = new SimpleBooleanProperty ();
199193
200194 private final ContextMenu contextMenu = new ContextMenu ();
201195 private final Menu tagWithComment = new Menu (Messages .contextMenuTags , new ImageView (ImageCache .getImage (SaveAndRestoreController .class , "/icons/save-and-restore/snapshot-add_tag.png" )));
@@ -239,8 +233,6 @@ public class SaveAndRestoreController extends SaveAndRestoreBaseController
239233 new ExportToCSVMenuItem (this , selectedItemsProperty , this ::exportToCSV )
240234 );
241235
242- private final SimpleStringProperty webSocketTrackerText = new SimpleStringProperty ();
243-
244236
245237 @ Override
246238 public void initialize (URL url , ResourceBundle resourceBundle ) {
@@ -347,13 +339,13 @@ public Filter fromString(String s) {
347339 contextMenu .getItems ().addAll (menuItems );
348340 treeView .setContextMenu (contextMenu );
349341
350- loadTreeData ( );
351-
352- webSocketTrackerLabel . textProperty ().bind (webSocketTrackerText );
342+ splitPane . disableProperty (). bind ( serviceConnected . not () );
343+ treeView . visibleProperty (). bind ( serviceConnected );
344+ errorPane . visibleProperty ().bind (serviceConnected . not () );
353345
354346 webSocketClientService .addWebSocketMessageHandler (this );
355- webSocketClientService .setConnectCallback (() -> Platform . runLater (() -> webSocketTrackerText . setValue ( "Web Socket Connected" )) );
356- webSocketClientService .setDisconnectCallback (() -> Platform . runLater (() -> webSocketTrackerText . setValue ( "Web Socket Disconnected" )) );
347+ webSocketClientService .setConnectCallback (this :: handleWebSocketConnected );
348+ webSocketClientService .setDisconnectCallback (this :: handleWebSocketDisconnected );
357349 webSocketClientService .connect ();
358350 }
359351
@@ -365,11 +357,7 @@ public void loadTreeData() {
365357
366358 JobManager .schedule ("Load save-and-restore tree data" , monitor -> {
367359 Node rootNode = saveAndRestoreService .getRootNode ();
368- if (rootNode == null ) { // Service off-line or not reachable
369- treeInitializationCountDownLatch .countDown ();
370- errorPane .visibleProperty ().set (true );
371- return ;
372- }
360+ treeInitializationCountDownLatch .countDown ();
373361 TreeItem <Node > rootItem = createTreeItem (rootNode );
374362 List <String > savedTreeViewStructure = getSavedTreeStructure ();
375363 // Check if there is a save tree structure. Also check that the first node id (=tree root)
@@ -385,19 +373,20 @@ public void loadTreeData() {
385373 }
386374 });
387375 setChildItems (childNodesMap , rootItem );
376+
388377 } else {
389378 List <Node > childNodes = saveAndRestoreService .getChildNodes (rootItem .getValue ());
390379 List <TreeItem <Node >> childItems = childNodes .stream ().map (this ::createTreeItem ).sorted (treeNodeComparator ).toList ();
391380 rootItem .getChildren ().addAll (childItems );
392381 }
393-
394382 Platform .runLater (() -> {
395383 treeView .setRoot (rootItem );
396384 expandNodes (treeView .getRoot ());
397385 // Event handler for expanding nodes
398386 treeView .getRoot ().addEventHandler (TreeItem .<Node >branchExpandedEvent (), e -> expandTreeNode (e .getTreeItem ()));
399387 treeInitializationCountDownLatch .countDown ();
400388 });
389+
401390 loadFilters ();
402391 });
403392 }
@@ -920,7 +909,7 @@ public void saveLocalState() {
920909
921910 @ Override
922911 public boolean handleTabClosed () {
923- saveLocalState ();
912+ // saveLocalState();
924913 webSocketClientService .closeWebSocket ();
925914 return true ;
926915 }
@@ -1170,14 +1159,12 @@ private void filterAddedOrUpdated(Filter filter) {
11701159 filtersList .add (filter );
11711160 } else {
11721161 final int index = filtersList .indexOf (filter );
1173- Platform .runLater (() -> {
1174- filtersList .set (index , filter );
1175- filtersComboBox .valueProperty ().set (filter );
1176- // If this is the active filter, update the tree view
1177- if (filter .equals (filtersComboBox .getSelectionModel ().getSelectedItem ())) {
1178- applyFilter (filter );
1179- }
1180- });
1162+ filtersList .set (index , filter );
1163+ filtersComboBox .valueProperty ().set (filter );
1164+ // If this is the active filter, update the tree view
1165+ if (filter .equals (filtersComboBox .getSelectionModel ().getSelectedItem ())) {
1166+ applyFilter (filter );
1167+ }
11811168 }
11821169 }
11831170
@@ -1444,4 +1431,19 @@ public void handleWebSocketMessage(SaveAndRestoreWebSocketMessage saveAndRestore
14441431 case FILTER_REMOVED -> filterRemoved ((String ) saveAndRestoreWebSocketMessage .payload ());
14451432 }
14461433 }
1434+
1435+ private void handleWebSocketConnected () {
1436+ serviceConnected .setValue (true );
1437+ Platform .runLater (() -> {
1438+ });
1439+ loadTreeData ();
1440+ }
1441+
1442+ private void handleWebSocketDisconnected () {
1443+ serviceConnected .setValue (false );
1444+ Platform .runLater (() -> {
1445+
1446+ });
1447+ saveLocalState ();
1448+ }
14471449}
0 commit comments