I am trying to implement vaadin fieldgroup but it does not bind the values.
And it is giving me the following error :
Communication problem
Invalid JSON response from server:
Here is my code.
Model Class:
public class LoggedCustomer {
private String Id;
private String Name;
private String Cell;
private String email;
private String address;
public String getId() {
return Id;
}
public void setId(String id) {
Id = id;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getCell() {
return Cell;
}
public void setCell(String cell) {
Cell = cell;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
Customer Layout Class:
public class CustomerFormView extends FormLayout {
#PropertyId("id")
private TextField id = new TextField("Customer Id");
#PropertyId("name")
private TextField name = new TextField("Customer Name");
#PropertyId("cell")
private TextField cell = new TextField("Customer Cell Number");
#PropertyId("email")
private TextField email = new TextField("Customer Email");
#PropertyId("address")
private TextField address = new TextField("Customer Address");
public CustomerFormView() {
setSpacing(true);
addComponent(id);
addComponent(name);
addComponent(cell);
addComponent(email);
addComponent(address);
}
}
Main UI Class:
public class LoggedIn extends UI {
#WebServlet(value = "/loggedin", asyncSupported = true)
#VaadinServletConfiguration(productionMode = false, ui = LoggedIn.class)
public static class Servlet extends VaadinServlet {
}
#Override
protected void init(VaadinRequest request) {
HorizontalLayout hori = new HorizontalLayout();
setContent(hori);
hori.setSpacing(true);
hori.setMargin(true);
Item customer = createCustomer();
hori.addComponent(createView(customer));
hori.addComponent(displayCustomer(customer));
}
private Layout createView(Item item) {
VerticalLayout formLayout = new VerticalLayout();
formLayout.setMargin(true);
formLayout.setSizeFull();
CustomerFormView productEditLayout = new CustomerFormView();
formLayout.addComponent(productEditLayout);
final FieldGroup binder = new FieldGroup(item);
binder.bindMemberFields(productEditLayout);
HorizontalLayout footer = new HorizontalLayout();
footer.setSpacing(true);
footer.addComponent(new Button("Save", new Button.ClickListener() {
#Override
public void buttonClick(ClickEvent event) {
try {
binder.commit();
} catch (InvalidValueException e) {
} catch (CommitException e) {
}
}
}));
footer.addComponent(new Button("Cancel", new Button.ClickListener() {
#Override
public void buttonClick(ClickEvent event) {
binder.discard();
}
}));
formLayout.addComponent(footer);
return formLayout;
}
private Layout displayCustomer(Item item) {
FormLayout layout = new FormLayout();
Label name = new Label();
name.setPropertyDataSource(item.getItemProperty("name"));
name.setCaption("Name");
layout.addComponent(name);
return layout;
}
private static Item createCustomer() {
LoggedCustomer customer = new LoggedCustomer();
customer.setName("");
customer.setId("");
customer.setCell("");
customer.setEmail("");
customer.setAddress("");
return new BeanItem<LoggedCustomer>(customer);
}
}
this is the full code of my application in which I am working but the fieldgroup binder is not working and giving the error.
Kindly someone help me to identify where is the problem and what i am doing wrong in the code.
I shall be thankful.... :)
Related
I have a student class and I've implemented all my methods correctly. However, I do not know how to get the information out of the object to display them into the GUI, such as the image file and also the texts to be shown.
So, in the GUI Frame I have their name, title, group and demowhat as labels and then the imageFile to actually show the image from the link.
class PersonInfo
{
protected String name;
protected String title;
protected String imageFile;
public PersonInfo(String name, String title, String imageFile)
{
this.name = name;
this.title = title;
this.imageFile = imageFile;
}
public PersonInfo(PersonInfo pi)
{
this(pi.name, pi.title, pi.imageFile);
}
public String getName()
{ return name; }
public String getTitle()
{ return title; }
public String getImageFile()
{ return imageFile; }
public void SetInfo(String name, String title, String imageFile)
{
this.name = name;
this.title = title;
this.imageFile = imageFile;
}
#Override public String toString()
{
return String.format("name: %s%ntitle: %s%nimageFile:%s%n", name, title, imageFile);
}
}
class Student extends PersonInfo
{
private String group;
private String demoWhat;
public Student(String name, String title, String imageFile, String group, String demoWhat)
{
super(name, title, imageFile);
this.group = group;
this.demoWhat = demoWhat;
}
public Student(Student s)
{
super(s);
}
public String getGroup()
{
return group;
}
public String getDemoWhat()
{
return demoWhat;
}
public void SetInfo(String name, String title, String imageFile, String group, String demoWhat)
{
super.SetInfo(name, title, imageFile);
this.group = group;
this.demoWhat = demoWhat;
}
#Override
public String toString()
{
return String.format ("%s" + "group: %s%n" + "demoWhat: %s%n", super.toString (), group, demoWhat);
}
}
class GUI2 extends JFrame
{
private JLabel label1;
private final JLabel image2;
public GUI2()
{
super("Welcome to 121 Demo System");
setLayout( new FlowLayout());
JButton plainJButton = new JButton("Refresh button to get the next student");
add(plainJButton);
ImageIcon image = new ImageIcon(getClass().getResource("images/xx.png"));
Image imageSIM = image.getImage();
Image imageSIMResized = imageSIM.getScaledInstance(260, 180, DO_NOTHING_ON_CLOSE);
image = new ImageIcon(imageSIMResized);
image2 = new JLabel(image);
add(image2);
ButtonHandler handler1 = new ButtonHandler();
plainJButton.addActionListener(handler1);
}
class ButtonHandler implements ActionListener //call student here
{
#Override
public void actionPerformed(ActionEvent event)
{
GUI3 gui3 = new GUI3();
setLayout( new FlowLayout());
gui3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gui3.setSize(450,400);
gui3.setVisible(true);
**//I WANT THE GUI TO POP UP WITH THE NAME, TITLE, IMAGEFILE, GROUP AND DEMOWHAT**
Student student1 = new Student("name", "full time student","images/xxx.JPG", "I am from group 12", "I wish to demo A1");
add(label1);
}
}
}
class GUI3 extends JFrame //firststudent
{
private final JLabel image3;
public GUI3()
{
super("Let us welcome xxx");
JButton plainJButton = new JButton("OK");
add(plainJButton);
//ImageIcon image = new ImageIcon(getClass().getResource("images/xxx.JPG"));
//Image imagexxx= image.getImage();
//Image xxxResized = imagexxx.getScaledInstance(210, 280, DO_NOTHING_ON_CLOSE);
//image = new ImageIcon(xxxResized);
//image3 = new JLabel(image);
//add(image3);
ButtonHandler handler2 = new ButtonHandler();
plainJButton.addActionListener(handler2);
}
}
I tried making the student object in the ButtonHandler class, but then I don't know what to do from here.
Create a JPanel that renders your student. Here is a small example, based on your student class:
class StudentPanel extends JPanel {
JTextField tfGroup;
public StudentPanel() {
add(new JLabel("Group"));
tfGroup = new JTextField();
add(tfGroup);
}
public void setStudent(Student student) {
tfGroup.setText(student.getGroup());
}
}
You will want to add more fields and look at the sizing and arrangement of fields and labels. Maybe your application needs more than one way to render a student (short, full, list).
Once you have such a view, use it like so:
public static void main(String[] args) {
Student student = ... // populate the data you want to show somehow
JFrame f = new JFrame();
StudentPanel panel = new StudentPanel();
panel.setStudent(student);
f.add(panel);
f.pack();
f.setVisible(true);
}
I have 3 classes the first one is Library Item this is the super class. The other two classes are Book and Movie. When I want to fill my table view I want to make sure the correct property is called when populating the table view. I know it is easier to just call the director and author the same for ease of use, but I want to get it working for learning purposes. I have left out packages and imports for relevance.
LibraryItem class
public abstract class LibraryItem {
private int itemCode;
private String title;
private boolean availability;
private int memberIdentifier;
private LocalDate dateLent;
protected LibraryItem(int itemCode, String title, boolean availability, int memberIdentifier, LocalDate dateLent) {
this.itemCode = itemCode;
this.title = title;
this.availability = availability;
this.memberIdentifier = memberIdentifier;
this.dateLent = dateLent;
}
public int getItemCode() {
return itemCode;
}
public String getTitle() {
return title;
}
public boolean isAvailability() {
return availability;
}
public void setAvailability(boolean availability) {
this.availability = availability;
}
public int getMemberIdentifier() {
return memberIdentifier;
}
public void setMemberIdentifier(int memberIdentifier) {
this.memberIdentifier = memberIdentifier;
}
public LocalDate getDateLent() {
return dateLent;
}
public void setDateLent(LocalDate dateLent) {
this.dateLent = dateLent;
}
}
Book class
public class Book extends LibraryItem {
private String author;
protected Book(int itemCode, String title, boolean isLent, int memberIdentifier, LocalDate dateLent, String author) {
super(itemCode, title, isLent, memberIdentifier, dateLent);
this.author = author;
}
}
Movie class
public class Movie extends LibraryItem {
private String director;
protected Movie(int itemCode, String title, boolean isLent, int memberIdentifier, LocalDate dateLent, String director) {
super(itemCode, title, isLent, memberIdentifier, dateLent);
this.director = director;
}
}
I was thinking maybe there is some kind of check I can do for each row implemented so the correct value will be given,
This was my attempt:
public class CollectionController implements Initializable {
#FXML
private TableView<LibraryItem> libraryItemsTable;
#FXML
private TableColumn<LibraryItem, String> itemCodeColumn;
#FXML
private TableColumn<LibraryItem, String> availableColumn;
#FXML
private TableColumn<LibraryItem, String> titleColumn;
#FXML
private TableColumn<LibraryItem, String> authorDirectorColumn;
private LibraryService libraryService = new LibraryService();
#Override
public void initialize(URL location, ResourceBundle resources) {
initializeTableView();
}
private void initializeTableView() {
List<LibraryItem> libraryItems = libraryService.getLibraryItems();
itemCodeColumn.setCellValueFactory(new PropertyValueFactory<>("itemCode"));
availableColumn.setCellValueFactory(new PropertyValueFactory<>("availability"));
titleColumn.setCellValueFactory(new PropertyValueFactory<>("title"));
// implement here check for each new row
if (checkIfBook(row))
authorDirectorColumn.setCellValueFactory(new PropertyValueFactory<>("author"));
else
authorDirectorColumn.setCellValueFactory(new PropertyValueFactory<>("director"));
//
libraryItemsTable.getItems().addAll(libraryItems);
}
If you follow the advice here and avoid the use of PropertyValueFactory, the solution becomes reasonably clear:
titleColumn.setCellValueFactory(data ->
new SimpleStringProperty(data.getValue().getTitle()));
authorDirectorColumn.setCellValueFactory(data -> {
LibraryItem item = data.getValue();
if (item instanceof Book book) {
return new SimpleStringProperty(book.getAuthor());
} else if (item instanceof Movie movie) {
return new SimpleStringProperty(movie.getProducer());
} else {
return null ;
}
});
Here's a complete example (I simplified the model classes for brevity, but retained enough to demonstrate the point):
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import java.io.IOException;
public class HelloApplication extends Application {
#Override
public void start(Stage stage) throws IOException {
TableView<LibraryItem> table = new TableView<>();
TableColumn<LibraryItem, String> titleColumn = new TableColumn<>("Title");
TableColumn<LibraryItem, String> authorProducerColumn = new TableColumn<>("Author/Producer");
table.getColumns().add(titleColumn);
table.getColumns().add(authorProducerColumn);
titleColumn.setCellValueFactory(data -> new SimpleStringProperty(data.getValue().getTitle()));
authorProducerColumn.setCellValueFactory(data -> {
LibraryItem item = data.getValue();
if (item instanceof Book book) {
return new SimpleStringProperty(book.getAuthor());
} else if (item instanceof Movie movie) {
return new SimpleStringProperty(movie.getProducer());
} else return null ;
});
for (int i = 1 ; i <= 10 ; i++) {
Book book = new Book("Book "+i, "Author "+i);
Movie movie = new Movie("Movie "+i, "Producer "+i);
table.getItems().addAll(book, movie);
}
BorderPane root = new BorderPane(table);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public class LibraryItem {
private String title ;
public LibraryItem(String title) {
this.title = title ;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
public class Movie extends LibraryItem {
private String producer ;
public Movie(String title, String producer) {
super(title);
this.producer = producer ;
}
public String getProducer() {
return producer;
}
public void setProducer(String producer) {
this.producer = producer;
}
}
public class Book extends LibraryItem {
private String author ;
public Book(String title, String author) {
super(title);
this.author = author ;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
}
public static void main(String[] args) {
launch();
}
}
I have following two classes whose basical purpose to create an array of objects...
class MovieInfo
{ private String movieTitle;
private String movieRating;
private String movieImg;
private String movieShowTimes;
private static double adultPrice;
private static double childPrice;
MovieInfo(String title, String rating, String img, String showTimes)
{
movieTitle = title;
movieRating = rating;
movieImg = img;
movieShowTimes = showTimes;
}
/*....sets gets methods.... */
}
///////////////////////////////
class MovieList
{
MovieInfo[] mList;
public void createList()
{
mList = new MovieInfo[22];
mList[0] = new MovieInfo("A United Kingdom","PG","A_United_Kingdom.jpg","yyyn");
mList[1] = new MovieInfo("Amitiville The Awakening","18A","AmitivilleAwakening.jpg","yyyn");
mList[2] = new MovieInfo("Arrival","14A","arrival.jpg","yyyy");
mList[3] = new MovieInfo("Baywatch","14A","baywatch.jpg","yyyy");
mList[4] = new MovieInfo("Beauty and the Beast","PG","Beauty_and_the_Beast.jpg","yyyn");
}
}
I also have JList which is attached to JPanel and radio buttons..
And my problem is that I can not get how to display name of the movie from mList[0] on this JList when I click 1st rbutton, name of the movie from mList[1] when I click 2nd rbutton and etc....
Yes I know that I need to register listener for my rbuttons and group them and add ItemStateChange (just did not want to add too much code here)... I am asking here about logic after the lines of
if(e.getSource() instanceof JRadioButton)
{
Please help! Any ideas will be highly appreciated!
You could write a custom CellRenderer, as shown in the docs.
For example, having a Movie bean and a MoviesListCellRenderer which extends DefaultListCellRenderer you could end up with something like this:
public class JListCards {
private JFrame frame;
private JPanel radiosPane;
private JRadioButton[] radios;
private String[] radiosNames = {"Movie", "Classification", "Price"};
private JList <Movie> moviesList;
private ButtonGroup group;
private Movie[] movies = new Movie[] {
new Movie("Happy Feet", "AA", 10),
new Movie("Star Wars", "B12", 15),
new Movie("Logan", "C", 20)
};
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new JListCards().createAndShowGui());
}
public void createAndShowGui() {
frame = new JFrame(getClass().getSimpleName());
radiosPane = new JPanel(new GridLayout(1, 3));
radios = new JRadioButton[3];
group = new ButtonGroup();
for (int i = 0; i < radios.length; i++) {
radios[i] = new JRadioButton(radiosNames[i]);
radios[i].addActionListener(listener);
radiosPane.add(radios[i]);
group.add(radios[i]);
}
radios[0].setSelected(true);
moviesList = new JList<Movie>(movies);
moviesList.setCellRenderer(new MoviesListCellRenderer(0));
frame.add(moviesList);
frame.add(radiosPane, BorderLayout.SOUTH);
frame.pack();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
ActionListener listener = new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
for (int i = 0; i < radios.length; i++) {
if (e.getSource().equals(radios[i])) {
moviesList.setCellRenderer(new MoviesListCellRenderer(i));
break;
}
}
}
};
class MoviesListCellRenderer extends DefaultListCellRenderer {
private int attribute;
public MoviesListCellRenderer(int attribute) {
this.attribute = attribute;
}
#Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof Movie) {
Movie movie = (Movie) value;
switch (attribute) {
case 0:
setText(movie.getMovieName());
break;
case 1:
setText(movie.getClassification());
break;
default:
setText(String.valueOf(movie.getPrice()));
break;
}
}
return this;
}
}
class Movie {
private String movieName;
private String classification;
private double price;
public Movie(String movieName, String classification, double price) {
super();
this.movieName = movieName;
this.classification = classification;
this.price = price;
}
public String getMovieName() {
return movieName;
}
public void setMovieName(String movieName) {
this.movieName = movieName;
}
public String getClassification() {
return classification;
}
public void setClassification(String classification) {
this.classification = classification;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
}
Which as you can see, changes the cell renderer based on the radio selected, this code can still be improved but should give you an idea:
So in basic form I want to get selected text from tableview.
I have my SetCoachFXML in which I have tableview, with some data in it. Next to that I have choose button. How can I get selected text from tableview when I click on choose button?
http://imgur.com/wA6n792
I tried suggestion from here but I get nothing.
Here is my setcoach controller class:
public class SetCoachController implements Initializable {
//Kolone i tabela za prikazivanje trenera
#FXML
private TableColumn<Coaches, String> coachesNameCol;
#FXML
private TableColumn<Coaches, String> coachesLNCol;
#FXML
private TableView<Coaches> coachTable;
#FXML
private Button chooseBtn;
#FXML
private Button cancelBtn;
private ObservableList<Coaches> coachesData;
#Override
public void initialize(URL url, ResourceBundle rb) {
coachesNameCol
.setCellValueFactory(new PropertyValueFactory<Coaches, String>(
"name"));
coachesLNCol
.setCellValueFactory(new PropertyValueFactory<Coaches, String>(
"lastName"));
coachesData = FXCollections.observableArrayList();
coachTable.setItems(coachesData);
coachTable.setEditable(false);
CoachBase.get();
loadCoachesData();
}
//sql upit
public void loadCoachesData() {
try {
ResultSet rs = CoachBase.query("SELECT * FROM CoachTable");
coachesData.clear();
while (rs.next()) {
coachesData.add(new Coaches(rs.getString("Name"), rs.getString("Lastname")));
}
} catch (Exception e) {
System.out.println("" + e.getMessage());
}
}
public void chooseAction(ActionEvent event) {
Coaches coach = (Coaches) coachTable.getSelectionModel().getSelectedItem();
System.out.println(coach.getcoachesName());
}
public void cancelAction(ActionEvent event) {
Stage stage = (Stage) cancelBtn.getScene().getWindow();
stage.close();
}
and my Coaches class:
public class Coaches {
private SimpleIntegerProperty id = new SimpleIntegerProperty();
private SimpleStringProperty name = new SimpleStringProperty();
private SimpleStringProperty lastName = new SimpleStringProperty();
private SimpleIntegerProperty age = new SimpleIntegerProperty();
public Coaches(Integer id, String name, String lastName, int age) {
this.name.setValue(name);
this.lastName.setValue(lastName);
this.age.setValue(age);
}
public Coaches(String name, String lastName) {
this.name.setValue(name);
this.lastName.setValue(lastName);
}
public Integer getId() {
if (id == null) {
return 0;
}
return id.getValue();
}
public String getcoachesName() {
if (name != null) {
return "";
}
return name.getValueSafe();
}
public String getlastName() {
if (lastName != null) {
return "";
}
return lastName.getValueSafe();
}
public Integer getAge() {
if (age == null) {
return 0;
}
return age.getValue();
}
public SimpleIntegerProperty IdProperty() {
return id;
}
public SimpleStringProperty nameProperty() {
return name;
}
public SimpleStringProperty lastNameProperty() {
return lastName;
}
public SimpleIntegerProperty ageProperty() {
return age;
}
}
I think what's happening is when you click on the button, your loosing focus on the selected cell which means when you try to retrieving data, nothing happens.
What you need to do is make sure that when you click on the button, the cell/row is still selected.
Then you can do something like:
// To retrieve
Person person = (Person)taview.getSelectionModel().getSelectedItem();
System.out.println(person.getName());
I want to use a TreeView to display categories and actual content. I used this tutorial to follow my example, since they do something similiar but they simplify it.
I have something like this
public class Category {
final StringProperty categoryName = new SimpleStringProperty();
final ListProperty<Contact> contactList = new SimpleListProperty<>(FXCollections.<Contact>observableArrayList());
public Category(String name, List<Contact> contactList) {
this.categoryName.set(name);
this.contactList.setAll(contactList);
}
public StringProperty categoryNameProperty() { return this.categoryName; }
public ListProperty<Contact> contactListProperty() { return this.contactList; }
}
public class Contact {
final StringProperty contactName = new SimpleStringProperty();
public Contact(String name) {
this.contactName.set(name);
}
public StringProperty contactNameProperty() { return this.contactName; }
}
And now I want to build a TreeView out of a List<Category> with the underlying contacts automatically inserted as child nodes. Is this possible? If possible I would like not modify the Model itself. I thought of extending TreeItem<T> but I am not sure how far this will get me.
Ok I solved this with this, somebody by change a better solution?
public class Main extends Application {
#Override
public void start(Stage stage) {
Scene scene = new Scene(new Group());
stage.setWidth(300);
stage.setHeight(500);
final TreeView<MailTreeItem> tree = new TreeView<>();
final List<Category> categoryList = FXCollections.observableArrayList();
tree.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<TreeItem<MailTreeItem>>() {
#Override
public void changed(
ObservableValue<? extends TreeItem<MailTreeItem>> observable,
TreeItem<MailTreeItem> oldValue,
TreeItem<MailTreeItem> newValue) {
newValue.getValue();
}
});
final List<Contact> categoryContact1List = FXCollections.observableArrayList();
categoryContact1List.add(new Contact("Hans"));
categoryContact1List.add(new Contact("Dieter"));
final List<Contact> categoryContact2List = FXCollections.observableArrayList();
categoryContact2List.add(new Contact("Peter"));
categoryList.add(new Category("Freunde", categoryContact1List));
categoryList.add(new Category("Feinde", categoryContact2List));
final TreeItem<MailTreeItem> root = new TreeItem<MailTreeItem>(new RootTreeItem());
root.setExpanded(true);
tree.setRoot(root);
for (Category category : categoryList) {
final List<Contact> contactList = category.contactListProperty().get();
final TreeItem<MailTreeItem> categoryTreeItem = new TreeItem<MailTreeItem>(new CategoryTreeItem(category));
for (Contact contact : contactList) {
categoryTreeItem.getChildren().add(new TreeItem<MailTreeItem>(new ContactTreeItem(contact)));
}
root.getChildren().add(categoryTreeItem);
}
final VBox vbox = new VBox();
vbox.setSpacing(5);
vbox.setPadding(new Insets(10, 0, 0, 10));
vbox.getChildren().addAll(tree);
((Group) scene.getRoot()).getChildren().addAll(vbox);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
public interface MailTreeItem {
public boolean isCategory();
public boolean isContact();
public Category getCategory();
public Contact getContact();
}
public class RootTreeItem implements MailTreeItem {
#Override public String toString() { return "root"; }
#Override public boolean isCategory() { return false; }
#Override public boolean isContact() { return false; }
#Override public Category getCategory() { return null; }
#Override public Contact getContact() { return null; }
}
public class CategoryTreeItem implements MailTreeItem {
private ObjectProperty<Category> category = new SimpleObjectProperty<>();
public CategoryTreeItem(Category category) {
this.category.set(category);
}
public ObjectProperty<Category> categoryProperty() { return this.category; }
#Override public String toString() { return this.category.get().categoryNameProperty().get(); }
public boolean isCategory() { return true; }
public boolean isContact() { return false; }
public Category getCategory() { return this.category.get(); }
public Contact getContact() { return null; }
}
public class ContactTreeItem implements MailTreeItem {
private final ObjectProperty<Contact> contact = new SimpleObjectProperty<>();
public ContactTreeItem(Contact contact) {
this.contact.set(contact);
}
public ObjectProperty<Contact> contactProperty() { return this.contact; }
#Override public String toString() { return this.contact.get().contactNameProperty().get(); }
public boolean isCategory() { return false; }
public boolean isContact() { return true; }
public Category getCategory() { return null; }
public Contact getContact() { return this.contact.get(); }
}
public class Category {
private final StringProperty categoryName = new SimpleStringProperty();
private final ListProperty<Contact> contactList = new SimpleListProperty<>(FXCollections.<Contact>observableArrayList());
public Category(String name, List<Contact> contactList) {
this.categoryName.set(name);
this.contactList.setAll(contactList);
}
public StringProperty categoryNameProperty() { return this.categoryName; }
public ListProperty<Contact> contactListProperty() { return this.contactList; }
}
public class Contact {
private final StringProperty contactName = new SimpleStringProperty();
public Contact(String name) {
this.contactName.set(name);
}
public StringProperty contactNameProperty() { return this.contactName; }
}
}