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

Commit

Permalink
Merge pull request #94 from JrmCkh/show-next-ui-branch
Browse files Browse the repository at this point in the history
Add show next UI
  • Loading branch information
JrmCkh authored Mar 28, 2023
2 parents d474ad2 + dd6425d commit 9423864
Show file tree
Hide file tree
Showing 17 changed files with 270 additions and 66 deletions.
10 changes: 5 additions & 5 deletions src/main/java/ezschedule/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ public interface Logic {
*/
ReadOnlyScheduler getScheduler();

/**
* Returns an unmodifiable view of the upcoming list of events
*/
ObservableList<Event> getUpcomingEventList();

/**
* Returns an unmodifiable view of the list of events
*/
Expand All @@ -48,6 +43,11 @@ public interface Logic {
*/
ObservableList<Event> getFilteredEventList();

/**
* Returns an unmodifiable view of the upcoming list of events
*/
ObservableList<Event> getUpcomingEventList();

/**
* Updates the filtered list of events
*/
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/ezschedule/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ public ReadOnlyScheduler getScheduler() {
return model.getScheduler();
}

@Override
public ObservableList<Event> getUpcomingEventList() {
return model.getUpcomingEventList();
}

@Override
public ObservableList<Event> getEventList() {
return model.getEventList();
Expand All @@ -75,6 +70,11 @@ public ObservableList<Event> getFilteredEventList() {
return model.getFilteredEventList();
}

@Override
public ObservableList<Event> getUpcomingEventList() {
return model.getUpcomingEventList();
}

@Override
public void updateFilteredEventList(Predicate<Event> predicate) {
model.updateFilteredEventList(predicate);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/ezschedule/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public class DeleteCommand extends Command {
public static final String COMMAND_WORD = "delete";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the event identified by the index number used in the displayed event list.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 1";
+ ": Deletes the event identified by the index number used in the displayed event list.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_DELETE_EVENT_SUCCESS = "Deleted Event: %1$s";

Expand All @@ -47,7 +47,7 @@ public CommandResult execute(Model model) throws CommandException {
@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof DeleteCommand // instanceof handles nulls
&& targetIndex.equals(((DeleteCommand) other).targetIndex)); // state check
|| (other instanceof DeleteCommand // instanceof handles nulls
&& targetIndex.equals(((DeleteCommand) other).targetIndex)); // state check
}
}
5 changes: 3 additions & 2 deletions src/main/java/ezschedule/logic/commands/ShowNextCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public class ShowNextCommand extends Command {

public static final String COMMAND_WORD = "next";
public static final int SHOW_UPCOMING_COUNT_ONE = 1;

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Display upcoming events."
+ "\nCan be used without any parameters."
Expand All @@ -29,9 +30,9 @@ public ShowNextCommand(UpcomingEventPredicate predicate) {
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
model.updateFilteredEventList(predicate);
model.updateUpcomingEventList(predicate);
return new CommandResult(
String.format(Messages.MESSAGE_EVENTS_LISTED_OVERVIEW, model.getFilteredEventList().size()));
String.format(Messages.MESSAGE_EVENTS_LISTED_OVERVIEW, model.getUpcomingEventList().size()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ezschedule.logic.parser;

import static ezschedule.logic.commands.ShowNextCommand.SHOW_UPCOMING_COUNT_ONE;

import ezschedule.commons.core.Messages;
import ezschedule.logic.commands.ShowNextCommand;
import ezschedule.logic.parser.exceptions.ParseException;
Expand All @@ -20,7 +22,7 @@ public class ShowNextCommandParser implements Parser<ShowNextCommand> {
public ShowNextCommand parse(String userInput) throws ParseException {
// No argument provided, just show the next one
if (userInput.isBlank()) {
return new ShowNextCommand(new UpcomingEventPredicate(1));
return new ShowNextCommand(new UpcomingEventPredicate(SHOW_UPCOMING_COUNT_ONE));
}

try {
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/ezschedule/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ public interface Model {
*/
void setEvent(Event target, Event editedEvent);

/**
* Returns an unmodifiable view of the upcoming event list
*/
ObservableList<Event> getUpcomingEventList();

/**
* Returns an unmodifiable view of the event list
*/
Expand All @@ -101,10 +96,22 @@ public interface Model {
*/
ObservableList<Event> getFilteredEventList();

/**
* Returns an unmodifiable view of the upcoming event list
*/
ObservableList<Event> getUpcomingEventList();

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

/**
* Updates the filter of the upcoming event list to filter by the given {@code predicate}.
*
* @throws NullPointerException if {@code predicate} is null.
*/
void updateUpcomingEventList(Predicate<Event> predicate);
}
29 changes: 20 additions & 9 deletions src/main/java/ezschedule/model/ModelManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ezschedule.model;

import static ezschedule.commons.util.CollectionUtil.requireAllNonNull;
import static ezschedule.logic.commands.ShowNextCommand.SHOW_UPCOMING_COUNT_ONE;
import static java.util.Objects.requireNonNull;

import java.nio.file.Path;
Expand All @@ -10,18 +11,21 @@
import ezschedule.commons.core.GuiSettings;
import ezschedule.commons.core.LogsCenter;
import ezschedule.model.event.Event;
import ezschedule.model.event.UpcomingEventPredicate;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;

/**
* Represents the in-memory model of the scheduler data.
*/
public class ModelManager implements Model {

private static final Logger logger = LogsCenter.getLogger(ModelManager.class);

private final Scheduler scheduler;
private final UserPrefs userPrefs;
private final FilteredList<Event> filteredEvents;
private final FilteredList<Event> upcomingEvents;

/**
* Initializes a ModelManager with the given scheduler and userPrefs.
Expand All @@ -34,6 +38,8 @@ public ModelManager(ReadOnlyScheduler scheduler, ReadOnlyUserPrefs userPrefs) {
this.scheduler = new Scheduler(scheduler);
this.userPrefs = new UserPrefs(userPrefs);
filteredEvents = new FilteredList<>(this.scheduler.getEventList());
upcomingEvents = new FilteredList<>(this.scheduler.getEventList());
updateUpcomingEventList(new UpcomingEventPredicate(SHOW_UPCOMING_COUNT_ONE));
}

public ModelManager() {
Expand Down Expand Up @@ -102,31 +108,25 @@ public boolean hasEventAtTime(Event event) {
@Override
public void deleteEvent(Event target) {
scheduler.removeEvent(target);
updateUpcomingEventList(new UpcomingEventPredicate());
}

@Override
public void addEvent(Event event) {
scheduler.addEvent(event);
updateFilteredEventList(PREDICATE_SHOW_ALL_EVENTS);
updateUpcomingEventList(new UpcomingEventPredicate());
}

@Override
public void setEvent(Event target, Event editedEvent) {
requireAllNonNull(target, editedEvent);
scheduler.setEvent(target, editedEvent);
updateUpcomingEventList(new UpcomingEventPredicate());
}

//=========== Event List Accessors =============================================================

/**
* Returns an unmodifiable view of the list of {@code Event} backed by the internal list of
* {@code scheduler}
*/
@Override
public ObservableList<Event> getUpcomingEventList() {
return scheduler.getUpcomingEvents();
}

/**
* Returns an unmodifiable view of the list of {@code Event} backed by the internal list of
* {@code scheduler}
Expand All @@ -141,12 +141,23 @@ public ObservableList<Event> getFilteredEventList() {
return filteredEvents;
}

@Override
public ObservableList<Event> getUpcomingEventList() {
return upcomingEvents;
}

@Override
public void updateFilteredEventList(Predicate<Event> predicate) {
requireNonNull(predicate);
filteredEvents.setPredicate(predicate);
}

@Override
public void updateUpcomingEventList(Predicate<Event> predicate) {
requireNonNull(predicate);
upcomingEvents.setPredicate(predicate);
}

@Override
public boolean equals(Object obj) {
// short circuit if same object
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ezschedule/model/ReadOnlyScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import javafx.collections.ObservableList;

/**
* Unmodifiable view of an scheduler
* Unmodifiable view of the scheduler
*/
public interface ReadOnlyScheduler {

Expand Down
23 changes: 0 additions & 23 deletions src/main/java/ezschedule/model/Scheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,16 @@

import ezschedule.model.event.Event;
import ezschedule.model.event.UniqueEventList;
import ezschedule.model.event.UpcomingEventPredicate;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;

/**
* Wraps all data at the scheduler level
* Duplicates are not allowed (by .isSameEvent comparison)
*/
public class Scheduler implements ReadOnlyScheduler {
private static final int DISPLAY_UPCOMING_COUNT = 1;
private static final UpcomingEventPredicate predicate = new UpcomingEventPredicate(DISPLAY_UPCOMING_COUNT);

private final UniqueEventList events;

private FilteredList<Event> upcomingEvents;

/*
* The 'unusual' code block below is a non-static initialization block, sometimes used to avoid duplication
* between constructors. See https://docs.oracle.com/javase/tutorial/java/javaOO/initial.html
Expand All @@ -38,7 +32,6 @@ public class Scheduler implements ReadOnlyScheduler {
* Listeners are attached in here.
*/
public Scheduler() {
upcomingEvents = new FilteredList<>(getEventList());

// Attach a listener to auto-sort events in chronological order
events.addListChangeListener(c -> {
Expand All @@ -48,12 +41,6 @@ public Scheduler() {
}
}
});

events.addListChangeListener(c -> {
while (c.next()) { /* Do nothing */ }
upcomingEvents.setPredicate(predicate);
});

}

/**
Expand Down Expand Up @@ -126,17 +113,7 @@ public void removeEvent(Event key) {
events.remove(key);
}

/**
* Returns the list of upcoming {@code Event}
*
* @return
*/
public FilteredList<Event> getUpcomingEvents() {
return upcomingEvents;
}

//// util methods

@Override
public String toString() {
return events.asUnmodifiableObservableList().size() + " events";
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/ezschedule/model/event/UpcomingEventPredicate.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,22 @@
*/
public class UpcomingEventPredicate implements Predicate<Event> {

private int upcomingCount;
private static int upcomingCount;
private int count;

/**
* Constructor for UpcomingEventPredicate to reuse the given count.
*/
public UpcomingEventPredicate() {
count = upcomingCount;
}

/**
* Constructor for UpcomingEventPredicate with given count.
*/
public UpcomingEventPredicate(int count) {
upcomingCount = count;
this.count = count;
}

// Events should be in chronological order
Expand All @@ -21,13 +33,13 @@ public boolean test(Event event) {
return false;
}

return upcomingCount-- > 0;
return count-- > 0;
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof UpcomingEventPredicate // instanceof handles nulls
&& upcomingCount == ((UpcomingEventPredicate) other).upcomingCount); // state check
&& count == ((UpcomingEventPredicate) other).count); // state check
}
}
10 changes: 10 additions & 0 deletions src/main/java/ezschedule/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class MainWindow extends UiPart<Stage> {

// Independent Ui parts residing in this Ui container
private EventListPanel eventListPanel;
private ShowNextPanel showNextPanel;
private ResultDisplay resultDisplay;

@FXML
Expand All @@ -46,6 +47,8 @@ public class MainWindow extends UiPart<Stage> {
@FXML
private StackPane statusbarPlaceholder;
@FXML
private StackPane showNextPlaceholder;
@FXML
private StackPane calendarPlaceholder;

/**
Expand Down Expand Up @@ -121,6 +124,9 @@ void fillInnerParts() {
CommandBox commandBox = new CommandBox(this::executeCommand);
commandBoxPlaceholder.getChildren().add(commandBox.getRoot());

showNextPanel = new ShowNextPanel(logic.getUpcomingEventList());
showNextPlaceholder.getChildren().add(showNextPanel.getRoot());

Calendar calendar = new Calendar(logic.getEventList(), logic::updateFilteredEventList);
calendarPlaceholder.getChildren().add(calendar.getRoot());
}
Expand Down Expand Up @@ -169,6 +175,10 @@ public EventListPanel getEventListPanel() {
return eventListPanel;
}

public ShowNextPanel getShowPanel() {
return showNextPanel;
}

/**
* Executes the command and returns the result.
*
Expand Down
Loading

0 comments on commit 9423864

Please sign in to comment.