From 76d8e4e4999b0dc13f6fd87520f6b7d31a64da40 Mon Sep 17 00:00:00 2001 From: Tan Wang Leng Date: Sun, 7 Jan 2018 19:15:52 +0800 Subject: [PATCH] StatusBarFooter: Show total persons In order to determine the total number of contacts in the address book, the user has to scroll the list all the way down to the last person, as the ID of the last person gives an indication of the total number of persons. This forces the user to use the graphical user interface to find such an information. Let's modify StatusBarFooter so that it shows the total number of persons in the current address book. --- .../java/seedu/address/ui/MainWindow.java | 3 ++- .../seedu/address/ui/StatusBarFooter.java | 13 +++++++-- src/main/resources/view/StatusBarFooter.fxml | 3 ++- .../guihandles/StatusBarFooterHandle.java | 27 +++++++++++++++++++ .../seedu/address/ui/StatusBarFooterTest.java | 26 ++++++++++++------ 5 files changed, 60 insertions(+), 12 deletions(-) diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index 0e361a4d7baf..75d5b3cbabb5 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -128,7 +128,8 @@ void fillInnerParts() { ResultDisplay resultDisplay = new ResultDisplay(); resultDisplayPlaceholder.getChildren().add(resultDisplay.getRoot()); - StatusBarFooter statusBarFooter = new StatusBarFooter(prefs.getAddressBookFilePath()); + StatusBarFooter statusBarFooter = new StatusBarFooter(prefs.getAddressBookFilePath(), + logic.getFilteredPersonList().size()); statusbarPlaceholder.getChildren().add(statusBarFooter.getRoot()); CommandBox commandBox = new CommandBox(logic); diff --git a/src/main/java/seedu/address/ui/StatusBarFooter.java b/src/main/java/seedu/address/ui/StatusBarFooter.java index f6ba29502422..364d7196d68f 100644 --- a/src/main/java/seedu/address/ui/StatusBarFooter.java +++ b/src/main/java/seedu/address/ui/StatusBarFooter.java @@ -24,6 +24,8 @@ public class StatusBarFooter extends UiPart { public static final String SYNC_STATUS_INITIAL = "Not updated yet in this session"; public static final String SYNC_STATUS_UPDATED = "Last Updated: %s"; + public static final String TOTAL_PERSONS_STATUS = "%d person(s) total"; + /** * Used to generate time stamps. * @@ -41,13 +43,15 @@ public class StatusBarFooter extends UiPart { @FXML private StatusBar syncStatus; @FXML + private StatusBar totalPersonsStatus; + @FXML private StatusBar saveLocationStatus; - - public StatusBarFooter(Path saveLocation) { + public StatusBarFooter(Path saveLocation, int totalPersons) { super(FXML); setSyncStatus(SYNC_STATUS_INITIAL); setSaveLocation(Paths.get(".").resolve(saveLocation).toString()); + setTotalPersons(totalPersons); registerAsAnEventHandler(this); } @@ -73,11 +77,16 @@ private void setSyncStatus(String status) { Platform.runLater(() -> syncStatus.setText(status)); } + private void setTotalPersons(int totalPersons) { + Platform.runLater(() -> this.totalPersonsStatus.setText(String.format(TOTAL_PERSONS_STATUS, totalPersons))); + } + @Subscribe public void handleAddressBookChangedEvent(AddressBookChangedEvent abce) { long now = clock.millis(); String lastUpdated = new Date(now).toString(); logger.info(LogsCenter.getEventHandlingLogMessage(abce, "Setting last updated status to " + lastUpdated)); setSyncStatus(String.format(SYNC_STATUS_UPDATED, lastUpdated)); + setTotalPersons(abce.data.getPersonList().size()); } } diff --git a/src/main/resources/view/StatusBarFooter.fxml b/src/main/resources/view/StatusBarFooter.fxml index 041e1ff9004f..a449715511e4 100644 --- a/src/main/resources/view/StatusBarFooter.fxml +++ b/src/main/resources/view/StatusBarFooter.fxml @@ -10,5 +10,6 @@ - + + diff --git a/src/test/java/guitests/guihandles/StatusBarFooterHandle.java b/src/test/java/guitests/guihandles/StatusBarFooterHandle.java index 33c5d1d788b8..0a744047a9c9 100644 --- a/src/test/java/guitests/guihandles/StatusBarFooterHandle.java +++ b/src/test/java/guitests/guihandles/StatusBarFooterHandle.java @@ -11,18 +11,22 @@ public class StatusBarFooterHandle extends NodeHandle { public static final String STATUS_BAR_PLACEHOLDER = "#statusbarPlaceholder"; private static final String SYNC_STATUS_ID = "#syncStatus"; + private static final String TOTAL_PERSONS_STATUS_ID = "#totalPersonsStatus"; private static final String SAVE_LOCATION_STATUS_ID = "#saveLocationStatus"; private final StatusBar syncStatusNode; + private final StatusBar totalPersonsStatusNode; private final StatusBar saveLocationNode; private String lastRememberedSyncStatus; + private String lastRememberedTotalPersonsStatus; private String lastRememberedSaveLocation; public StatusBarFooterHandle(Node statusBarFooterNode) { super(statusBarFooterNode); syncStatusNode = getChildNode(SYNC_STATUS_ID); + totalPersonsStatusNode = getChildNode(TOTAL_PERSONS_STATUS_ID); saveLocationNode = getChildNode(SAVE_LOCATION_STATUS_ID); } @@ -33,6 +37,13 @@ public String getSyncStatus() { return syncStatusNode.getText(); } + /** + * Returns the text of the 'total persons' portion of the status bar. + */ + public String getTotalPersonsStatus() { + return totalPersonsStatusNode.getText(); + } + /** * Returns the text of the 'save location' portion of the status bar. */ @@ -55,6 +66,22 @@ public boolean isSyncStatusChanged() { return !lastRememberedSyncStatus.equals(getSyncStatus()); } + + /** + * Remembers the content of the 'total persons' portion of the status bar. + */ + public void rememberTotalPersonsStatus() { + lastRememberedTotalPersonsStatus = getTotalPersonsStatus(); + } + + /** + * Returns true if the current content of the 'total persons' is different from the value remembered by the most + * recent {@code rememberTotalPersonsStatus()} call. + */ + public boolean isTotalPersonsStatusChanged() { + return !lastRememberedTotalPersonsStatus.equals(getTotalPersonsStatus()); + } + /** * Remembers the content of the 'save location' portion of the status bar. */ diff --git a/src/test/java/seedu/address/ui/StatusBarFooterTest.java b/src/test/java/seedu/address/ui/StatusBarFooterTest.java index c7d21684a472..f8f29b058d4b 100644 --- a/src/test/java/seedu/address/ui/StatusBarFooterTest.java +++ b/src/test/java/seedu/address/ui/StatusBarFooterTest.java @@ -2,8 +2,10 @@ import static org.junit.Assert.assertEquals; import static seedu.address.testutil.EventsUtil.postNow; +import static seedu.address.testutil.TypicalPersons.ALICE; import static seedu.address.ui.StatusBarFooter.SYNC_STATUS_INITIAL; import static seedu.address.ui.StatusBarFooter.SYNC_STATUS_UPDATED; +import static seedu.address.ui.StatusBarFooter.TOTAL_PERSONS_STATUS; import java.nio.file.Path; import java.nio.file.Paths; @@ -19,14 +21,17 @@ import guitests.guihandles.StatusBarFooterHandle; import seedu.address.commons.events.model.AddressBookChangedEvent; -import seedu.address.model.AddressBook; +import seedu.address.testutil.AddressBookBuilder; public class StatusBarFooterTest extends GuiUnitTest { private static final Path STUB_SAVE_LOCATION = Paths.get("Stub"); private static final Path RELATIVE_PATH = Paths.get("."); - private static final AddressBookChangedEvent EVENT_STUB = new AddressBookChangedEvent(new AddressBook()); + private static final AddressBookChangedEvent EVENT_STUB = new AddressBookChangedEvent( + new AddressBookBuilder().withPerson(ALICE).build()); + + private static final int INITIAL_TOTAL_PERSONS = 0; private static final Clock originalClock = StatusBarFooter.getClock(); private static final Clock injectedClock = Clock.fixed(Instant.now(), ZoneId.systemDefault()); @@ -47,7 +52,7 @@ public static void tearDownAfterClass() { @Before public void setUp() { - StatusBarFooter statusBarFooter = new StatusBarFooter(STUB_SAVE_LOCATION); + StatusBarFooter statusBarFooter = new StatusBarFooter(STUB_SAVE_LOCATION, INITIAL_TOTAL_PERSONS); uiPartRule.setUiPart(statusBarFooter); statusBarFooterHandle = new StatusBarFooterHandle(statusBarFooter.getRoot()); @@ -56,21 +61,26 @@ public void setUp() { @Test public void display() { // initial state - assertStatusBarContent(RELATIVE_PATH.resolve(STUB_SAVE_LOCATION).toString(), SYNC_STATUS_INITIAL); + assertStatusBarContent(RELATIVE_PATH.resolve(STUB_SAVE_LOCATION).toString(), SYNC_STATUS_INITIAL, + String.format(TOTAL_PERSONS_STATUS, INITIAL_TOTAL_PERSONS)); // after address book is updated postNow(EVENT_STUB); assertStatusBarContent(RELATIVE_PATH.resolve(STUB_SAVE_LOCATION).toString(), - String.format(SYNC_STATUS_UPDATED, new Date(injectedClock.millis()).toString())); + String.format(SYNC_STATUS_UPDATED, new Date(injectedClock.millis()).toString()), + String.format(TOTAL_PERSONS_STATUS, EVENT_STUB.data.getPersonList().size())); } /** - * Asserts that the save location matches that of {@code expectedSaveLocation}, and the - * sync status matches that of {@code expectedSyncStatus}. + * Asserts that the save location matches that of {@code expectedSaveLocation}, the + * sync status matches that of {@code expectedSyncStatus}, and the total persons matches that of + * {@code expectedTotalPersonsStatus}. */ - private void assertStatusBarContent(String expectedSaveLocation, String expectedSyncStatus) { + private void assertStatusBarContent(String expectedSaveLocation, String expectedSyncStatus, + String expectedTotalPersonsStatus) { assertEquals(expectedSaveLocation, statusBarFooterHandle.getSaveLocation()); assertEquals(expectedSyncStatus, statusBarFooterHandle.getSyncStatus()); + assertEquals(expectedTotalPersonsStatus, statusBarFooterHandle.getTotalPersonsStatus()); guiRobot.pauseForHuman(); }