Skip to content

Instantly share code, notes, and snippets.

@Surendev
Last active December 27, 2016 10:58
Show Gist options
  • Select an option

  • Save Surendev/b4c3e624de5e7395fa8a1609c32aa3bf to your computer and use it in GitHub Desktop.

Select an option

Save Surendev/b4c3e624de5e7395fa8a1609c32aa3bf to your computer and use it in GitHub Desktop.
package com.controllers;
import dto.fx.TableRowModel;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* Created by surik on 12/21/16
*/
public class JoinViewController {
@FXML private TableView<TableRowModel> availableGamesTable;
@FXML private TableColumn<TableRowModel, String> creator;
@FXML private TableColumn<TableRowModel, String> gameName;
@FXML private TableColumn<TableRowModel, Button> join;
@FXML private Button cancelJoin;
private Map<Integer, Button> joins = new HashMap<>();
private int joinButtonsSize = 0;
@FXML
private void initialize() {
creator.setCellValueFactory(cellData -> cellData.getValue().creatorProperty());
gameName.setCellValueFactory(cellData -> cellData.getValue().gameNameProperty());
join.setCellValueFactory(cellData -> cellData.getValue().getJoin()
/*new Callback<TableColumn.CellDataFeatures<TableRowModel, Button>, ObservableValue<Button>>() {
@Override
public ObservableValue<Button> call(TableColumn.CellDataFeatures<TableRowModel, Button> param) {
return new ButtonCell("Join");
}
}*/);
join.setId("join" + joinButtonsSize);
System.out.println("added");
}
public JoinViewController() {
}
public void setTableData(ObservableList<TableRowModel> data){
availableGamesTable.setItems(data);
}
public void joinToGame(ActionEvent actionEvent) throws IOException {
cancelJoin.getScene().getWindow().hide();
}
public void cancelJoin(ActionEvent actionEvent) {
cancelJoin.getScene().getWindow().hide();
}
private class ButtonCell extends TableCell<TableRowModel, Button> {
private Button cellButton;
ButtonCell(String text){
cellButton = new Button(text);
cellButton.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent t) {
System.out.println("Sout");
}
});
}
}
}
public class TableRowModel {
private StringProperty creator;
private StringProperty gameName;
private Button join;
public TableRowModel(String gameName,String creator) {
this.gameName = new SimpleStringProperty(gameName);
this.creator = new SimpleStringProperty(creator);
this.join = new Button("Join");
}
public String getGameName() {
return gameName.get();
}
public StringProperty gameNameProperty() {
return gameName;
}
public void setGameName(String gameName) {
this.gameName.set(gameName);
}
public String getCreator() {
return creator.get();
}
public StringProperty creatorProperty() {
return creator;
}
public void setCreator(String creator) {
this.creator.set(creator);
}
public ObservableValue<Button> getJoin() {
return new SimpleObjectProperty<>(join);
}
public void setJoin(Button join) {
this.join = join;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment