public void showRecords(Account account) { if (recordsListModel != null) { recordsListModel.clear(); } if (controller.getCurrentAccount() != null) { for (Record record : controller.getRecords(account)) { recordsListModel.add(record); } recordsTable.setItems(recordsListModel); dateColumn.setCellValueFactory(new PropertyValueFactory<>("date")); amountColumn.setCellValueFactory(new PropertyValueFactory<>("amount")); descrColumn.setCellValueFactory(new PropertyValueFactory<>("description")); isPutColumn.setCellValueFactory(new PropertyValueFactory<>("isPut")); categoryNameColumn.setCellValueFactory(new PropertyValueFactory<>("categoryName")); removeRecordButtonColumn.setCellFactory( new Callback<TableColumn<Record, String>, TableCell<Record, String>>() { @Override public TableCell<Record, String> call(TableColumn<Record, String> param) { return new TableCell<Record, String>() { @Override public void updateItem(String item, boolean empty) { super.updateItem(item, empty); TableRow currentRow = getTableRow(); if (empty) { setText(null); setGraphic(null); } else { currentRow .hoverProperty() .addListener( new ChangeListener<Boolean>() { @Override public void changed( ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (currentRow.isHover()) { removeRecordButton = new Button(); removeRecordButton .getStylesheets() .add( this.getClass() .getResource("css/removerecbutton.css") .toExternalForm()); removeRecordButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { param .getTableView() .getSelectionModel() .select(getIndex()); Record item = recordsTable.getSelectionModel().getSelectedItem(); if (item != null) { controller.setCurrentRecord(item); showRemoveRecordStage(); } } }); // setGraphic(removeRecordButton); setContentDisplay(ContentDisplay.GRAPHIC_ONLY); } else { setGraphic(null); } } }); } } }; } }); removeRecordButtonColumn.setStyle("-fx-alignment: CENTER;"); isPutColumn.setCellFactory( new Callback<TableColumn<Record, Boolean>, TableCell<Record, Boolean>>() { @Override public TableCell<Record, Boolean> call(TableColumn<Record, Boolean> column) { return new TableCell<Record, Boolean>() { @Override public void updateItem(Boolean item, boolean empty) { super.updateItem(item, empty); TableRow currentRow = getTableRow(); if (item != null) { if (item) { setText("Пополнение"); if (currentRow.isHover()) { currentRow.setStyle("-fx-background-color: cyan"); } } else { setText("Снятие"); // // currentRow.setStyle("-fx-background-color: pink"); } } } }; } }); // dateColumn.setCellValueFactory(cellData -> cellData.getValue().dateProperty()); // amountColumn.setCellValueFactory(cellData -> // cellData.getValue().amountProperty().asObject()); // descrColumn.setCellValueFactory(cellData -> // cellData.getValue().descriptionProperty()); // isPutColumn.setCellValueFactory(cellData -> // cellData.getValue().isPutProperty()); // categoryNameColumn.setCellValueFactory(cellData -> // cellData.getValue().categoryNameProperty()); } }
public void collectAccountTable() { if (accountsTableModel != null) { accountsTableModel.clear(); } for (Account account : controller.getAccounts(controller.getCurrentUser())) { accountsTableModel.add(account); } accountsTable.setItems(accountsTableModel); accountsTable.getSelectionModel().selectFirst(); if (accountsTable.getSelectionModel().getSelectedItem() != null) { controller.setCurrentAccount(accountsTable.getSelectionModel().getSelectedItem()); } accountsColumn.setCellValueFactory(new PropertyValueFactory<Account, String>("description")); removeAccountsButtonColumn.setCellFactory( new Callback<TableColumn<Account, Button>, TableCell<Account, Button>>() { @Override public TableCell<Account, Button> call(TableColumn<Account, Button> param) { return new TableCell<Account, Button>() { @Override public void updateItem(Button item, boolean empty) { super.updateItem(item, empty); TableRow currentRow = getTableRow(); if (empty) { setText(null); setGraphic(null); } else { currentRow .hoverProperty() .addListener( new ChangeListener<Boolean>() { @Override public void changed( ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (currentRow.isHover()) { removeAccountButton = new Button(); removeAccountButton .getStylesheets() .add( this.getClass() .getResource("css/removeaccbutton.css") .toExternalForm()); removeAccountButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { param.getTableView().getSelectionModel().select(getIndex()); Account item = accountsTable.getSelectionModel().getSelectedItem(); if (item != null) { controller.setSelectedAccount(item); showRemoveAccountStage(); } } }); // setGraphic(removeAccountButton); setContentDisplay(ContentDisplay.GRAPHIC_ONLY); } else { setGraphic(null); } } }); } } }; } }); removeAccountsButtonColumn.setStyle("-fx-alignment: CENTER;"); }