// Create the new nodes
Set<Date> keySet = dateMap.keySet();
Date[] dates = new Date[keySet.size()];
keySet.toArray(dates);
Arrays.sort(dates);
Node node=null;
String lastDateStr="";
int numPrograms = 0;
for (Date date : dates) {
numPrograms += dateMap.get(date).size();
}
// show week nodes if there are less than 2 programs per day on average
boolean createWeekNodes = mGroupWeekly && (numPrograms <= dates.length * 2);
boolean isShowingWeekNodes = createWeekNodes;
for (Date date : dates) {
String dateStr;
if (mNodeYesterday.equals(date)) {
dateStr = Localizer.getLocalization(Localizer.I18N_YESTERDAY);
isShowingWeekNodes = false;
}
else if (mNodeToday.equals(date)) {
dateStr = Localizer.getLocalization(Localizer.I18N_TODAY);
isShowingWeekNodes = false;
}
else if (mNodeTomorrow.equals(date)) {
dateStr = Localizer.getLocalization(Localizer.I18N_TOMORROW);
isShowingWeekNodes = false;
}
else {
if (createWeekNodes) {
int weeks = date.getNumberOfDaysSince(mNodeToday) / 7;
if (weeks <= 3) {
dateStr = mLocalizer.msg("weeks."+weeks,"in {0} weeks",weeks);
}
else {
dateStr = mLocalizer.msg("weeks.later","later");
}
}
else {
dateStr = date.getLongDateString();
}
}
if (!dateStr.equals(lastDateStr)) {
node = new Node(Node.STRUCTURE_NODE, dateStr);
mDefaultNode.add(node);
lastDateStr = dateStr;
}
List<PluginTreeNode> list = dateMap.get(date);
PluginTreeNode[] nodeArr = new PluginTreeNode[list.size()];
list.toArray(nodeArr);
Arrays.sort(nodeArr);
for (PluginTreeNode element : nodeArr) {
Node newNode = new Node((ProgramItem)element.getUserObject());
newNode.setNodeFormatter(element.getNodeFormatter(createWeekNodes && isShowingWeekNodes));
node.add(newNode);
}
isShowingWeekNodes = createWeekNodes;
}