Created
August 16, 2012 17:58
-
-
Save ripla/3372122 to your computer and use it in GitHub Desktop.
Scaladin registration example 1-2: table and form added
This file contains 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
import vaadin.scala._ | |
import com.mongodb.casbah.Imports._ | |
import com.novus.salat.grater | |
import com.novus.salat.global._ | |
import scala.util.Random | |
import scala.reflect.BeanProperty | |
class MongoExample extends Application("Mongo & Vaadin, tied together with Scala") { | |
val registrations: MongoCollection = MongoConnection()("vaadin-scala-mongo-example")("registrations") | |
def mapRegistrations: List[Registration] = registrations.map(grater[Registration].asObject(_)).toList | |
def saveRegistration(registration: Registration): Unit = registrations += grater[Registration].asDBObject(registration) | |
override val main: ComponentContainer = new VerticalLayout { | |
sizeFull() | |
styleName = Reindeer.LAYOUT_WHITE | |
val tableLayout = new VerticalLayout { | |
size(50 pct, 50 pct) | |
spacing = true | |
val table = new Table { | |
sizeFull() | |
styleNames += (Reindeer.TABLE_BORDERLESS, Reindeer.TABLE_STRONG) | |
container = new BeanItemContainer(mapRegistrations) | |
visibleColumns = Seq("username", "realName") | |
} | |
val addButton = Button("Register", showForm) | |
components += (table, addButton) | |
} | |
lazy val form = new Form { | |
size(50 pct, 50 pct) | |
caption = "Registration" | |
footer = new HorizontalLayout { | |
components += Button("Save", showList) | |
} | |
} | |
components += tableLayout | |
alignment(tableLayout -> Alignment.MiddleCenter) | |
def showForm(): Unit = { /*TODO*/ } | |
def showList(): Unit = { /*TODO*/ } | |
} | |
} | |
case class Registration( | |
@BeanProperty var username: String = "username" + Random.nextInt, | |
@BeanProperty var password: String = "", | |
@BeanProperty var realName: String = "Joe Tester") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment