Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UI for searchmode #165

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.nio.file.Path;

import javafx.beans.property.BooleanProperty;
import javafx.collections.ObservableList;
import seedu.address.commons.core.GuiSettings;
import seedu.address.logic.commands.CommandResult;
Expand Down Expand Up @@ -51,4 +52,14 @@ public interface Logic {
* Set the user prefs' GUI settings.
*/
void setGuiSettings(GuiSettings guiSettings);

/**
* Returns the search mode status.
*/
BooleanProperty getSearchMode();

/**
* Get all persons in the address book.
*/
ObservableList<Person> getAllPersons();
}
16 changes: 16 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.nio.file.Path;
import java.util.logging.Logger;

import javafx.beans.property.BooleanProperty;
import javafx.collections.ObservableList;
import seedu.address.commons.core.GuiSettings;
import seedu.address.commons.core.LogsCenter;
Expand Down Expand Up @@ -105,4 +106,19 @@ public GuiSettings getGuiSettings() {
public void setGuiSettings(GuiSettings guiSettings) {
model.setGuiSettings(guiSettings);
}

/**
* Returns the search mode status.
*/
public BooleanProperty getSearchMode() {
return model.searchModeProperty();

}

/**
* Get all persons in the address book.
*/
public ObservableList<Person> getAllPersons() {
return model.getAllPersons();
}
}
7 changes: 7 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.nio.file.Path;
import java.util.function.Predicate;

