Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. private def notifyValueChange(
  2. containingDocument: XFormsContainingDocument,
  3. nodeInfo: NodeInfo,
  4. oldValue: String,
  5. newValue: String,
  6. isCalculate: Boolean,
  7. collector: XFormsEvent ⇒ Unit
  8. ) =
  9. Option(containingDocument.getInstanceForNode(nodeInfo)) match {
  10. case Some(modifiedInstance) ⇒
  11. // Tell the model about the value change
  12. try {
  13. val nodeName = nodeInfo.name
  14. var objectControl: XFormsObject = null
  15. try {
  16. objectControl = containingDocument.resolveObjectById(containingDocument.getEffectiveId, nodeName + "-control", null)
  17. } catch {
  18. case _: NullPointerException =>
  19. case e: Exception => e.printStackTrace(); XFormsServer.logger.warn(e.getMessage);
  20. }
  21. objectControl match {
  22. case selectControl: XFormsSelect1Control =>
  23. addLabelToNode(selectControl, newValue, nodeInfo)
  24. case valueComponentControl: XFormsValueComponentControl =>
  25. valueComponentControl.children.head match {
  26. case componentRootControl: XXFormsComponentRootControl =>
  27. componentRootControl.children.foreach {
  28. case wrappedSelectControl: XFormsSelect1Control =>
  29. addLabelToNode(wrappedSelectControl, newValue, nodeInfo)
  30. case _ =>
  31. }
  32. case _ =>
  33. }
  34. case _ =>
  35. }
  36. } catch {
  37. case e: Exception => e.printStackTrace(); XFormsServer.logger.warn(e.getMessage);
  38. }
  39. // rest of the method
  40.  
  41. private def addLabelToNode(control: XFormsSelect1Control, newValue: String, nodeInfo: NodeInfo): Unit = {
  42. try {
  43. val name = control.element.getQName.getName
  44. if ("select1".equals(name)) {
  45. val label = control.getItemset.selectedItems(newValue).head.label.label
  46. XFormsAPI.ensureAttribute(nodeInfo, new QName("label", null, null), label)
  47. } else if ("select".equals(name)) {
  48. val stringList = new util.ArrayList[String]()
  49. val newValueArray = newValue.split(" ")
  50. newValueArray.foreach(
  51. v => {
  52. val item = control.getItemset.selectedItems(newValue).find(i => i.value == v).get
  53. stringList.add(item.label.label)
  54. }
  55. )
  56. val label = stringList.toArray.mkString(" ")
  57. XFormsAPI.ensureAttribute(nodeInfo, new QName("label", null, null), label)
  58. }
  59. } catch {
  60. case _: NoSuchElementException => XFormsAPI.ensureAttribute(nodeInfo, new QName("label", null, null), "")
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement