Last active
December 27, 2016 10:58
-
-
Save Surendev/b4c3e624de5e7395fa8a1609c32aa3bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); | |
| } | |
| }); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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