This is a to-do list application that i made as a beginner. However, there is an error that says missing parameter type in this line of code:
todoTable.selectionModel().selectedItem.onChange(
(_, newValue) => showTodoDetails(Some(newValue))
)
I can't figure out what the problem is as I had no issue running with it earlier. And it also seems to be the only error that keeps me from finishing the to-do application program.
Below is the file that is having an error
package ch.makery.address.view
import ch.makery.address.model.Todo
import ch.makery.address.MainApp
import scalafx.scene.control.{Alert, Label, TableColumn, TableView}
import scalafxml.core.macros.sfxml
import scalafx.beans.property.StringProperty
import scala.util.{Failure, Success}
import scalafx.Includes._
import scalafx.event.ActionEvent
import scalafx.scene.control.Alert.AlertType
@sfxml
class TodoOverviewController(
private val todoTable : TableView[Todo],
private val titleColumn : TableColumn[Todo, String],
private val titleLabel : Label,
private val descriptionLabel : Label
) {
// initialize Table View display contents model
todoTable.items = MainApp.todoData
// initialize columns's cell values
titleColumn.cellValueFactory = {_.value.title}
showTodoDetails(None);
todoTable.selectionModel().selectedItem.onChange(
(_, newValue) => showTodoDetails(Some(newValue))
)
private def showTodoDetails (todo : Option[Todo]) = {
todo match {
case Some(todo) =>
// Fill the labels with info from the todo object.
titleLabel.text <== todo.title
descriptionLabel.text <== todo.description
case None =>
// todo is null, remove all the text.
titleLabel.text = ""
descriptionLabel.text = ""
}
}
def handleNewTodo(action : ActionEvent) = {
val todo = new Todo("")
val okClicked = MainApp.showTodoEditDialog(todo);
if (okClicked) {
todo.save() match {
case Success(x) =>
MainApp.todoData += todo
case Failure(e) =>
val alert = new Alert(Alert.AlertType.Warning) {
initOwner(MainApp.stage)
title = "Failed to Save"
headerText = "Database Error"
contentText = "Database problem filed to save changes"
}.showAndWait()
}
}
}
def handleEditTodo(action : ActionEvent) = {
val selectedTodo = todoTable.selectionModel().selectedItem.value
if (selectedTodo != null) {
val okClicked = MainApp.showTodoEditDialog(selectedTodo)
if (okClicked) {
selectedTodo.save() match {
case Success(x) =>
showTodoDetails(Some(selectedTodo))
case Failure(e) =>
val alert = new Alert(Alert.AlertType.Warning) {
initOwner(MainApp.stage)
title = "Failed to Save"
headerText = "Database Error"
contentText = "Database problem filed to save changes"
}.showAndWait()
}
}
} else {
// Nothing selected.
val alert = new Alert(Alert.AlertType.Warning){
initOwner(MainApp.stage)
title = "No Selection"
headerText = "No Todo Selected"
contentText = "Please select a todo in the table."
}.showAndWait()
}
}
def handleDeleteTodo(action : ActionEvent) = {
val selectedIndex = todoTable.selectionModel().selectedIndex.value
val selectedTodo = todoTable.selectionModel().selectedItem.value
if (selectedIndex >= 0) {
selectedTodo.save() match {
case Success(x) =>
todoTable.items().remove(selectedIndex);
case Failure(e) =>
val alert = new Alert(Alert.AlertType.Warning) {
initOwner(MainApp.stage)
title = "Failed to Save"
headerText = "Database Error"
contentText = "Database problem filed to save changes"
}.showAndWait()
}
} else {
// Nothing selected.
val alert = new Alert(AlertType.Warning){
initOwner(MainApp.stage)
title = "No Selection"
headerText = "No Todo Selected"
contentText = "Please select a todo in the table."
}.showAndWait()
}
}
}
The function passed to
onChange
takes 3 arguments, not 2, you should have