Edit sub entity through owning entities editor

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?

Hope this makes sense…

Something like, openEditor(“Baskets”, Basket.id).openEditor(“Fruits”,new Fruit)

So that after the fruit is created it redirects to the basket so I can see the newly added fruit and check before it saves.


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 {
    private Table<Task> tasksTable;
    private Metadata metadata;

    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
            // 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.setBasketName("Basket belongs to " + task.getTaskName());

                basket.setFruits(new ArrayList<>());

                // open Basket editor
                openEditor(basket, WindowManager.OpenType.NEW_TAB);

I’ve attached a small project to demonstrate how it works:

demo.zip (84.5 KB)