Skip to content

Commit

Permalink
Merge pull request AY2324S2-CS2103T-W13-4#39 from breezetall/adding-l…
Browse files Browse the repository at this point in the history
…ist-command

Adding list command
  • Loading branch information
nobodyishappy authored Mar 21, 2024
2 parents 7cf9ff9 + dcda260 commit e6f21bd
Show file tree
Hide file tree
Showing 18 changed files with 330 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.Person;
import seedu.address.model.task.Task;

/**
* API of the Logic component
Expand All @@ -33,6 +34,9 @@ public interface Logic {
/** Returns an unmodifiable view of the filtered list of persons */
ObservableList<Person> getFilteredPersonList();

/** Returns an unmodifiable view of the filtered list of tasks */
ObservableList<Task> getFilteredTaskList();

/**
* Returns the user prefs' address book file path.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.Person;
import seedu.address.model.task.Task;
import seedu.address.storage.Storage;

/**
Expand Down Expand Up @@ -72,6 +73,11 @@ public ObservableList<Person> getFilteredPersonList() {
return model.getFilteredPersonList();
}

@Override
public ObservableList<Task> getFilteredTaskList() {
return model.getFilteredTaskList();
}

@Override
public Path getAddressBookFilePath() {
return model.getAddressBookFilePath();
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/seedu/address/logic/commands/ListTaskCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_TASKS;

import seedu.address.model.Model;

/**
* Lists all tasks in the tasklist to the user.
*/
public class ListTaskCommand extends Command {

public static final String COMMAND_WORD = "listtask";

public static final String MESSAGE_SUCCESS = "Listed all tasks";


@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredTaskList(PREDICATE_SHOW_ALL_TASKS);
return new CommandResult(MESSAGE_SUCCESS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.ListTaskCommand;
import seedu.address.logic.parser.exceptions.ParseException;

/**
Expand Down Expand Up @@ -80,6 +81,9 @@ public Command parseCommand(String userInput) throws ParseException {
case ListCommand.COMMAND_WORD:
return new ListCommand();

case ListTaskCommand.COMMAND_WORD:
return new ListTaskCommand();

case AssignCommand.COMMAND_WORD:
return new AssignCommandParser().parse(arguments);

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public interface Model {
/** {@code Predicate} that always evaluate to true */
Predicate<Person> PREDICATE_SHOW_ALL_PERSONS = unused -> true;

/** {@code Predicate} that always evaluate to true */
Predicate<Task> PREDICATE_SHOW_ALL_TASKS = unused -> true;

/**
* Replaces user prefs data with the data in {@code userPrefs}.
*/
Expand Down Expand Up @@ -122,6 +125,15 @@ static void setTaskList(TaskList taskList) {}
*/
boolean hasTask(Task task);

/**
* Updates the filter of the filtered task list to filter by the given {@code predicate}.
* @throws NullPointerException if {@code predicate} is null.
*/
void updateFilteredTaskList(Predicate<Task> predicate);

/** Returns an unmodifiable view of the filtered task list */
ObservableList<Task> getFilteredTaskList();

/**
* Returns true if the {@code index} is within the task list.
*/
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ModelManager implements Model {
private final TaskList taskList;
private final UserPrefs userPrefs;
private final FilteredList<Person> filteredPersons;
private final FilteredList<Task> filteredTasks;

/**
* Initializes a ModelManager with the given addressBook and userPrefs.
Expand All @@ -38,6 +39,7 @@ public ModelManager(ReadOnlyAddressBook addressBook, TaskList taskList, ReadOnly
this.taskList = taskList;
this.userPrefs = new UserPrefs(userPrefs);
filteredPersons = new FilteredList<>(this.addressBook.getPersonList());
filteredTasks = new FilteredList<>(this.taskList.getSerializeTaskList());
}

public ModelManager() {
Expand Down Expand Up @@ -142,6 +144,7 @@ public void setPerson(Person target, Person editedPerson) {
@Override
public void addTask(Task task) {
taskList.addTask(task);
updateFilteredTaskList(PREDICATE_SHOW_ALL_TASKS);
}

@Override
Expand Down Expand Up @@ -183,6 +186,21 @@ public TaskList getTaskList() {
return taskList;
}

/**
* Returns an unmodifiable view of the list of {@code Task} backed by the internal list of
* {@code versionedAddressBook}
*/
@Override
public ObservableList<Task> getFilteredTaskList() {
return filteredTasks;
}

@Override
public void updateFilteredTaskList(Predicate<Task> predicate) {
requireNonNull(predicate);
filteredTasks.setPredicate(predicate);
}

// =========== Filtered Person List Accessors
// =============================================================

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/seedu/address/model/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
public class TaskList {
private ArrayList<Task> taskList;
private ObservableList<Task> observableList = FXCollections.observableArrayList();

/**
* Constructor of the class.
Expand All @@ -32,6 +33,7 @@ public TaskList(TaskList toBeCopied) {
}

public void setTaskList(TaskList tasks) {
observableList.setAll(tasks.observableList);
taskList = new ArrayList<>(tasks.getSerializeTaskList());
}

Expand All @@ -42,6 +44,7 @@ public void setTaskList(TaskList tasks) {
*/
public void addTask(Task task) {
taskList.add(task);
observableList.add(task);
}

/**
Expand All @@ -64,7 +67,7 @@ public void deleteTask(Task task) {
}

public ObservableList<Task> getSerializeTaskList() {
return FXCollections.unmodifiableObservableList(FXCollections.observableArrayList(taskList));
return observableList;
}

public boolean hasTask(Task task) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class MainWindow extends UiPart<Stage> {

// Independent Ui parts residing in this Ui container
private PersonListPanel personListPanel;
private TaskListPanel taskListPanel;
private ResultDisplay resultDisplay;
private HelpWindow helpWindow;

Expand All @@ -43,6 +44,8 @@ public class MainWindow extends UiPart<Stage> {

@FXML
private StackPane personListPanelPlaceholder;
@FXML
private StackPane taskListPanelPlaceholder;

@FXML
private StackPane resultDisplayPlaceholder;
Expand Down Expand Up @@ -110,6 +113,9 @@ private void setAccelerator(MenuItem menuItem, KeyCombination keyCombination) {
* Fills up all the placeholders of this window.
*/
void fillInnerParts() {
taskListPanel = new TaskListPanel(logic.getFilteredTaskList());
taskListPanelPlaceholder.getChildren().add(taskListPanel.getRoot());

personListPanel = new PersonListPanel(logic.getFilteredPersonList());
personListPanelPlaceholder.getChildren().add(personListPanel.getRoot());

Expand Down Expand Up @@ -167,6 +173,10 @@ public PersonListPanel getPersonListPanel() {
return personListPanel;
}

public TaskListPanel getTaskListPanel() {
return taskListPanel;
}

/**
* Executes the command and returns the result.
*
Expand Down
55 changes: 55 additions & 0 deletions src/main/java/seedu/address/ui/TaskCard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package seedu.address.ui;

import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import seedu.address.model.task.Task;

/**
* An UI component that displays information of a {@code Person}.
*/
public class TaskCard extends UiPart<Region> {

private static final String FXML = "TaskListCard.fxml";

/**
* Note: Certain keywords such as "location" and "resources" are reserved keywords in JavaFX.
* As a consequence, UI elements' variable names cannot be set to such keywords
* or an exception will be thrown by JavaFX during runtime.
*
* @see <a href="https://github.com/se-edu/addressbook-level4/issues/336">The issue on AddressBook level 4</a>
*/

public final Task task;

@FXML
private HBox cardPane;
@FXML
private Label name;
@FXML
private Label id;
@FXML
private Label mark;
@FXML
private Label description;

/*
@FXML
private Label email;
@FXML
private FlowPane tags;
*/

/**
* Creates a {@code TaskCode} with the given {@code Task} and index to display.
*/
public TaskCard(Task task, int displayedIndex) {
super(FXML);
this.task = task;
id.setText(displayedIndex + ". ");
//name.setText(task.getName().fullName);
//mark.setText(task.getMark().value);
description.setText(task.getDescription());
}
}
49 changes: 49 additions & 0 deletions src/main/java/seedu/address/ui/TaskListPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package seedu.address.ui;

import java.util.logging.Logger;

import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.layout.Region;
import seedu.address.commons.core.LogsCenter;
import seedu.address.model.task.Task;

/**
* Panel containing the list of persons.
*/
public class TaskListPanel extends UiPart<Region> {
private static final String FXML = "TaskListPanel.fxml";
private final Logger logger = LogsCenter.getLogger(TaskListPanel.class);

@FXML
private ListView<Task> taskListView;

/**
* Creates a {@code PersonListPanel} with the given {@code ObservableList}.
*/
public TaskListPanel(ObservableList<Task> taskList) {
super(FXML);
taskListView.setItems(taskList);
taskListView.setCellFactory(listView -> new TaskListViewCell());
}

/**
* Custom {@code ListCell} that displays the graphics of a {@code Person} using a {@code PersonCard}.
*/
class TaskListViewCell extends ListCell<Task> {
@Override
protected void updateItem(Task task, boolean empty) {
super.updateItem(task, empty);

if (empty || task == null) {
setGraphic(null);
setText(null);
} else {
setGraphic(new TaskCard(task, getIndex() + 1).getRoot());
}
}
}

}
39 changes: 25 additions & 14 deletions src/main/resources/view/MainWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.stage.Stage?>

<fx:root type="javafx.stage.Stage" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1"
title="Address App" minWidth="450" minHeight="600" onCloseRequest="#handleExit">
<fx:root minHeight="600" minWidth="450" onCloseRequest="#handleExit" title="Address App" type="javafx.stage.Stage" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1">
<icons>
<Image url="@/images/address_book_32.png" />
</icons>
Expand All @@ -33,25 +33,36 @@
</Menu>
</MenuBar>

<StackPane VBox.vgrow="NEVER" fx:id="commandBoxPlaceholder" styleClass="pane-with-border">
<StackPane fx:id="commandBoxPlaceholder" styleClass="pane-with-border" VBox.vgrow="NEVER">
<padding>
<Insets top="5" right="10" bottom="5" left="10" />
<Insets bottom="5" left="10" right="10" top="5" />
</padding>
</StackPane>

<StackPane VBox.vgrow="NEVER" fx:id="resultDisplayPlaceholder" styleClass="pane-with-border"
minHeight="100" prefHeight="100" maxHeight="100">
<StackPane fx:id="resultDisplayPlaceholder" maxHeight="100" minHeight="100" prefHeight="100" styleClass="pane-with-border" VBox.vgrow="NEVER">
<padding>
<Insets top="5" right="10" bottom="5" left="10" />
<Insets bottom="5" left="10" right="10" top="5" />
</padding>
</StackPane>
<HBox prefWidth="200.0">
<children>

<VBox fx:id="personList" styleClass="pane-with-border" minWidth="340" prefWidth="340" VBox.vgrow="ALWAYS">
<padding>
<Insets top="10" right="10" bottom="10" left="10" />
</padding>
<StackPane fx:id="personListPanelPlaceholder" VBox.vgrow="ALWAYS"/>
</VBox>
<VBox fx:id="personList" minWidth="340" prefWidth="600.0" styleClass="pane-with-border">
<padding>
<Insets bottom="10" left="10" right="10" top="10" />
</padding>
<StackPane fx:id="personListPanelPlaceholder" VBox.vgrow="ALWAYS" />
</VBox>


<VBox fx:id="taskList" minWidth="340" prefWidth="340.0" styleClass="pane-with-border">
<padding>
<Insets bottom="10" left="10" right="10" top="10" />
</padding>
<StackPane fx:id="taskListPanelPlaceholder" VBox.vgrow="ALWAYS" />
</VBox>
</children>
</HBox>

<StackPane fx:id="statusbarPlaceholder" VBox.vgrow="NEVER" />
</VBox>
Expand Down
Loading

0 comments on commit e6f21bd

Please sign in to comment.