import javafx.beans.property.BooleanProperty;
import javafx.collections.ObservableList;
import seedu.address.commons.core.GuiSettings;
import seedu.address.model.event.EventManager;
Expand Down Expand Up @@ -121,4 +122,10 @@ public interface Model {
*/
Predicate<Person> getLastPredicate();

/**
* Get all persons in the address book.
*/
ObservableList<Person> getAllPersons();

BooleanProperty searchModeProperty();
}
18 changes: 15 additions & 3 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.function.Predicate;
import java.util.logging.Logger;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import seedu.address.commons.core.GuiSettings;
Expand All @@ -26,7 +28,7 @@ public class ModelManager implements Model {
private final EventManager eventManager;
private final FilteredList<Person> filteredPersons;

private boolean searchMode = false;
private BooleanProperty searchMode = new SimpleBooleanProperty(false);
private Predicate<Person> lastPredicate = PREDICATE_SHOW_ALL_PERSONS;

/**
Expand Down Expand Up @@ -169,16 +171,22 @@ public Predicate<Person> getLastPredicate() {
* Checks the search mode of the model.
*/
public boolean getSearchMode() {
return searchMode;
return searchMode.get();
}

/**
* Sets the search mode of the model.
*/
public void setSearchMode(boolean searchMode) {
this.searchMode = searchMode;
this.searchMode.set(searchMode);
}

/**
* Returns the search mode object.
*/
public BooleanProperty searchModeProperty() {
return searchMode;
}
@Override
public boolean equals(Object other) {
if (other == this) {
Expand All @@ -198,5 +206,9 @@ public boolean equals(Object other) {
}


@Override
public ObservableList<Person> getAllPersons() {
return addressBook.getPersonList();
}

}
34 changes: 32 additions & 2 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import javafx.scene.control.TextInputControl;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import seedu.address.commons.core.GuiSettings;
Expand All @@ -32,6 +34,7 @@ public class MainWindow extends UiPart<Stage> {

// Independent Ui parts residing in this Ui container
private PersonListPanel personListPanel;
private PersonListPanel allPersonListPanel;
private EventListPanel eventListPanel;
private ResultDisplay resultDisplay;
private HelpWindow helpWindow;
Expand Down Expand Up @@ -69,6 +72,28 @@ public MainWindow(Stage primaryStage, Logic logic) {
setAccelerators();

helpWindow = new HelpWindow();
logic.getSearchMode().addListener((observable, oldValue, newValue) -> updateUiBasedOnSearchMode(newValue));

}

private void updateUiBasedOnSearchMode(boolean isSearchMode) {
HBox hbox = new HBox();
HBox.setHgrow(hbox, Priority.ALWAYS);
hbox.setPrefWidth(personListPanelPlaceholder.getWidth());
hbox.setPrefHeight(personListPanelPlaceholder.getHeight());

personListPanel = new PersonListPanel(logic.getFilteredPersonList());
HBox.setHgrow(personListPanel.getRoot(), Priority.ALWAYS);
hbox.getChildren().add(personListPanel.getRoot());

if (isSearchMode) {
allPersonListPanel = new PersonListPanel(logic.getAllPersons());
HBox.setHgrow(allPersonListPanel.getRoot(), Priority.ALWAYS);
hbox.getChildren().add(allPersonListPanel.getRoot());
}

personListPanelPlaceholder.getChildren().clear();
personListPanelPlaceholder.getChildren().add(hbox);
}

public Stage getPrimaryStage() {
Expand Down Expand Up @@ -113,8 +138,13 @@ private void setAccelerator(MenuItem menuItem, KeyCombination keyCombination) {
* Fills up all the placeholders of this window.
*/
void fillInnerParts() {
personListPanel = new PersonListPanel(logic.getFilteredPersonList());
personListPanelPlaceholder.getChildren().add(personListPanel.getRoot());
updateUiBasedOnSearchMode(logic.getSearchMode().get());
// personListPanel = new PersonListPanel(logic.getFilteredPersonList());
// personListPanelPlaceholder.getChildren().add(personListPanel.getRoot());
// if (logic.getSearchMode()) {
// allPersonListPanel = new PersonListPanel(logic.getAllPersons());
// personListPanelPlaceholder.getChildren().add(allPersonListPanel.getRoot());
// }

eventListPanel = new EventListPanel(logic.getFilteredEventList());
eventListPanelPlaceholder.getChildren().add(eventListPanel.getRoot());
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/seedu/address/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ public void getFilteredPersonList_modifyList_throwsUnsupportedOperationException
assertThrows(UnsupportedOperationException.class, () -> logic.getFilteredPersonList().remove(0));
}

@Test
public void getSearchMode() {
assertEquals(false, logic.getSearchMode().get());
}

@Test
public void getAllPersons() {
assertEquals(model.getAddressBook().getPersonList(), logic.getAllPersons());
}


/**
* Executes the command and confirms that
* - no exceptions are thrown <br>
Expand Down Expand Up @@ -181,4 +192,6 @@ public void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath)
expectedModel.addPerson(expectedPerson);
assertCommandFailure(addCommand, CommandException.class, expectedMessage, expectedModel);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.junit.jupiter.api.Test;

import javafx.beans.property.BooleanProperty;
import javafx.collections.ObservableList;
import seedu.address.commons.core.GuiSettings;
import seedu.address.logic.Messages;
Expand Down Expand Up @@ -193,6 +194,19 @@ public boolean getSearchMode() {
public Predicate<Person> getLastPredicate() {
throw new AssertionError("This method should not be called.");
}



@Override
public ObservableList<Person> getAllPersons() {
throw new AssertionError("This method should not be called.");
}

@Override
public BooleanProperty searchModeProperty() {
throw new AssertionError("This method should not be called.");
}

}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/seedu/address/model/ModelManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ public void getFilteredPersonList_modifyList_throwsUnsupportedOperationException
assertThrows(UnsupportedOperationException.class, () -> modelManager.getFilteredPersonList().remove(0));
}

@Test
public void searchModeProperty() {
assertEquals(false, modelManager.searchModeProperty().get());
}

@Test
public void getAllPersons() {
assertEquals(modelManager.getAddressBook().getPersonList(), modelManager.getAllPersons());
}

@Test
public void equals() {
AddressBook addressBook = new AddressBookBuilder().withPerson(ALICE).withPerson(BENSON).build();
Expand Down