Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ability to create property by value or by type #46

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions addon/src/main/scala/vaadin/scala/Property.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package vaadin.scala
import scala.reflect.ClassTag

object Property {
def apply[T](value: T): Property[T] = new ObjectProperty[T](value)
def apply[T](value: T): Property[T] = new ObjectProperty[T](value, value.getClass.asInstanceOf[Class[T]])

def apply[T](classOfT: Class[T]): Property[T] = new ObjectProperty[T](null.asInstanceOf[T], classOfT)

def unapply(property: Property[_]): Option[Any] = {
if (property != null) property.value
Expand Down Expand Up @@ -50,8 +52,8 @@ trait PropertyEditor extends PropertyViewer {
*/
class BasicProperty[T](override val p: com.vaadin.data.Property[T]) extends Property[T]

class ObjectProperty[T](value: T) extends Property[T] {
val p = new com.vaadin.data.util.ObjectProperty[T](value)
class ObjectProperty[T](value: T, classOfT: Class[T]) extends Property[T] {
val p = new com.vaadin.data.util.ObjectProperty[T](value, classOfT)
}

class VaadinPropertyDelegator[T](scaladinProperty: Property[T]) extends com.vaadin.data.Property[T] {
Expand Down
4 changes: 2 additions & 2 deletions addon/src/test/scala/vaadin/scala/tests/LabelTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ class LabelTests extends FunSuite {
}

ignore("property: Property") {
val property = new ObjectProperty("test")
val property = new ObjectProperty("test", classOf[String])
val label = new Label
label.property = property
assert(label.property === Some(property))
}

test("property: Some") {
val option = Some(new ObjectProperty("test"))
val option = Some(new ObjectProperty("test", classOf[String]))
val label = new Label
label.property = option
assert(label.property.get.value === option.get.value)
Expand Down