Automatic insertion of Row in the table during data entry #253

I have a master detail UI where I have a table column listener b which a new row is inserted when a new value is entered in the particular column. The code looks as follows:

 linesDs.addItemPropertyChangeListener(e -> {

            if ("quantity".equals(e.getProperty())) {
                ProductionGrLines line = metadata.create(ProductionGrLines.class);
                //showNotification("none", NotificationType.HUMANIZED);

I want to improve this functionality but seems like I need to know answer to the following questions:

  1. I want to insert the new row only at the end of the table (currently it is added randomly
  2. I can count the total number of Rows the table has. How can I get if the current row is the last row of the table. I want to insert a new row only when the user is editing a particular column of the last row. The new row should be created just below that.
  3. After a new row is created, the focus is lost, goes to URL or anywhere but i want the cursor moves to the new row created