0

Whenever I click a row, I want to update the table with new information. For some reason when I click it is not doing anything and errors out. Any idea why I can't do this?

public HierarchyItemTreeCellCallback(TreeView<Requirement> treeView, DataModel dataModelIn)
{
    super();
    treeViewParent = treeView;
    dataModel = dataModelIn;
  }

  @Override
    public TreeCell<Requirement> call(TreeView<Requirement> param)
    {
    TreeCell<Requirement> cell = new HierarchyItemTreeCell();
    cell.addEventFilter(MouseEvent.MOUSE_PRESSED,new EventHandler<MouseEvent>()
    {
            @Override
            public void handle(MouseEvent event)
            {
                HierarchyTabController hierarchyTabController = new HierarchyTabController(dataModel);
                Requirement req1 = new Requirement("ID", "21", 1, REQUIREMENT_TYPE.SOFTWARE);
                hierarchyTabController.updateTableRow(req1);
            }
    });
    return cell;
  }

Here is the controller logic:

public void updateTableRow(Requirement r)
{
    REQUIREMENT_TYPE reqType = REQUIREMENT_TYPE.SOFTWARE;
    Requirement req1 = new Requirement("ID", "21", 1, reqType);
    ObservableList<Requirement> list = FXCollections.observableArrayList(req1);
    name.setCellValueFactory(new PropertyValueFactory<>("name"));
    description.setCellValueFactory(new PropertyValueFactory<>("description"));
    tableView.getItems().setAll(list);
    tableView.setItems(list);
}

This works whenever I do not call the updateTableRow function from the MouseEvent. However, it is not working when I try to call the controller and update the values from the MouseEvent. Any idea what I am doing wrong?

lakeIn231
  • 1,177
  • 3
  • 14
  • 34
  • Table cell? or Tree cell? – James_D Apr 19 '17 at 19:43
  • Tree Cell @James_D – lakeIn231 Apr 19 '17 at 19:43
  • Oh yeah... @fabian is as fed up with this question as I am. "I created a new instance of the controller class. Why are the fields injected by the `FXMLLoader` null?" – James_D Apr 19 '17 at 19:45
  • Hmmm. I guess I cannot create a new instance of the controller class? What is the work around then? How can I update the new values? @James_D – lakeIn231 Apr 19 '17 at 19:47
  • Well you can, obviously, create a new instance of the controller class, but it's pretty useless, as you presumably want to call `updateTableRow(...)` on the actual controller, not some arbitrary other instance of the same class. You can get the controller from the `FXMLLoader` when you actually load the FXML. – James_D Apr 19 '17 at 19:48
  • See http://stackoverflow.com/questions/36482632/javafx-using-objects-from-maincontroller-or-other-controllers-in-proper-controll or http://stackoverflow.com/questions/34457811/javafx-how-to-get-instance-of-the-controller-object or http://stackoverflow.com/questions/10751271/accessing-fxml-controller-class or... – James_D Apr 19 '17 at 19:50

0 Answers0