My application provides a little table. If the user clicks on the checkbox, the table is in editable mode and the fields are open. So far, so good.
If the user - after changing some fields - clicks on the save button, I will receive all the rows from the table to check the changes and save the new values into the database.
Here the source code
package com.mycompany
import com.vaadin.Application
import com.vaadin.data.{Container, Property}
import com.vaadin.ui._
@SuppressWarnings(Array("serial"))
@SerialVersionUID(1L)
class TableSample extends Application {
private var mainWindow: Window = null
override def init() {
mainWindow = new Window("TableSample")
val table = new Table("Nobel Prize for Literature")
table.addContainerProperty("First name", classOf[String]
, null)
table.addContainerProperty("Last name", classOf[String]
, null)
table.addContainerProperty("Year", classOf[String]
, null)
val array = new scala.Array[java.lang.Object]
(3)
array(0) = "Thomas"; array(1) = "Mann"; array(2) = "1929"
table.addItem(array, 1)
array(0) = "W.B. "; array(1) = "Yeats"; array(2) = "1923"
table.addItem(array, 2)
array(0) = "Günter"; array(1) = "Gass"; array(2) = "1999"
table.addItem(array, 3)
table.setSelectable(true)
table.setMultiSelect(true)
table.setImmediate(true)
val current = new Label("Selected: - ")
table.addListener(new Property.ValueChangeListener() {
def valueChange(p1: com.vaadin.data.Property.ValueChangeEvent) {
current.setValue("Selected: " + table.getValue)
}
})
val saveButton = new Button("Save")
saveButton.setVisible(false)
var switchEditable = new CheckBox("Editable");
switchEditable.addListener(new Property.ValueChangeListener() {
def valueChange(event: com.vaadin.data.Property.ValueChangeEvent) {
table.setEditable(event.getProperty.getValue.toString.toBoolean)
if (table.isEditable) {
saveButton.setVisible(true)
} else {
saveButton.setVisible(false)
}
}
});
saveButton.addListener(new Button.ClickListener() {
def buttonClick(event: com.vaadin.ui.Button#ClickEvent) {
//
//[b]
TODO get table data - how receive the rows from the table?
//
[/b]
}
});
switchEditable.setImmediate(true);
mainWindow.addComponent(switchEditable);
mainWindow.addComponent(saveButton)
mainWindow.addComponent(table)
mainWindow.addComponent(current)
setMainWindow(mainWindow)
}
}
How can I receive the rows from the table? Is it necessary to implement a TableFieldFactory? If yes, how I can implement a TableFieldFactory in my scala application?