forked from AY1920S1-CS2103T-T09-4/main
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CustomerCard.java
72 lines (61 loc) · 2.08 KB
/
CustomerCard.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package seedu.address.ui.cards;
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.customer.Customer;
import seedu.address.ui.UiPart;
/**
* An UI component that displays information of a {@code Customer}.
*/
public class CustomerCard extends UiPart<Region> {
private static final String FXML = "PersonListCard.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 Customer customer;
@FXML
private HBox cardPane;
@FXML
private Label name;
@FXML
private Label id;
@FXML
private Label contactNumber;
@FXML
private Label email;
@FXML
private FlowPane tags;
public CustomerCard(Customer customer, int displayedIndex) {
super(FXML);
this.customer = customer;
id.setText(displayedIndex + ". ");
name.setText(customer.getName().fullName);
contactNumber.setText(customer.getContactNumber().value);
email.setText(customer.getEmail().value);
customer.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 CustomerCard)) {
return false;
}
// state check
CustomerCard card = (CustomerCard) other;
return id.getText().equals(card.id.getText())
&& customer.equals(card.customer);
}
}