What is the best way to copy or duplicate a row in a table component in a screen?
I have added a button to the groupTable component in my screen descriptor file fin-txfer-browser2.xml.
<groupTable id="table"
width="100%"
dataContainer="genNodesDc">
<actions>
<action id="create" type="create"/>
<action id="edit" type="edit"/>
<action id="refresh" type="refresh"/>
<action id="remove" type="remove"/>
<action id="duplicate" />
</actions>
<columns>
<column id="id2"/>
<column id="id2Calc"/>
<column id="id2Cmp"/>
<column id="id2Dup"/>
<column id="type1_Id"/>
<column id="type1_Id2"/>
<column id="desc1"/>
</columns>
<simplePagination/>
<buttonsPanel id="buttonsPanel"
alwaysVisible="true">
<button id="createBtn" action="table.create"/>
<button id="duplicateBtn" action="table.duplicate" caption="Duplicate" icon="font-icon:COPY"/>
<button id="editBtn" action="table.edit"/>
<button id="refreshBtn" action="table.refresh"/>
<button id="removeBtn" action="table.remove"/>
</buttonsPanel>
I have added the following to my screen controller file FinTxferBrowse2.java:
@UiController("ampata_FinTxfer.browse2")
@UiDescriptor("fin-txfer-browse2.xml")
@LookupComponent("table")
public class FinTxferBrowse2 extends MasterDetailScreen<GenNode> {
@Autowired
private DataManager dataManager;
@Autowired
private CollectionContainer<GenNode> genNodesDc;
@Autowired
private Notifications notifications;
@Autowired
private GroupTable<GenNode> table;
@Subscribe("duplicateBtn")
public void onDuplicateBtnClick1(Button.ClickEvent event) {
table.getSelected().stream().forEach(e -> {
genNodesDc.getMutableItems().add(e);
notifications.create()
.withCaption("Duplicated Id2: " + e.getId2().toString())
.show();
});
}
}
However, it doesn’t seem to work.
Do I need to copy the object and then use the dataManager.save() method ?
Also, do I need to reload the data container to refresh the table?
Thank you in advance.