Permalink
Browse files

Added Embedded.parameters for handling parameters, added propertyValu…

…eFormatter and other missing methods to Table, wrote some tests for TreeTable
  • Loading branch information...
1 parent 41ea098 commit 448026f1e56ef079525fa46ed8841841985c49fc @henrikerola committed Jun 27, 2012
@@ -1,6 +1,7 @@
package vaadin.scala
import vaadin.scala.mixins.EmbeddedMixin
+import scala.collection.mutable
package mixins {
trait EmbeddedMixin extends AbstractComponentMixin
@@ -15,9 +16,31 @@ object Embedded {
}
}
+/**
+ * @see com.vaadin.ui.Embedded
+ * @author Henri Kerola / Vaadin
+ */
class Embedded(override val p: com.vaadin.ui.Embedded with EmbeddedMixin = new com.vaadin.ui.Embedded with EmbeddedMixin) extends AbstractComponent(p) {
- // TODO: parameters
+ lazy val parameters: mutable.Map[String, String] = new mutable.Map[String, String] {
+ def -=(name: String): this.type = { p.removeParameter(name); this }
+ def +=(parameter: (String, String)): this.type = { update(parameter._1, parameter._2); this }
+ override def update(name: String, value: String) {
+ p.setParameter(name, value)
+ this
+ }
+ def get(name: String) = Option(p.getParameter(name))
+ override def size = {
+ import scala.collection.JavaConversions._
+ p.getParameterNames.size
+ }
+ def iterator: Iterator[(String, String)] = {
+ import scala.collection.JavaConversions._
+ p.getParameterNames.map { name =>
+ (name, p.getParameter(name))
+ }
+ }
+ }
// TODO: the same clickListeners can be found from Panel, use a trait instead of copy-pasting?
lazy val clickListeners = new ListenersTrait[ClickEvent, ClickListener] {
@@ -31,34 +54,34 @@ class Embedded(override val p: com.vaadin.ui.Embedded with EmbeddedMixin = new c
def alternateText_=(alternateText: Option[String]) = p.setAlternateText(alternateText.getOrElse(null))
// TODO: better name than objectType?
- def objectType = Embedded.Type(p.getType)
+ def objectType: Embedded.Type.Value = Embedded.Type(p.getType)
def objectType_=(objectType: Embedded.Type.Value) = p.setType(objectType.id)
def source: Option[Resource] = wrapperFor[Resource](p.getSource)
def source_=(source: Option[Resource]) = if (source.isDefined) p.setSource(source.get.p) else p.setSource(null)
def source_=(source: Resource) = if (source == null) p.setSource(null) else p.setSource(source.p)
- def codebase = Option(p.getCodebase);
- def codebase_=(codebase: Option[String]) = p.setCodebase(if (codebase.isDefined) codebase.get else null)
+ def codebase: Option[String] = Option(p.getCodebase);
+ def codebase_=(codebase: Option[String]) = p.setCodebase(codebase.getOrElse(null))
def codebase_=(codebase: String) = p.setCodebase(codebase)
- def codetype = Option(p.getCodetype);
- def codetype_=(codetype: Option[String]) = p.setCodetype(if (codetype.isDefined) codetype.get else null)
+ def codetype: Option[String] = Option(p.getCodetype);
+ def codetype_=(codetype: Option[String]) = p.setCodetype(codetype.getOrElse(null))
def codetype_=(codetype: String) = p.setCodetype(codetype)
- def standby = Option(p.getStandby);
- def standby_=(standby: Option[String]) = p.setStandby(if (standby.isDefined) standby.get else null)
+ def standby: Option[String] = Option(p.getStandby);
+ def standby_=(standby: Option[String]) = p.setStandby(standby.getOrElse(null))
def standby_=(standby: String) = p.setStandby(standby)
- def mimeType = Option(p.getMimeType);
- def mimeType_=(mimeType: Option[String]) = p.setMimeType(if (mimeType.isDefined) mimeType.get else null)
+ def mimeType: Option[String] = Option(p.getMimeType);
+ def mimeType_=(mimeType: Option[String]) = p.setMimeType(mimeType.getOrElse(null))
def mimeType_=(mimeType: String) = p.setMimeType(mimeType)
- def classId = Option(p.getClassId);
- def classId_=(classId: Option[String]) = p.setClassId(if (classId.isDefined) classId.get else null)
+ def classId: Option[String] = Option(p.getClassId);
+ def classId_=(classId: Option[String]) = p.setClassId(classId.getOrElse(null))
def classId_=(classId: String) = p.setClassId(classId)
- def archive = Option(p.getArchive);
- def archive_=(archive: Option[String]) = p.setArchive(if (archive.isDefined) archive.get else null)
+ def archive: Option[String] = Option(p.getArchive);
+ def archive_=(archive: Option[String]) = p.setArchive(archive.getOrElse(null))
def archive_=(archive: String) = p.setArchive(archive)
}
@@ -10,9 +10,15 @@ import vaadin.scala.internal.ColumnReorderListener
import vaadin.scala.internal.ColumnResizeListener
import vaadin.scala.internal.TableColumnGenerator
import vaadin.scala.internal.CellStyleGenerator
+import vaadin.scala.internal.WrapperUtil
package mixins {
- trait TableMixin extends AbstractSelectMixin with ContainerOrderedMixin with ContainerSortableMixin
+ trait TableMixin extends AbstractSelectMixin with ContainerOrderedMixin with ContainerSortableMixin { self: com.vaadin.ui.Table =>
+ override protected def formatPropertyValue(rowId: Any, colId: Any, property: com.vaadin.data.Property): String = wrapper.get.asInstanceOf[Table].propertyValueFormatter match {
+ case Some(formatter) => formatter(Table.FormatPropertyEvent(WrapperUtil.wrapperFor[Table](this).get, rowId, colId)).getOrElse(null)
+ case None => self.formatPropertyValue(rowId, colId, property)
+ }
+ }
}
object Table {
@@ -49,8 +55,14 @@ object Table {
case class ColumnReorderEvent(component: Component) extends Event
case class ColumnGenerationEvent(table: Table, itemId: Any, propertyId: Any) extends Event
case class CellStyleGenerationEvent(itemId: Any, propertyId: Any) extends Event
+ case class FormatPropertyEvent(table: Table, itemId: Any, propertyId: Any) extends Event
+
}
+/**
+ * @see com.vaadin.ui.Table
+ * @author Henri Kerola / Vaadin
+ */
class Table(override val p: com.vaadin.ui.Table with TableMixin = new com.vaadin.ui.Table with TableMixin)
extends AbstractSelect(p) with ContainerOrdered with ContainerSortable with ItemDescriptionGeneratorOwner with ItemClickNotifier {
@@ -104,12 +116,15 @@ class Table(override val p: com.vaadin.ui.Table with TableMixin = new com.vaadin
def cacheRate = p.getCacheRate
def cacheRate_=(cacheRate: Double) = p.setCacheRate(cacheRate)
- def currentPageFirstItemId: Any = p.getCurrentPageFirstItemId
- def currentPageFirstItemId(currentPageFirstItemId: Any) = p.setCurrentPageFirstItemId(currentPageFirstItemId)
+ def currentPageFirstItemIndex: Int = p.getCurrentPageFirstItemIndex
+ def currentPageFirstItemIndex_=(currentPageFirstItemIndex: Int) = p.setCurrentPageFirstItemIndex(currentPageFirstItemIndex)
+
+ def currentPageFirstItemId: Option[Any] = Option(p.getCurrentPageFirstItemId)
+ def currentPageFirstItemId_=(currentPageFirstItemId: Any) = p.setCurrentPageFirstItemId(currentPageFirstItemId)
def columnCollapsingAllowed = p.isColumnCollapsingAllowed
def columnCollapsingAllowed_=(columnCollapsingAllowed: Boolean) = p.setColumnCollapsingAllowed(columnCollapsingAllowed)
-
+
def columnCollapsible(propertyId: Any): Boolean = p.isColumnCollapsible(propertyId)
def columnCollapsible(propertyId: Any, collabsible: Boolean) = p.setColumnCollapsible(propertyId, collabsible)
@@ -122,8 +137,9 @@ class Table(override val p: com.vaadin.ui.Table with TableMixin = new com.vaadin
def sortable = !p.isSortDisabled
def sortable_=(sortable: Boolean) = p.setSortDisabled(!sortable)
- // TODO: sortContainerPropertyId: Any = p.getSortContainerPropertyId
- // TODO: setSortContainerPropertyId
+ def sortContainerPropertyId: Option[Any] = Option(p.getSortContainerPropertyId)
+ def sortContainerPropertyId_=(sortContainerPropertyId: Option[Any]) = p.setSortContainerPropertyId(sortContainerPropertyId.getOrElse(null))
+ def sortContainerPropertyId_=(sortContainerPropertyId: Any) = p.setSortContainerPropertyId(sortContainerPropertyId)
def sortAscending = p.isSortAscending
def sortAscending_=(sortAscending: Boolean) = p.setSortAscending(true)
@@ -174,6 +190,9 @@ class Table(override val p: com.vaadin.ui.Table with TableMixin = new com.vaadin
case None => p.setTableFieldFactory(null)
}
+ var propertyValueFormatter: Option[Table.FormatPropertyEvent => Option[String]] = None
+ def propertyValueFormatter_=(propertyValueFormatter: Table.FormatPropertyEvent => Option[String]): Unit = this.propertyValueFormatter = Some(propertyValueFormatter)
+
lazy val headerClickListeners = new ListenersTrait[Table.HeaderClickEvent, HeaderClickListener] {
override def listeners = p.getListeners(classOf[com.vaadin.ui.Table.HeaderClickListener])
override def addListener(elem: Table.HeaderClickEvent => Unit) = p.addListener(new HeaderClickListener(elem))
@@ -4,11 +4,9 @@ import vaadin.scala.mixins.TreeTableMixin
import vaadin.scala.mixins.ContainerHierarchicalMixin
package mixins {
- trait TreeTableMixin extends TableMixin with ContainerHierarchicalMixin
-}
-
-object TreeTable {
-
+ trait TreeTableMixin extends TableMixin with ContainerHierarchicalMixin { self: com.vaadin.ui.TreeTable =>
+
+ }
}
/**
@@ -13,20 +13,35 @@ class EmbeddedTests extends FunSuite {
assert(Embedded.Type.image.id === com.vaadin.ui.Embedded.TYPE_IMAGE)
assert(Embedded.Type.browser.id === com.vaadin.ui.Embedded.TYPE_BROWSER)
}
-
+
+ test("parameters") {
+ val embedded = new Embedded
+ embedded.parameters += "param1" -> "value1"
+ embedded.parameters += "param2" -> "value2"
+ embedded.parameters += "param3" -> "value3"
+ assert(embedded.parameters.size === 3)
+ assert(embedded.parameters === Map("param1" -> "value1", "param2" -> "value2", "param3" -> "value3"))
+
+ embedded.parameters += "param2" -> "new value 2"
+ assert(embedded.parameters === Map("param1" -> "value1", "param2" -> "new value 2", "param3" -> "value3"))
+
+ embedded.parameters -= "param1"
+ assert(embedded.parameters.size === 2)
+ assert(embedded.parameters === Map("param2" -> "new value 2", "param3" -> "value3"))
+ }
+
test("alternateText") {
- val embedded = new Embedded
- assert(embedded.alternateText === None)
-
- embedded.alternateText = "alternate"
- assert(embedded.alternateText === Some("alternate"))
-
- embedded.alternateText = None
- assert(embedded.alternateText === None)
-
- embedded.alternateText = Some("alternate")
- assert(embedded.alternateText === Some("alternate"))
-
+ val embedded = new Embedded
+ assert(embedded.alternateText === None)
+
+ embedded.alternateText = "alternate"
+ assert(embedded.alternateText === Some("alternate"))
+
+ embedded.alternateText = None
+ assert(embedded.alternateText === None)
+
+ embedded.alternateText = Some("alternate")
+ assert(embedded.alternateText === Some("alternate"))
}
test("objectType") {
@@ -12,7 +12,9 @@ import org.mockito.Mockito
@RunWith(classOf[JUnitRunner])
class TableTests extends FunSuite with BeforeAndAfter with MockitoSugar {
- class VaadinTable extends com.vaadin.ui.Table with TableMixin
+ class VaadinTable extends com.vaadin.ui.Table with TableMixin {
+ override def formatPropertyValue(rowId: Any, colId: Any, property: com.vaadin.data.Property): String = super.formatPropertyValue(rowId, colId, property)
+ }
var table: Table = _
var spy: VaadinTable = _
@@ -173,6 +175,22 @@ class TableTests extends FunSuite with BeforeAndAfter with MockitoSugar {
table.cacheRate = 0.33
assert(table.cacheRate === 0.33)
}
+
+ test("currentPageFirstItemIndex") {
+ assert(table.currentPageFirstItemIndex === 0)
+ Mockito.verify(spy).getCurrentPageFirstItemIndex
+
+ table.currentPageFirstItemIndex = 10
+ Mockito.verify(spy).setCurrentPageFirstItemIndex(10)
+ }
+
+ test("currentPageFirstItemId") {
+ assert(table.currentPageFirstItemId === None)
+ Mockito.verify(spy).getCurrentPageFirstItemId
+
+ table.currentPageFirstItemId = "test"
+ Mockito.verify(spy).setCurrentPageFirstItemId("test")
+ }
test("columnCollapsingAllowed") {
assert(!table.columnCollapsingAllowed)
@@ -208,6 +226,19 @@ class TableTests extends FunSuite with BeforeAndAfter with MockitoSugar {
table.sortable = false
assert(!table.sortable)
}
+
+ test("sortContainerPropertyId") {
+ assert(table.sortContainerPropertyId === None)
+
+ table.sortContainerPropertyId = Some("col1")
+ assert(table.sortContainerPropertyId === Some("col1"))
+
+ table.sortContainerPropertyId = None
+ assert(table.sortContainerPropertyId === None)
+
+ table.sortContainerPropertyId = "col1"
+ assert(table.sortContainerPropertyId === Some("col1"))
+ }
test("selectionMode, default should be None") {
assert(table.selectionMode === SelectionMode.None)
@@ -256,5 +287,44 @@ class TableTests extends FunSuite with BeforeAndAfter with MockitoSugar {
table.footerVisible = true
assert(table.footerVisible)
}
+
+ test("propertyValueFormatter") {
+ val formatter = { e: Table.FormatPropertyEvent =>
+ None
+ }
+
+ assert(table.propertyValueFormatter === None)
+
+ table.propertyValueFormatter = formatter
+ assert(table.propertyValueFormatter === Some(formatter))
+
+ table.propertyValueFormatter = None
+ assert(table.propertyValueFormatter === None)
+
+ table.propertyValueFormatter = Some(formatter)
+ assert(table.propertyValueFormatter === Some(formatter))
+
+ }
+
+ test("propertyValueFormatter2") {
+ var eventTable: Table = null
+ var itemId: Any = null
+ var propertyId: Any = null
+
+
+ val formatter = { e: Table.FormatPropertyEvent =>
+ eventTable = e.table
+ itemId = e.itemId
+ propertyId = e.propertyId
+ Some("test")
+ }
+ table.propertyValueFormatter = formatter
+
+ assert(table.p.asInstanceOf[VaadinTable].formatPropertyValue("itemId", "propId", null) === "test")
+ assert(itemId === "itemId")
+ assert(propertyId === "propId")
+ assert(eventTable === table)
+
+ }
}
@@ -0,0 +1,55 @@
+package vaadin.scala.tests
+
+import vaadin.scala._
+import org.scalatest.FunSuite
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+import org.scalatest.BeforeAndAfter
+import org.scalatest.mock.MockitoSugar
+import vaadin.scala.mixins.TreeTableMixin
+import org.mockito.Mockito
+
+@RunWith(classOf[JUnitRunner])
+class TreeTableTests extends FunSuite with BeforeAndAfter with MockitoSugar {
+
+ class VaadinTreeTable extends com.vaadin.ui.TreeTable with TreeTableMixin
+
+ var treeTable: TreeTable = _
+ var spy: VaadinTreeTable = _
+
+ before {
+ val vaadinTree = new VaadinTreeTable
+ spy = Mockito.spy(vaadinTree)
+ treeTable = new TreeTable(spy)
+ }
+
+ test("collapsed(itemId, collapsed)") {
+ treeTable.collapsed('itemId, true)
+ Mockito.verify(spy).setCollapsed('itemId, true)
+ }
+
+ test("hierarchyColumn") {
+ assert(treeTable.hierarchyColumn === None)
+
+ treeTable.hierarchyColumn = 'col1
+ assert(treeTable.hierarchyColumn === Some('col1))
+
+ treeTable.hierarchyColumn = None
+ assert(treeTable.hierarchyColumn === None)
+
+ treeTable.hierarchyColumn = Some('col1)
+ assert(treeTable.hierarchyColumn === Some('col1))
+ }
+
+ test("collapsed(itemId)") {
+ assert(treeTable.collapsed('itemId))
+ Mockito.verify(spy).isCollapsed('itemId)
+ }
+
+ test("animationsEnabled") {
+ assert(!treeTable.animationsEnabled)
+
+ treeTable.animationsEnabled = true
+ assert(treeTable.animationsEnabled)
+ }
+}

0 comments on commit 448026f

Please sign in to comment.