Javafx tableview with data from multiple classes

故事扮演 提交于 2019-11-29 12:54:18

In my opition you only have one nice solution for this.

You need a extra Class that holds your TaskControl, ContextControl and ProjectControl.

Your Code can look something like that.

class Wrapper{
 private TaskControl taskControl;
 private ContextControl contextControl;
 private ProjectControl projectControl;
 ...
 public Boolean isDone(){
   return taskControl != null ? taskControl.isDone() : null;
  }
}


@FXML
private TableView<Wrapper> tblView;

@FXML
private TableColumn<Wrapper, Boolean> colErledigt;

colErledigt.setCellValueFactory(
            new PropertyValueFactory<Wrapper, Boolean>("isDone"));

Solved it by adding an additional String to my TaskControl, that contains the names of all the projects it contains. It gets the names through a function that I call just before I create the ObservableList for the Table Column.

private String projectsAsString;
    ...
public final void convertProjectsToString() {

    String projects = "";

    for (Project p : this.getProjects()) {
        ProjectControl pp = (ProjectControl) p;
        projects += pp.getName() + ", ";
    }
    if (projects != null && projects != "" && projects.length() > 4) {
        projects = projects.substring(0, projects.length() - 2);
    }
    this.projectsAsString = projects;
}

Thank you guys anyways for helping me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!