-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved selectionListeners to its own trait (SelectionNotifier) (part of …
…#59)
- Loading branch information
Henri Kerola
committed
Jan 3, 2015
1 parent
e3297cf
commit 3485629
Showing
5 changed files
with
44 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
addon/src/main/scala/vaadin/scala/event/SelectionEvent.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package vaadin.scala.event | ||
|
||
import vaadin.scala.Component | ||
|
||
/** | ||
* | ||
* @author Henri Kerola / Vaadin | ||
*/ | ||
case class SelectionEvent(component: Component, added: Seq[Any], removed: Seq[Any]) | ||
extends ComponentEvent(component) |
21 changes: 21 additions & 0 deletions
21
addon/src/main/scala/vaadin/scala/event/SelectionNotifier.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package vaadin.scala.event | ||
|
||
import com.vaadin.ui.{ AbstractComponent => VaadinAbstractComponent } | ||
import com.vaadin.event.SelectionEvent.{SelectionNotifier => VaadinSelectionNotifier} | ||
import vaadin.scala.ListenersSet | ||
import vaadin.scala.internal.{ListenersTrait, GridSelectionListener} | ||
|
||
/** | ||
* | ||
* @author Henri Kerola / Vaadin | ||
*/ | ||
trait SelectionNotifier { | ||
self: { def p: VaadinAbstractComponent with VaadinSelectionNotifier } => | ||
|
||
lazy val selectionListeners: ListenersSet[SelectionEvent => Unit] = | ||
new ListenersTrait[SelectionEvent, GridSelectionListener] { | ||
override def listeners = p.getListeners(classOf[com.vaadin.event.SelectionEvent]) | ||
override def addListener(elem: SelectionEvent => Unit) = p.addSelectionListener(new GridSelectionListener(elem)) | ||
override def removeListener(elem: GridSelectionListener) = p.removeSelectionListener(elem) | ||
} | ||
} |
13 changes: 7 additions & 6 deletions
13
addon/src/main/scala/vaadin/scala/internal/GridSelectionListener.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
package vaadin.scala.internal | ||
|
||
import com.vaadin.event.SelectionEvent | ||
import com.vaadin.event.{SelectionEvent => VaadinSelectionEvent} | ||
import com.vaadin.event.SelectionEvent.SelectionListener | ||
import vaadin.scala.Grid | ||
import vaadin.scala.Component | ||
import vaadin.scala.event.SelectionEvent | ||
|
||
/** | ||
* | ||
* @author Henri Kerola / Vaadin | ||
*/ | ||
class GridSelectionListener(val action: Grid.SelectionEvent => Unit) | ||
class GridSelectionListener(val action: SelectionEvent => Unit) | ||
extends SelectionListener with Listener { | ||
override def select(event: SelectionEvent): Unit = { | ||
val grid = wrapperFor[Grid](event.getSource).get | ||
override def select(event: VaadinSelectionEvent): Unit = { | ||
val component = wrapperFor[Component](event.getSource).get | ||
val added = event.getAdded.toArray | ||
val removed = event.getRemoved.toArray | ||
action(Grid.SelectionEvent(grid, added, removed)) | ||
action(SelectionEvent(component, added, removed)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters