From 152a54de8fa08cf0c706fbf3ace1e508d4deb50c Mon Sep 17 00:00:00 2001 From: Mike Duff Date: Wed, 25 Sep 2013 15:23:18 -0500 Subject: [PATCH] Issue #2375 - Only display the configured number of messages in the notification center. Peer review comments Change-Id: I17c1f0a2d2cf910a52a0bdb655d39a08e47494ea Former-commit-id: 179d7c38caae9689797889d3c72fb2a5618aa47d [formerly dfd23d61fb8bf09dbac71594d593df9719730a8c] [formerly 08078bbd5408f7d6cf083e9fa4d5a3cd11130945] [formerly 4ee719b32c095fe98a6af89fdaa1ec4d8f4353f5 [formerly 08078bbd5408f7d6cf083e9fa4d5a3cd11130945 [formerly f4ac1c5a665346641cc9fcffa67aed522b1967e3]]] Former-commit-id: 4ee719b32c095fe98a6af89fdaa1ec4d8f4353f5 Former-commit-id: d0a801651f9c8ca642d546aa95b54479f0cfe2d5 [formerly 7b1ff055d051b783e3a4d23cbbeee3bc760f4f47] Former-commit-id: 848530acad100de4bab57a8988b22ada29a91eaf --- .../notification/NotificationTableComp.java | 49 +++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/notification/NotificationTableComp.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/notification/NotificationTableComp.java index 81b0c99f4c..0994b29a2d 100644 --- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/notification/NotificationTableComp.java +++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/notification/NotificationTableComp.java @@ -41,6 +41,7 @@ import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; import com.raytheon.uf.common.datadelivery.event.notification.NotificationRecord; +import com.raytheon.uf.common.time.util.TimeUtil; import com.raytheon.uf.viz.core.notification.NotificationMessage; import com.raytheon.uf.viz.datadelivery.common.ui.ITableChange; import com.raytheon.uf.viz.datadelivery.common.ui.ITableFind; @@ -793,14 +794,14 @@ public class NotificationTableComp extends TableComp implements ITableFind { public void populateTableDataRows( ArrayList notificationRecords) { List notificationList = new ArrayList(); - + MessageLoadXML messageLoad = null; NotificationConfigManager configMan = NotificationConfigManager .getInstance(); ArrayList users = configMan.getFilterXml().getUserFilterXml() .getUserList(); if (notificationRecords == null) { - MessageLoadXML messageLoad = msgLoadCallback.getMessageLoad(); + messageLoad = msgLoadCallback.getMessageLoad(); handler = new NotificationHandler(); notificationList = handler.intialLoad(messageLoad, users); masterTableList.clearAll(); @@ -808,7 +809,7 @@ public class NotificationTableComp extends TableComp implements ITableFind { } else { for (NotificationRecord rec : notificationRecords) { // prevents duplicates - if (currentRecordIds.contains(rec.getId()) == false) { + if (!currentRecordIds.contains(rec.getId())) { notificationList.add(rec); } } @@ -845,10 +846,52 @@ public class NotificationTableComp extends TableComp implements ITableFind { } } + messageLoad = msgLoadCallback.getMessageLoad(); + if (messageLoad != null) { + if (!messageLoad.isLoadAllMessages()) { + // Sort data by time + sortByTime(filteredTableList); + + int loadLast = messageLoad.getLoadLast(); + + // Keep only the specified number of rows + if (messageLoad.isNumMessages()) { + int numRecs = filteredTableList.getDataArray().size(); + if (numRecs > loadLast) { + for (int i = loadLast - 1; i < numRecs; i++) { + filteredTableList.removeDataRow(i); + } + } + } else { + long backTime = loadLast * TimeUtil.MILLIS_PER_HOUR; + long currentTime = TimeUtil.currentTimeMillis(); + List dataList = filteredTableList + .getDataArray(); + List indicesToRemove = new ArrayList(); + for (int i = 0; i < dataList.size(); i++) { + if (currentTime - dataList.get(i).getDate().getTime() > backTime) { + indicesToRemove.add(i); + } + } + + for (int i : indicesToRemove) { + filteredTableList.removeDataRow(i); + } + } + } + } + + // Now do the configured sort updateSortDirection(this.sortedColumn, filteredTableList, false); filteredTableList.sortData(); } + private void sortByTime(TableDataManager data) { + data.setSortDirection(SortDirection.DESCENDING); + data.setSortColumn("Time"); + data.sortData(); + } + /** * Clear the table display. */