Custom ValueExtractor for CheckListView (or any other Control subclasses)

Issue #592 new
Laurent Fleitas
created an issue

Hi, I want to add a Custom ValueExtractor for a CheckListView which trigger "on check change" and return the "checked items". When I add it

static {
        ValueExtractor.addObservableValueExtractor(c -> c instanceof CheckListView, c -> ((CheckListView<?>) c).checkModelProperty());
        ValueExtractor.addValueExtractor(n -> n instanceof CheckListView, lv -> {
            return ((CheckListView<?>) lv).getCheckModel().getCheckedItems();

it is ignored because CheckListView is an instance of ListView and the code for "getObservableValueExtractor" return your default implementation for ListView

public static final Optional<Callback<Control, ObservableValue<?>>> getObservableValueExtractor(final Control c) {
        for( ObservableValueExtractor e: extractors ) {
            if ( e.applicability.test(c)) return Optional.of(e.extraction);
        return Optional.empty();

It is the same issue for "addValueExtractor"..., your predicate is first in List<ObservableValueExtractor> extractors, so it cannot reach our predicate if we want to do it on a subclass of a Control already implemented.

I propose you to add a Map with the class instead of a predicate, so we can override the default implementation: Map<Class, ObservableValueExtractor> and Map<Class, NodeValueExtractor>?

Or maybe something else? Thx.

Comments (4)

  1. Jonathan Courtoy


    I've the same issue with the ValidationSupport usage. I can't set validation on CheckListView because of this issue.... The change of checkboxes states doesn't fire any event to perform a new validation of this field because it listens the itemProperty (instead of checkItems).

    Is it possible to add a way to override the extractors list ? An other simple way (in addition to the Laurent's way) should be to add new extractors at the beginning of the list (instead of at the end) : we can add a new extractor for CheckListView that will be tested before the ListView extractor.


  2. Stefano Negri

    Hi, I have the same issue (just for reference it is "the same as"/"very similar to" issues #623 and #561). Adding new elements at the beginning of the list as suggested by Jonathan Courtoy doesn't seem to have any drawbacks and is very easy to implement. If it is considered acceptable I could easily provide a pull request...

  3. Log in to comment