From 62d5680ac7ec530fa71fd7613bfb681cb7826b1d Mon Sep 17 00:00:00 2001 From: Procrastinatus Date: Mon, 23 Oct 2017 22:01:20 +0800 Subject: [PATCH 1/8] Added "Schedule" (Model + Logic + UI + Storage) --- .../SchedulePanelSelectionChangedEvent.java | 25 +++ src/main/java/seedu/address/logic/Logic.java | 4 + .../seedu/address/logic/LogicManager.java | 6 + .../java/seedu/address/model/AddressBook.java | 38 ++++ src/main/java/seedu/address/model/Model.java | 20 +++ .../seedu/address/model/ModelManager.java | 28 +++ .../address/model/ReadOnlyAddressBook.java | 7 + .../model/schedule/ReadOnlySchedule.java | 37 ++++ .../address/model/schedule/Schedule.java | 92 ++++++++++ .../address/model/schedule/ScheduleName.java | 63 +++++++ .../model/schedule/UniqueScheduleList.java | 165 ++++++++++++++++++ .../DuplicateScheduleException.java | 12 ++ .../exceptions/NoSchedulesException.java | 6 + .../exceptions/ScheduleNotFoundException.java | 6 + .../address/storage/XmlAdaptedSchedule.java | 47 +++++ .../storage/XmlSerializableAddressBook.java | 18 ++ .../java/seedu/address/ui/BrowserPanel.java | 57 ++++-- .../java/seedu/address/ui/MainWindow.java | 11 +- .../java/seedu/address/ui/ScheduleCard.java | 64 +++++++ .../seedu/address/ui/ScheduleListPanel.java | 90 ++++++++++ src/main/resources/view/BrowserPanel.fxml | 5 +- src/main/resources/view/ScheduleListCard.fxml | 37 ++++ .../resources/view/ScheduleListPanel.fxml | 10 ++ .../logic/commands/AddCommandTest.java | 23 +++ .../seedu/address/model/AddressBookTest.java | 7 + 25 files changed, 861 insertions(+), 17 deletions(-) create mode 100644 src/main/java/seedu/address/commons/events/ui/SchedulePanelSelectionChangedEvent.java create mode 100644 src/main/java/seedu/address/model/schedule/ReadOnlySchedule.java create mode 100644 src/main/java/seedu/address/model/schedule/Schedule.java create mode 100644 src/main/java/seedu/address/model/schedule/ScheduleName.java create mode 100644 src/main/java/seedu/address/model/schedule/UniqueScheduleList.java create mode 100644 src/main/java/seedu/address/model/schedule/exceptions/DuplicateScheduleException.java create mode 100644 src/main/java/seedu/address/model/schedule/exceptions/NoSchedulesException.java create mode 100644 src/main/java/seedu/address/model/schedule/exceptions/ScheduleNotFoundException.java create mode 100644 src/main/java/seedu/address/storage/XmlAdaptedSchedule.java create mode 100644 src/main/java/seedu/address/ui/ScheduleCard.java create mode 100644 src/main/java/seedu/address/ui/ScheduleListPanel.java create mode 100644 src/main/resources/view/ScheduleListCard.fxml create mode 100644 src/main/resources/view/ScheduleListPanel.fxml diff --git a/src/main/java/seedu/address/commons/events/ui/SchedulePanelSelectionChangedEvent.java b/src/main/java/seedu/address/commons/events/ui/SchedulePanelSelectionChangedEvent.java new file mode 100644 index 000000000000..1e05e7a99a17 --- /dev/null +++ b/src/main/java/seedu/address/commons/events/ui/SchedulePanelSelectionChangedEvent.java @@ -0,0 +1,25 @@ +package seedu.address.commons.events.ui; + +import seedu.address.commons.events.BaseEvent; +import seedu.address.ui.ScheduleCard; + +/** + * Represents a selection change in the Person List Panel + */ +public class SchedulePanelSelectionChangedEvent extends BaseEvent { + + private final ScheduleCard newSelection; + + public SchedulePanelSelectionChangedEvent(ScheduleCard newSelection) { + this.newSelection = newSelection; + } + + @Override + public String toString() { + return this.getClass().getSimpleName(); + } + + public ScheduleCard getNewSelection() { + return newSelection; + } +} diff --git a/src/main/java/seedu/address/logic/Logic.java b/src/main/java/seedu/address/logic/Logic.java index a63c37af8f49..ecdc4e5814c5 100644 --- a/src/main/java/seedu/address/logic/Logic.java +++ b/src/main/java/seedu/address/logic/Logic.java @@ -6,6 +6,7 @@ import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.group.ReadOnlyGroup; import seedu.address.model.person.ReadOnlyPerson; +import seedu.address.model.schedule.ReadOnlySchedule; /** * API of the Logic component @@ -26,6 +27,9 @@ public interface Logic { /** Returns an unmodifiable view of the filtered list of groups */ ObservableList getFilteredGroupList(); + /** Returns an unmodifiable view of the filtered list of schedules */ + ObservableList getFilteredScheduleList(); + /** Returns the list of input entered by the user, encapsulated in a {@code ListElementPointer} object */ ListElementPointer getHistorySnapshot(); } diff --git a/src/main/java/seedu/address/logic/LogicManager.java b/src/main/java/seedu/address/logic/LogicManager.java index 811a6d5da3ad..af0797119ad5 100644 --- a/src/main/java/seedu/address/logic/LogicManager.java +++ b/src/main/java/seedu/address/logic/LogicManager.java @@ -13,6 +13,7 @@ import seedu.address.model.Model; import seedu.address.model.group.ReadOnlyGroup; import seedu.address.model.person.ReadOnlyPerson; +import seedu.address.model.schedule.ReadOnlySchedule; /** * The main LogicManager of the app. @@ -56,6 +57,11 @@ public ObservableList getFilteredGroupList() { return model.getFilteredGroupList(); } + @Override + public ObservableList getFilteredScheduleList() { + return model.getFilteredScheduleList(); + } + @Override public ListElementPointer getHistorySnapshot() { return new ListElementPointer(history.getHistory()); diff --git a/src/main/java/seedu/address/model/AddressBook.java b/src/main/java/seedu/address/model/AddressBook.java index cc0ea4ba00f6..6103ea0826ef 100644 --- a/src/main/java/seedu/address/model/AddressBook.java +++ b/src/main/java/seedu/address/model/AddressBook.java @@ -22,6 +22,11 @@ import seedu.address.model.person.exceptions.DuplicatePersonException; import seedu.address.model.person.exceptions.NoPersonsException; import seedu.address.model.person.exceptions.PersonNotFoundException; +import seedu.address.model.schedule.ReadOnlySchedule; +import seedu.address.model.schedule.Schedule; +import seedu.address.model.schedule.UniqueScheduleList; +import seedu.address.model.schedule.exceptions.DuplicateScheduleException; +import seedu.address.model.schedule.exceptions.ScheduleNotFoundException; import seedu.address.model.tag.Tag; import seedu.address.model.tag.UniqueTagList; @@ -35,6 +40,7 @@ public class AddressBook implements ReadOnlyAddressBook { private final UniquePersonList persons; private final UniqueTagList tags; private final UniqueGroupList groups; + private final UniqueScheduleList schedules; /* * The 'unusual' code block below is an non-static initialization block, sometimes used to avoid duplication @@ -47,6 +53,7 @@ public class AddressBook implements ReadOnlyAddressBook { persons = new UniquePersonList(); tags = new UniqueTagList(); groups = new UniqueGroupList(); + schedules = new UniqueScheduleList(); } public AddressBook() {} @@ -249,6 +256,32 @@ public boolean removeGroup(ReadOnlyGroup key) throws GroupNotFoundException { throw new GroupNotFoundException(); } } + + //// schedule-level operations + + /** + * Adds a schedule to the address book. + * + * @throws DuplicateScheduleException if an equivalent schedule already exists. + */ + + public void addSchedule(ReadOnlySchedule s) throws DuplicateScheduleException { + Schedule newSchedule = new Schedule(s); + schedules.add(newSchedule); + } + + /** + * Removes {@code key} from this {@code AddressBook}. + * @throws ScheduleNotFoundException if the {@code key} is not in this {@code AddressBook}. + */ + public boolean removeSchedule(ReadOnlySchedule key) throws ScheduleNotFoundException { + if (schedules.remove(key)) { + return true; + } else { + throw new ScheduleNotFoundException(); + } + } + //// util methods @Override @@ -272,6 +305,11 @@ public ObservableList getGroupList() { return groups.asObservableList(); } + @Override + public ObservableList getScheduleList() { + return schedules.asObservableList(); + } + @Override public boolean equals(Object other) { return other == this // short circuit if same object diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index a5986ad9389d..add790c3a6b7 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -11,6 +11,9 @@ import seedu.address.model.person.exceptions.DuplicatePersonException; import seedu.address.model.person.exceptions.NoPersonsException; import seedu.address.model.person.exceptions.PersonNotFoundException; +import seedu.address.model.schedule.ReadOnlySchedule; +import seedu.address.model.schedule.exceptions.DuplicateScheduleException; +import seedu.address.model.schedule.exceptions.ScheduleNotFoundException; /** * The API of the Model component. @@ -22,6 +25,9 @@ public interface Model { /** {@code Predicate} that always evaluate to true */ Predicate PREDICATE_SHOW_ALL_GROUPS = unused -> true; + /** {@code Predicate} that always evaluate to true */ + Predicate PREDICATE_SHOW_ALL_SCHEDULES = unused -> true; + /** Clears existing backing model and replaces with the provided new data. */ void resetData(ReadOnlyAddressBook newData); @@ -43,6 +49,12 @@ public interface Model { /** Deletes the given group */ void deleteGroup(ReadOnlyGroup group) throws GroupNotFoundException; + /** Adds the given schedule */ + void addSchedule(ReadOnlySchedule schedule) throws DuplicateScheduleException; + + /** Deletes the given schedule */ + void deleteSchedule(ReadOnlySchedule schedule) throws ScheduleNotFoundException; + /** * Replaces the given person {@code target} with {@code editedPerson}. * @@ -60,6 +72,9 @@ void updatePerson(ReadOnlyPerson target, ReadOnlyPerson editedPerson) /** Returns an unmodifiable view of the filtered group list */ ObservableList getFilteredGroupList(); + /** Returns an unmodifiable view of the filtered schedule list */ + ObservableList getFilteredScheduleList(); + /** * Updates the filter of the filtered person list to filter by the given {@code predicate}. * @throws NullPointerException if {@code predicate} is null. @@ -72,4 +87,9 @@ void updatePerson(ReadOnlyPerson target, ReadOnlyPerson editedPerson) */ void updateFilteredGroupList(Predicate predicate); + /** + * Updates the filter of the filtered schedule list to filter by the given {@code predicate}. + * @throws NullPointerException if {@code predicate} is null. + */ + void updateFilteredScheduleList(Predicate predicate); } diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index dbac15fc9685..b16ac1b46d5d 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -20,6 +20,9 @@ import seedu.address.model.person.exceptions.DuplicatePersonException; import seedu.address.model.person.exceptions.NoPersonsException; import seedu.address.model.person.exceptions.PersonNotFoundException; +import seedu.address.model.schedule.ReadOnlySchedule; +import seedu.address.model.schedule.exceptions.DuplicateScheduleException; +import seedu.address.model.schedule.exceptions.ScheduleNotFoundException; /** * Represents the in-memory model of the address book data. @@ -31,6 +34,7 @@ public class ModelManager extends ComponentManager implements Model { private final AddressBook addressBook; private final FilteredList filteredPersons; private final FilteredList filteredGroups; + private final FilteredList filteredSchedules; /** * Initializes a ModelManager with the given addressBook and userPrefs. @@ -44,6 +48,7 @@ public ModelManager(ReadOnlyAddressBook addressBook, UserPrefs userPrefs) { this.addressBook = new AddressBook(addressBook); filteredPersons = new FilteredList<>(this.addressBook.getPersonList()); filteredGroups = new FilteredList<>(this.addressBook.getGroupList()); + filteredSchedules = new FilteredList<>(this.addressBook.getScheduleList()); } public ModelManager() { @@ -106,6 +111,19 @@ public void deleteGroup(ReadOnlyGroup target) throws GroupNotFoundException { indicateAddressBookChanged(); } + @Override + public void addSchedule(ReadOnlySchedule schedule) throws DuplicateScheduleException { + addressBook.addSchedule(schedule); + updateFilteredScheduleList(PREDICATE_SHOW_ALL_SCHEDULES); + indicateAddressBookChanged(); + } + + @Override + public void deleteSchedule(ReadOnlySchedule target) throws ScheduleNotFoundException { + addressBook.removeSchedule(target); + indicateAddressBookChanged(); + } + //=========== Filtered Person List Accessors ============================================================= /** @@ -122,6 +140,11 @@ public ObservableList getFilteredGroupList() { return FXCollections.unmodifiableObservableList(filteredGroups); } + @Override + public ObservableList getFilteredScheduleList() { + return FXCollections.unmodifiableObservableList(filteredSchedules); + } + @Override public void updateFilteredPersonList(Predicate predicate) { requireNonNull(predicate); @@ -134,6 +157,11 @@ public void updateFilteredGroupList(Predicate predicate) { filteredGroups.setPredicate(predicate); } + @Override + public void updateFilteredScheduleList(Predicate predicate) { + requireNonNull(predicate); + filteredSchedules.setPredicate(predicate); + } @Override public boolean equals(Object obj) { // short circuit if same object diff --git a/src/main/java/seedu/address/model/ReadOnlyAddressBook.java b/src/main/java/seedu/address/model/ReadOnlyAddressBook.java index 1bb6f55b8923..30e2ab51e200 100644 --- a/src/main/java/seedu/address/model/ReadOnlyAddressBook.java +++ b/src/main/java/seedu/address/model/ReadOnlyAddressBook.java @@ -3,6 +3,7 @@ import javafx.collections.ObservableList; import seedu.address.model.group.ReadOnlyGroup; import seedu.address.model.person.ReadOnlyPerson; +import seedu.address.model.schedule.ReadOnlySchedule; import seedu.address.model.tag.Tag; /** @@ -28,4 +29,10 @@ public interface ReadOnlyAddressBook { */ ObservableList getGroupList(); + /** + * Returns an unmodifiable view of the schedules list. + * This list will not contain any duplicate schedules. + */ + ObservableList getScheduleList(); + } diff --git a/src/main/java/seedu/address/model/schedule/ReadOnlySchedule.java b/src/main/java/seedu/address/model/schedule/ReadOnlySchedule.java new file mode 100644 index 000000000000..c3d4a1f695a4 --- /dev/null +++ b/src/main/java/seedu/address/model/schedule/ReadOnlySchedule.java @@ -0,0 +1,37 @@ +package seedu.address.model.schedule; + +import javafx.beans.property.ObjectProperty; +import javafx.collections.ObservableList; + +/** + * A read-only immutable interface for a Group in the addressbook. + * Implementations should guarantee: details are present and not null, field values are validated. + */ +public interface ReadOnlySchedule { + + ObjectProperty nameProperty(); + ScheduleName getName(); + ObservableList getSchedules(); + + /** + * Returns true if both have the same state. (interfaces cannot override .equals) + */ + default boolean isSameStateAs(ReadOnlySchedule other) { + return other == this // short circuit if same object + || (other != null // this is first to avoid NPE below + && other.getName().equals(this.getName()) // state checks here onwards + && other.getSchedules().equals(this.getSchedules())); + } + + /** + * Formats the Schedule as text, showing schedule name. + */ + default String getAsText() { + final StringBuilder builder = new StringBuilder(); + builder.append(getName()) + .append(" Schedule Name: ") + .append(getName()); + return builder.toString(); + } + +} diff --git a/src/main/java/seedu/address/model/schedule/Schedule.java b/src/main/java/seedu/address/model/schedule/Schedule.java new file mode 100644 index 000000000000..1fe75ce9b1c4 --- /dev/null +++ b/src/main/java/seedu/address/model/schedule/Schedule.java @@ -0,0 +1,92 @@ +package seedu.address.model.schedule; + +import static java.util.Objects.requireNonNull; + +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.collections.ObservableList; +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.schedule.exceptions.DuplicateScheduleException; +import seedu.address.model.schedule.exceptions.ScheduleNotFoundException; + +/** + * Represents a Schedule in an address book. + * Guarantees: details are present and not null, field values are validated. + */ +public class Schedule implements ReadOnlySchedule { + + private ObjectProperty scheduleName; + /** + * A Schedule will have an empty schedules list by default + */ + private final UniqueScheduleList schedules = new UniqueScheduleList(); + + /** + * Every field must be present and not null. + */ + public Schedule(ScheduleName name) { + requireNonNull(name); + this.scheduleName = new SimpleObjectProperty<>(name); + } + + /** + * Every field must be present and not null. + */ + public Schedule(String name) throws IllegalValueException { + requireNonNull(name); + this.scheduleName = new SimpleObjectProperty<>(new ScheduleName(name)); + } + /** + * Creates a copy of the given ReadOnlySchedule. + */ + public Schedule(ReadOnlySchedule source) { + this(source.getName()); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Schedule // instanceof handles nulls + && this.scheduleName.toString().equals(((Schedule) other).scheduleName.toString())); // state check + } + + @Override + public int hashCode() { + return scheduleName.hashCode(); + } + + /** + * Format state as text for viewing. + */ + public String toString() { + return getAsText(); + } + + public void addMember(ReadOnlySchedule schedule) throws DuplicateScheduleException { + this.schedules.add(schedule); + } + + public void deleteMember(ReadOnlySchedule schedule) throws ScheduleNotFoundException { + this.schedules.remove(schedule); + } + + @Override + public ObjectProperty nameProperty() { + return scheduleName; + } + + @Override + public ScheduleName getName() { + return scheduleName.get(); + } + + public void setScheduleName(ScheduleName name) { + this.scheduleName.set(requireNonNull(name)); + } + + @Override + public ObservableList getSchedules() { + return schedules.asObservableList(); + } + +} diff --git a/src/main/java/seedu/address/model/schedule/ScheduleName.java b/src/main/java/seedu/address/model/schedule/ScheduleName.java new file mode 100644 index 000000000000..0471891fff0c --- /dev/null +++ b/src/main/java/seedu/address/model/schedule/ScheduleName.java @@ -0,0 +1,63 @@ +package seedu.address.model.schedule; + +import static java.util.Objects.requireNonNull; + +import seedu.address.commons.exceptions.IllegalValueException; + +/** + * Represents a Schedule's name in the address book. + * Guarantees: immutable; is valid as declared in {@link #isValidName(String)} + */ +public class ScheduleName { + + public static final String MESSAGE_SCHEDULE_CONSTRAINTS = "Schedule names should contain only " + + "alphanumeric characters, spaces, underscores and dashes"; + + /* + * The first character of the address must not be a whitespace, + * otherwise " " (a blank string) becomes a valid input. + */ + public static final String SCHEDULE_VALIDATION_REGEX = "^[a-zA-Z0-9]([\\w -]*[a-zA-Z0-9])?$"; + + public final String fullName; + + /** + * Validates given name. + * + * @throws IllegalValueException if given name string is invalid. + */ + public ScheduleName(String name) throws IllegalValueException { + requireNonNull(name); + String trimmedName = name.trim(); + if (!isValidName(trimmedName)) { + throw new IllegalValueException(MESSAGE_SCHEDULE_CONSTRAINTS); + } + this.fullName = trimmedName; + } + + /** + * Returns true if a given string is a valid schedule name. + */ + public static boolean isValidName(String test) { + return test.matches(SCHEDULE_VALIDATION_REGEX); + } + + + @Override + public String toString() { + return fullName; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof ScheduleName // instanceof handles nulls + && this.fullName.equals(((ScheduleName) other).fullName)); // state check + } + + @Override + public int hashCode() { + return fullName.hashCode(); + } + +} diff --git a/src/main/java/seedu/address/model/schedule/UniqueScheduleList.java b/src/main/java/seedu/address/model/schedule/UniqueScheduleList.java new file mode 100644 index 000000000000..c439150da6f9 --- /dev/null +++ b/src/main/java/seedu/address/model/schedule/UniqueScheduleList.java @@ -0,0 +1,165 @@ +package seedu.address.model.schedule; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.fxmisc.easybind.EasyBind; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import seedu.address.commons.util.CollectionUtil; +import seedu.address.model.schedule.exceptions.DuplicateScheduleException; +import seedu.address.model.schedule.exceptions.ScheduleNotFoundException; + + +/** + * A list of schedules that enforces no nulls and uniqueness between its elements. + * + * Supports minimal set of list operations for the app's features. + * + * @see Schedule#equals(Object) + */ + + +public class UniqueScheduleList implements Iterable { + + private final ObservableList internalList = FXCollections.observableArrayList(); + // used by asObservableList() + private final ObservableList mappedList = EasyBind.map(internalList, (schedule) -> schedule); + + /** + * Creates a UniqueScheduleList using given Schedules. + * Enforces no nulls. + */ + public UniqueScheduleList(Set schedules) { + requireAllNonNull(schedules); + internalList.addAll(schedules); + + assert CollectionUtil.elementsAreUnique(internalList); + } + + /** + * Constructs empty ScheduleList. + */ + public UniqueScheduleList() {} + + /** + * Returns all schedules in this list as a Set. + * This set is mutable and change-insulated against the internal list. + */ + + /** + * Returns true if the list contains an equivalent Schedule as the given argument. + */ + public boolean contains(ReadOnlySchedule toCheck) { + requireNonNull(toCheck); + return internalList.contains(toCheck); + } + + /** + * Returns a set representation of the schedule. + */ + public Set toSet() { + assert CollectionUtil.elementsAreUnique(internalList); + return new HashSet<>(internalList); + } + + /** + * Ensures every schedule in the argument list exists in this object. + */ + public void mergeFrom(UniqueScheduleList from) { + final Set alreadyInside = this.toSet(); + from.internalList.stream() + .filter(schedule -> !alreadyInside.contains(schedule)) + .forEach(internalList::add); + + assert CollectionUtil.elementsAreUnique(internalList); + } + + /** + * Adds a Schedule to the list. + * + * @throws seedu.address.model.schedule.exceptions.DuplicateScheduleException + * if the Schedule to add is a duplicate of an existing Schedule in the list. + */ + public void add(ReadOnlySchedule toAdd) throws DuplicateScheduleException { + requireNonNull(toAdd); + if (contains(toAdd)) { + throw new DuplicateScheduleException(); + } + internalList.add(new Schedule(toAdd)); + + assert CollectionUtil.elementsAreUnique(internalList); + } + + /** + * Removes the equivalent schedule from the list. + * + * @throws ScheduleNotFoundException if no such schedule could be found in the list. + */ + public boolean remove(ReadOnlySchedule toRemove) throws ScheduleNotFoundException { + requireNonNull(toRemove); + final boolean scheduleFoundAndDeleted = internalList.remove(toRemove); + if (!scheduleFoundAndDeleted) { + throw new ScheduleNotFoundException(); + } + return scheduleFoundAndDeleted; + } + + @Override + public Iterator iterator() { + assert CollectionUtil.elementsAreUnique(internalList); + return internalList.iterator(); + } + + public void setSchedules(UniqueScheduleList replacement) { + this.internalList.setAll(replacement.internalList); + } + + public void setSchedules(List schedules) throws DuplicateScheduleException { + final UniqueScheduleList replacement = new UniqueScheduleList(); + for (final ReadOnlySchedule schedule: schedules) { + replacement.add(new Schedule(schedule)); + } + setSchedules(replacement); + } + + /** + * Returns the backing list as an unmodifiable {@code ObservableList}. + */ + public ObservableList asObservableList() { + assert CollectionUtil.elementsAreUnique(internalList); + return FXCollections.unmodifiableObservableList(mappedList); + } + + @Override + public boolean equals(Object other) { + assert CollectionUtil.elementsAreUnique(internalList); + return other == this // short circuit if same object + || (other instanceof seedu.address.model.schedule.UniqueScheduleList // instanceof handles nulls + && this.internalList.equals(((seedu.address.model.schedule.UniqueScheduleList) other).internalList)); + } + + /** + * Returns true if the element in this list is equal to the elements in {@code other}. + * The elements do not have to be in the same order. + */ + public boolean equalsOrderInsensitive(seedu.address.model.schedule.UniqueScheduleList other) { + assert CollectionUtil.elementsAreUnique(internalList); + assert CollectionUtil.elementsAreUnique(other.internalList); + return this == other || new HashSet<>(this.internalList).equals(new HashSet<>(other.internalList)); + } + + @Override + public int hashCode() { + assert CollectionUtil.elementsAreUnique(internalList); + return internalList.hashCode(); + } + +} + diff --git a/src/main/java/seedu/address/model/schedule/exceptions/DuplicateScheduleException.java b/src/main/java/seedu/address/model/schedule/exceptions/DuplicateScheduleException.java new file mode 100644 index 000000000000..a2e91a98c637 --- /dev/null +++ b/src/main/java/seedu/address/model/schedule/exceptions/DuplicateScheduleException.java @@ -0,0 +1,12 @@ +package seedu.address.model.schedule.exceptions; + +import seedu.address.commons.exceptions.DuplicateDataException; + +/** + * Signals that the operation will result in duplicate Schedule objects. + */ +public class DuplicateScheduleException extends DuplicateDataException { + public DuplicateScheduleException() { + super("Operation would result in duplicate schedules"); + } +} diff --git a/src/main/java/seedu/address/model/schedule/exceptions/NoSchedulesException.java b/src/main/java/seedu/address/model/schedule/exceptions/NoSchedulesException.java new file mode 100644 index 000000000000..5559cf5a1391 --- /dev/null +++ b/src/main/java/seedu/address/model/schedule/exceptions/NoSchedulesException.java @@ -0,0 +1,6 @@ +package seedu.address.model.schedule.exceptions; + +/** + * Signals that the operation is unable to sort due to an empty list. + */ +public class NoSchedulesException extends Exception {} diff --git a/src/main/java/seedu/address/model/schedule/exceptions/ScheduleNotFoundException.java b/src/main/java/seedu/address/model/schedule/exceptions/ScheduleNotFoundException.java new file mode 100644 index 000000000000..726bb0596e5a --- /dev/null +++ b/src/main/java/seedu/address/model/schedule/exceptions/ScheduleNotFoundException.java @@ -0,0 +1,6 @@ +package seedu.address.model.schedule.exceptions; + +/** + * Signals that the operation is unable to find the specified person. + */ +public class ScheduleNotFoundException extends Exception {} diff --git a/src/main/java/seedu/address/storage/XmlAdaptedSchedule.java b/src/main/java/seedu/address/storage/XmlAdaptedSchedule.java new file mode 100644 index 000000000000..284fff0c45dc --- /dev/null +++ b/src/main/java/seedu/address/storage/XmlAdaptedSchedule.java @@ -0,0 +1,47 @@ +package seedu.address.storage; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlElement; + +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.schedule.ReadOnlySchedule; +import seedu.address.model.schedule.Schedule; + + + + +/** + * JAXB-friendly adapted version of the Schedule. + */ +public class XmlAdaptedSchedule { + + @XmlElement(required = true) + private String scheduleName; + @XmlElement + private List schedules = new ArrayList<>(); + /** + * Constructs an XmlAdapteddSchedule. + * This is the no-arg constructor that is required by JAXB. + */ + public XmlAdaptedSchedule() {} + + /** + * Converts a given Tag into this class for JAXB use. + * + * @param source future changes to this will not affect the created + */ + public XmlAdaptedSchedule(ReadOnlySchedule source) { + scheduleName = source.getName().toString(); + } + + /** + * Converts this jaxb-friendly adapted group object into the model's Group object. + * + * @throws IllegalValueException if there were any data constraints violated in the adapted person + */ + public Schedule toModelType() throws IllegalValueException { + return new Schedule(scheduleName); + } + +} diff --git a/src/main/java/seedu/address/storage/XmlSerializableAddressBook.java b/src/main/java/seedu/address/storage/XmlSerializableAddressBook.java index 4ad67ef10c4e..9f31b231a0c7 100644 --- a/src/main/java/seedu/address/storage/XmlSerializableAddressBook.java +++ b/src/main/java/seedu/address/storage/XmlSerializableAddressBook.java @@ -13,6 +13,7 @@ import seedu.address.model.ReadOnlyAddressBook; import seedu.address.model.group.ReadOnlyGroup; import seedu.address.model.person.ReadOnlyPerson; +import seedu.address.model.schedule.ReadOnlySchedule; import seedu.address.model.tag.Tag; /** @@ -27,6 +28,8 @@ public class XmlSerializableAddressBook implements ReadOnlyAddressBook { private List tags; @XmlElement private List groups; + @XmlElement + private List schedules; /** * Creates an empty XmlSerializableAddressBook. @@ -36,6 +39,7 @@ public XmlSerializableAddressBook() { persons = new ArrayList<>(); tags = new ArrayList<>(); groups = new ArrayList<>(); + schedules = new ArrayList<>(); } /** @@ -46,6 +50,7 @@ public XmlSerializableAddressBook(ReadOnlyAddressBook src) { persons.addAll(src.getPersonList().stream().map(XmlAdaptedPerson::new).collect(Collectors.toList())); tags.addAll(src.getTagList().stream().map(XmlAdaptedTag::new).collect(Collectors.toList())); groups.addAll(src.getGroupList().stream().map(XmlAdaptedGroup::new).collect(Collectors.toList())); + schedules.addAll(src.getScheduleList().stream().map(XmlAdaptedSchedule::new).collect(Collectors.toList())); } @Override @@ -90,4 +95,17 @@ public ObservableList getGroupList() { return FXCollections.unmodifiableObservableList(groups); } + @Override + public ObservableList getScheduleList() { + final ObservableList schedules = this.schedules.stream().map(s -> { + try { + return s.toModelType(); + } catch (IllegalValueException e) { + e.printStackTrace(); + //TODO: better error handling + return null; + } + }).collect(Collectors.toCollection(FXCollections::observableArrayList)); + return FXCollections.unmodifiableObservableList(schedules); + } } diff --git a/src/main/java/seedu/address/ui/BrowserPanel.java b/src/main/java/seedu/address/ui/BrowserPanel.java index acf2d720322a..18c07768bde1 100644 --- a/src/main/java/seedu/address/ui/BrowserPanel.java +++ b/src/main/java/seedu/address/ui/BrowserPanel.java @@ -19,6 +19,7 @@ import javafx.scene.image.ImageView; import javafx.scene.layout.BorderPane; import javafx.scene.layout.Region; +import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.paint.ImagePattern; @@ -46,6 +47,9 @@ public class BrowserPanel extends UiPart { @FXML private WebView browser; + @FXML + private Circle contactImageCircle; + @FXML private BorderPane socialIcon1Placeholder; @@ -64,6 +68,11 @@ public class BrowserPanel extends UiPart { @FXML private VBox contactDetailsVBox; + //This has a getter method as MainWindow.java needs to + // access this node to populate it with Logic.getFilteredScheduleList(). + @FXML + private StackPane schedulePlaceholder; + private ParallelTransition pt; public BrowserPanel() { @@ -72,28 +81,33 @@ public BrowserPanel() { // To prevent triggering events for typing inside the loaded Web page. getRoot().setOnKeyPressed(Event::consume); loadDefaultPage(); - - setupContactDetailsBox(); - + //Setup needed JFX nodes which will be updated upon selecting persons + setupContactImageCircle(); + setupContactDetailsVBox(); + setupScheduleListViewPlaceholder(); registerAsAnEventHandler(this); } private void setContactImage() { - Circle cir = new Circle(250, 250, 90); - cir.setStroke(Color.valueOf("#3fc380")); - cir.setStrokeWidth(5); - cir.setStrokeDashOffset(20); Image img = new Image("images/maleIcon.png"); - cir.setFill(new ImagePattern(img)); - cir.radiusProperty().bind(Bindings.min( + contactImageCircle.setVisible(true); + contactImageCircle.setFill(new ImagePattern(img)); + easeIn(contactImageCircle); + } + + private void setupContactImageCircle() { + contactImageCircle = new Circle(250, 250, 90); + contactImageCircle.setStroke(Color.valueOf("#3fc380")); + contactImageCircle.setStrokeWidth(5); + contactImageCircle.radiusProperty().bind(Bindings.min( contactImagePlaceholder.widthProperty().divide(3), contactImagePlaceholder.heightProperty().divide(3)) ); - contactImagePlaceholder.setCenter(cir); - easeIn(cir); + contactImagePlaceholder.setCenter(contactImageCircle); + contactImageCircle.setVisible(false); } - private void setupContactDetailsBox() { + private void setupContactDetailsVBox() { contactDetailsVBox.setSpacing(0); contactDetailsVBox.getChildren().addAll( new Label(""), @@ -122,7 +136,6 @@ private void setIcons() { Circle cir = new Circle(250, 250, 30); cir.setStroke(Color.valueOf("#3fc380")); cir.setStrokeWidth(5); - cir.setStrokeDashOffset(20); cir.radiusProperty().bind(Bindings.min( socialIconPlaceholders[i].widthProperty().divide(3), socialIconPlaceholders[i].heightProperty().divide(3)) @@ -133,6 +146,10 @@ private void setIcons() { } } + private void setupScheduleListViewPlaceholder() { + schedulePlaceholder.setVisible(false); + } + private void loadPersonPage(ReadOnlyPerson person) { loadPage(GOOGLE_SEARCH_URL_PREFIX + person.getName().fullName.replaceAll(" ", "+") + GOOGLE_SEARCH_URL_SUFFIX); @@ -164,10 +181,14 @@ private void handlePersonPanelSelectionChangedEvent(PersonPanelSelectionChangedE setContactImage(); setContactDetails(event.getNewSelection().person); setIcons(); + setSchedule(); } private void setContactDetails(ReadOnlyPerson person) { //Set up name label separately as it has no icons + contactDetailsVBox.setSpacing(0); + contactDetailsVBox.getChildren().addAll(); + Label name = (Label) contactDetailsVBox.getChildren().get(0); name.setText("" + person.getName()); name.setStyle("-fx-font-size: 60;"); @@ -197,6 +218,12 @@ private void setContactDetails(ReadOnlyPerson person) { } } + private void setSchedule() { + schedulePlaceholder.setVisible(true); + //scheduleListView.setStyle("-fx-alignment: center-left; -fx-padding: 0 0 0 10;"); + easeIn(schedulePlaceholder); + } + /** * Animates any node passed into this method with an ease-in */ @@ -214,4 +241,8 @@ private void easeIn(Node node) { pt.getChildren().addAll(ft, tt); pt.play(); } + + public StackPane getSchedulePlaceholder() { + return schedulePlaceholder; + } } diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index 910a6797658a..0069876cf293 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -132,18 +132,23 @@ void fillInnerParts() { browserPanel = new BrowserPanel(); browserPlaceholder.getChildren().add(browserPanel.getRoot()); + //TODO: Edit ScheduleListPanel.java to take in schedules instead of persons, + //TODO: and the line below to getFilteredScheduleList(). + //TODO: I've included CorrectScheduleListPanel.txt in dropbox, can copypaste + ScheduleListPanel scheduleListPanel = new ScheduleListPanel(logic.getFilteredPersonList()); + browserPanel.getSchedulePlaceholder().getChildren().add(scheduleListPanel.getRoot()); + personListPanel = new PersonListPanel(logic.getFilteredPersonList()); personListPanelPlaceholder.getChildren().add(personListPanel.getRoot()); - GroupListPanel groupListPanel; - groupListPanel = new GroupListPanel(logic.getFilteredGroupList()); //logic needs to get groupList instead + GroupListPanel groupListPanel = new GroupListPanel(logic.getFilteredGroupList()); groupListPanelPlaceholder.getChildren().add(groupListPanel.getRoot()); ResultDisplay resultDisplay = new ResultDisplay(); resultDisplayPlaceholder.getChildren().add(resultDisplay.getRoot()); StatusBarFooter statusBarFooter = new StatusBarFooter(prefs.getAddressBookFilePath(), - logic.getFilteredPersonList().size()); + logic.getFilteredPersonList().size()); statusbarPlaceholder.getChildren().add(statusBarFooter.getRoot()); CommandBox commandBox = new CommandBox(logic); diff --git a/src/main/java/seedu/address/ui/ScheduleCard.java b/src/main/java/seedu/address/ui/ScheduleCard.java new file mode 100644 index 000000000000..8ce1b9d1e4b9 --- /dev/null +++ b/src/main/java/seedu/address/ui/ScheduleCard.java @@ -0,0 +1,64 @@ +package seedu.address.ui; + +import javafx.beans.binding.Bindings; +import javafx.fxml.FXML; +import javafx.scene.control.Label; +import javafx.scene.layout.Region; +import seedu.address.model.schedule.ReadOnlySchedule; + + +/** + * An UI component that displays information of a {@code Schedule}. + */ +public class ScheduleCard extends UiPart { + + private static final String FXML = "ScheduleListCard.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 AddressBook level 4 + */ + + public final ReadOnlySchedule schedule; + + @FXML + private Label scheduleName; + @FXML + private Label scheduleId; + + public ScheduleCard(ReadOnlySchedule schedule, int displayedIndex) { + super(FXML); + this.schedule = schedule; + scheduleId.setText(displayedIndex + ". "); + bindListeners(schedule); + } + + /** + * Binds the individual UI elements to observe their respective {@code Schedule} properties + * so that they will be notified of any changes. + */ + private void bindListeners(ReadOnlySchedule schedule) { + scheduleName.textProperty().bind(Bindings.convert(schedule.nameProperty())); + } + + @Override + public boolean equals(Object other) { + // short circuit if same object + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof ScheduleCard)) { + return false; + } + + // state check + ScheduleCard card = (ScheduleCard) other; + return scheduleId.getText().equals(card.scheduleId.getText()) + && schedule.equals(card.schedule); + } +} diff --git a/src/main/java/seedu/address/ui/ScheduleListPanel.java b/src/main/java/seedu/address/ui/ScheduleListPanel.java new file mode 100644 index 000000000000..4545eb749e2f --- /dev/null +++ b/src/main/java/seedu/address/ui/ScheduleListPanel.java @@ -0,0 +1,90 @@ +package seedu.address.ui; + +import java.util.logging.Logger; + +import org.fxmisc.easybind.EasyBind; + +import com.google.common.eventbus.Subscribe; + +import javafx.application.Platform; +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.commons.events.ui.JumpToListRequestEvent; +import seedu.address.commons.events.ui.PersonPanelSelectionChangedEvent; +import seedu.address.model.person.ReadOnlyPerson; + + + +/** + * Panel containing the list of schedules. + */ +public class ScheduleListPanel extends UiPart { + private static final String FXML = "ScheduleListPanel.fxml"; + private final Logger logger = LogsCenter.getLogger(ScheduleListPanel.class); + + @FXML + private ListView scheduleListView; + + public ScheduleListPanel(ObservableList scheduleList) { + super(FXML); + setConnections(scheduleList); + registerAsAnEventHandler(this); + } + + private void setConnections(ObservableList scheduleList) { + ObservableList mappedList = EasyBind.map( + scheduleList, (person) -> new PersonCard(person, scheduleList.indexOf(person) + 1)); + scheduleListView.setItems(mappedList); + scheduleListView.setCellFactory(listView -> new personListViewCell()); + setEventHandlerForSelectionChangeEvent(); + } + + private void setEventHandlerForSelectionChangeEvent() { + scheduleListView.getSelectionModel().selectedItemProperty() + .addListener((observable, oldValue, newValue) -> { + if (newValue != null) { + logger.fine("Selection in schedule list panel changed to : '" + newValue + "'"); + raise(new PersonPanelSelectionChangedEvent(newValue)); + } + }); + } + + /** + * Scrolls to the {@code ScheduleCard} at the {@code index} and selects it. + */ + private void scrollTo(int index) { + Platform.runLater(() -> { + scheduleListView.scrollTo(index); + scheduleListView.getSelectionModel().clearAndSelect(index); + }); + } + + @Subscribe + private void handleJumpToListRequestEvent(JumpToListRequestEvent event) { + logger.info(LogsCenter.getEventHandlingLogMessage(event)); + scrollTo(event.targetIndex); + } + + /** + * Custom {@code ListCell} that displays the graphics of a {@code ScheduleCard}. + */ + class personListViewCell extends ListCell { + + @Override + protected void updateItem(PersonCard schedule, boolean empty) { + super.updateItem(schedule, empty); + + if (empty || schedule == null) { + setGraphic(null); + setText(null); + } else { + setGraphic(schedule.getRoot()); + } + } + } + +} diff --git a/src/main/resources/view/BrowserPanel.fxml b/src/main/resources/view/BrowserPanel.fxml index 199aeb12c059..3fff4bd92c8b 100644 --- a/src/main/resources/view/BrowserPanel.fxml +++ b/src/main/resources/view/BrowserPanel.fxml @@ -1,5 +1,7 @@ + + @@ -7,7 +9,7 @@ - + @@ -38,6 +40,7 @@ + diff --git a/src/main/resources/view/ScheduleListCard.fxml b/src/main/resources/view/ScheduleListCard.fxml new file mode 100644 index 000000000000..282e6280eba8 --- /dev/null +++ b/src/main/resources/view/ScheduleListCard.fxml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/view/ScheduleListPanel.fxml b/src/main/resources/view/ScheduleListPanel.fxml new file mode 100644 index 000000000000..fcb565c89dc6 --- /dev/null +++ b/src/main/resources/view/ScheduleListPanel.fxml @@ -0,0 +1,10 @@ + + + + + + + + diff --git a/src/test/java/seedu/address/logic/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/AddCommandTest.java index 8a019610266c..2886f0f86777 100644 --- a/src/test/java/seedu/address/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddCommandTest.java @@ -29,6 +29,9 @@ import seedu.address.model.person.exceptions.DuplicatePersonException; import seedu.address.model.person.exceptions.NoPersonsException; import seedu.address.model.person.exceptions.PersonNotFoundException; +import seedu.address.model.schedule.ReadOnlySchedule; +import seedu.address.model.schedule.exceptions.DuplicateScheduleException; +import seedu.address.model.schedule.exceptions.ScheduleNotFoundException; import seedu.address.testutil.PersonBuilder; public class AddCommandTest { @@ -122,6 +125,16 @@ public void deleteGroup(ReadOnlyGroup group) throws GroupNotFoundException { } + @Override + public void addSchedule(ReadOnlySchedule schedule) throws DuplicateScheduleException { + + } + + @Override + public void deleteSchedule(ReadOnlySchedule schedule) throws ScheduleNotFoundException { + + } + @Override public void resetData(ReadOnlyAddressBook newData) { fail("This method should not be called."); @@ -155,6 +168,11 @@ public ObservableList getFilteredGroupList() { return null; } + @Override + public ObservableList getFilteredScheduleList() { + return null; + } + @Override public void updateFilteredPersonList(Predicate predicate) { fail("This method should not be called."); @@ -164,6 +182,11 @@ public void updateFilteredPersonList(Predicate predicate) { public void updateFilteredGroupList(Predicate predicate) { } + + @Override + public void updateFilteredScheduleList(Predicate predicate) { + + } } /** diff --git a/src/test/java/seedu/address/model/AddressBookTest.java b/src/test/java/seedu/address/model/AddressBookTest.java index 17d714595c8e..0a4ad31f6b88 100644 --- a/src/test/java/seedu/address/model/AddressBookTest.java +++ b/src/test/java/seedu/address/model/AddressBookTest.java @@ -19,6 +19,7 @@ import seedu.address.model.group.ReadOnlyGroup; import seedu.address.model.person.Person; import seedu.address.model.person.ReadOnlyPerson; +import seedu.address.model.schedule.ReadOnlySchedule; import seedu.address.model.tag.Tag; public class AddressBookTest { @@ -77,6 +78,7 @@ private static class AddressBookStub implements ReadOnlyAddressBook { private final ObservableList persons = FXCollections.observableArrayList(); private final ObservableList tags = FXCollections.observableArrayList(); private final ObservableList groups = FXCollections.observableArrayList(); + private final ObservableList schedules = FXCollections.observableArrayList(); AddressBookStub(Collection persons, Collection tags) { this.persons.setAll(persons); @@ -97,6 +99,11 @@ public ObservableList getTagList() { public ObservableList getGroupList() { return groups; } + + @Override + public ObservableList getScheduleList() { + return schedules; + } } } From 799451728435f8f251ddea30188e721f11cb3690 Mon Sep 17 00:00:00 2001 From: Procrastinatus Date: Tue, 24 Oct 2017 16:34:18 +0800 Subject: [PATCH 2/8] Fixed empty test methods (for Codacy) --- .../java/seedu/address/ui/MainWindow.java | 5 +---- .../seedu/address/ui/ScheduleListPanel.java | 22 +++++++++---------- .../resources/view/ScheduleListPanel.fxml | 5 +++-- .../logic/commands/AddCommandTest.java | 12 +++++----- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index 0069876cf293..924fee57e484 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -132,10 +132,7 @@ void fillInnerParts() { browserPanel = new BrowserPanel(); browserPlaceholder.getChildren().add(browserPanel.getRoot()); - //TODO: Edit ScheduleListPanel.java to take in schedules instead of persons, - //TODO: and the line below to getFilteredScheduleList(). - //TODO: I've included CorrectScheduleListPanel.txt in dropbox, can copypaste - ScheduleListPanel scheduleListPanel = new ScheduleListPanel(logic.getFilteredPersonList()); + ScheduleListPanel scheduleListPanel = new ScheduleListPanel(logic.getFilteredScheduleList()); browserPanel.getSchedulePlaceholder().getChildren().add(scheduleListPanel.getRoot()); personListPanel = new PersonListPanel(logic.getFilteredPersonList()); diff --git a/src/main/java/seedu/address/ui/ScheduleListPanel.java b/src/main/java/seedu/address/ui/ScheduleListPanel.java index 4545eb749e2f..71381ef56bec 100644 --- a/src/main/java/seedu/address/ui/ScheduleListPanel.java +++ b/src/main/java/seedu/address/ui/ScheduleListPanel.java @@ -14,8 +14,8 @@ import javafx.scene.layout.Region; import seedu.address.commons.core.LogsCenter; import seedu.address.commons.events.ui.JumpToListRequestEvent; -import seedu.address.commons.events.ui.PersonPanelSelectionChangedEvent; -import seedu.address.model.person.ReadOnlyPerson; +import seedu.address.commons.events.ui.SchedulePanelSelectionChangedEvent; +import seedu.address.model.schedule.ReadOnlySchedule; @@ -27,19 +27,19 @@ public class ScheduleListPanel extends UiPart { private final Logger logger = LogsCenter.getLogger(ScheduleListPanel.class); @FXML - private ListView scheduleListView; + private ListView scheduleListView; - public ScheduleListPanel(ObservableList scheduleList) { + public ScheduleListPanel(ObservableList scheduleList) { super(FXML); setConnections(scheduleList); registerAsAnEventHandler(this); } - private void setConnections(ObservableList scheduleList) { - ObservableList mappedList = EasyBind.map( - scheduleList, (person) -> new PersonCard(person, scheduleList.indexOf(person) + 1)); + private void setConnections(ObservableList scheduleList) { + ObservableList mappedList = EasyBind.map( + scheduleList, (schedule) -> new ScheduleCard(schedule, scheduleList.indexOf(schedule) + 1)); scheduleListView.setItems(mappedList); - scheduleListView.setCellFactory(listView -> new personListViewCell()); + scheduleListView.setCellFactory(listView -> new scheduleListViewCell()); setEventHandlerForSelectionChangeEvent(); } @@ -48,7 +48,7 @@ private void setEventHandlerForSelectionChangeEvent() { .addListener((observable, oldValue, newValue) -> { if (newValue != null) { logger.fine("Selection in schedule list panel changed to : '" + newValue + "'"); - raise(new PersonPanelSelectionChangedEvent(newValue)); + raise(new SchedulePanelSelectionChangedEvent(newValue)); } }); } @@ -72,10 +72,10 @@ private void handleJumpToListRequestEvent(JumpToListRequestEvent event) { /** * Custom {@code ListCell} that displays the graphics of a {@code ScheduleCard}. */ - class personListViewCell extends ListCell { + class scheduleListViewCell extends ListCell { @Override - protected void updateItem(PersonCard schedule, boolean empty) { + protected void updateItem(ScheduleCard schedule, boolean empty) { super.updateItem(schedule, empty); if (empty || schedule == null) { diff --git a/src/main/resources/view/ScheduleListPanel.fxml b/src/main/resources/view/ScheduleListPanel.fxml index fcb565c89dc6..f37ecd4eec81 100644 --- a/src/main/resources/view/ScheduleListPanel.fxml +++ b/src/main/resources/view/ScheduleListPanel.fxml @@ -4,7 +4,8 @@ - -