Permalink
Browse files

Moving listeners related classes to better places

  • Loading branch information...
1 parent b7518cf commit 4d736ede28be88f6c9b6950941d44980856ead28 @henrikerola committed Sep 11, 2012
@@ -4,6 +4,7 @@ import vaadin.scala.mixins.AbstractSplitPanelMixin
import vaadin.scala.mixins.HorizontalSplitPanelMixin
import vaadin.scala.mixins.VerticalSplitPanelMixin
import vaadin.scala.internal.SplitterClickListener
+import vaadin.scala.internal.ListenersTrait
package mixins {
trait AbstractSplitPanelMixin extends AbstractLayoutMixin
@@ -2,6 +2,7 @@ package vaadin.scala
import vaadin.scala.mixins.AbstractTextFieldMixin
import vaadin.scala.internal.TextChangeListener
+import vaadin.scala.internal.ListenersTrait
import com.vaadin.event.FieldEvents
package mixins {
@@ -3,6 +3,7 @@ package vaadin.scala
import vaadin.scala.mixins.ButtonMixin
import vaadin.scala.internal.WrapperUtil
import vaadin.scala.internal.ButtonClickListener
+import vaadin.scala.internal.ListenersTrait
package mixins {
trait ButtonMixin extends AbstractFieldMixin
@@ -1,5 +1,7 @@
package vaadin.scala
+import vaadin.scala.internal.ListenersTrait
+import vaadin.scala.internal.ClickListener
import vaadin.scala.mixins.EmbeddedMixin
import scala.collection.mutable
@@ -7,8 +7,4 @@ trait Event
// TODO: button should be enumeration or something instead of Int
abstract class AbstractClickEvent(component: Component, button: Int, clientX: Int, clientY: Int, relativeX: Int, relativeY: Int, doubleClick: Boolean, altKey: Boolean, ctrlKey: Boolean, metaKey: Boolean, shiftKey: Boolean) extends Event
-case class ClickEvent(component: Component, button: Int, clientX: Int, clientY: Int, relativeX: Int, relativeY: Int, doubleClick: Boolean, altKey: Boolean, ctrlKey: Boolean, metaKey: Boolean, shiftKey: Boolean) extends AbstractClickEvent(component, button, clientX, clientY, relativeX, relativeY, doubleClick, altKey, ctrlKey, metaKey, shiftKey)
-
-class ClickListener(val action: ClickEvent => Unit) extends com.vaadin.event.MouseEvents.ClickListener with Listener {
- def click(e: com.vaadin.event.MouseEvents.ClickEvent) = action(ClickEvent(wrapperFor[Table](e.getComponent).get, e.getButton, e.getClientX, e.getClientY, e.getRelativeX, e.getRelativeY, e.isDoubleClick, e.isAltKey, e.isCtrlKey, e.isMetaKey, e.isShiftKey))
-}
+case class ClickEvent(component: Component, button: Int, clientX: Int, clientY: Int, relativeX: Int, relativeY: Int, doubleClick: Boolean, altKey: Boolean, ctrlKey: Boolean, metaKey: Boolean, shiftKey: Boolean) extends AbstractClickEvent(component, button, clientX, clientY, relativeX, relativeY, doubleClick, altKey, ctrlKey, metaKey, shiftKey)
@@ -1,6 +1,7 @@
package vaadin.scala
import vaadin.scala.internal.ItemClickListener
+import vaadin.scala.internal.ListenersTrait
case class ItemClickEvent(component: Component, item: Item, itemId: Any, propertyId: Option[Any], button: Int, clientX: Int, clientY: Int, relativeX: Int, relativeY: Int, doubleClick: Boolean, altKey: Boolean, ctrlKey: Boolean, metaKey: Boolean, shiftKey: Boolean) extends AbstractClickEvent(component, button, clientX, clientY, relativeX, relativeY, doubleClick, altKey, ctrlKey, metaKey, shiftKey)
@@ -1,5 +1,8 @@
package vaadin.scala
+import vaadin.scala.internal.ListenersTrait
+import vaadin.scala.internal.ItemDescriptionGenerator
+
// TODO: move traits and classes to correct packages
case class ItemDescriptionEvent(component: Component, itemId: Any, propertyId: Any) extends Event
@@ -19,9 +22,4 @@ trait ItemDescriptionGeneratorOwner { self: { def p: { def getItemDescriptionGen
case Some(generator) => itemDescriptionGenerator = generator
}
-}
-
-// FIXME: should not extend Listener?
-class ItemDescriptionGenerator(val action: ItemDescriptionEvent => String) extends com.vaadin.ui.AbstractSelect.ItemDescriptionGenerator with Listener {
- def generateDescription(source: com.vaadin.ui.Component, itemId: Any, propertyId: Any) = action(ItemDescriptionEvent(wrapperFor[Component](source).get, itemId, propertyId))
}
@@ -1,6 +1,7 @@
package vaadin.scala
import vaadin.scala.internal.LayoutClickListener
+import vaadin.scala.internal.ListenersTrait
case class LayoutClickEvent(component: Component, clickedComponent: Component, childComponent: Component, button: Int, clientX: Int, clientY: Int, relativeX: Int, relativeY: Int, doubleClick: Boolean, altKey: Boolean, ctrlKey: Boolean, metaKey: Boolean, shiftKey: Boolean) extends AbstractClickEvent(component, button, clientX, clientY, relativeX, relativeY, doubleClick, altKey, ctrlKey, metaKey, shiftKey)
@@ -6,40 +6,7 @@ import vaadin.scala.internal.FocusListener
import vaadin.scala.internal.ExpandListener
import vaadin.scala.internal.CollapseListener
import vaadin.scala.internal.ValueChangeListener
-trait Listener {
- def action: Any
-
- protected def wrapperFor[T](vaadinComponent: com.vaadin.ui.Component): Option[T] = internal.WrapperUtil.wrapperFor[T](vaadinComponent)
-}
-
-trait ListenersTrait[E, L <: Listener] extends mutable.Set[E => Unit] {
-
- import scala.collection.JavaConverters._
- def contains(key: E => Unit) = {
- iterator.contains(key)
- }
- def iterator(): Iterator[E => Unit] = {
- val list = listeners.asScala.map(_.asInstanceOf[L].action)
- list.iterator.asInstanceOf[Iterator[E => Unit]]
- }
- def +=(elem: => Unit) = { addListener((e: E) => elem); this }
- def +=(elem: E => Unit) = { addListener(elem); this }
- def -=(elem: E => Unit) = {
- val list = listeners.asScala.foreach { e =>
- if (e.asInstanceOf[L].action == elem) {
- removeListener(e.asInstanceOf[L])
- this
- }
- }
- this
- }
-
- protected def listeners: java.util.Collection[_]
-
- protected def addListener(elem: E => Unit);
-
- protected def removeListener(elem: L);
-}
+import vaadin.scala.internal.ListenersTrait
case class BlurEvent(component: Component) extends Event
@@ -1,5 +1,7 @@
package vaadin.scala
+import vaadin.scala.internal.ListenersTrait
+import vaadin.scala.internal.ClickListener
import vaadin.scala.mixins.PanelMixin
package mixins {
@@ -3,6 +3,7 @@ package vaadin.scala
import vaadin.scala.mixins.TabSheetMixin
import vaadin.scala.internal.WrapperUtil
import vaadin.scala.internal.SelectedTabChangeListener
+import vaadin.scala.internal.ListenersTrait
package mixins {
trait TabSheetMixin extends AbstractComponentContainerMixin
@@ -11,6 +11,7 @@ import vaadin.scala.internal.ColumnResizeListener
import vaadin.scala.internal.TableColumnGenerator
import vaadin.scala.internal.CellStyleGenerator
import vaadin.scala.internal.WrapperUtil
+import vaadin.scala.internal.ListenersTrait
import scala.collection.mutable
package mixins {
@@ -6,6 +6,7 @@ import vaadin.scala.internal.UploadStartedListener
import vaadin.scala.internal.UploadFinishedListener
import vaadin.scala.internal.UploadFailedListener
import vaadin.scala.internal.UploadSucceededListener
+import vaadin.scala.internal.ListenersTrait
import vaadin.scala.mixins.UploadMixin
package mixins {
@@ -1,6 +1,7 @@
package vaadin.scala
import vaadin.scala.internal.FragmentChangedListener
+import vaadin.scala.internal.ListenersTrait
import vaadin.scala.mixins.UriFragmentUtilityMixin
package mixins {
@@ -0,0 +1,7 @@
+package vaadin.scala.internal
+
+trait Listener {
+ def action: Any
+
+ protected def wrapperFor[T](vaadinComponent: com.vaadin.ui.Component): Option[T] = WrapperUtil.wrapperFor[T](vaadinComponent)
+}
@@ -0,0 +1,32 @@
+package vaadin.scala.internal
+
+import scala.collection.mutable
+
+trait ListenersTrait[E, L <: Listener] extends mutable.Set[E => Unit] {
+
+ import scala.collection.JavaConverters._
+ def contains(key: E => Unit) = {
+ iterator.contains(key)
+ }
+ def iterator(): Iterator[E => Unit] = {
+ val list = listeners.asScala.map(_.asInstanceOf[L].action)
+ list.iterator.asInstanceOf[Iterator[E => Unit]]
+ }
+ def +=(elem: => Unit) = { addListener((e: E) => elem); this }
+ def +=(elem: E => Unit) = { addListener(elem); this }
+ def -=(elem: E => Unit) = {
+ val list = listeners.asScala.foreach { e =>
+ if (e.asInstanceOf[L].action == elem) {
+ removeListener(e.asInstanceOf[L])
+ this
+ }
+ }
+ this
+ }
+
+ protected def listeners: java.util.Collection[_]
+
+ protected def addListener(elem: E => Unit);
+
+ protected def removeListener(elem: L);
+}
@@ -1,9 +1,9 @@
package vaadin.scala.internal
import vaadin.scala.Table
-import vaadin.scala.Listener
import vaadin.scala.Tree
import vaadin.scala.Component
+import vaadin.scala.ItemDescriptionEvent
class ColumnReorderListener(val action: Table.ColumnReorderEvent => Unit) extends com.vaadin.ui.Table.ColumnReorderListener with Listener {
def columnReorder(e: com.vaadin.ui.Table.ColumnReorderEvent) = action(Table.ColumnReorderEvent(wrapperFor[Table](e.getComponent).get))
@@ -24,4 +24,8 @@ class CellStyleGenerator(val generator: Table.CellStyleGenerationEvent => Option
// FIXME: should not extend Listener?
class ItemStyleGenerator(val action: Tree.ItemStyleEvent => Option[String]) extends com.vaadin.ui.Tree.ItemStyleGenerator with Listener {
def getStyle(itemId: Any) = action(Tree.ItemStyleEvent(itemId)).orNull
+}
+
+class ItemDescriptionGenerator(val action: ItemDescriptionEvent => String) extends com.vaadin.ui.AbstractSelect.ItemDescriptionGenerator with Listener {
+ def generateDescription(source: com.vaadin.ui.Component, itemId: Any, propertyId: Any) = action(ItemDescriptionEvent(wrapperFor[Component](source).get, itemId, propertyId))
}
@@ -76,4 +76,8 @@ class ButtonClickListener(val action: Button.ClickEvent => Unit) extends com.vaa
class TextChangeListener(val action: AbstractTextField.TextChangeEvent => Unit) extends com.vaadin.event.FieldEvents.TextChangeListener with Listener {
def textChange(e: com.vaadin.event.FieldEvents.TextChangeEvent) = action(AbstractTextField.TextChangeEvent(wrapperFor[AbstractTextField](e.getComponent).get, e.getText, e.getCursorPosition))
+}
+
+class ClickListener(val action: ClickEvent => Unit) extends com.vaadin.event.MouseEvents.ClickListener with Listener {
+ def click(e: com.vaadin.event.MouseEvents.ClickEvent) = action(ClickEvent(wrapperFor[Table](e.getComponent).get, e.getButton, e.getClientX, e.getClientY, e.getRelativeX, e.getRelativeY, e.isDoubleClick, e.isAltKey, e.isCtrlKey, e.isMetaKey, e.isShiftKey))
}

0 comments on commit 4d736ed

Please sign in to comment.