Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY1819S2#90 from yonggqiii/master
Browse files Browse the repository at this point in the history
Trying this pull request now
  • Loading branch information
jwl1997 authored Mar 27, 2019
2 parents bd36dbb + 534cfa7 commit e4d866d
Show file tree
Hide file tree
Showing 14 changed files with 152 additions and 25 deletions.
17 changes: 17 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,21 @@ public interface Logic {
* @see seedu.address.model.Model#setSelectedPerson(Person)
*/
void setSelectedPerson(Person person);

/**
* Selected event in the filtered event list.
* null if no event is selected.
*
* @see seedu.address.model.Model#selectedEventProperty()
*/
ReadOnlyProperty<Event> selectedEventProperty();

/**
* Sets the selected event in the filtered event list.
*
* @see seedu.address.model.Model#setSelectedEvent(Event)
*/
void setSelectedEvent(Event event);

Person getSelectedPerson();
}
11 changes: 11 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,15 @@ public void setSelectedPerson(Person person) {
model.setSelectedPerson(person);
}

@Override
public Person getSelectedPerson() { return model.getSelectedPerson(); }

@Override
public ReadOnlyProperty<Event> selectedEventProperty() { return model.selectedEventProperty(); }

@Override
public void setSelectedEvent(Event event) {
model.setSelectedEvent(event);
}
}

