I want to create a task list of entities that need to be handled.
I have an entity say “Baskets” which owns a collection of fruit.
How would I go about creating a method of adding a fruit though a task list. e.g. Having a list of tasks which i can select and press a button which opens up the fruits editor/creator inside the baskets editor/creator?
You can open the Fruit editor from the Task browser, passing a datasource with a newly created Fruit as a parameter, and when the Fruit is commited, create the parent Task and Basket entities to complete the graph and finally open the Basket editor:
public class TaskBrowse extends AbstractLookup {
@Inject
private Table<Task> tasksTable;
@Inject
private Metadata metadata;
@Inject
private Datasource<Fruit> fruitDs;
public void createNewBasketWithFruits() {
if (tasksTable.getSingleSelected() != null) {
// create a new fruit
Fruit fruit = metadata.create(Fruit.class);
fruit.setFruitName("New Orange");
// and set it to a datasource which will store fruit edited in its editor screen
fruitDs.setItem(fruit);
// open fruit editor passing also the datasource as parent
AbstractEditor fruitEditor = openEditor(fruit, WindowManager.OpenType.THIS_TAB, Collections.emptyMap(), fruitDs);
// when the fruit editor is committed
fruitEditor.addCloseWithCommitListener(() -> {
// get edited fruit
Fruit editedFruit = fruitDs.getItem();
// create parent Task and Basket entities and make the whole graph
Task task = tasksTable.getSingleSelected();
Basket basket = metadata.create(Basket.class);
basket.setTask(task);
basket.setBasketName("Basket belongs to " + task.getTaskName());
editedFruit.setBasket(basket);
basket.setFruits(new ArrayList<>());
basket.getFruits().add(editedFruit);
// open Basket editor
openEditor(basket, WindowManager.OpenType.NEW_TAB);
});
}
}
}
I’ve attached a small project to demonstrate how it works: