changeset 7429:1f4a206cca0c

[SCENEBUILDER] DTL-6702 KIT : LibraryPanelController.setDisplayMode() breaks and raises an NPE
author yjoan
date Fri, 04 Jul 2014 17:10:40 +0200
parents c369d4c75688
children 26573bfa3a11
files apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/panel/library/LibraryPanelController.java
diffstat 1 files changed, 62 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/panel/library/LibraryPanelController.java	Fri Jul 04 15:13:31 2014 +0200
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/panel/library/LibraryPanelController.java	Fri Jul 04 17:10:40 2014 +0200
@@ -120,7 +120,7 @@
     Label noSearchResults;
     @FXML ListView<LibraryListItem> libSearchList;
     
-    @FXML ListView<LibraryListItem> libList = new ListView<>();
+    @FXML ListView<LibraryListItem> libList = null;
     
     @FXML StackPane libPane;
 
@@ -239,6 +239,52 @@
         setUserLibraryPathString();
     }
 
+    private void displayModeDidChange(DISPLAY_MODE displayMode) {
+        if (libAccordion != null) {
+            switch (displayMode) {
+                case SECTIONS:
+                    libAccordion.setVisible(true);
+                    libAccordion.setManaged(true);
+                    noSearchResults.setVisible(false);
+                    noSearchResults.setManaged(false);
+                    libSearchList.setVisible(false);
+                    libSearchList.setManaged(false);
+                    getLibList().setVisible(false);
+                    getLibList().setManaged(false);
+                    break;
+                case SEARCH:
+                    libAccordion.setVisible(false);
+                    libAccordion.setManaged(false);
+                    if (libSearchList.getItems().isEmpty()) {
+                        noSearchResults.setVisible(true);
+                        noSearchResults.setManaged(true);
+                        libSearchList.setVisible(false);
+                        libSearchList.setManaged(false);
+                    } else {
+                        noSearchResults.setVisible(false);
+                        noSearchResults.setManaged(false);
+                        libSearchList.setVisible(true);
+                        libSearchList.setManaged(true);
+                    }
+                    getLibList().setVisible(false);
+                    getLibList().setManaged(false);
+                    break;
+                case LIST:
+                    libAccordion.setVisible(false);
+                    libAccordion.setManaged(false);
+                    noSearchResults.setVisible(false);
+                    noSearchResults.setManaged(false);
+                    libSearchList.setVisible(false);
+                    libSearchList.setManaged(false);
+                    getLibList().setVisible(true);
+                    getLibList().setManaged(true);
+                    break;
+                default:
+                    break;
+            }
+        }
+    }
+
     /*
      * Private
      */
@@ -275,48 +321,7 @@
     
     public void setDisplayMode(DISPLAY_MODE displayMode) {
         this.currentDisplayMode = displayMode;
-        
-        switch (displayMode) {
-            case SECTIONS:
-                libAccordion.setVisible(true);
-                libAccordion.setManaged(true);
-                noSearchResults.setVisible(false);
-                noSearchResults.setManaged(false);
-                libSearchList.setVisible(false);
-                libSearchList.setManaged(false);
-                libList.setVisible(false);
-                libList.setManaged(false);
-                break;
-            case SEARCH:
-                libAccordion.setVisible(false);
-                libAccordion.setManaged(false);
-                if (libSearchList.getItems().isEmpty()) {
-                    noSearchResults.setVisible(true);
-                    noSearchResults.setManaged(true);
-                    libSearchList.setVisible(false);
-                    libSearchList.setManaged(false);
-                } else {
-                    noSearchResults.setVisible(false);
-                    noSearchResults.setManaged(false);
-                    libSearchList.setVisible(true);
-                    libSearchList.setManaged(true);
-                }
-                libList.setVisible(false);
-                libList.setManaged(false);
-                break;
-            case LIST:
-                libAccordion.setVisible(false);
-                libAccordion.setManaged(false);
-                noSearchResults.setVisible(false);
-                noSearchResults.setManaged(false);
-                libSearchList.setVisible(false);
-                libSearchList.setManaged(false);
-                libList.setVisible(true);
-                libList.setManaged(true);
-                break;
-            default:
-                break;
-        }
+        displayModeDidChange(displayMode);
     }
     
     public DISPLAY_MODE getDisplayMode() {
@@ -405,7 +410,7 @@
         List<TitledPane> panes = libAccordion.getPanes();
         
         searchData.clear();
-        libList.getItems().clear();
+        getLibList().getItems().clear();
         
         if (getEditorController().getLibrary().getItems().size() > 0) {
             // Construct a sorted set of all lib section names.
@@ -440,9 +445,9 @@
 
                 searchData.addAll(libData.get(sectionName));
 
-                libList.getItems().add(new LibraryListItem(sectionName));
+                getLibList().getItems().add(new LibraryListItem(sectionName));
                 for (LibraryItem item : libData.get(sectionName)) {
-                    libList.getItems().add(new LibraryListItem(item));
+                    getLibList().getItems().add(new LibraryListItem(item));
                 }
             }
 
@@ -454,12 +459,12 @@
                 libSearchList.setCellFactory(cb);
             }
 
-            if (libList.getCellFactory() == null) {
-                libList.setCellFactory(cb);
+            if (getLibList().getCellFactory() == null) {
+                getLibList().setCellFactory(cb);
             }
 
             libSearchList.addEventHandler(KeyEvent.KEY_RELEASED, keyEventHandler);
-            libList.addEventHandler(KeyEvent.KEY_RELEASED, keyEventHandler);
+            getLibList().addEventHandler(KeyEvent.KEY_RELEASED, keyEventHandler);
         }
     }
     
@@ -1026,4 +1031,12 @@
             assert userLibraryPathString != null;
         }
     }
+    
+    private ListView<LibraryListItem> getLibList() {
+        if (libList == null) {
+            libList = new ListView<>();
+        }
+        
+        return libList;
+    }
 }