min = min == null ? n : comparator.min(min, n);
max = max == null ? n : comparator.max(max, n);
}
}
Range previousRange = (Range) rangeFilter.getRangeProperty().getValue();
Range newRange;
if (min == null || max == null) {
newRange = null;
rangeFilter.getRangeProperty().setValue(newRange);
} else {
if (previousRange == null) {
newRange = new Range(min, max, min, max, values);
rangeFilter.getRangeProperty().setValue(newRange);
} else if(previousRange != null && (previousRange.getMinimum() == null || previousRange.getMaximum() == null)) {
//Opening projects
newRange = new Range(previousRange.getLowerBound(), previousRange.getUpperBound(), min, max, previousRange.isLeftInclusive(), previousRange.isRightInclusive(), values);
rangeFilter.getRangeProperty().setValue(newRange);
} else {
//Collect some info
boolean stickyLeft = previousRange.getMinimum().equals(previousRange.getLowerBound());
boolean stickyRight = previousRange.getMaximum().equals(previousRange.getUpperBound());
Number lowerBound = previousRange.getLowerBound();
Number upperBound = previousRange.getUpperBound();
//The inteval grows on the right
if (stickyRight && comparator.superior(max, upperBound)) {
upperBound = max;
}
//The interval grows on the left
if (stickyLeft && comparator.inferior(min, lowerBound)) {
lowerBound = min;
}
//The interval shrinks on the right
if (comparator.superior(upperBound, max)) {
upperBound = max;
}
//The interval shrinks on the left
if (comparator.inferior(lowerBound, min)) {
lowerBound = min;
}
newRange = new Range(lowerBound, upperBound, min, max, previousRange.isLeftInclusive(), previousRange.isRightInclusive(), values);
if (!newRange.equals(previousRange)) {
rangeFilter.getRangeProperty().setValue(newRange);
}
}
}
}