Skip to content
This repository has been archived by the owner on Mar 5, 2023. It is now read-only.

Commit

Permalink
StatusBarFooter: Show total persons
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yamgent committed Aug 18, 2018
1 parent 83699f1 commit 76d8e4e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/seedu/address/ui/StatusBarFooter.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class StatusBarFooter extends UiPart<Region> {
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.
*
Expand All @@ -41,13 +43,15 @@ public class StatusBarFooter extends UiPart<Region> {
@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);
}

Expand All @@ -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());
}
}
3 changes: 2 additions & 1 deletion src/main/resources/view/StatusBarFooter.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
<ColumnConstraints hgrow="SOMETIMES" minWidth="10" prefWidth="100" />
</columnConstraints>
<StatusBar styleClass="stack-pane" fx:id="syncStatus" />
<StatusBar styleClass="stack-pane" fx:id="saveLocationStatus" GridPane.columnIndex="1" nodeOrientation="RIGHT_TO_LEFT" />
<StatusBar styleClass="stack-pane" fx:id="totalPersonsStatus" GridPane.columnIndex="1" />
<StatusBar styleClass="stack-pane" fx:id="saveLocationStatus" GridPane.columnIndex="2" nodeOrientation="RIGHT_TO_LEFT" />
</GridPane>
27 changes: 27 additions & 0 deletions src/test/java/guitests/guihandles/StatusBarFooterHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@ public class StatusBarFooterHandle extends NodeHandle<Node> {
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);
}

Expand All @@ -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.
*/
Expand All @@ -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.
*/
Expand Down
26 changes: 18 additions & 8 deletions src/test/java/seedu/address/ui/StatusBarFooterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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();
}

Expand Down

0 comments on commit 76d8e4e

Please sign in to comment.