18 changes: 17 additions & 1 deletion src/main/java/seedu/address/logic/commands/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,35 @@ public class CommandResult {
/** The application should exit. */
private final boolean exit;

/** The application should switch views. */
private final boolean switchView;

/**
* Constructs a {@code CommandResult} with the specified fields.
*/
public CommandResult(String feedbackToUser, boolean showHelp, boolean exit, boolean switchView) {
this.feedbackToUser = requireNonNull(feedbackToUser);
this.showHelp = showHelp;
this.exit = exit;
this.switchView = switchView;
}

/**
* Constructs a {@code CommandResult} with the specified showHelp and exit fields.
*/
public CommandResult(String feedbackToUser, boolean showHelp, boolean exit) {
this.feedbackToUser = requireNonNull(feedbackToUser);
this.showHelp = showHelp;
this.exit = exit;
this.switchView = false;
}

/**
* Constructs a {@code CommandResult} with the specified {@code feedbackToUser},
* and other fields set to their default value.
*/
public CommandResult(String feedbackToUser) {
this(feedbackToUser, false, false);
this(feedbackToUser, false, false, false);
}

public String getFeedbackToUser() {
Expand All @@ -46,6 +60,8 @@ public boolean isExit() {
return exit;
}

public boolean isSwitchView() { return switchView; }

@Override
public boolean equals(Object other) {
if (other == this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ExitCommand extends Command {

@Override
public CommandResult execute(Model model, CommandHistory history) {
return new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, false, true);
return new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, false, true, false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public class HelpCommand extends Command {

@Override
public CommandResult execute(Model model, CommandHistory history) {
return new CommandResult(SHOWING_HELP_MESSAGE, true, false);
return new CommandResult(SHOWING_HELP_MESSAGE, true, false, false);
}
}
24 changes: 24 additions & 0 deletions src/main/java/seedu/address/logic/commands/SwitchCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package seedu.address.logic.commands;

import seedu.address.logic.CommandHistory;
import seedu.address.model.Model;

/**
* Switches the view from Person view to Events view, and vice versa.
*/
public class SwitchCommand extends Command {

public static final String COMMAND_WORD = "switch";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Switches to the next view.\n"
+ "Example: " + COMMAND_WORD
+ " will switch to Events view from Person view, and vice versa";

public static final String SHOWING_SWITCH_MESSAGE = "Switched view.";

@Override
public CommandResult execute(Model model, CommandHistory history) {
return new CommandResult(SHOWING_SWITCH_MESSAGE, false, false, true);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import seedu.address.logic.commands.PhotoCommand;
import seedu.address.logic.commands.RedoCommand;
import seedu.address.logic.commands.SelectCommand;
import seedu.address.logic.commands.SwitchCommand;
import seedu.address.logic.commands.UndoCommand;

import seedu.address.logic.parser.exceptions.ParseException;
Expand Down Expand Up @@ -79,6 +80,9 @@ public Command parseCommand(String userInput) throws ParseException {
case SelectCommand.COMMAND_WORD:
return new SelectCommandParser().parse(arguments);

case SwitchCommand.COMMAND_WORD:
return new SwitchCommand();

case DeleteCommand.COMMAND_WORD:
return new DeleteCommandParser().parse(arguments);

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/ui/EventCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class EventCard extends UiPart<Region> {
@FXML
private Label endDateTime;
@FXML
private FlowPane persons;
private FlowPane tags;

public EventCard(Event event, int displayedIndex) {
super(FXML);
Expand All @@ -47,7 +47,7 @@ public EventCard(Event event, int displayedIndex) {
venue.setText(event.getVenue().value);
startDateTime.setText(event.getStartDateTime().value);
endDateTime.setText(event.getEndDateTime().value);
event.getPersons().forEach(person -> persons.getChildren().add(new Label(person.getName().fullName)));
tags.getChildren().add(new Label(event.getLabel().toString()));
}

@Override
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/seedu/address/ui/EventListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
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.event.Event;

/**
* Panel containing the list of events.
*/
public class EventListPanel extends UiPart<Region> {

public class EventListPanel extends ListPanel {
private static final String FXML = "EventListPanel.fxml";
private final Logger logger = LogsCenter.getLogger(PersonListPanel.class);
private final Logger logger = LogsCenter.getLogger(EventListPanel.class);

@FXML
private ListView<Event> eventListView;
Expand All @@ -29,11 +29,11 @@ public EventListPanel(ObservableList<Event> eventList, ObservableValue<Event> se
eventListView.setItems(eventList);
eventListView.setCellFactory(listView -> new EventListViewCell());
eventListView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
logger.fine("Selection in person list panel changed to : '" + newValue + "'");
logger.fine("Selection in event list panel changed to : '" + newValue + "'");
onSelectedEventChange.accept(newValue);
});
selectedEvent.addListener((observable, oldValue, newValue) -> {
logger.fine("Selected person changed to: " + newValue);
logger.fine("Selected event changed to: " + newValue);

// Don't modify selection if we are already selecting the selected person,
// otherwise we would have an infinite loop.
Expand All @@ -52,7 +52,7 @@ public EventListPanel(ObservableList<Event> eventList, ObservableValue<Event> se
}

/**
* Custom {@code ListCell} that displays the graphics of a {@code Event} using am {@code EventCard}.
* Custom {@code ListCell} that displays the graphics of a {@code Event} using an {@code EventCard}.
*/
class EventListViewCell extends ListCell<Event> {
@Override
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/seedu/address/ui/ListPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package seedu.address.ui;

import javafx.scene.layout.Region;

/**
* This abstract class allows for different types of ListPanels to be created.
*/
public abstract class ListPanel extends UiPart<Region> {

ListPanel(String fxml) {
super(fxml);
}

}
62 changes: 52 additions & 10 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
public class MainWindow extends UiPart<Stage> {

private static final String FXML = "MainWindow.fxml";
private static final int WINDOW_STATE_SHOW_PERSONS = 0;
private static final int WINDOW_STATE_SHOW_EVENTS = 1;

private final Logger logger = LogsCenter.getLogger(getClass());

Expand All @@ -30,9 +32,10 @@ public class MainWindow extends UiPart<Stage> {

// Independent Ui parts residing in this Ui container
private BrowserPanel browserPanel;
private PersonListPanel personListPanel;
private ListPanel listPanel;
private ResultDisplay resultDisplay;
private HelpWindow helpWindow;
private int currentState;

@FXML
private StackPane browserPlaceholder;
Expand All @@ -44,7 +47,7 @@ public class MainWindow extends UiPart<Stage> {
private MenuItem helpMenuItem;

@FXML
private StackPane personListPanelPlaceholder;
private StackPane listPanelPlaceholder;

@FXML
private StackPane resultDisplayPlaceholder;
Expand All @@ -58,6 +61,7 @@ public MainWindow(Stage primaryStage, Logic logic) {
// Set dependencies
this.primaryStage = primaryStage;
this.logic = logic;
this.currentState = WINDOW_STATE_SHOW_PERSONS;

// Configure the UI
setWindowDefaultSize(logic.getGuiSettings());
Expand Down Expand Up @@ -109,12 +113,7 @@ private void setAccelerator(MenuItem menuItem, KeyCombination keyCombination) {
* Fills up all the placeholders of this window.
*/
void fillInnerParts() {
browserPanel = new BrowserPanel(logic.selectedPersonProperty());
browserPlaceholder.getChildren().add(browserPanel.getRoot());

personListPanel = new PersonListPanel(logic.getFilteredPersonList(), logic.selectedPersonProperty(),
logic::setSelectedPerson);
personListPanelPlaceholder.getChildren().add(personListPanel.getRoot());
resetView();

resultDisplay = new ResultDisplay();
resultDisplayPlaceholder.getChildren().add(resultDisplay.getRoot());
Expand All @@ -126,6 +125,46 @@ void fillInnerParts() {
commandBoxPlaceholder.getChildren().add(commandBox.getRoot());
}

/**
* Switches the view of the UI when the switch command is entered.
*/
void handleSwitch() {
this.currentState += 1;
this.currentState = this.currentState % 2;
resetView();
}

/**
* Resets the view given the current state of the UI.
*/
void resetView() {
listPanelPlaceholder.getChildren().clear();
browserPlaceholder.getChildren().clear();
if (currentState == WINDOW_STATE_SHOW_PERSONS) {
browserPanel = new BrowserPanel(logic.selectedPersonProperty());
browserPlaceholder.getChildren().add(browserPanel.getRoot());
listPanel = new PersonListPanel(logic.getFilteredPersonList(), logic.selectedPersonProperty(),
logic::setSelectedPerson);
listPanelPlaceholder.getChildren().add(listPanel.getRoot());
} else if (currentState == WINDOW_STATE_SHOW_EVENTS) {
browserPanel = new BrowserPanel(logic.selectedPersonProperty());
browserPlaceholder.getChildren().add(browserPanel.getRoot());
listPanel = new EventListPanel(logic.getFilteredEventList(), logic.selectedEventProperty(),
logic::setSelectedEvent);
listPanelPlaceholder.getChildren().add(listPanel.getRoot());
}
}

void handlePersonCommand() {
this.currentState = WINDOW_STATE_SHOW_PERSONS;
resetView();
}

void handleEventCommand() {
this.currentState = WINDOW_STATE_SHOW_EVENTS;
resetView();
}

/**
* Sets the default size based on {@code guiSettings}.
*/
Expand Down Expand Up @@ -166,8 +205,8 @@ private void handleExit() {
primaryStage.hide();
}

public PersonListPanel getPersonListPanel() {
return personListPanel;
public ListPanel getListPanel() {
return listPanel;
}

/**
Expand All @@ -189,6 +228,9 @@ private CommandResult executeCommand(String commandText) throws CommandException
handleExit();
}

if (commandResult.isSwitchView()) {
handleSwitch();
}
return commandResult;
} catch (CommandException | ParseException e) {
logger.info("Invalid command: " + commandText);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/seedu/address/ui/PersonListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
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.person.Person;

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

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/view/EventListCard.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</Label>
<Label fx:id="name" text="\$name" styleClass="cell_big_label" />
</HBox>
<FlowPane fx:id="persons" />
<FlowPane fx:id="tags" />
<Label fx:id="venue" styleClass="cell_small_label" text="\$venue" />
<Label fx:id="startDateTime" styleClass="cell_small_label" text="\$startDateTime" />
<Label fx:id="endDateTime" styleClass="cell_small_label" text="\$endDateTime" />
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/view/MainWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<padding>
<Insets top="10" right="10" bottom="10" left="10" />
</padding>
<StackPane fx:id="personListPanelPlaceholder" VBox.vgrow="ALWAYS"/>
<StackPane fx:id="listPanelPlaceholder" VBox.vgrow="ALWAYS"/>
</VBox>

<StackPane fx:id="browserPlaceholder" prefWidth="340" >
Expand Down

0 comments on commit e4d866d

Please sign in to comment.