Skip to content
Browse files

Wrapper for HierarchicalContainer

  • Loading branch information...
1 parent 3c610d5 commit 0bc3e7d3483fe236ad9305d70f3b76599df0325a @henrikerola committed Oct 14, 2012
View
25 addon/src/main/scala/vaadin/scala/HierarchicalContainer.scala
@@ -0,0 +1,25 @@
+package vaadin.scala
+
+import vaadin.scala.mixins.HierarchicalContainerMixin
+
+package mixins {
+ trait HierarchicalContainerMixin extends IndexedContainerMixin with ContainerHierarchicalMixin
+}
+
+/**
+ * @see com.vaadin.data.util.HierarchicalContainer
+ * @author Henri Kerola / Vaadin
+ */
+class HierarchicalContainer(override val p: com.vaadin.data.util.HierarchicalContainer with HierarchicalContainerMixin = new com.vaadin.data.util.HierarchicalContainer with HierarchicalContainerMixin)
+ extends IndexedContainer(p) with Container.Hierarchical {
+
+ def moveAfterSibling(itemId: Any, siblingId: Any): Unit = p.moveAfterSibling(itemId, siblingId)
+
+ def removeItemRecursively(itemId: Any): Unit = p.removeItemRecursively(itemId)
+
+ def includeParentsWhenFiltering: Boolean = p.isIncludeParentsWhenFiltering
+ def includeParentsWhenFiltering_=(includeParentsWhenFiltering: Boolean): Unit = p.setIncludeParentsWhenFiltering(includeParentsWhenFiltering)
+
+ // TODO: static removeItemRecursively(Container.Hierarchical container, Object itemId)
+ // TODO: protected doSort(), doFilterContainer, passesFilters
+}
View
2 addon/src/main/scala/vaadin/scala/Tree.scala
@@ -24,7 +24,7 @@ object Tree {
class Tree(override val p: com.vaadin.ui.Tree with TreeMixin = new com.vaadin.ui.Tree with TreeMixin)
extends AbstractSelect(p) with Container.Hierarchical with ItemDescriptionGeneratorOwner with ItemClickNotifier with ExpandNotifier with CollapseNotifier {
- // TODO: should set container to wrapped HierarchicalContainer
+ container = new HierarchicalContainer
def expanded(itemId: Any): Boolean = p.isExpanded(itemId)
View
2 addon/src/main/scala/vaadin/scala/TreeTable.scala
@@ -16,7 +16,7 @@ package mixins {
class TreeTable(override val p: com.vaadin.ui.TreeTable with TreeTableMixin = new com.vaadin.ui.TreeTable with TreeTableMixin)
extends Table(p) with Container.Hierarchical with ExpandNotifier with CollapseNotifier {
- // TODO: should set container to wrapped HierarchicalContainer
+ container = new HierarchicalContainer
def collapsed(itemId: Any, collapsed: Boolean) = p.setCollapsed(itemId, collapsed)
View
45 addon/src/test/scala/vaadin/scala/tests/HierarchicalContainerTests.scala
@@ -0,0 +1,45 @@
+package vaadin.scala.tests
+
+import vaadin.scala.HierarchicalContainer
+import vaadin.scala.mixins.HierarchicalContainerMixin
+import org.mockito.Mockito
+
+class HierarchicalContainerTests extends ScaladinTestSuite {
+
+ class VaadinHierarchicalContainer extends com.vaadin.data.util.HierarchicalContainer with HierarchicalContainerMixin
+
+ var vaadinContainer: VaadinHierarchicalContainer = _
+ var spy: VaadinHierarchicalContainer = _
+ var container: HierarchicalContainer = _
+
+ var mockedVaadinContainer: VaadinHierarchicalContainer = _
+ var containerWithMock: HierarchicalContainer = _
+
+ before {
+ vaadinContainer = new VaadinHierarchicalContainer
+ spy = Mockito.spy(vaadinContainer)
+ container = new HierarchicalContainer(spy)
+
+ mockedVaadinContainer = mock[VaadinHierarchicalContainer]
+ containerWithMock = new HierarchicalContainer(mockedVaadinContainer)
+ }
+
+ test("moveAfterSibling") {
+ containerWithMock.moveAfterSibling('itemId, 'siblingId)
+ Mockito.verify(mockedVaadinContainer).moveAfterSibling('itemId, 'siblingId)
+ }
+
+ test("removeItemRecursively") {
+ containerWithMock.removeItemRecursively('itemId)
+ Mockito.verify(mockedVaadinContainer).removeItemRecursively('itemId)
+ }
+
+ test("includeParentsWhenFiltering") {
+ assert(container.includeParentsWhenFiltering)
+ container.includeParentsWhenFiltering = false
+ assert(!container.includeParentsWhenFiltering)
+ Mockito.verify(spy).setIncludeParentsWhenFiltering(false)
+ Mockito.verify(spy, Mockito.times(2)).isIncludeParentsWhenFiltering()
+ }
+
+}
View
10 addon/src/test/scala/vaadin/scala/tests/ScaladinTestSuite.scala
@@ -0,0 +1,10 @@
+package vaadin.scala.tests
+
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+import org.scalatest.FunSuite
+import org.scalatest.BeforeAndAfter
+import org.scalatest.mock.MockitoSugar
+
+@RunWith(classOf[JUnitRunner])
+class ScaladinTestSuite extends FunSuite with BeforeAndAfter with MockitoSugar
View
4 addon/src/test/scala/vaadin/scala/tests/TreeTableTests.scala
@@ -52,4 +52,8 @@ class TreeTableTests extends FunSuite with BeforeAndAfter with MockitoSugar {
treeTable.animationsEnabled = true
assert(treeTable.animationsEnabled)
}
+
+ test("container") {
+ assert(treeTable.container.get.getClass === classOf[HierarchicalContainer])
+ }
}
View
4 addon/src/test/scala/vaadin/scala/tests/TreeTests.scala
@@ -77,5 +77,9 @@ class TreeTests extends FunSuite with BeforeAndAfter with MockitoSugar {
assert(tree.p.getItemStyleGenerator.getStyle("test2") === null)
assert(tree.p.getItemStyleGenerator.getStyle(null) === null)
}
+
+ test("container") {
+ assert(tree.container.get.getClass === classOf[HierarchicalContainer])
+ }
}

0 comments on commit 0bc3e7d

Please sign in to comment.
Something went wrong with that request. Please try again.