Binding.scala FXML: How to populate an ObservableList property - scala

I have code like this:
val state = Var(initialState)
// ...
type SavedSearchCmb = ComboBox[SavedSearch]
val savedSearchesCmb: Binding[SavedSearchCmb] =
<SavedSearchCmb>
<items>
{state.bind.savedSearches}
</items>
</SavedSearchCmb>
The compiler complains,
[error] found : Seq[com.dev1on1.timer.YouTrackAPI.SavedSearch]
[error] required: javafx.collections.ObservableList[com.dev1on1.timer.YouTrackAPI.SavedSearch]
[error] <items>
What's the right way to generate the items?

According to the specification of FXML:
A read-only list property is a Bean property whose getter returns an instance of java.util.List and has no corresponding setter method. The contents of a read-only list element are automatically added to the list as they are processed.
items is a list property of SavedSearchCmb, however, it is not read-only as there is a setter setItems. As a result, the previous version of Binding.scala does append content of the savedSearches to the items property, instead, it tries to assign the Constants to items via setItems.
That is to say, the previous behavior of Binding.scala is extractly correct according to the specification.
The FXML behavior is very inconvenient.
Fortunately, Binding.scala does not have to support the extractly same syntax of Oracle's javafx.fxml.FXMLLoader.
I decide to break the specification, allowing appending content of the data-binding expressions to any list properties, no matter it is read-only or not.
The change has been include in Binding.scala 11.0.1. Your code should compile if you upgrade to Binding.scala 11.0.1.
We can do better than the original FXML specification. That's why you choose Binding.scala over javafx.fxml.FXMLLoader.

Related

Unity Custom Editor - Add Data Fields Based on Derived Type

Final goal: create a custom editor that will let me select from a list of types and then enter additional parameters specific to that type.
To this end, I have created a pure data type, let's call it BasicData, with a SpecificData parameter of an abstract base type, let's call it ExtraData. The idea is to have the type information in BasicData (enum value), and then populate the SpecificData field in the custom editor code so that when I change selection a new object from a class derived from ExtraData. Then its values can be further edited by additional fields created for that specific type, as shown here.
I started doing the above, but I ran into problems trying to get the actual object being edited in order to set the SpecificData property. My classes are not Unity objects or scripts, and I'd rather not turn them into such just for this. I might be able to use reflection to do this but then changes in the editor won't take effect while it runs, from what I understand.
What is the best way to accomplish this?

OPAL: Manually creating an annotated method

in the OPAL framework, is it possible to manually create an annotated method?
I currently have the following code:
Method(0, "signaturePolymorphicMethod",
MethodDescriptor(ObjectType("java/lang/Object"), VoidType), Seq())
and I want to add the annotation
#java.lang.invoke.MethodHandle$PolymorphicSignature
to this method. How can I do this?
Annotations are generally stored using the JVM's general "Attributes" mechanism.
In this case the annotation is a non-public inner class of MethodHandle with the "Runtime Retention Policy". Hence, to mark a method as having a "Polymorphic Signature" it is necessary to add the RuntimeVisibibleAnnotations_Attribute to the respective method's attributes table. However, given that the visibility of the annotation is limited to the java.lang.invoke package this is (in this specific case) probably rarely useful. Nevertheless, it is possible to query methods in the respective package

What is the meaning of private[context]

I'm trying to wrap my head around the Scala language and figured the best way to learn is to put it into practice. When copy pasting code between a Java project (Spring) and my Scala project the IDE did a conversion I do not understand. Searching for it on the internet and in the docs gave me nothing to work with unfortunately.
The code:
#Bean private[context] def passwordEncoder: PasswordEncoder = {
return new BCryptPasswordEncoder
}
When compiling the above code the compiler complains:
`error: context is not an enclosing class`
Can anybody explain what the private[context] part means?
context is just a placeholder, where you can fill in the context in which you'd like the method to be private. This is optional though. If you don't specify the context, the member becomes "class-private", which afaik behaves like private does in Java.
Background: Scala offers more than one degree of access specification: the object-private specification, i.e. private[this], stipulates that the member in question can only be seen by members called on that same object, not from different objects, even if they are of the same type. Instead of this you can also use a package name or even root, which is an alias for the root namespace.
More information on this can be found in "Section 5.2 - Modifiers" of the Scala Language Reference:
The private modifier can be used with any definition or declaration in a template.
[...]
The modifier can be qualified with an identifier C (e.g. private[C]) that must denote a class or package enclosing the definition. Members labeled with such a modifier are accessible respectively only from code inside the package C or only from code inside the class C and its companion module (ยง5.4).

Adding and removing Data Annotation attributes dynamically

I have a little bit of a curve ball for you. Maybe just a design issue...maybe even something as simple as me not understanding Data annotation providers.
Anyway here we go:
I have a class which represents some model data. Let's say it represents a package/box/carton.
It actually represents all of these things so I use the class in several different views. Sometimes I want the attribute of the field Package_Description to be
So that it shows up as Box Number : input box here.
Now if i want it to appear as "Carton Name" my only option would be to sub type it. Or use a separate class to have the annotations for this class. My quandary is that some of the field names are user configurable and therefore I cannot have a static definition!
(By the way i am using third party librarys [Telerik MVC Grid] do display these field names so i cannot change the fact that it's looking at data annotation )
So I just need to know is there a way to add attributes dynamically?
Create an anonymous type on the fly, sub class the original and then add attributes using reflection?
Or what other options are open to me, do I need to somehow implement a different annotation provider?
Attributes are part of the definition of the type. Because of that, you can't modify attributes of existing classes during runtime.
You could create a new type during runtime (not an anonymous type), but I think that's not such a good idea. I'm sure whatever component you're using, it allows you to specify the appearance explicitly.

In compiled Scala, what is the bitmap$0 field?

I have noticed some of my Scala classes contain a field with the name bitmap$0 of type int. What is this?
That's where the initialization states for lazy vals are stored. When you access a lazy val (or a nested object, which is equivalent), the compiler uses the bitmap field to determine whether it's already been evaluated.
When lazy vals are initialized, this field is also used for synchronization when the value is initialized.