These are chat archives for ThoughtWorksInc/Binding.scala

26th
May 2017
nafg
@nafg
May 26 2017 04:47
Hi, I'm trying the code snippet at https://github.com/ThoughtWorksInc/Binding.scala/wiki/FXML and it's hanging the compiler!
If I ctrl-C it I get:
[error] /home/naftoli/dev/timer/javafx/src/main/scala/com/dev1on1/timer/Fxml.scala:17: exception during macro expansion: 
[error] java.lang.InterruptedException
[error]     at java.lang.Object.wait(Native Method)
[error]     at java.lang.Object.wait(Object.java:502)
[error]     at com.thoughtworks.binding.fxml$Macros$.<init>(fxml.scala:555)
[error]     at com.thoughtworks.binding.fxml$Macros$.<clinit>(fxml.scala)
[error]     at com.thoughtworks.binding.fxml$Macros$XmlTransformer$$anonfun$com$thoughtworks$binding$fxml$Macros$XmlTransformer$$transformXmlValue$1.applyOrElse(fxml.scala:1228)
[error]     at com.thoughtworks.binding.fxml$Macros$XmlTransformer$$anonfun$com$thoughtworks$binding$fxml$Macros$XmlTransformer$$transformXmlValue$1.applyOrElse(fxml.scala:1219)
[error]     at scala.PartialFunction$Lifted.apply(PartialFunction.scala:223)
[error]     at scala.PartialFunction$Lifted.apply(PartialFunction.scala:219)
[error]     at com.thoughtworks.Extractor$PartialFunctionToExtractor$$anon$3.unapply(Extractor.scala:98)
[error]     at com.thoughtworks.binding.fxml$Macros$XmlTransformer$$anonfun$com$thoughtworks$binding$fxml$Macros$XmlTransformer$$expand$1.applyOrElse(fxml.scala:1415)
[error]     at com.thoughtworks.binding.fxml$Macros$XmlTransformer$$anonfun$com$thoughtworks$binding$fxml$Macros$XmlTransformer$$expand$1.applyOrElse(fxml.scala:1414)
[error]     at scala.PartialFunction$Lifted.apply(PartialFunction.scala:223)
[error]     at scala.PartialFunction$Lifted.apply(PartialFunction.scala:219)
[error]     at com.thoughtworks.Extractor$PartialFunctionToExtractor$$anon$3.unapply(Extractor.scala:98)
[error]     at com.thoughtworks.binding.fxml$Macros$XmlTransformer$$anonfun$com$thoughtworks$binding$fxml$Macros$XmlTransformer$$transformBlock$1$$anonfun$37.apply(fxml.scala:1427)
[error]     at com.thoughtworks.binding.fxml$Macros$XmlTransformer$$anonfun$com$thoughtworks$binding$fxml$Macros$XmlTransformer$$transformBlock$1$$anonfun$37.apply(fxml.scala:1425)
[error]     at scala.collection.immutable.List.flatMap(List.scala:327)
[error]     at com.thoughtworks.binding.fxml$Macros$XmlTransformer$$anonfun$com$thoughtworks$binding$fxml$Macros$XmlTransformer$$transformBlock$1.applyOrElse(fxml.scala:1425)
[error]     at com.thoughtworks.binding.fxml$Macros$XmlTransformer$$anonfun$com$thoughtworks$binding$fxml$Macros$XmlTransformer$$transformBlock$1.applyOrElse(fxml.scala:1423)
[error]     at scala.PartialFunction$Lifted.apply(PartialFunction.scala:223)
[error]     at scala.PartialFunction$Lifted.apply(PartialFunction.scala:219)
[error]     at com.thoughtworks.Extractor$PartialFunctionToExtractor$$anon$3.unapply(Extractor.scala:98)
[error]     at com.thoughtworks.binding.fxml$Macros$XmlTransformer.transform(fxml.scala:1445)
[error]     at com.thoughtworks.binding.fxml$Macros$$anonfun$macroTransform$1.apply(fxml.scala:1484)
[error]     at com.thoughtworks.binding.fxml$Macros$$anonfun$macroTransform$1.apply(fxml.scala:1465)
[error]     at com.thoughtworks.sde.core.Preprocessor.replaceDefBody(Preprocessor.scala:35)
[error]     at com.thoughtworks.binding.fxml$Macros.macroTransform(fxml.scala:1464)
[error]   @fxml override def start(primaryStage: Stage): Unit = {
杨博 (Yang Bo)
@Atry
May 26 2017 04:49
Seems like some dead locks when initialization of JavaFX
@nafg Would you mind creating an issue?
nafg
@nafg
May 26 2017 04:54
@Atry hi. Any workaround?
Can you explain what's going wrong? And why is it checking for isFxApplicationThread in a compiler process?
杨博 (Yang Bo)
@Atry
May 26 2017 04:54
Let me see how to reproduce first
nafg
@nafg
May 26 2017 04:55
I literally copy-pasted the snippet from the wiki
杨博 (Yang Bo)
@Atry
May 26 2017 04:55
JDK version?
nafg
@nafg
May 26 2017 04:55
8
1.8.0_131
杨博 (Yang Bo)
@Atry
May 26 2017 04:59
Could you create a minimal project to reproduce the issue, please
nafg
@nafg
May 26 2017 04:59
Sure
杨博 (Yang Bo)
@Atry
May 26 2017 05:00

Have you ran tried to clone the Binding.scala repository and run sbt test?

There is a similar sample:
https://github.com/ThoughtWorksInc/Binding.scala/blob/11.0.x/fxml/.jvm/src/test/scala/com/thoughtworks/binding/FxmlSample.scala

nafg
@nafg
May 26 2017 05:02
Ok let me do that
@Atry it would seem to me that the problem is there's no AWT thread running
BTW @Atry how can fxml be used with JS?
杨博 (Yang Bo)
@Atry
May 26 2017 05:07
I still did not know how to reproduce it
nafg
@nafg
May 26 2017 05:07
@Atry your code is compiling fine for me (tests pass), let me try pasting into there
杨博 (Yang Bo)
@Atry
May 26 2017 05:09
The way JVM loading JavaFX's library is very strange
nafg
@nafg
May 26 2017 05:10
How is it used with scala.js?
BTW for different jvm/js code, it's better to use CrossType.Full
That way you don't keep important things in dot files (dirs) :)
杨博 (Yang Bo)
@Atry
May 26 2017 05:11
The macro need some JavaFX classes like javafx.fxml.JavaFXBuilderFactory in order to compile @fxml
nafg
@nafg
May 26 2017 05:12
For some reason when I try to run the class you pointed to it gives java.lang.ClassNotFoundException: com.thoughtworks.binding.FxmlSample
(a lot of other output too)
杨博 (Yang Bo)
@Atry
May 26 2017 05:13
Still, reproduce steps
nafg
@nafg
May 26 2017 05:13
And when I modify it it doesn't seem to compile
Ok
Is there any good way to share other than a full github repo?
nafg
@nafg
May 26 2017 05:18
@Atry ok I think I see what's happening: it only hangs when I already ran an AWT app in the same JVM
or rather javafx perhaps?
杨博 (Yang Bo)
@Atry
May 26 2017 05:19
If it is the case fork := true in build.sbt would help
Feel free to create an issue
nafg
@nafg
May 26 2017 05:20
ok thanks!
nafg
@nafg
May 26 2017 05:25
@Atry since (little known fact) sbt will compile source in project top level directory, I made the repro as a gist that you can download as a zip.
Ticket: ThoughtWorksInc/Binding.scala#50
Actually I have sbt-revolver in this codebase already, so using it would solve the problem too. It hung because I had done run anyway
杨博 (Yang Bo)
@Atry
May 26 2017 05:27
A very good bug report
nafg
@nafg
May 26 2017 05:27
thanks :)
nafg
@nafg
May 26 2017 05:36
This message was deleted
nafg
@nafg
May 26 2017 05:39
oh so it's a property?
杨博 (Yang Bo)
@Atry
May 26 2017 05:39
Yes, it's a JavaBean property
nafg
@nafg
May 26 2017 05:43
@Atry how does it decide what's a property and what's a constructor?
also I see properties are also allowed as attributes
杨博 (Yang Bo)
@Atry
May 26 2017 05:46
Usually by naming conventions. See JavaBeans Specification.
nafg
@nafg
May 26 2017 05:53
@Atry thanks. Next question: :) I'm trying to port a bit of javafx code to binding.scala. How would I do the equivalent of a ComboBox that's using generics?
right now I have val savedSearchesCmb = new ComboBox[SavedSearch]
and I do setItems on it
杨博 (Yang Bo)
@Atry
May 26 2017 05:55
I don't think FXML supports generics.
nafg
@nafg
May 26 2017 05:55
@Atry how would you suggest doing the equivalent?
杨博 (Yang Bo)
@Atry
May 26 2017 05:57
I did not test ComboBox. You can have a try and see whan happens
nafg
@nafg
May 26 2017 05:57
@Atry what I mean is, how would you suggest writing a dynamically populated combo box whose selection is used in other bindings
Did you test anything comparable?
Ok I will experiment.
@Atry can I just reference comboBox.value somewhere else somehow?
I didn't use binding.scala in scala.js so I'm very vague on a lot of things
@Atry how would I access its value property somewhere else?
(unrelated to generics matter)
Or should I have an onChange set a Var?
杨博 (Yang Bo)
@Atry
May 26 2017 06:02
I don't understand your situation. I guess the question for general usage is better to ask on StackOverflow.
nafg
@nafg
May 26 2017 06:02
@Atry I mean does binding.scala expose the property of a Binding[Control]
杨博 (Yang Bo)
@Atry
May 26 2017 06:02
There is a binding.scala tag
nafg
@nafg
May 26 2017 06:06
@Atry AFAICT <ComboBox></ComboBox> doesn't compile
unless there's something I can put inside that will work
[error] /home/naftoli/dev/timer/javafx/src/main/scala/com/dev1on1/timer/Fxml.scala:28: class ComboBox takes type parameters
[error]       <ComboBox><items>{SavedSearch("", "")}</items></ComboBox>
杨博 (Yang Bo)
@Atry
May 26 2017 06:07
Still, try StackOverflow
nafg
@nafg
May 26 2017 06:07
Ok, but I think it's a bug ;)
@Atry are you actually using FXMLLoader or just imitating it?
杨博 (Yang Bo)
@Atry
May 26 2017 06:08
just imitating
nafg
@nafg
May 26 2017 06:09
how can I see what scala code the macro is generating?
杨博 (Yang Bo)
@Atry
May 26 2017 06:11
There are a lot of flags for Scala compiler to show those information. Try scalac -X and scalac -Y
Would you mind report the ComboBox problem on issue tracker, please?
A workaround is
type MyComboBox = ComboBox[SavedSearch];
<MyComboBox>...</MyComboBox>
nafg
@nafg
May 26 2017 06:21
Oh nice, I thought of something similar but inferior, extending it
ThoughtWorksInc/Binding.scala#51
How do I get an ObservableList?
  val state = Var(initialState)

    type SavedSearchCmb = ComboBox[SavedSearch]
    val savedSearchesCmb: Binding[SavedSearchCmb] =
      <SavedSearchCmb>
        <items>
          {state.bind.savedSearches}
        </items>
      </SavedSearchCmb>
This message was deleted
gives
[error]  found   : Seq[com.dev1on1.timer.YouTrackAPI.SavedSearch]
[error]  required: javafx.collections.ObservableList[com.dev1on1.timer.YouTrackAPI.SavedSearch]
[error]         <items>
杨博 (Yang Bo)
@Atry
May 26 2017 06:28
I suggest you ask it on StackOverflow. Since other people may experience the same problem
nafg
@nafg
May 26 2017 06:28
ok
杨博 (Yang Bo)
@Atry
May 26 2017 06:33
I guess you may want to add more tags if you want more people see the question
nafg
@nafg
May 26 2017 06:33
Like?