forked from nus-cs2103-AY2324S2/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 #96 from ananya21/add-comment
Created addCommentCommand.java
- Loading branch information
Showing
11 changed files
with
308 additions
and
2 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
src/main/java/seedu/address/logic/commands/AddCommentCommand.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,89 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.project.Comment; | ||
import seedu.address.model.project.Member; | ||
|
||
/** | ||
* Adds a project to the DevPlanPro. | ||
*/ | ||
public class AddCommentCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "add comment"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + " /from PERSON_NAME" | ||
+ " /in PROJECT_NAME"; | ||
|
||
public static final String MESSAGE_SUCCESS = "The comment %1$s has been added to the project %2$s."; | ||
|
||
public static final String MESSAGE_PROJECT_NOT_FOUND = "Project %1$s not found: " | ||
+ "Please make sure the project exists."; | ||
|
||
public static final String MESSAGE_MEMBER_NOT_FOUND = "Team member %1s not found: " | ||
+ "Please make sure the person exists."; | ||
|
||
private final Person commentProject; | ||
|
||
private final Member commentFrom; | ||
|
||
private Comment comment; | ||
|
||
/** | ||
* Creates an AddCommand to add the specified {@code Person} | ||
*/ | ||
public AddCommentCommand(Person project, Member member, String comment) { | ||
requireNonNull(project); | ||
this.commentProject = project; | ||
this.commentFrom = member; | ||
this.comment = new Comment(comment, member); | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
if (!model.hasPerson(commentProject)) { | ||
throw new CommandException(String.format(MESSAGE_PROJECT_NOT_FOUND, | ||
Messages.format(commentProject))); | ||
} | ||
|
||
Person foundProject = model.findPerson(commentProject.getName()); | ||
|
||
if (!foundProject.hasMember(commentFrom)) { | ||
throw new CommandException(String.format(MESSAGE_MEMBER_NOT_FOUND, commentFrom)); | ||
} | ||
|
||
Person project = model.findPerson(commentProject.getName()); | ||
project.addComment(comment); | ||
|
||
return new CommandResult(String.format(MESSAGE_SUCCESS, comment, Messages.format(commentProject))); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof AddCommentCommand)) { | ||
return false; | ||
} | ||
|
||
AddCommentCommand otherAddCommentCommand = (AddCommentCommand) other; | ||
return commentProject.equals(otherAddCommentCommand.commentProject); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("Project", commentProject) | ||
.toString(); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/seedu/address/logic/parser/AddCommentCommandParser.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,52 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.logic.commands.AddCommentCommand; | ||
import seedu.address.logic.commands.AddTaskCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.person.Name; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.project.Member; | ||
|
||
|
||
/** | ||
* Parses input arguments and creates a new AddProjectCommand object | ||
*/ | ||
public class AddCommentCommandParser implements Parser<AddCommentCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the AddProjectCommand | ||
* and returns an AddProjectCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public AddCommentCommand parse(String args) throws ParseException { | ||
try { | ||
if (!args.contains(" /from ")) { // Check if the input correctly uses "/to" | ||
throw new ParseException(String.format( | ||
MESSAGE_INVALID_COMMAND_FORMAT, | ||
AddCommentCommand.MESSAGE_USAGE)); | ||
} | ||
if (!args.contains(" /in ")) { // Check if the input correctly uses "/to" | ||
throw new ParseException(String.format( | ||
MESSAGE_INVALID_COMMAND_FORMAT, | ||
AddCommentCommand.MESSAGE_USAGE)); | ||
} | ||
String comment = args.split(" /from")[0]; | ||
String memberAndProject = args.split(" /from ")[1]; | ||
if ((comment.length() == 0) || (comment.length() == 0)) { | ||
throw new ParseException("Please enter a comment"); | ||
} | ||
String memberName = memberAndProject.split(" /in")[0]; | ||
Member member = new Member(memberName); | ||
String projectName = memberAndProject.split(" /in")[1]; | ||
Name name = ParserUtil.parseName(projectName); | ||
Person project = new Person(name); | ||
return new AddCommentCommand(project, member, comment); | ||
} catch (ArrayIndexOutOfBoundsException e) { | ||
throw new ParseException(String.format( | ||
MESSAGE_INVALID_COMMAND_FORMAT, | ||
AddTaskCommand.MESSAGE_USAGE)); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package seedu.address.model.project; | ||
|
||
/** | ||
* Comments within projects | ||
* comments have a string field and a member field | ||
*/ | ||
public class Comment { | ||
private String comment; | ||
private Member member; | ||
|
||
/** | ||
* constructor for comment object | ||
* @param comment comment in string format | ||
* @param member person who made the comment | ||
*/ | ||
public Comment(String comment, Member member) { | ||
this.comment = comment; | ||
this.member = member; | ||
} | ||
|
||
/** | ||
* @return project member who made the comment | ||
*/ | ||
public Member getMember() { | ||
return member; | ||
} | ||
|
||
/** | ||
* @return comment in string format | ||
*/ | ||
@Override | ||
public String toString() { | ||
return comment; | ||
} | ||
} |
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,43 @@ | ||
package seedu.address.ui; | ||
|
||
import javafx.fxml.FXML; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.layout.HBox; | ||
import javafx.scene.layout.Region; | ||
import seedu.address.model.project.Comment; | ||
import seedu.address.model.project.Member; | ||
|
||
/** | ||
* Container for comments written within projects | ||
*/ | ||
public class CommentCard extends UiPart<Region> { | ||
private static final String FXML = "CommentListCard.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> | ||
*/ | ||
|
||
private final Member member; | ||
|
||
@FXML | ||
private HBox cardPane; | ||
@FXML | ||
private Label name; | ||
|
||
@FXML | ||
private Label comment; | ||
|
||
/** | ||
* Creates a {@code PersonCode} with the given {@code Person} and index to display. | ||
*/ | ||
public CommentCard(Comment commentAdd) { | ||
super(FXML); | ||
this.member = commentAdd.getMember(); | ||
name.setText(member.getName().fullName); | ||
comment.setText(commentAdd.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
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,27 @@ | ||
<?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.VBox?> | ||
|
||
<HBox id="taskCardPane" fx:id="taskCardPane" xmlns="http://javafx.com/javafx/17" 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 top="5" right="5" bottom="5" left="15" /> | ||
</padding> | ||
<HBox spacing="5" alignment="CENTER_LEFT"> | ||
<Label fx:id="name" text="\$first" styleClass="cell_big_label" /> | ||
</HBox> | ||
<Label fx:id="comment" styleClass="cell_small_label" text="\$comment" /> | ||
</VBox> | ||
</GridPane> | ||
</HBox> |
Oops, something went wrong.