From 20af245763f60b4baccd035fa324632226a2c656 Mon Sep 17 00:00:00 2001 From: LiuXuanIan Date: Mon, 1 Apr 2019 22:27:03 +0800 Subject: [PATCH 01/13] Dispaly WorkList. --- .../java/seedu/equipment/logic/Logic.java | 19 +++ .../seedu/equipment/logic/LogicManager.java | 16 ++ .../equipment/model/EquipmentManager.java | 1 + .../java/seedu/equipment/model/Model.java | 23 +++ .../seedu/equipment/model/ModelManager.java | 27 ++- .../model/ReadOnlyEquipmentManager.java | 6 + .../equipment/model/UniqueWorkListList.java | 3 +- .../seedu/equipment/model/WorkListId.java | 1 + .../DuplicateEquipmentException.java | 6 +- .../equipment/ui/EquipmentListPanel.java | 1 + .../java/seedu/equipment/ui/MainWindow.java | 12 ++ .../java/seedu/equipment/ui/WorkListCard.java | 72 ++++++++ .../seedu/equipment/ui/WorkListListPanel.java | 74 ++++++++ src/main/resources/view/MainWindow.fxml | 9 +- src/main/resources/view/WorkListListCard.fxml | 35 ++++ .../resources/view/WorkListListPanel.fxml | 8 + .../guihandles/WorkListCardHandle.java | 89 ++++++++++ .../guihandles/WorkListListPanelHandle.java | 159 ++++++++++++++++++ .../logic/commands/AddCommandTest.java | 23 +++ .../commands/AddWorkListCommandTest.java | 21 +++ .../equipment/model/EquipmentManagerTest.java | 6 + .../equipment/model/ModelManagerTest.java | 14 +- .../equipment/testutil/TypicalIndexes.java | 3 + .../equipment/testutil/TypicalWorkLists.java | 10 +- .../seedu/equipment/ui/WorkListCardTest.java | 72 ++++++++ .../seedu/equipment/ui/WorkListPanelTest.java | 97 +++++++++++ .../equipment/ui/testutil/GuiTestAssert.java | 34 ++++ 27 files changed, 830 insertions(+), 11 deletions(-) create mode 100644 src/main/java/seedu/equipment/ui/WorkListCard.java create mode 100644 src/main/java/seedu/equipment/ui/WorkListListPanel.java create mode 100644 src/main/resources/view/WorkListListCard.fxml create mode 100644 src/main/resources/view/WorkListListPanel.fxml create mode 100644 src/test/java/guitests/guihandles/WorkListCardHandle.java create mode 100644 src/test/java/guitests/guihandles/WorkListListPanelHandle.java create mode 100644 src/test/java/seedu/equipment/ui/WorkListCardTest.java create mode 100644 src/test/java/seedu/equipment/ui/WorkListPanelTest.java diff --git a/src/main/java/seedu/equipment/logic/Logic.java b/src/main/java/seedu/equipment/logic/Logic.java index 2a5bad16197c..ee31532194c8 100644 --- a/src/main/java/seedu/equipment/logic/Logic.java +++ b/src/main/java/seedu/equipment/logic/Logic.java @@ -10,6 +10,7 @@ import seedu.equipment.logic.parser.exceptions.ParseException; import seedu.equipment.model.Model; import seedu.equipment.model.ReadOnlyEquipmentManager; +import seedu.equipment.model.WorkList; import seedu.equipment.model.equipment.Equipment; /** @@ -35,6 +36,9 @@ public interface Logic { /** Returns an unmodifiable view of the filtered list of persons */ ObservableList getFilteredPersonList(); + /** Returns an unmodifiable view of the filtered list of WorkLists */ + ObservableList getFilteredWorkListList(); + /** * Returns an unmodifiable view of the list of commands entered by the user. * The list is ordered from the least recent command to the most recent command. @@ -64,10 +68,25 @@ public interface Logic { */ ReadOnlyProperty selectedEquipmentProperty(); + /** + * Selected WorkList in the filtered WorkList list. + * null if no WorkList is selected. + * + * @see Model#selectedWorkListProperty() + */ + ReadOnlyProperty selectedWorkListProperty(); + /** * Sets the selected equipment in the filtered equipment list. * * @see Model#setSelectedEquipment(Equipment) */ void setSelectedPerson(Equipment equipment); + + /** + * Sets the selected WorkList in the filtered WorkList list. + * + * @see Model#setSelectedWorkList(WorkList) + */ + void setSelectedWorkList(WorkList workList); } diff --git a/src/main/java/seedu/equipment/logic/LogicManager.java b/src/main/java/seedu/equipment/logic/LogicManager.java index cc0c979bd3d0..7babf6ec37bc 100644 --- a/src/main/java/seedu/equipment/logic/LogicManager.java +++ b/src/main/java/seedu/equipment/logic/LogicManager.java @@ -15,6 +15,7 @@ import seedu.equipment.logic.parser.exceptions.ParseException; import seedu.equipment.model.Model; import seedu.equipment.model.ReadOnlyEquipmentManager; +import seedu.equipment.model.WorkList; import seedu.equipment.model.equipment.Equipment; import seedu.equipment.storage.Storage; @@ -76,6 +77,11 @@ public ObservableList getFilteredPersonList() { return model.getFilteredPersonList(); } + @Override + public ObservableList getFilteredWorkListList() { + return model.getFilteredWorkListList(); + } + @Override public ObservableList getHistory() { return history.getHistory(); @@ -101,8 +107,18 @@ public ReadOnlyProperty selectedEquipmentProperty() { return model.selectedEquipmentProperty(); } + @Override + public ReadOnlyProperty selectedWorkListProperty() { + return model.selectedWorkListProperty(); + } + @Override public void setSelectedPerson(Equipment equipment) { model.setSelectedEquipment(equipment); } + + @Override + public void setSelectedWorkList(WorkList workList) { + model.setSelectedWorkList(workList); + } } diff --git a/src/main/java/seedu/equipment/model/EquipmentManager.java b/src/main/java/seedu/equipment/model/EquipmentManager.java index c57011463d04..d5e2a4e469cd 100644 --- a/src/main/java/seedu/equipment/model/EquipmentManager.java +++ b/src/main/java/seedu/equipment/model/EquipmentManager.java @@ -199,6 +199,7 @@ public ObservableList getPersonList() { return equipment.asUnmodifiableObservableList(); } + @Override public ObservableList getWorkListList() { return worklist.asUnmodifiableObservableList(); } diff --git a/src/main/java/seedu/equipment/model/Model.java b/src/main/java/seedu/equipment/model/Model.java index 8fe94eea154f..61920c885ef1 100644 --- a/src/main/java/seedu/equipment/model/Model.java +++ b/src/main/java/seedu/equipment/model/Model.java @@ -76,6 +76,12 @@ public interface Model { */ void deleteEquipment(Equipment target); + /** + * Deletes the given WorkList. + * The WorkList must exist in the Equipment Manager. + */ + void deleteWorkList(WorkList target); + /** * Adds the given equipment. * {@code equipment} must not already exist in the equipment manager. @@ -145,17 +151,34 @@ public interface Model { */ ReadOnlyProperty selectedEquipmentProperty(); + /** + * Selected WorkList in the filtered WorkList list. + * null if no WorkList is selected. + */ + ReadOnlyProperty selectedWorkListProperty(); + /** * Returns the selected equipment in the filtered equipment list. * null if no equipment is selected. */ Equipment getSelectedEquipment(); + /** + * Returns the selected WorkList in the filtered WorkList list. + * null if no WorkList is selected. + */ + WorkList getSelectedWorkList(); + /** * Sets the selected equipment in the filtered equipment list. */ void setSelectedEquipment(Equipment equipment); + /** + * Sets the selected WorkList in the filtered WorkList list. + */ + void setSelectedWorkList(WorkList workList); + /** Removes the given {@code tag} from all {@code Equipment}s. */ void deleteTag(Tag tag); diff --git a/src/main/java/seedu/equipment/model/ModelManager.java b/src/main/java/seedu/equipment/model/ModelManager.java index ae2b3b519267..d27bb746d45a 100644 --- a/src/main/java/seedu/equipment/model/ModelManager.java +++ b/src/main/java/seedu/equipment/model/ModelManager.java @@ -30,6 +30,7 @@ public class ModelManager implements Model { private final FilteredList filteredEquipments; private final FilteredList filteredWorkList; private final SimpleObjectProperty selectedEquipment = new SimpleObjectProperty<>(); + private final SimpleObjectProperty selectedWorkList = new SimpleObjectProperty<>(); /** * Initializes a ModelManager with the given equipmentManager and userPrefs. @@ -116,6 +117,11 @@ public void deleteEquipment(Equipment target) { versionedEquipmentManager.removePerson(target); } + @Override + public void deleteWorkList(WorkList target) { + versionedEquipmentManager.removeWorkList(target); + } + @Override public void addEquipment(Equipment equipment) { versionedEquipmentManager.addPerson(equipment); @@ -206,6 +212,26 @@ public void commitEquipmentManager() { versionedEquipmentManager.commit(); } + //=========== Selected WorkList =========================================================================== + + @Override + public ReadOnlyProperty selectedWorkListProperty() { + return selectedWorkList; + } + + @Override + public WorkList getSelectedWorkList() { + return selectedWorkList.getValue(); + } + + @Override + public void setSelectedWorkList(WorkList workList) { + if (workList != null && !filteredWorkList.contains(workList)) { + throw new EquipmentNotFoundException(); + } + selectedWorkList.setValue(workList); + } + //=========== Selected equipment =========================================================================== @Override @@ -260,7 +286,6 @@ private void ensureSelectedPersonIsValid(ListChangeListener.Change getPersonList(); + /** + * Returns an unmodifiable view of the WorkList list. + * This list will not contain any duplicate WorkLists. + */ + ObservableList getWorkListList(); + } diff --git a/src/main/java/seedu/equipment/model/UniqueWorkListList.java b/src/main/java/seedu/equipment/model/UniqueWorkListList.java index 6f32b5b6cde6..25bfa3e17dc2 100644 --- a/src/main/java/seedu/equipment/model/UniqueWorkListList.java +++ b/src/main/java/seedu/equipment/model/UniqueWorkListList.java @@ -82,7 +82,8 @@ public boolean areWorkListUnique(List workListList) { * Returns the backing list as an unmodifiable {@code ObservableList}. */ public ObservableList asUnmodifiableObservableList() { - return internalUnmodifiableList; + internalList.add(new WorkList("12 May 2019", "Mei Yen")); + return FXCollections.unmodifiableObservableList(internalList); } @Override diff --git a/src/main/java/seedu/equipment/model/WorkListId.java b/src/main/java/seedu/equipment/model/WorkListId.java index cbb11c4081a1..09deefa25fcf 100644 --- a/src/main/java/seedu/equipment/model/WorkListId.java +++ b/src/main/java/seedu/equipment/model/WorkListId.java @@ -14,6 +14,7 @@ public class WorkListId { */ public WorkListId() { thisId = idHist + 1; + idHist++; } public int getId() { diff --git a/src/main/java/seedu/equipment/model/equipment/exceptions/DuplicateEquipmentException.java b/src/main/java/seedu/equipment/model/equipment/exceptions/DuplicateEquipmentException.java index 9e5452c37a01..2230ed76279a 100644 --- a/src/main/java/seedu/equipment/model/equipment/exceptions/DuplicateEquipmentException.java +++ b/src/main/java/seedu/equipment/model/equipment/exceptions/DuplicateEquipmentException.java @@ -1,11 +1,11 @@ package seedu.equipment.model.equipment.exceptions; /** - * Signals that the operation will result in duplicate Persons (Persons are considered duplicates if they have the same - * identity). + * Signals that the operation will result in duplicate Equipments (Equipments are considered duplicates + * if they have the same identity). */ public class DuplicateEquipmentException extends RuntimeException { public DuplicateEquipmentException() { - super("Operation would result in duplicate persons"); + super("Operation would result in duplicate equipments"); } } diff --git a/src/main/java/seedu/equipment/ui/EquipmentListPanel.java b/src/main/java/seedu/equipment/ui/EquipmentListPanel.java index be2520ba9294..c99d812a3951 100644 --- a/src/main/java/seedu/equipment/ui/EquipmentListPanel.java +++ b/src/main/java/seedu/equipment/ui/EquipmentListPanel.java @@ -26,6 +26,7 @@ public class EquipmentListPanel extends UiPart { public EquipmentListPanel(ObservableList equipmentList, ObservableValue selectedPerson, Consumer onSelectedPersonChange) { super(FXML); + //System.out.println(personListView.getEditingIndex()); personListView.setItems(equipmentList); personListView.setCellFactory(listView -> new PersonListViewCell()); personListView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { diff --git a/src/main/java/seedu/equipment/ui/MainWindow.java b/src/main/java/seedu/equipment/ui/MainWindow.java index 32b3234b7ee9..82952e5bfc77 100644 --- a/src/main/java/seedu/equipment/ui/MainWindow.java +++ b/src/main/java/seedu/equipment/ui/MainWindow.java @@ -35,6 +35,7 @@ public class MainWindow extends UiPart { // Independent Ui parts residing in this Ui container private BrowserPanel browserPanel; private EquipmentListPanel equipmentListPanel; + private WorkListListPanel workListListPanel; private ResultDisplay resultDisplay; private HelpWindow helpWindow; @@ -49,6 +50,9 @@ public class MainWindow extends UiPart { @FXML private StackPane personListPanelPlaceholder; + + @FXML + private StackPane workListPanelPlaceholder; @FXML private StackPane resultDisplayPlaceholder; @@ -120,6 +124,10 @@ void fillInnerParts() { logic::setSelectedPerson); personListPanelPlaceholder.getChildren().add(equipmentListPanel.getRoot()); + workListListPanel = new WorkListListPanel(logic.getFilteredWorkListList(), logic.selectedWorkListProperty(), + logic::setSelectedWorkList); + workListPanelPlaceholder.getChildren().add(workListListPanel.getRoot()); + resultDisplay = new ResultDisplay(); resultDisplayPlaceholder.getChildren().add(resultDisplay.getRoot()); @@ -193,6 +201,10 @@ public EquipmentListPanel getEquipmentListPanel() { return equipmentListPanel; } + public WorkListListPanel getWorkListListPanel() { + return workListListPanel; + } + /** * Executes the command and returns the result. * diff --git a/src/main/java/seedu/equipment/ui/WorkListCard.java b/src/main/java/seedu/equipment/ui/WorkListCard.java new file mode 100644 index 000000000000..bd2de81e096b --- /dev/null +++ b/src/main/java/seedu/equipment/ui/WorkListCard.java @@ -0,0 +1,72 @@ +package seedu.equipment.ui; + +import javafx.fxml.FXML; +import javafx.scene.control.Label; +import javafx.scene.layout.FlowPane; +import javafx.scene.layout.HBox; +import javafx.scene.layout.Region; +import seedu.equipment.model.WorkList; + +/** + * An UI component that displays information of a {@code WorkList}. + */ +public class WorkListCard extends UiPart { + + private static final String FXML = "WorkListListCard.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 The issue on EquipmentManager + */ + + public final WorkList workList; + + @FXML + private HBox cardPane; + @FXML + private Label id; + @FXML + private Label date; + @FXML + private Label worklistid; + @FXML + private Label assignee; + @FXML + private FlowPane equipments; + + public WorkListCard(WorkList workList, int displayedIndex) { + super(FXML); + this.workList = workList; + id.setText(displayedIndex + ". "); + assignee.setText(workList.getAssignee()); + date.setText(workList.getDate()); + worklistid.setText(String.valueOf(workList.getId().getId())); + workList.getEquipments().forEach(equipment -> { + String equipmentName = equipment.getName().name; + equipments.getChildren().add(new Label(equipmentName)); + }); + } + + @Override + public boolean equals(Object other) { + // short circuit if same object + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof WorkListCard)) { + return false; + } + + // state check + WorkListCard card = (WorkListCard) other; + return id.getText().equals(card.id.getText()) + && workList.equals(card.workList); + } +} diff --git a/src/main/java/seedu/equipment/ui/WorkListListPanel.java b/src/main/java/seedu/equipment/ui/WorkListListPanel.java new file mode 100644 index 000000000000..b2217f94414a --- /dev/null +++ b/src/main/java/seedu/equipment/ui/WorkListListPanel.java @@ -0,0 +1,74 @@ +package seedu.equipment.ui; + +import java.util.Objects; +import java.util.function.Consumer; +import java.util.logging.Logger; + +import javafx.beans.value.ObservableValue; +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.equipment.commons.core.LogsCenter; +import seedu.equipment.model.WorkList; + +/** + * Panel containing the list of WorkLists. + */ +public class WorkListListPanel extends UiPart { + private static final String FXML = "WorkListListPanel.fxml"; + private final Logger logger = LogsCenter.getLogger(WorkListListPanel.class); + + @FXML + private ListView workListListView; + + public WorkListListPanel(ObservableList workListList, ObservableValue selectedPerson, + Consumer onselectedWorkListChange) { + super(FXML); + if(workListListView == null) { + System.out.println("NULL!!!!!"); + } + workListListView.setItems(workListList); + workListListView.setCellFactory(listView -> new workListListViewCell()); + workListListView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { + logger.fine("Selection in WorkList list panel changed to : '" + newValue + "'"); + onselectedWorkListChange.accept(newValue); + }); + selectedPerson.addListener((observable, oldValue, newValue) -> { + logger.fine("Selected WorkList changed to: " + newValue); + + // Don't modify selection if we are already selecting the selected WorkLists, + // otherwise we would have an infinite loop. + if (Objects.equals(workListListView.getSelectionModel().getSelectedItem(), newValue)) { + return; + } + + if (newValue == null) { + workListListView.getSelectionModel().clearSelection(); + } else { + int index = workListListView.getItems().indexOf(newValue); + workListListView.scrollTo(index); + workListListView.getSelectionModel().clearAndSelect(index); + } + }); + } + + /** + * Custom {@code ListCell} that displays the graphics of a {@code WorkList} using a {@code WorkListCard}. + */ + class workListListViewCell extends ListCell { + @Override + protected void updateItem(WorkList workList, boolean empty) { + super.updateItem(workList, empty); + + if (empty || workList == null) { + setGraphic(null); + setText(null); + } else { + setGraphic(new WorkListCard(workList, getIndex() + 1).getRoot()); + } + } + } + +} diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml index 0249e85146ec..245910e935c6 100644 --- a/src/main/resources/view/MainWindow.fxml +++ b/src/main/resources/view/MainWindow.fxml @@ -12,7 +12,7 @@ + title="Address App" minWidth="900" minHeight="600" onCloseRequest="#handleExit"> @@ -54,6 +54,13 @@ + + + + + + + diff --git a/src/main/resources/view/WorkListListCard.fxml b/src/main/resources/view/WorkListListCard.fxml new file mode 100644 index 000000000000..5b9c04063bb7 --- /dev/null +++ b/src/main/resources/view/WorkListListCard.fxml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/view/WorkListListPanel.fxml b/src/main/resources/view/WorkListListPanel.fxml new file mode 100644 index 000000000000..558685a39b60 --- /dev/null +++ b/src/main/resources/view/WorkListListPanel.fxml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/test/java/guitests/guihandles/WorkListCardHandle.java b/src/test/java/guitests/guihandles/WorkListCardHandle.java new file mode 100644 index 000000000000..c5fe43fdae70 --- /dev/null +++ b/src/test/java/guitests/guihandles/WorkListCardHandle.java @@ -0,0 +1,89 @@ +package guitests.guihandles; + +import java.util.List; +import java.util.stream.Collectors; + +import com.google.common.collect.ImmutableMultiset; + +import javafx.scene.Node; +import javafx.scene.control.Label; +import javafx.scene.layout.Region; +import seedu.equipment.model.WorkList; + +/** + * Provides a handle to a WorkList card in the WorkList list panel. + */ +public class WorkListCardHandle extends NodeHandle { + private static final String ID_FIELD_ID = "#id"; + private static final String ASSIGNEE_FIELD_ID = "#assignee"; + private static final String WORKLISTID_FIELD_ID = "#worklistid"; + private static final String DATE_FIELD_ID = "#date"; + private static final String EQUIPMENTSS_FIELD_ID = "#equipments"; + + private final Label idLabel; + private final Label assigneeLabel; + private final Label worklistidLabel; + private final Label dateLabel; + private final List