in trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SelectRangeChoiceBarRenderer.java [824:980]
private int _getItems(
FacesContext context,
RenderingContext rc,
UIComponent component,
List<SelectItem> items,
long minValue,
long maxValue,
long value,
int blockSize,
UIComponent rangeLabel)
{
int selectedIndex = -1;
boolean maxUnknown = (maxValue == XhtmlConstants.MAX_VALUE_UNKNOWN);
// Zero-indexed block index.
long blockIndex = (value - minValue + blockSize - 1L) / blockSize;
// sometimes a record set won't start on a multiple of blockSize. So
// remember to add any offset:
// this can safely be an int because it is an index into the blockSize,
// which is itself an int:
int offset = (int) (value - (minValue + (blockIndex * blockSize)));
if (offset < 0)
offset = offset + blockSize;
// Total number of blocks (again, zero-indexed)
long maxBlockIndex;
if (maxUnknown)
maxBlockIndex = blockIndex + 1;
else
{
maxBlockIndex = (maxValue - minValue - offset) / blockSize;
if (offset > 0)
maxBlockIndex++;
}
// Calculate the first block that should be shown. The order goes:
// Group 0: 0-28 + More
// Group 1:Previous + 29-56 + More
// Group 2:Previous + 57-84 + More
// etc..
long firstBlockIndex;
// If everything is visible, or we're in the first group, start at zero.
if ((maxBlockIndex <= (_MAX_VISIBLE_OPTIONS - 1L)) ||
(blockIndex <= (_MAX_VISIBLE_OPTIONS - 2L)))
firstBlockIndex = 0;
else
firstBlockIndex = ((blockIndex - 1L) / (_MAX_VISIBLE_OPTIONS - 2L)) *
(_MAX_VISIBLE_OPTIONS - 2L);
// And we always show a total of 30 groups (or straight to the end)
long lastBlockIndex = firstBlockIndex + (_MAX_VISIBLE_OPTIONS - 1L);
if (lastBlockIndex > maxBlockIndex)
lastBlockIndex = maxBlockIndex;
boolean showAllActive = getShowAll(component, getFacesBean(component));
// Add "Show All" option if showAll was set to true OR
// when there are less than 30 groups (maxBlockIndex
// start as zero, hence "29") and only allow it when there's
// more than 1 visible item!
if (showAllActive ||
(!maxUnknown && (lastBlockIndex > firstBlockIndex) &&
(maxBlockIndex <= (_MAX_VISIBLE_OPTIONS - 1L))
))
{
// Omit show all if it's not supported
if (showAllSupported())
{
items.add(_createShowAllSelectItem(rc,
maxValue));
if (showAllActive)
selectedIndex = 0;
}
}
for (blockIndex = firstBlockIndex;
blockIndex <= lastBlockIndex;
blockIndex++)
{
long blockStart = minValue + (blockIndex * blockSize);
// if there is an offset, then adjust accordingly. for example, if the
// offset is 7 (and the blockSize is 10), then the new blockStarts are:
// 1-7, 8-17, 18-27, etc ...
if (offset > 0)
blockStart += (offset - blockSize);
final int currentRecordSize;
// check to see if this is the very first record set in a table using an
// offset:
if (blockStart < minValue)
{
// treat this specially. this is the 1-7 case from the example above:
blockStart = minValue;
currentRecordSize = offset;
}
else
{
currentRecordSize = blockSize;
}
// return immediately if the start of the next range is not available.
if (maxUnknown)
{
if (!isRowAvailable(component, (int)blockStart - 1))
return selectedIndex;
}
String text;
// Need "Previous..."
if ((blockIndex == firstBlockIndex) &&
(blockIndex != 0))
{
text = rc.getTranslatedString(_PREVIOUS_TEXT_KEY);
}
// Need "More..." (on the last block, either 'cause
// the total number of blocks is unknown or we've shown enough blocks
// However, don't show More... if the total number of blocks is unknown,
// and we checked and found out that the start of the next block doesn't
// exist.
else if ((blockIndex == lastBlockIndex) &&
(maxUnknown || (lastBlockIndex < maxBlockIndex)))
{
text = rc.getTranslatedString(_MORE_TEXT_KEY);
}
else
{
text = null;
}
// =-=AEW I don't understand this next line...
long currValue = showAllActive ? minValue - 1 : value;// Don't select
SelectItem item = _createNavigationItem(context,
rc,
component,
blockStart,
currentRecordSize,
maxValue,
text,
rangeLabel);
if ((currValue >= blockStart) &&
(currValue < (blockStart + currentRecordSize)))
{
selectedIndex = items.size();
}
items.add(item);
}
return selectedIndex;
}