forked from nus-cs2103-AY2122S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from yongxiangng/branch-feature-details
Implement details command
- Loading branch information
Showing
19 changed files
with
461 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/seedu/address/logic/commands/DetailsCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.NameEqualKeywordPredicate; | ||
|
||
/** | ||
* Finds and displays the details of person whose name matches the keyword exactly. | ||
* Keyword matching is exact and case sensitive. | ||
*/ | ||
public class DetailsCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "details"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Displays the details of a member from the " | ||
+ "specified keywords (case-sensitive and exact match).\n" | ||
+ "Parameters: NAME (case-sensitive)\n" | ||
+ "Example: " + COMMAND_WORD + " Xiao Ming"; | ||
|
||
private final NameEqualKeywordPredicate predicate; | ||
|
||
public DetailsCommand(NameEqualKeywordPredicate predicate) { | ||
this.predicate = predicate; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
requireNonNull(model); | ||
model.updateFilteredPersonList(predicate); | ||
assert model.getFilteredPersonList().size() < 2; | ||
if (model.getFilteredPersonList().size() == 0) { | ||
return new CommandResult( | ||
String.format(Messages.MESSAGE_PERSON_DETAILS_NOT_FOUND, predicate), | ||
false, false, true); | ||
} else { | ||
return new CommandResult( | ||
String.format(Messages.MESSAGE_PERSON_DETAILS_FOUND, predicate), | ||
false, false, true); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof DetailsCommand // instanceof handles nulls | ||
&& predicate.equals(((DetailsCommand) other).predicate)); // state check | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/seedu/address/logic/parser/DetailsCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.logic.commands.DetailsCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.person.Name; | ||
import seedu.address.model.person.NameEqualKeywordPredicate; | ||
|
||
/** | ||
* Parses input arguments and creates a new DetailsCommand object | ||
*/ | ||
public class DetailsCommandParser implements Parser<DetailsCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the DetailsCommand | ||
* and returns a DetailsCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public DetailsCommand parse(String args) throws ParseException { | ||
try { | ||
Name name = ParserUtil.parseName(args); | ||
return new DetailsCommand(new NameEqualKeywordPredicate(name)); | ||
} catch (ParseException pe) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, DetailsCommand.MESSAGE_USAGE)); | ||
} | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/seedu/address/model/person/NameEqualKeywordPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package seedu.address.model.person; | ||
|
||
import java.util.function.Predicate; | ||
|
||
/** | ||
* Tests that a {@code Person}'s {@code Name} matches the keyword given exactly. | ||
*/ | ||
public class NameEqualKeywordPredicate implements Predicate<Person> { | ||
private final Name keyword; | ||
|
||
public NameEqualKeywordPredicate(Name keyword) { | ||
this.keyword = keyword; | ||
} | ||
|
||
@Override | ||
public boolean test(Person person) { | ||
return keyword.equals(person.getName()); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof NameEqualKeywordPredicate // instanceof handles nulls | ||
&& keyword.equals(((NameEqualKeywordPredicate) other).keyword)); // state check | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.keyword.toString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package seedu.address.ui; | ||
|
||
import java.util.Comparator; | ||
|
||
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.person.Person; | ||
|
||
/** | ||
* An UI component that displays the detailed information of a {@code Person}. | ||
*/ | ||
public class PersonDetailsCard extends UiPart<Region> { | ||
|
||
private static final String FXML = "PersonDetailsCard.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 Person person; | ||
|
||
@FXML | ||
private HBox cardPane; | ||
@FXML | ||
private Label name; | ||
@FXML | ||
private Label phone; | ||
@FXML | ||
private Label address; | ||
@FXML | ||
private Label email; | ||
@FXML | ||
private FlowPane tags; | ||
|
||
/** | ||
* Creates a {@code PersonDetailsCard} with the given {@code Person}. | ||
*/ | ||
public PersonDetailsCard(Person person) { | ||
super(FXML); | ||
this.person = person; | ||
name.setText(person.getName().fullName); | ||
phone.setText(person.getPhone().value); | ||
address.setText(person.getAddress().value); | ||
email.setText(person.getEmail().value); | ||
person.getTags().stream() | ||
.sorted(Comparator.comparing(tag -> tag.tagName)) | ||
.forEach(tag -> tags.getChildren().add(new Label(tag.tagName))); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
// short circuit if same object | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof PersonDetailsCard)) { | ||
return false; | ||
} | ||
|
||
// state check | ||
PersonDetailsCard card = (PersonDetailsCard) other; | ||
return person.equals(card.person); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.geometry.Insets?> | ||
<?import javafx.scene.control.Label?> | ||
<?import javafx.scene.layout.ColumnConstraints?> | ||
<?import javafx.scene.layout.FlowPane?> | ||
<?import javafx.scene.layout.GridPane?> | ||
<?import javafx.scene.layout.HBox?> | ||
<?import javafx.scene.layout.Region?> | ||
<?import javafx.scene.layout.RowConstraints?> | ||
<?import javafx.scene.layout.VBox?> | ||
|
||
<HBox id="cardPane" fx:id="cardPane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"> | ||
<GridPane HBox.hgrow="ALWAYS"> | ||
<columnConstraints> | ||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10" prefWidth="150" /> | ||
</columnConstraints> | ||
<VBox alignment="CENTER_LEFT" minHeight="105" GridPane.columnIndex="0"> | ||
<padding> | ||
<Insets bottom="5" left="15" right="5" top="5" /> | ||
</padding> | ||
<HBox alignment="CENTER_LEFT" spacing="5"> | ||
<Label fx:id="name" styleClass="cell_big_label" text="\$first" /> | ||
<Label fx:id="id" styleClass="cell_big_label" text="details"> | ||
<minWidth> | ||
<!-- Ensures that the label text is never truncated --> | ||
<Region fx:constant="USE_PREF_SIZE" /> | ||
</minWidth> | ||
</Label> | ||
</HBox> | ||
<FlowPane fx:id="tags" /> | ||
<Label fx:id="phone" styleClass="cell_small_label" text="\$phone" /> | ||
<Label fx:id="address" styleClass="cell_small_label" text="\$address" /> | ||
<Label fx:id="email" styleClass="cell_small_label" text="\$email" /> | ||
</VBox> | ||
<rowConstraints> | ||
<RowConstraints /> | ||
</rowConstraints> | ||
</GridPane> | ||
</HBox> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.