Skip to content

Commit

Permalink
Closes: #6 #9 Adding/removing listeners in scala API by listenerSets …
Browse files Browse the repository at this point in the history
…and Cleanup hierarchy of components
  • Loading branch information
LukaszByczynski committed May 7, 2015
1 parent 2fdf747 commit 0c7ea74
Show file tree
Hide file tree
Showing 83 changed files with 830 additions and 548 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package org.vaadin.addons.rinne
import com.vaadin.ui.{AbsoluteLayout, Component}
import org.vaadin.addons.rinne.mixins.{AbstractLayoutMixin, ComponentContainerMixin, ComponentMixin, LayoutClickNotifierMixin}

class VAbsoluteLayout extends AbsoluteLayout
with AbstractLayoutMixin with ComponentContainerMixin with ComponentMixin with LayoutClickNotifierMixin {
class VAbsoluteLayout extends AbsoluteLayout with AbstractLayoutMixin {

def add[C <: Component](component: C, location: String): C = {
addComponent(component, location)
Expand Down
4 changes: 2 additions & 2 deletions addon/src/main/scala/org/vaadin/addons/rinne/VAccordion.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.vaadin.addons.rinne

import com.vaadin.ui.Accordion
import org.vaadin.addons.rinne.mixins.TabSheetMixin
import org.vaadin.addons.rinne.mixins._

class VAccordion extends Accordion with TabSheetMixin
class VAccordion extends Accordion with TabSheetMixin
6 changes: 2 additions & 4 deletions addon/src/main/scala/org/vaadin/addons/rinne/VAudio.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.vaadin.addons.rinne

import com.vaadin.ui.Audio
import org.vaadin.addons.rinne.mixins.AbstractMediaMixin
import org.vaadin.addons.rinne.mixins.{ComponentMixin, AbstractComponentMixin, AbstractMediaMixin}

class VAudio extends Audio with AbstractMediaMixin {

}
class VAudio extends Audio with AbstractMediaMixin
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.vaadin.addons.rinne

import com.vaadin.ui.BrowserFrame
import org.vaadin.addons.rinne.mixins.AbstractEmbeddedMixin
import org.vaadin.addons.rinne.mixins.{ComponentMixin, AbstractComponentMixin, AbstractEmbeddedMixin}

class VBrowserFrame extends BrowserFrame with AbstractEmbeddedMixin
52 changes: 2 additions & 50 deletions addon/src/main/scala/org/vaadin/addons/rinne/VButton.scala
Original file line number Diff line number Diff line change
@@ -1,54 +1,6 @@
package org.vaadin.addons.rinne

import com.vaadin.ui.Button
import org.vaadin.addons.rinne.events._
import org.vaadin.addons.rinne.mixins.{AbstractComponentMixin, FocusableMixin}
import org.vaadin.addons.rinne.mixins._

import scala.collection.JavaConverters._

class VButton extends Button with AbstractComponentMixin with BlurNotifier with FocusNotifier with FocusableMixin {

lazy val clickListeners: ListenersSet[Button.ClickEvent => Unit] =
new ListenersTrait[Button.ClickEvent, ButtonClickListener] {
override def listeners = getListeners(classOf[Button.ClickEvent])

override def addListener(elem: Button.ClickEvent => Unit) = addClickListener(new ButtonClickListener(elem))

override def removeListener(elem: ButtonClickListener) = removeClickListener(elem)

override def clear(): Unit = {
super.clear()
listeners.asScala.foreach(_ => removeListener(_))
}
}
private var _clickKeyShortcut: Option[KeyShortcut] = None

def clickKeyShortcut_=(clickShortcut: Option[KeyShortcut]) {
_clickKeyShortcut = clickShortcut
clickShortcut match {
case None => removeClickShortcut()
case Some(shortcut) => setClickShortcut(shortcut.keyCode.value, shortcut.modifiers.map(_.value): _*)
}
}

def disableOnClick: Boolean = isDisableOnClick

def disableOnClick_=(disableOnClick: Boolean) {
setDisableOnClick(disableOnClick)
}

def clickKeyShortcut: Option[KeyShortcut] = _clickKeyShortcut

def htmlContentAllowed: Boolean = isHtmlContentAllowed

def htmlContentAllowed_=(htmlContentAllowed: Boolean) {
setHtmlContentAllowed(htmlContentAllowed)
}


def clickKeyShortcut_=(clickShortcut: KeyShortcut) {
this.clickKeyShortcut = Option(clickShortcut)
}


}
class VButton extends Button with ButtonMixin
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class VCalendar extends Calendar with AbstractComponentMixin {
def weeklyCaptionFormat: String = getWeeklyCaptionFormat

def weeklyCaptionFormat_=(value: String): Unit = setWeeklyCaptionFormat(value)

}


9 changes: 6 additions & 3 deletions addon/src/main/scala/org/vaadin/addons/rinne/VCheckBox.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package org.vaadin.addons.rinne

import com.vaadin.event.FieldEvents.{BlurNotifier, FocusNotifier}
import com.vaadin.ui.CheckBox
import org.vaadin.addons.rinne.mixins.AbstractFieldMixin
import org.vaadin.addons.rinne.mixins.{AbstractFieldMixin, BlurNotifierMixin, FocusNotifierMixin}

class VCheckBox extends CheckBox with AbstractFieldMixin[java.lang.Boolean] {
class VCheckBox extends CheckBox
with AbstractFieldMixin[java.lang.Boolean] with BlurNotifierMixin with BlurNotifier with FocusNotifierMixin with FocusNotifier {

def value_=(value: Boolean) {
def value_=(value: Boolean): Unit = {
setValue(value)
}

def boolValue: Boolean = getValue

}
19 changes: 18 additions & 1 deletion addon/src/main/scala/org/vaadin/addons/rinne/VColorPicker.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
package org.vaadin.addons.rinne

import java.util

import com.vaadin.ui.ColorPicker
import com.vaadin.ui.components.colorpicker.{ColorChangeEvent, ColorChangeListener}
import org.vaadin.addons.rinne.events.ListenersSet
import org.vaadin.addons.rinne.mixins.AbstractComponentMixin

class VColorPicker extends ColorPicker with AbstractComponentMixin
class VColorPicker extends ColorPicker with AbstractComponentMixin {

lazy val colorChangeListeners = new ListenersSet[ColorChangeEvent, ColorChangeListener] {
override protected def addListener(listener: ListenerLambda): Unit = addColorChangeListener(
new Listener(listener) with ColorChangeListener {
override def colorChanged(event: ColorChangeEvent): Unit = listener(event)
}
)

override protected def removeListener(listener: ColorChangeListener): Unit = removeColorChangeListener(listener)

override protected def listeners: util.Collection[_] = getListeners(classOf[ColorChangeEvent])
}
}
4 changes: 2 additions & 2 deletions addon/src/main/scala/org/vaadin/addons/rinne/VComboBox.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package org.vaadin.addons.rinne

import com.vaadin.shared.ui.combobox.FilteringMode
import com.vaadin.ui.ComboBox
import org.vaadin.addons.rinne.mixins.{AbstractSelectMixin, ContainerMixin}
import org.vaadin.addons.rinne.mixins.AbstractSelectMixin

class VComboBox extends ComboBox with AbstractSelectMixin with ContainerMixin {
class VComboBox extends ComboBox with AbstractSelectMixin {

def inputPrompt: Option[String] = Option(getInputPrompt)

Expand Down
7 changes: 3 additions & 4 deletions addon/src/main/scala/org/vaadin/addons/rinne/VCssLayout.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package org.vaadin.addons.rinne

import com.vaadin.ui.{Component, CssLayout}
import org.vaadin.addons.rinne.events.LayoutClickNotifierMixin
import org.vaadin.addons.rinne.mixins.AbstractLayoutMixin
import org.vaadin.addons.rinne.mixins.{LayoutClickNotifierMixin, AbstractLayoutMixin}

class VCssLayout extends CssLayout with AbstractLayoutMixin with LayoutClickNotifierMixin {

private var _cssMap = Map.empty[Component, String]
private var _cssMap = Map[Component, String]()

def add[C <: Component](component: C, css: => String = null): C = {
add(component)
Expand All @@ -16,7 +15,7 @@ class VCssLayout extends CssLayout with AbstractLayoutMixin with LayoutClickNoti
component
}

override def getCss(component: Component): String = _cssMap.getOrElse(component, "")
def getCssForComponent(component: Component): Option[String] = _cssMap.get(component)

override def removeComponent(component: Component) = {
super.removeComponent(component)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ class VCustomComponent extends CustomComponent with ComponentMixin {

def compositionRoot: Option[Component] = Option(getCompositionRoot)

def compositionRoot_=(component: Component) {
def compositionRoot_=(component: Component): Unit = {
setCompositionRoot(component)
}

def compositionRoot_=(component: Option[Component]) {
def compositionRoot_=(component: Option[Component]): Unit = {
setCompositionRoot(component.orNull)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ class VCustomLayout extends CustomLayout with AbstractLayoutMixin {

def templateName = Option(getTemplateName)

def templateName_=(templateName: String) = setTemplateName(templateName)
def templateName_=(templateName: String): Unit = setTemplateName(templateName)

def templateContents = Option(getTemplateContents)

def templateContents_=(templateContents: String) = setTemplateContents(templateContents)
def templateContents_=(templateContents: String): Unit = setTemplateContents(templateContents)

def add[C <: Component](component: C, location: String): C = {
addComponent(component, location)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.vaadin.addons.rinne

import com.vaadin.ui.DateField
import org.vaadin.addons.rinne.mixins.DateFieldMixin

class VDateField extends DateFieldMixin
class VDateField extends DateField with DateFieldMixin
41 changes: 14 additions & 27 deletions addon/src/main/scala/org/vaadin/addons/rinne/VEmbedded.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package org.vaadin.addons.rinne

import com.vaadin.server.Resource
import com.vaadin.ui.Embedded
import org.vaadin.addons.rinne.mixins.AbstractComponentMixin
import org.vaadin.addons.rinne.mixins.{AbstractComponentMixin, ComponentMixin, MouseClickNotifierMixin}

import scala.collection.mutable

class VEmbedded extends Embedded with AbstractComponentMixin {
class VEmbedded extends Embedded with AbstractComponentMixin with ComponentMixin with MouseClickNotifierMixin {

lazy val parameters: mutable.Map[String, String] = new mutable.Map[String, String] with Serializable {
def -=(name: String): this.type = {
Expand Down Expand Up @@ -36,51 +35,39 @@ class VEmbedded extends Embedded with AbstractComponentMixin {
}
}

def alternateText: Option[String] = Option(getAlternateText)

def alternateText_=(alternateText: Option[String]) = setAlternateText(alternateText.orNull)

def alternateText_=(alternateText: String) = setAlternateText(alternateText)

def source: Option[Resource] = Option(getSource)

def source_=(source: Resource) = setSource(source)

def source_=(source: Option[Resource]) = setSource(source.orNull)

def codebase: Option[String] = Option(getCodebase)

def codebase_=(codebase: String) = setCodebase(codebase)
def codebase_=(codebase: String): Unit = setCodebase(codebase)

def codebase_=(codebase: Option[String]) = setCodebase(codebase.orNull)
def codebase_=(codebase: Option[String]): Unit = setCodebase(codebase.orNull)

def codetype: Option[String] = Option(getCodetype)

def codetype_=(codetype: String) = setCodetype(codetype)
def codetype_=(codetype: String): Unit = setCodetype(codetype)

def codetype_=(codetype: Option[String]) = setCodetype(codetype.orNull)
def codetype_=(codetype: Option[String]): Unit = setCodetype(codetype.orNull)

def standby: Option[String] = Option(getStandby)

def standby_=(standby: String) = setStandby(standby)
def standby_=(standby: String): Unit = setStandby(standby)

def standby_=(standby: Option[String]) = setStandby(standby.orNull)
def standby_=(standby: Option[String]): Unit = setStandby(standby.orNull)

def mimeType: Option[String] = Option(getMimeType)

def mimeType_=(mimeType: String) = setMimeType(mimeType)
def mimeType_=(mimeType: String): Unit = setMimeType(mimeType)

def mimeType_=(mimeType: Option[String]) = setMimeType(mimeType.orNull)
def mimeType_=(mimeType: Option[String]): Unit = setMimeType(mimeType.orNull)

def classId: Option[String] = Option(getClassId)

def classId_=(classId: String) = setClassId(classId)
def classId_=(classId: String): Unit = setClassId(classId)

def classId_=(classId: Option[String]) = setClassId(classId.orNull)
def classId_=(classId: Option[String]): Unit = setClassId(classId.orNull)

def archive: Option[String] = Option(getArchive)

def archive_=(archive: String) = setArchive(archive)
def archive_=(archive: String): Unit = setArchive(archive)

def archive_=(archive: Option[String]) = setArchive(archive.orNull)
def archive_=(archive: Option[String]): Unit = setArchive(archive.orNull)
}
57 changes: 56 additions & 1 deletion addon/src/main/scala/org/vaadin/addons/rinne/VFlash.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,59 @@ package org.vaadin.addons.rinne
import com.vaadin.ui.Flash
import org.vaadin.addons.rinne.mixins.AbstractEmbeddedMixin

class VFlash extends Flash with AbstractEmbeddedMixin
import scala.collection.mutable

class VFlash extends Flash with AbstractEmbeddedMixin {

lazy val parameters: mutable.Map[String, String] = new mutable.Map[String, String] with Serializable {
def -=(name: String): this.type = {
removeParameter(name)
this
}

def +=(parameter: (String, String)): this.type = {
update(parameter._1, parameter._2)
this
}

override def update(name: String, value: String) {
setParameter(name, value)
}

def get(name: String): Option[String] = Option(getParameter(name))

override def size = {
import scala.collection.JavaConverters._
getParameterNames.asScala.size
}

def iterator: Iterator[(String, String)] = {
import scala.collection.JavaConverters._
getParameterNames.asScala.map { name => (name, getParameter(name)) }.toIterator
}
}

def codebase: Option[String] = Option(getCodebase)

def codebase_=(codebase: String): Unit = setCodebase(codebase)

def codebase_=(codebase: Option[String]): Unit = setCodebase(codebase.orNull)

def codetype: Option[String] = Option(getCodetype)

def codetype_=(codetype: String): Unit = setCodetype(codetype)

def codetype_=(codetype: Option[String]): Unit = setCodetype(codetype.orNull)

def standby: Option[String] = Option(getStandby)

def standby_=(standby: String): Unit = setStandby(standby)

def standby_=(standby: Option[String]): Unit = setStandby(standby.orNull)

def archive: Option[String] = Option(getArchive)

def archive_=(archive: String): Unit = setArchive(archive)

def archive_=(archive: Option[String]): Unit = setArchive(archive.orNull)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package org.vaadin.addons.rinne
import com.vaadin.ui.FormLayout
import org.vaadin.addons.rinne.mixins.AbstractOrderedLayoutMixin

class VFormLayout extends FormLayout with AbstractOrderedLayoutMixin
class VFormLayout extends FormLayout with AbstractOrderedLayoutMixin
Loading

0 comments on commit 0c7ea74

Please sign in to comment.