Skip to content

Commit

Permalink
Merge pull request #58 from tyouwei/GUI
Browse files Browse the repository at this point in the history
GUI Improvements
  • Loading branch information
tyouwei authored Oct 19, 2023
2 parents 8620019 + 097dda3 commit 11901a0
Show file tree
Hide file tree
Showing 34 changed files with 386 additions and 70 deletions.
24 changes: 21 additions & 3 deletions src/main/java/seedu/letsgethired/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,28 @@ public static String getErrorMessageForDuplicatePrefixes(Prefix... duplicatePref
/**
* Formats the {@code internApplication} for display to the user.
*/
public static String format(InternApplication internApplication) {
public static String formatDisplay(InternApplication internApplication) {
final StringBuilder builder = new StringBuilder();
builder.append(internApplication.getCompany())
builder.append("Company: ")
.append(internApplication.getCompany())
.append("\nRole: ")
.append(internApplication.getRole())
.append("\nCycle: ")
.append(internApplication.getCycle())
.append("\nStatus: ")
.append(internApplication.getStatus())
.append("\nNotes: ")
.append(internApplication.getNote());
return builder.toString();
}

/**
* Formats the {@code internApplication} for feedback to the user.
*/
public static String formatFeedback(InternApplication internApplication) {
final StringBuilder builder = new StringBuilder();
builder.append("Company: ")
.append(internApplication.getCompany())
.append("; Role: ")
.append(internApplication.getRole())
.append("; Cycle: ")
Expand All @@ -48,5 +67,4 @@ public static String format(InternApplication internApplication) {
.append(internApplication.getNote());
return builder.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class AddCommand extends Command {
+ PREFIX_CYCLE + "Summer 2024"
+ PREFIX_STATUS + "Accepted";

public static final String MESSAGE_SUCCESS = "New intern application added: %1$s";
public static final String MESSAGE_SUCCESS = "New intern application added";
public static final String MESSAGE_DUPLICATE_INTERN_APPLICATION =
"This application already exists in the intern tracker";

Expand All @@ -55,7 +55,7 @@ public CommandResult execute(Model model) throws CommandException {
}

model.addInternApplication(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd)));
return new CommandResult(MESSAGE_SUCCESS, Messages.formatDisplay(toAdd));
}

@Override
Expand Down
33 changes: 29 additions & 4 deletions src/main/java/seedu/letsgethired/logic/commands/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,50 @@ public class CommandResult {
/** The application should exit. */
private final boolean exit;

private final String detailsToUser;

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

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

/**
* Constructs a {@code CommandResult} with the specified {@code feedbackToUser}, {@code showHelp} and {@code exit},
* and other fields set to their default value.
*/
public CommandResult(String feedbackToUser, boolean showHelp, boolean exit) {
this(feedbackToUser, "", false, 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);
}

public String getFeedbackToUser() {
return feedbackToUser;
}

public String getDetailsToUser() {
return detailsToUser;
}

public boolean isShowHelp() {
return showHelp;
}
Expand All @@ -62,18 +85,20 @@ public boolean equals(Object other) {
CommandResult otherCommandResult = (CommandResult) other;
return feedbackToUser.equals(otherCommandResult.feedbackToUser)
&& showHelp == otherCommandResult.showHelp
&& exit == otherCommandResult.exit;
&& exit == otherCommandResult.exit
&& detailsToUser.equals(otherCommandResult.detailsToUser);
}

@Override
public int hashCode() {
return Objects.hash(feedbackToUser, showHelp, exit);
return Objects.hash(feedbackToUser, detailsToUser, showHelp, exit);
}

@Override
public String toString() {
return new ToStringBuilder(this)
.add("feedbackToUser", feedbackToUser)
.add("detailsToUser", detailsToUser)
.add("showHelp", showHelp)
.add("exit", exit)
.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public CommandResult execute(Model model) throws CommandException {
InternApplication internApplicationToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deleteInternApplication(internApplicationToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_INTERN_APPLICATION_SUCCESS,
Messages.format(internApplicationToDelete)));
Messages.formatFeedback(internApplicationToDelete)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public CommandResult execute(Model model) throws CommandException {

model.setInternApplication(internApplicationToEdit, editedInternApplication);
model.updateFilteredInternApplicationList(PREDICATE_SHOW_ALL_APPLICATIONS);
return new CommandResult(String.format(MESSAGE_EDIT_INTERN_APPLICATION_SUCCESS,
Messages.format(editedInternApplication)));
return new CommandResult(MESSAGE_EDIT_INTERN_APPLICATION_SUCCESS,
Messages.formatDisplay(editedInternApplication));
}

/**
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/seedu/letsgethired/logic/commands/NoteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class NoteCommand extends Command {
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_NOTE + "John Street is the leading market maker in the APAC region";
public static final String MESSAGE_ADD_NOTE_SUCCESS = "Added note to InternApplication: %1$s";
public static final String MESSAGE_DELETE_NOTE_SUCCESS = "Removed note from InternApplication: %1$s";
public static final String MESSAGE_DELETE_NOTE_SUCCESS = "Removed note from InternApplication";
public static final String NO_NOTE_PARAMETER_MESSAGE = "A note field must be provided. "
+ "If you intended to delete a note, you can type i/ instead.";

Expand Down Expand Up @@ -56,9 +56,11 @@ public CommandResult execute(Model model) throws CommandException {

InternApplication internApplicationToEdit = lastShownList.get(index.getZeroBased());
InternApplication editedInternApplication = new InternApplication(
internApplicationToEdit.getCompany(), internApplicationToEdit.getRole(),
internApplicationToEdit.getCompany(),
internApplicationToEdit.getRole(),
internApplicationToEdit.getCycle(),
note, internApplicationToEdit.getStatus());
note,
internApplicationToEdit.getStatus());

model.setInternApplication(internApplicationToEdit, editedInternApplication);
model.updateFilteredInternApplicationList(PREDICATE_SHOW_ALL_APPLICATIONS);
Expand All @@ -68,7 +70,7 @@ public CommandResult execute(Model model) throws CommandException {

private String generateSuccessMessage(InternApplication internApplicationToEdit) {
String message = !note.value.isEmpty() ? MESSAGE_ADD_NOTE_SUCCESS : MESSAGE_DELETE_NOTE_SUCCESS;
return String.format(message, Messages.format(internApplicationToEdit));
return message;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ViewCommand extends Command {
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_VIEW_INTERN_APPLICATION_SUCCESS = "Viewed intern application: %1$s";
public static final String MESSAGE_VIEW_INTERN_APPLICATION_SUCCESS = "Viewed intern application";

private final Index targetIndex;

Expand All @@ -43,8 +43,8 @@ public CommandResult execute(Model model) throws CommandException {

InternApplication internApplicationToView = lastShownList.get(targetIndex.getZeroBased());
model.setCurrentInternApplication(internApplicationToView);
return new CommandResult(String.format(MESSAGE_VIEW_INTERN_APPLICATION_SUCCESS,
Messages.format(internApplicationToView)));
return new CommandResult(MESSAGE_VIEW_INTERN_APPLICATION_SUCCESS,
Messages.formatDisplay(internApplicationToView));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public boolean equals(Object other) {
return false;
}

// No comparing notes because notes is not a strict differentiating factor
InternApplication otherInternApplication = (InternApplication) other;
return company.equals(otherInternApplication.company)
&& role.equals(otherInternApplication.role)
Expand All @@ -90,7 +91,7 @@ public boolean equals(Object other) {

@Override
public int hashCode() {
// use this method for custom fields hashing instead of implementing your own
// No comparing notes because notes is not a strict differentiating factor
return Objects.hash(company, role, cycle, status);
}

Expand Down
14 changes: 11 additions & 3 deletions src/main/java/seedu/letsgethired/model/application/Note.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,17 @@ public String toString() {

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Note // instanceof handles nulls
&& value.equals(((Note) other).value)); // state check
if (other == this) {
return true;
}

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

Note otherNote = (Note) other;
return value.equals(otherNote.value);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public Role(String role) {
* Returns true if a given string is a valid role.
*/
public static boolean isValidRole(String test) {
boolean t = test.matches(VALIDATION_REGEX);
return test.matches(VALIDATION_REGEX);
}

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/seedu/letsgethired/ui/CommandExecutor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package seedu.letsgethired.ui;

import seedu.letsgethired.logic.commands.CommandResult;
import seedu.letsgethired.logic.commands.exceptions.CommandException;
import seedu.letsgethired.logic.parser.exceptions.ParseException;

/**
* Represents a function that can execute commands.
*/
@FunctionalInterface
public interface CommandExecutor {
/**
* Executes the command and returns the result.
*
* @see seedu.letsgethired.logic.Logic#execute(String)
*/
CommandResult execute(String commandText) throws CommandException, ParseException;
}
24 changes: 23 additions & 1 deletion src/main/java/seedu/letsgethired/ui/InternApplicationCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import seedu.letsgethired.logic.commands.exceptions.CommandException;
import seedu.letsgethired.logic.parser.exceptions.ParseException;
import seedu.letsgethired.model.application.InternApplication;

/**
Expand All @@ -23,6 +25,8 @@ public class InternApplicationCard extends UiPart<Region> {

public final InternApplication internApplication;

private final CommandExecutor commandExecutor;
private int indexNum;
@FXML
private HBox cardPane;
@FXML
Expand All @@ -41,14 +45,32 @@ public class InternApplicationCard extends UiPart<Region> {
/**
* Creates a {@code InternApplicationCard} with the given {@code internApplication} and index to display.
*/
public InternApplicationCard(InternApplication internApplication, int displayedIndex) {
public InternApplicationCard(InternApplication internApplication,
int displayedIndex,
CommandExecutor commandExecutor) {
super(FXML);
this.internApplication = internApplication;
this.indexNum = displayedIndex;
this.commandExecutor = commandExecutor;

id.setText(displayedIndex + ". ");
company.setText(internApplication.getCompany().value);
role.setText(internApplication.getRole().value);
status.setText(internApplication.getStatus().value);
note.setText(internApplication.getNote().value);
cycle.setText(internApplication.getCycle().value);
}

/**
* Displays card details on the SelectView
*/
@FXML
public void handleCardClick() {
String commandText = "view " + this.indexNum;
try {
commandExecutor.execute(commandText);
} catch (CommandException | ParseException e) {
//should never reach here unless the hard-coded input is wrong
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@
*/
public class InternApplicationListPanel extends UiPart<Region> {
private static final String FXML = "InternApplicationListPanel.fxml";
private final CommandExecutor commandExecutor;
private final Logger logger = LogsCenter.getLogger(InternApplicationListPanel.class);

@FXML
private ListView<InternApplication> internApplicationListView;

/**
* Creates a {@code InternApplicationListPanel} with the given {@code ObservableList}.
*/
public InternApplicationListPanel(ObservableList<InternApplication> internApplicationList) {
public InternApplicationListPanel(ObservableList<InternApplication> internApplicationList,
CommandExecutor commandExecutor) {
super(FXML);
internApplicationListView.setItems(internApplicationList);
internApplicationListView.setCellFactory(listView -> new InternApplicationListViewCell());
this.commandExecutor = commandExecutor;
}

/**
Expand All @@ -42,9 +44,24 @@ protected void updateItem(InternApplication internApplication, boolean empty) {
setGraphic(null);
setText(null);
} else {
setGraphic(new InternApplicationCard(internApplication, getIndex() + 1).getRoot());
setGraphic(new InternApplicationCard(internApplication, getIndex() + 1, commandExecutor).getRoot());
}
}
}

/**
* Gets selected Intern Application from the list panel
* @return Selected InternApplication from the list
*/
public InternApplication getSelectedItem() {
return internApplicationListView.getSelectionModel().getSelectedItem();
}

/**
* Gets index of selected Intern Application from the list panel
* @return Index of selected InternApplication from the list
*/
public int getSelectedItemIndex() {
return internApplicationListView.getSelectionModel().getSelectedIndex() + 1;
}
}
Loading

0 comments on commit 11901a0

Please sign in to comment.