Skip to content

Commit ddbac74

Browse files
author
Risto Yrjänä
committed
Initial import.
0 parents  commit ddbac74

9 files changed

+212
-0
lines changed

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.project
2+
.cache
3+
.classpath
4+
bin
5+
project/project
6+
project/target
7+
src/main/webapp/VAADIN/widgetsets
8+
target

build.sbt

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import net.thunderklaus.GwtPlugin._
2+
3+
name := "Vaadin, Scala and Mongo"
4+
5+
scalaVersion := "2.9.2"
6+
7+
seq(webSettings: _*)
8+
9+
//seq(gwtSettings: _*)
10+
11+
//gwtVersion := "2.4.0"
12+
13+
resolvers ++= Seq("TypeSafe repo" at "http://repo.typesafe.com/typesafe/releases",
14+
"Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots")
15+
16+
17+
// basic dependencies
18+
libraryDependencies ++= Seq(
19+
"com.vaadin" % "vaadin" % "6.8.2",
20+
"org.eclipse.jetty" % "jetty-webapp" % "8.0.4.v20111024" % "container"
21+
)
22+
23+
libraryDependencies ++= Seq(
24+
//Casbah and Salat
25+
"org.mongodb" % "casbah_2.9.2" % "2.4.1",
26+
//"com.mongodb.casbah" % "casbah_2.9.0-1" % "2.1.5.0",
27+
"com.novus" %% "salat" % "1.9.1-SNAPSHOT"
28+
)
29+
30+
31+
32+
// hack: sbt-gwt-plugin assumes that sources are in src/main/java
33+
//javaSource in Compile <<= (scalaSource in Compile)
34+
35+
//gwtModules := List("vaadin.scala.example.mongo.MongoExampleWidgetset")
36+
37+
// more correct place would be to compile widgetset under the target dir and configure jetty to find it from there
38+
//gwtTemporaryPath := file(".") / "src" / "main" / "webapp" / "VAADIN" / "widgetsets"

lib/scaladin_2.9.2-2.0.0-SNAPSHOT.jar

1.09 MB
Binary file not shown.

