|
|
@ -22,7 +22,7 @@ import org.zkoss.zul.Messagebox;
|
|
|
|
import org.zkoss.zul.Window;
|
|
|
|
import org.zkoss.zul.Window;
|
|
|
|
|
|
|
|
|
|
|
|
public class ListViewModel<T extends DataModel> {
|
|
|
|
public class ListViewModel<T extends DataModel> {
|
|
|
|
|
|
|
|
|
|
|
|
private boolean confirmDelete = false;
|
|
|
|
private boolean confirmDelete = false;
|
|
|
|
private boolean filter = false;
|
|
|
|
private boolean filter = false;
|
|
|
|
private Window editWin;
|
|
|
|
private Window editWin;
|
|
|
@ -37,29 +37,29 @@ public class ListViewModel<T extends DataModel> {
|
|
|
|
private boolean sortDesc = true;
|
|
|
|
private boolean sortDesc = true;
|
|
|
|
private boolean newRec = false;
|
|
|
|
private boolean newRec = false;
|
|
|
|
private boolean fullFill = false;
|
|
|
|
private boolean fullFill = false;
|
|
|
|
|
|
|
|
|
|
|
|
protected Service<T> service;
|
|
|
|
protected Service<T> service;
|
|
|
|
protected Class<T> dataClass;
|
|
|
|
protected Class<T> dataClass;
|
|
|
|
protected String formZul;
|
|
|
|
protected String formZul;
|
|
|
|
protected Filter<T> dataFilter;
|
|
|
|
protected Filter<T> dataFilter;
|
|
|
|
|
|
|
|
|
|
|
|
public List<T> getDataList() {
|
|
|
|
public List<T> getDataList() {
|
|
|
|
if (dataList == null) {
|
|
|
|
if (dataList == null) {
|
|
|
|
dataList = new ArrayList<T>();
|
|
|
|
dataList = new ArrayList<T>();
|
|
|
|
loadFromDbSync();
|
|
|
|
loadFromDbSync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return dataList;
|
|
|
|
return dataList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setDataBean(T data) {
|
|
|
|
public void setDataBean(T data) {
|
|
|
|
this.dataBean = data;
|
|
|
|
this.dataBean = data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setDataFilter(Filter<T> dataFilter) {
|
|
|
|
public void setDataFilter(Filter<T> dataFilter) {
|
|
|
|
this.dataFilter = dataFilter;
|
|
|
|
this.dataFilter = dataFilter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public T getFilterTemplate() {
|
|
|
|
public T getFilterTemplate() {
|
|
|
|
if (filterTemplate == null) {
|
|
|
|
if (filterTemplate == null) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -70,18 +70,18 @@ public class ListViewModel<T extends DataModel> {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return filterTemplate;
|
|
|
|
return filterTemplate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public T getDataBean() {
|
|
|
|
public T getDataBean() {
|
|
|
|
return dataBean;
|
|
|
|
return dataBean;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean getConfirmDelete() {
|
|
|
|
public boolean getConfirmDelete() {
|
|
|
|
return confirmDelete;
|
|
|
|
return confirmDelete;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean getFilter() {
|
|
|
|
public boolean getFilter() {
|
|
|
|
return this.filter;
|
|
|
|
return this.filter;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -89,21 +89,20 @@ public class ListViewModel<T extends DataModel> {
|
|
|
|
public boolean getFullFill() {
|
|
|
|
public boolean getFullFill() {
|
|
|
|
return fullFill;
|
|
|
|
return fullFill;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void newRecMode() {
|
|
|
|
protected void newRecMode() {
|
|
|
|
newRec = true;
|
|
|
|
newRec = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void setEditBean(T edit) {
|
|
|
|
protected void setEditBean(T edit) {
|
|
|
|
this.editBean = edit;
|
|
|
|
this.editBean = edit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Command
|
|
|
|
@Command
|
|
|
|
@NotifyChange({"filter", "dataList", "dataBean"})
|
|
|
|
@NotifyChange({ "filter", "dataList", "dataBean" })
|
|
|
|
public void filter() {
|
|
|
|
public void filter() {
|
|
|
|
filter = !filter;
|
|
|
|
filter = !filter;
|
|
|
|
|
|
|
|
|
|
|
|
if (!filter) {
|
|
|
|
if (!filter) {
|
|
|
|
dataList = fullList;
|
|
|
|
dataList = fullList;
|
|
|
|
dataBean = null;
|
|
|
|
dataBean = null;
|
|
|
@ -113,19 +112,19 @@ public class ListViewModel<T extends DataModel> {
|
|
|
|
dataBean = null;
|
|
|
|
dataBean = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Command
|
|
|
|
@Command
|
|
|
|
@NotifyChange("dataList")
|
|
|
|
@NotifyChange("dataList")
|
|
|
|
public void doFilter() {
|
|
|
|
public void doFilter() {
|
|
|
|
if (dataFilter == null) {
|
|
|
|
if (dataFilter == null) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<T> result = service.filterList(fullList, dataFilter);
|
|
|
|
List<T> result = service.filterList(fullList, dataFilter);
|
|
|
|
selIndex = -1;
|
|
|
|
selIndex = -1;
|
|
|
|
dataList = result;
|
|
|
|
dataList = result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Command
|
|
|
|
@Command
|
|
|
|
public void addNew() {
|
|
|
|
public void addNew() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -138,66 +137,72 @@ public class ListViewModel<T extends DataModel> {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Command
|
|
|
|
@Command
|
|
|
|
public void edit() {
|
|
|
|
public void edit() {
|
|
|
|
int index = dataList.indexOf(dataBean);
|
|
|
|
int index = dataList.indexOf(dataBean);
|
|
|
|
newRec = false;
|
|
|
|
newRec = false;
|
|
|
|
if (index != -1) {
|
|
|
|
if (index != -1) {
|
|
|
|
selIndex = index;
|
|
|
|
selIndex = index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
editBean = service.getById(dataBean.getId());
|
|
|
|
editBean = service.getById(dataBean.getId());
|
|
|
|
showForm();
|
|
|
|
showForm();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Command
|
|
|
|
@Command
|
|
|
|
@NotifyChange("confirmDelete")
|
|
|
|
@NotifyChange("confirmDelete")
|
|
|
|
public void delObject() {
|
|
|
|
public void delObject() {
|
|
|
|
confirmDelete = true;
|
|
|
|
confirmDelete = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Command
|
|
|
|
@Command
|
|
|
|
@NotifyChange({"dataList", "dataBean"})
|
|
|
|
@NotifyChange({ "dataList", "dataBean" })
|
|
|
|
public void delete() {
|
|
|
|
public void delete() {
|
|
|
|
Messagebox.show("Opravdu smazat?", "Smazat záznam", Messagebox.YES|Messagebox.NO,
|
|
|
|
Messagebox.show("Opravdu smazat?", "Smazat záznam", Messagebox.YES
|
|
|
|
Messagebox.QUESTION, new EventListener<Event>() {
|
|
|
|
| Messagebox.NO, Messagebox.QUESTION,
|
|
|
|
|
|
|
|
new EventListener<Event>() {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onEvent(Event evt) throws Exception {
|
|
|
|
public void onEvent(Event evt) throws Exception {
|
|
|
|
if (((Integer)evt.getData()).intValue() == Messagebox.YES) {
|
|
|
|
if (((Integer) evt.getData()).intValue() == Messagebox.YES) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
service.delete(dataBean);
|
|
|
|
service.delete(dataBean);
|
|
|
|
dataList.remove(dataBean);
|
|
|
|
dataList.remove(dataBean);
|
|
|
|
dataBean = null;
|
|
|
|
dataBean = null;
|
|
|
|
BindUtils.postNotifyChange(null, null, ListViewModel.this, "dataList");
|
|
|
|
BindUtils.postNotifyChange(null, null,
|
|
|
|
BindUtils.postNotifyChange(null, null, ListViewModel.this, "dataBean");
|
|
|
|
ListViewModel.this, "dataList");
|
|
|
|
|
|
|
|
BindUtils.postNotifyChange(null, null,
|
|
|
|
|
|
|
|
ListViewModel.this, "dataBean");
|
|
|
|
} catch (DataIntegrityViolationException e) {
|
|
|
|
} catch (DataIntegrityViolationException e) {
|
|
|
|
Messagebox.show("Chyba při mazání záznamu", "Chyba", Messagebox.OK, Messagebox.ERROR);
|
|
|
|
Messagebox.show("Chyba při mazání záznamu",
|
|
|
|
|
|
|
|
"Chyba", Messagebox.OK,
|
|
|
|
|
|
|
|
Messagebox.ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
confirmDelete = false;
|
|
|
|
confirmDelete = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@NotifyChange({"dataList", "dataBean"})
|
|
|
|
@NotifyChange({ "dataList", "dataBean" })
|
|
|
|
private void onDelete() {
|
|
|
|
private void onDelete() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
service.delete(dataBean);
|
|
|
|
service.delete(dataBean);
|
|
|
|
dataList.remove(dataBean);
|
|
|
|
dataList.remove(dataBean);
|
|
|
|
dataBean = null;
|
|
|
|
dataBean = null;
|
|
|
|
} catch (DataIntegrityViolationException e) {
|
|
|
|
} catch (DataIntegrityViolationException e) {
|
|
|
|
Messagebox.show("Chyba při mazání záznamu", "Chyba", Messagebox.OK, Messagebox.ERROR);
|
|
|
|
Messagebox.show("Chyba při mazání záznamu", "Chyba", Messagebox.OK,
|
|
|
|
|
|
|
|
Messagebox.ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GlobalCommand
|
|
|
|
@GlobalCommand
|
|
|
|
@NotifyChange({"dataList", "dataBean"})
|
|
|
|
@NotifyChange({ "dataList", "dataBean" })
|
|
|
|
public void refresh() {
|
|
|
|
public void refresh() {
|
|
|
|
/*if (editBean != null && !editBean.isValid()) {
|
|
|
|
if (editBean != null && !editBean.isValid()) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
if (editBean.getCreated() == null) {
|
|
|
|
if (editBean.getCreated() == null) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -214,9 +219,9 @@ public class ListViewModel<T extends DataModel> {
|
|
|
|
dataList.set(selIndex, editBean);
|
|
|
|
dataList.set(selIndex, editBean);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GlobalCommand
|
|
|
|
@GlobalCommand
|
|
|
|
@NotifyChange({"dataList", "dataBean", "fullFill"})
|
|
|
|
@NotifyChange({ "dataList", "dataBean", "fullFill" })
|
|
|
|
public void reload() {
|
|
|
|
public void reload() {
|
|
|
|
dataBean = null;
|
|
|
|
dataBean = null;
|
|
|
|
dataList.clear();
|
|
|
|
dataList.clear();
|
|
|
@ -229,66 +234,66 @@ public class ListViewModel<T extends DataModel> {
|
|
|
|
if (editBean != null && !editBean.isValid()) {
|
|
|
|
if (editBean != null && !editBean.isValid()) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (selIndex > dataList.size() -1) {
|
|
|
|
if (selIndex > dataList.size() - 1) {
|
|
|
|
selIndex = -1;
|
|
|
|
selIndex = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (newRec) {
|
|
|
|
if (newRec) {
|
|
|
|
selIndex = dataList.size() -1;
|
|
|
|
selIndex = dataList.size() - 1;
|
|
|
|
newRec = false;
|
|
|
|
newRec = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Command
|
|
|
|
@Command
|
|
|
|
@NotifyChange("dataBean")
|
|
|
|
@NotifyChange("dataBean")
|
|
|
|
public void onSort(@BindingParam("column") String column) {
|
|
|
|
public void onSort(@BindingParam("column") String column) {
|
|
|
|
if (sortCol == null || this.sortCol.equals(column))
|
|
|
|
if (sortCol == null || this.sortCol.equals(column))
|
|
|
|
this.sortDesc = !this.sortDesc;
|
|
|
|
this.sortDesc = !this.sortDesc;
|
|
|
|
|
|
|
|
|
|
|
|
this.sortCol = column;
|
|
|
|
this.sortCol = column;
|
|
|
|
selIndex = -1;
|
|
|
|
selIndex = -1;
|
|
|
|
dataBean = null;
|
|
|
|
dataBean = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int getSelIndex() {
|
|
|
|
public int getSelIndex() {
|
|
|
|
return this.selIndex;
|
|
|
|
return this.selIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Command
|
|
|
|
@Command
|
|
|
|
@NotifyChange({"dataList", "fullFill"})
|
|
|
|
@NotifyChange({ "dataList", "fullFill" })
|
|
|
|
public void fullFill() {
|
|
|
|
public void fullFill() {
|
|
|
|
if (fullFill && dataList.isEmpty()) {
|
|
|
|
if (fullFill && dataList.isEmpty()) {
|
|
|
|
dataList.addAll(tmpList);
|
|
|
|
dataList.addAll(tmpList);
|
|
|
|
fullList = dataList;
|
|
|
|
fullList = dataList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// private void loadFromDb() {
|
|
|
|
// private void loadFromDb() {
|
|
|
|
// Thread fillThread = new Thread(new Runnable() {
|
|
|
|
// Thread fillThread = new Thread(new Runnable() {
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// @Override
|
|
|
|
// @Override
|
|
|
|
// public void run() {
|
|
|
|
// public void run() {
|
|
|
|
// tmpList = service.getAll();
|
|
|
|
// tmpList = service.getAll();
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// try {
|
|
|
|
// try {
|
|
|
|
// Thread.sleep(200);
|
|
|
|
// Thread.sleep(200);
|
|
|
|
// } catch (InterruptedException e) {
|
|
|
|
// } catch (InterruptedException e) {
|
|
|
|
// e.printStackTrace();
|
|
|
|
// e.printStackTrace();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// fullFill = true;
|
|
|
|
// fullFill = true;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// fillThread.start();
|
|
|
|
// fillThread.start();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
private void loadFromDbSync() {
|
|
|
|
private void loadFromDbSync() {
|
|
|
|
dataList.addAll(service.getAll());
|
|
|
|
dataList.addAll(service.getAll());
|
|
|
|
fullList = dataList;
|
|
|
|
fullList = dataList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void showForm() {
|
|
|
|
protected void showForm() {
|
|
|
|
Map<String, Object> arg = new HashMap<String, Object>();
|
|
|
|
Map<String, Object> arg = new HashMap<String, Object>();
|
|
|
|
arg.put("selected", editBean);
|
|
|
|
arg.put("selected", editBean);
|
|
|
|