this.listModel = listModel;
}
public void dataModelEdit(DataModelEvent event) {
if (event.isMethodCall(ItemListModel.EDIT_ITEM_COMMAND)) {
ItemModel editItem = (ItemModel) listModel.getArray().getHighlightedItem();
if (editItem != null && DialogManager.getPopupEditorAdaptor().popupEdit(editItem)) {
listModel.getArray().sort();
try {
PersistenceManager.saveItem(editItem) ;
int index = listModel.getArray().getChildIndex(editItem);
listModel.getArray().setHighlightedItem(index);
} catch (Exception e) {
//ignore
}
}
} else if (event.isMethodCall(ItemListModel.NEW_ITEM_COMMAND)) {
ItemModel newItem = new ItemModel();
if (DialogManager.getPopupEditorAdaptor().popupEdit(newItem)) {
int index = listModel.getArray().sortInsert(newItem);
listModel.getArray().setHighlightedItem(index);
try {
PersistenceManager.saveItem(newItem) ;
} catch (Exception e) {
e.printStackTrace(); //TODO
}
}
} else if (event.isMethodCall(ItemListModel.DELETE_ITEM_COMMAND)) {
ItemModel removeItem = (ItemModel) listModel.getArray().getHighlightedItem();
if (removeItem != null && DialogManager.ask("reallyDelete", "Yes", "No", true)) {
try {
PersistenceManager.remove(removeItem);
listModel.getArray().removeItem(removeItem);