project/plugins.sbt

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// xsbt-web-plugin
2+
resolvers += "Web plugin repo" at "http://siasia.github.com/maven2"
3+
4+
libraryDependencies <+= sbtVersion(v => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.1-0.2.10")
5+
6+
// sbteclipse
7+
resolvers += Classpaths.typesafeResolver
8+
9+
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.0.0")
10+
11+
// GWT compiler
12+
//resolvers += "GWT plugin repo" at "http://ripla.github.com/maven"
13+
14+
//addSbtPlugin("net.thunderklaus" % "sbt-gwt-plugin" % "1.1-SNAPSHOT")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package vaadin.scala.example.mongo
2+
3+
import vaadin.scala._
4+
import com.mongodb.casbah.Imports._
5+
import com.novus.salat._
6+
import com.novus.salat.global._
7+
import scala.util.Random
8+
import scala.reflect.BeanProperty
9+
10+
class MongoExampleMinimal extends Application("Mongo & Vaadin, tied together with Scala") {
11+
12+
val registrations: MongoCollection = MongoConnection()("vaadin-scala-mongo-example")("registrations")
13+
14+
def mapRegistrations: List[MinRegistration] = registrations.map(grater[MinRegistration].asObject(_)).toList
15+
16+
override val main: ComponentContainer = new HorizontalLayout {
17+
sizeFull()
18+
styleName = Reindeer.LAYOUT_WHITE
19+
20+
val tableLayout = new VerticalLayout {
21+
size(50 pct, 50 pct)
22+
spacing = true
23+
24+
val table = new Table {
25+
sizeFull()
26+
styleNames += (Reindeer.TABLE_BORDERLESS, Reindeer.TABLE_STRONG)
27+
container = new BeanItemContainer[MinRegistration](registrations.map(grater[MinRegistration].asObject(_)).toList)
28+
visibleColumns = Seq("username", "realName")
29+
}
30+
31+
val addButton: Button = Button("Register", showForm)
32+
33+
components += (table, addButton)
34+
}
35+
36+
val form = new Form {
37+
size(50 pct, 50 pct)
38+
caption = "Registration"
39+
formFieldFactory = createFormFieldFactory
40+
}
41+
42+
form.footer = new HorizontalLayout {
43+
components += Button("Save", showList)
44+
}
45+
46+
components += tableLayout
47+
48+
alignment(tableLayout -> Alignment.MiddleCenter)
49+
50+
def showForm(): Unit = {
51+
form.item = new BeanItem[MinRegistration](MinRegistration())
52+
form.visibleItemProperties = Seq("realName", "username", "password")
53+
replaceComponent(tableLayout, form)
54+
alignment(form -> Alignment.MiddleCenter)
55+
}
56+
57+
def showList(): Unit = {
58+
form.commit
59+
val bean = form.item.get.asInstanceOf[BeanItem[MinRegistration]].bean
60+
registrations.save(grater[MinRegistration].asDBObject(bean))
61+
tableLayout.table.container = new BeanItemContainer[MinRegistration](mapRegistrations)
62+
tableLayout.table.visibleColumns = Seq("username", "realName")
63+
replaceComponent(form, tableLayout)
64+
alignment(tableLayout -> Alignment.MiddleCenter)
65+
mainWindow.showNotification("User %s registered".format(bean.username))
66+
}
67+
}
68+
69+
def createFormFieldFactory = FormFieldFactory(_ match {
70+
case FormFieldIngredients(_, "password", _) =>
71+
Some(new PasswordField {
72+
caption = DefaultFieldFactory.createCaptionByPropertyId("password")
73+
required = true
74+
})
75+
76+
case otherIngredient => {
77+
val field = DefaultFieldFactory.createField(otherIngredient)
78+
field.foreach(_.required = true)
79+
field
80+
}
81+
})
82+
}
83+
84+
case class MinRegistration(
85+
@BeanProperty var username: String = "username" + Random.nextInt,
86+
@BeanProperty var password: String = "",
87+
@BeanProperty var realName: String = "Joe Tester")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<module>
2+
<inherits name="com.vaadin.terminal.gwt.DefaultWidgetSet" />
3+
4+
<!-- Add widgetset modules from add-ons here. E.g.
5+
<inherits name="org.vaadin.teemu.ratingstars.gwt.RatingStarsWidgetset" />
6+
-->
7+
</module>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package vaadin.scala.example.mongo
2+
3+
import scala.reflect.BeanProperty
4+
import scala.util.Random
5+
6+
case class Registration(
7+
@BeanProperty var username: String = "username" + Random.nextInt,
8+
@BeanProperty var password: String = "",
9+
@BeanProperty var realName: String = "Joe Tester")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package vaadin.scala.example.mongo
2+
3+
import com.mongodb.casbah.Imports._
4+
import com.novus.salat._
5+
import com.novus.salat.global._
6+
7+
object RegistrationService {
8+
val registrations: MongoCollection = MongoConnection()("vaadin-scala-mongo-example")("registrations")
9+
10+
def all: List[Registration] = registrations.map(grater[Registration].asObject(_)).toList
11+
def create(registration: Registration) {
12+
registrations += grater[Registration].asDBObject(registration)
13+
}
14+
}

src/main/webapp/WEB-INF/web.xml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app id="MongoExample" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
3+
<display-name>Vaadin, Scala and Mongo</display-name>
4+
<context-param>
5+
<description>
6+
Vaadin production mode</description>
7+
<param-name>productionMode</param-name>
8+
<param-value>false</param-value>
9+
</context-param>
10+
<servlet>
11+
<servlet-name>Minimal example</servlet-name>
12+
<servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
13+
<init-param>
14+
<description>Vaadin application class to start</description>
15+
<param-name>application</param-name>
16+
<param-value>vaadin.scala.example.mongo.MongoExampleMinimal</param-value>
17+
</init-param>
18+
<!--<init-param>
19+
<description>Application widgetset</description>
20+
<param-name>widgetset</param-name>
21+
<param-value>vaadin.scala.example.mongo.MongoExampleWidgetset</param-value>
22+
</init-param>-->
23+
</servlet>
24+
<servlet-mapping>
25+
<servlet-name>Minimal example</servlet-name>
26+
<url-pattern>/min/*</url-pattern>
27+
</servlet-mapping>
28+
29+
<servlet-mapping>
30+
<servlet-name>Minimal example</servlet-name>
31+
<url-pattern>/VAADIN/*</url-pattern>
32+
</servlet-mapping>
33+
34+
35+
</web-app>

0 commit comments

Comments
 (0)