title: JavaFx. Change TreeItem Style by condition
body: <p>There TreeView, each element of which implements Viewable interface:</p>
  
  <pre><code>public interface Viewable {
  
      enum ViewStyle {
  
          NEW("-fx-background-color: b8faa7;"),
          NEW_PARENT("-fx-background-color: b8ebbb;"),
          LOCKED("-fx-background-color: adadad; "),
          HAS_NO_DATA("-fx-background-color: eb8d8d;");
  
          String style;
  
          ViewStyle(String style){
              this.style = style;
          }
  
          public String getStyle() {
              return style;
          }
  
      }
  
      ViewStyle getViewStyle();
      void setViewStyle(ViewStyle style);
      StringProperty styleProperty();
  
      String getTreeItemTitle();
      void setTreeItemTitle(String title);
      StringProperty titleProperty();
  
  }
  </code></pre>
  
  <p>Each element has its own .styleProperty(), and get value from ViewStyle.getStyle()</p>
  
  <p>This property bind for each TreeCell.styleProperty():</p>
  
  <pre><code>treeView.setCellFactory(new Callback&lt;TreeView&lt;Viewable&gt;, TreeCell&lt;Viewable&gt;&gt;() {
              @Override
              public TreeCell&lt;Viewable&gt; call(TreeView&lt;Viewable&gt; param) {
                  return new TreeCell&lt;Viewable&gt;() {
                      @Override
                      protected void updateItem(Viewable item, boolean empty) {
                          textProperty().unbind();
                          styleProperty().unbind();
                          if (empty || item == null) {
                              setGraphic(null);
                              textProperty().set(null);
                              styleProperty().set(null);
                              return;
                          }
                          if (item != null) {
                              styleProperty().bind(item.styleProperty());
                              textProperty().bind(item.titleProperty());
                          }
                          super.updateItem(item, empty);
                      }
                  };
              }
          });
  </code></pre>
  
  <p>The problem is that tree cells are displayed ugly in the selection. That is the color of the selected cell does not change. Changing only the color of the letters (in accordance with the default theme), but it is not very convenient. Therefore, probably it is necessary to attach .css files. At the same time, I don't understand how to change the style (default and when selected) of the cell depending on the current ViewStyle.</p>