Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY1819S2#82 from yonggqiii/MASTER
Browse files Browse the repository at this point in the history
Created files necessary for event viewing in UI
  • Loading branch information
JiaruiWang-Jill authored Mar 26, 2019
2 parents f3e8ddf + 24655fd commit bd36dbb
Show file tree
Hide file tree
Showing 9 changed files with 349 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.event.Event;
import seedu.address.model.person.Person;

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

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

/**
* 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.
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.event.Event;
import seedu.address.model.person.Person;
import seedu.address.storage.Storage;

Expand Down Expand Up @@ -76,6 +77,9 @@ public ObservableList<Person> getFilteredPersonList() {
return model.getFilteredPersonList();
}

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

@Override
public ObservableList<String> getHistory() {
return history.getHistory();
Expand Down
29 changes: 27 additions & 2 deletions src/main/java/seedu/address/logic/commands/MeetCommand.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;

/**
* {@code MeetCommand} forms a meeting event with a list of persons.
Expand All @@ -20,18 +26,37 @@ public class MeetCommand extends Command {
+ "Parameters: INDEX\n"
+ "Example: " + COMMAND_WORD + " 1 4 5";

private Set<Integer> indices;
private List<Index> indices;
private List<Person> listOfPeopleSelected;

/**
* Creates a MeetCommand using a Set of integers based on the one-based index.
* @param indices The set of integers to be processed.
*/
public MeetCommand(Set<Integer> indices) {
this.indices = indices;
requireNonNull(indices);
this.indices = new ArrayList<>();
for (Integer i : indices) {
this.indices.add(Index.fromOneBased(i));
}
this.listOfPeopleSelected = new ArrayList<>();
}

@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
// Create the command result.
requireNonNull(model);

// Get the people that need to be operated on.
List<Person> listOfPeopleShown = model.getFilteredPersonList();
List<Person> personsOperatedOn = new ArrayList<>();
for (Index i : indices) {
personsOperatedOn.add(listOfPeopleShown.get(i.getZeroBased()));
}

//Only show people you want to meet
model.updateFilteredPersonList(x -> personsOperatedOn.contains(x));

throw new CommandException(MESSAGE_NOT_IMPLEMENTED);
}
}
70 changes: 70 additions & 0 deletions src/main/java/seedu/address/ui/EventCard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package seedu.address.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.address.model.event.Event;

/**
* A UI component that displays information of a {@code Event}.
*/
public class EventCard extends UiPart<Region> {

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

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

public final Event event;

@FXML
private HBox cardPane;
@FXML
private Label name;
@FXML
private Label id;
@FXML
private Label venue;
@FXML
private Label startDateTime;
@FXML
private Label endDateTime;
@FXML
private FlowPane persons;

public EventCard(Event event, int displayedIndex) {
super(FXML);
this.event = event;
id.setText(displayedIndex + ". ");
name.setText(event.getName().fullName);
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)));
}

@Override
public boolean equals(Object other) {
// short circuit if same object
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof EventCard)) {
return false;
}

// state check
EventCard card = (EventCard) other;
return id.getText().equals(card.id.getText())
&& event.equals(card.event);
}
}
86 changes: 86 additions & 0 deletions src/main/java/seedu/address/ui/EventInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package seedu.address.ui;

import java.util.logging.Logger;

import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.layout.Region;
import seedu.address.commons.core.LogsCenter;
import seedu.address.model.event.Event;

/**
* The person info display person info
*/
public class EventInfo extends UiPart<Region> {

public static final String FXML = "EventInfo.fxml";
public static final String DEFAULT_DESCRIPTION = "This is a default description";

@FXML
private Label titleNameLabel;
@FXML
private Label nameLabel;
@FXML
private Label venueLabel;
@FXML
private Label tagLabel;
@FXML
private Label startsOnLabel;
@FXML
private Label endsOnLabel;
@FXML
private Label descriptionLabel;

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

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


public EventInfo(ObservableValue<Event> selectedEvent) {
super(FXML);
showEventDetails(null);
// Load person page when selected person changes.
selectedEvent.addListener((observable, oldValue, newValue) ->
showEventDetails(newValue));
}

/**
* Fills all text fields to show details about the event.
* If the specified event is null, all text fields are cleared.
*
* @param event the event or null
*/
private void showEventDetails(Event event) {
if (event != null) {
// Fill the labels with info from the person object.
titleNameLabel.setText(event.getName().toString());
nameLabel.setText(event.getName().toString());
venueLabel.setText(event.getVenue().toString());
startsOnLabel.setText(event.getStartDateTime().toString());
endsOnLabel.setText(event.getEndDateTime().toString());
tagLabel.setText(event.getLabel().toString());
descriptionLabel.setText(DEFAULT_DESCRIPTION);

} else {
// Event is null, remove all the text.
nameLabel.setText("");
venueLabel.setText("");
startsOnLabel.setText("");
endsOnLabel.setText("");
tagLabel.setText("");
descriptionLabel.setText(DEFAULT_DESCRIPTION);
}
}
}





71 changes: 71 additions & 0 deletions src/main/java/seedu/address/ui/EventListPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package seedu.address.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.address.commons.core.LogsCenter;
import seedu.address.model.event.Event;

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

@FXML
private ListView<Event> eventListView;

public EventListPanel(ObservableList<Event> eventList, ObservableValue<Event> selectedEvent,
Consumer<Event> onSelectedEventChange) {
super(FXML);
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 + "'");
onSelectedEventChange.accept(newValue);
});
selectedEvent.addListener((observable, oldValue, newValue) -> {
logger.fine("Selected person changed to: " + newValue);

// Don't modify selection if we are already selecting the selected person,
// otherwise we would have an infinite loop.
if (Objects.equals(eventListView.getSelectionModel().getSelectedItem(), newValue)) {
return;
}

if (newValue == null) {
eventListView.getSelectionModel().clearSelection();
} else {
int index = eventListView.getItems().indexOf(newValue);
eventListView.scrollTo(index);
eventListView.getSelectionModel().clearAndSelect(index);
}
});
}

/**
* Custom {@code ListCell} that displays the graphics of a {@code Event} using am {@code EventCard}.
*/
class EventListViewCell extends ListCell<Event> {
@Override
protected void updateItem(Event event, boolean empty) {
super.updateItem(event, empty);

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

}
43 changes: 43 additions & 0 deletions src/main/resources/view/EventInfo.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Label?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>

<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<GridPane layoutX="44.0" layoutY="187.0" prefHeight="209.0" prefWidth="406.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Name" />
<Label text="Venue" GridPane.rowIndex="1" />
<Label text="Starts on" GridPane.rowIndex="2" />
<Label fx:id="nameLabel" styleClass="label-bright" text="Label" GridPane.columnIndex="1" />
<Label fx:id="venueLabel" styleClass="label-bright" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label fx:id="startsOnLabel" styleClass="label-bright" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label text="Ends on" GridPane.rowIndex="3" />
<Label fx:id="endsOnLabel" styleClass="label-bright" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label text="Description" GridPane.rowIndex="5" />
<Label fx:id="descriptionLabel" styleClass="label-bright" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="5" />
<Label text="Labels" GridPane.rowIndex="4" />
<Label fx:id="tagLabel" styleClass="label-bright" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="4" />
</children>
</GridPane>
<Label fx:id="titleNameLabel" layoutX="264.0" layoutY="89.0" styleClass="label-bright" text="Name" />
</children>
</AnchorPane>

Loading

0 comments on commit bd36dbb

Please sign in to comment.