copies now make new state for new subfilters

This commit is contained in:
millmanorama 2018-11-01 09:06:16 +01:00
parent 7f573f5ea5
commit b108c86195

View File

@ -43,11 +43,6 @@ class CompoundFilterStateImpl<SubFilterType extends TimelineFilter, FilterType e
CompoundFilterStateImpl(FilterType filter) { CompoundFilterStateImpl(FilterType filter) {
super(filter); super(filter);
filter.getSubFilters().forEach(this::addStateForSubFilter); filter.getSubFilters().forEach(this::addStateForSubFilter);
filter.getSubFilters().addListener((ListChangeListener.Change<? extends SubFilterType> change) -> {
while (change.next()) {
change.getAddedSubList().forEach(CompoundFilterStateImpl.this::addStateForSubFilter);
}
});
configureListeners(); configureListeners();
} }
@ -69,6 +64,13 @@ class CompoundFilterStateImpl<SubFilterType extends TimelineFilter, FilterType e
} }
private void configureListeners() { private void configureListeners() {
//Add a new subfilterstate whenever the underlying subfilters change.
getFilter().getSubFilters().addListener((ListChangeListener.Change<? extends SubFilterType> change) -> {
while (change.next()) {
change.getAddedSubList().forEach(this::addStateForSubFilter);
}
});
/* /*
* enforce the following relationship between a compound filter and its * enforce the following relationship between a compound filter and its
* subfilters: if a compound filter's active property changes, disable * subfilters: if a compound filter's active property changes, disable
@ -81,7 +83,6 @@ class CompoundFilterStateImpl<SubFilterType extends TimelineFilter, FilterType e
subFilterStates.forEach(subFilterState -> subFilterState.setSelected(true)); subFilterStates.forEach(subFilterState -> subFilterState.setSelected(true));
} }
}); });
} }
/** /**
@ -97,7 +98,6 @@ class CompoundFilterStateImpl<SubFilterType extends TimelineFilter, FilterType e
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void addStateForSubFilter(SubFilterType subFilter) { private void addStateForSubFilter(SubFilterType subFilter) {
if (subFilter instanceof CompoundFilter<?>) { if (subFilter instanceof CompoundFilter<?>) {
addSubFilterState((FilterState<SubFilterType>) new CompoundFilterStateImpl<>((CompoundFilter<?>) subFilter)); addSubFilterState((FilterState<SubFilterType>) new CompoundFilterStateImpl<>((CompoundFilter<?>) subFilter));
} else { } else {
@ -120,7 +120,6 @@ class CompoundFilterStateImpl<SubFilterType extends TimelineFilter, FilterType e
@Override @Override
public CompoundFilterStateImpl<SubFilterType, FilterType> copyOf() { public CompoundFilterStateImpl<SubFilterType, FilterType> copyOf() {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
CompoundFilterStateImpl<SubFilterType, FilterType> copy CompoundFilterStateImpl<SubFilterType, FilterType> copy
= new CompoundFilterStateImpl<>((FilterType) getFilter().copyOf(), = new CompoundFilterStateImpl<>((FilterType) getFilter().copyOf(),