Opravy bázových tříd. Toolbar v samostatném souboru.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package info.bukova.isspst.services;
|
||||
|
||||
import static ch.lambdaj.Lambda.filter;
|
||||
import info.bukova.isspst.dao.BaseDao;
|
||||
import info.bukova.isspst.data.DataModel;
|
||||
import info.bukova.isspst.filters.Filter;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -9,16 +12,10 @@ import java.util.Set;
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.Validator;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.NonUniqueResultException;
|
||||
import org.hibernate.Query;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import info.bukova.isspst.dao.BaseDao;
|
||||
import info.bukova.isspst.dao.IntegrityException;
|
||||
import info.bukova.isspst.data.DataModel;
|
||||
import info.bukova.isspst.filters.Filter;
|
||||
|
||||
public abstract class AbstractService<T extends DataModel> implements Service<T> {
|
||||
|
||||
protected BaseDao<T> dao;
|
||||
@@ -34,22 +31,22 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
|
||||
entity.setCreated(new Date());
|
||||
dao.add(entity);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void update(T entity) {
|
||||
entity.setModified(new Date());
|
||||
dao.modify(entity);
|
||||
if (entity.getCreated() == null) {
|
||||
add(entity);
|
||||
} else {
|
||||
entity.setModified(new Date());
|
||||
dao.modify(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void delete(T entity) {
|
||||
try {
|
||||
dao.delete(entity);
|
||||
} catch (HibernateException e) {
|
||||
throw new IntegrityException(e);
|
||||
}
|
||||
dao.delete(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package info.bukova.isspst.ui;
|
||||
|
||||
import info.bukova.isspst.dao.IntegrityException;
|
||||
import info.bukova.isspst.data.DataModel;
|
||||
import info.bukova.isspst.services.Service;
|
||||
import info.bukova.isspst.services.ValidationException;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.zkoss.bind.annotation.BindingParam;
|
||||
import org.zkoss.bind.annotation.Command;
|
||||
import org.zkoss.bind.annotation.ExecutionArgParam;
|
||||
@@ -14,7 +15,7 @@ import org.zkoss.bind.annotation.NotifyChange;
|
||||
import org.zkoss.zul.Messagebox;
|
||||
import org.zkoss.zul.Window;
|
||||
|
||||
public class FormViewModel<T> {
|
||||
public class FormViewModel<T extends DataModel> {
|
||||
|
||||
private T dataBean;
|
||||
private Map<String, String> errMessages;
|
||||
@@ -34,7 +35,7 @@ public class FormViewModel<T> {
|
||||
@NotifyChange("errMessages")
|
||||
public void save(@BindingParam("window") Window win) {
|
||||
try {
|
||||
service.update(dataBean);
|
||||
doSave();
|
||||
win.detach();
|
||||
} catch (ValidationException e) {
|
||||
errMessages = e.getMessages();
|
||||
@@ -44,9 +45,11 @@ public class FormViewModel<T> {
|
||||
classErr = "";
|
||||
}
|
||||
|
||||
Messagebox.show("Chyba validace", "Error", Messagebox.OK, Messagebox.ERROR);
|
||||
} catch (IntegrityException e) {
|
||||
Messagebox.show("Chyba validace", "Chyba", Messagebox.OK, Messagebox.ERROR);
|
||||
} catch (DataIntegrityViolationException e) {
|
||||
dataBean.setCreated(null);
|
||||
e.printStackTrace();
|
||||
Messagebox.show("Chyba při ukládání záznamu", "Chyba", Messagebox.OK, Messagebox.ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,5 +60,13 @@ public class FormViewModel<T> {
|
||||
protected void setErrMesages(Map<String, String> msgs) {
|
||||
this.errMessages = msgs;
|
||||
}
|
||||
|
||||
protected void doSave() {
|
||||
service.update(dataBean);
|
||||
}
|
||||
|
||||
public boolean isCanSave() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package info.bukova.isspst.ui;
|
||||
|
||||
import info.bukova.isspst.dao.IntegrityException;
|
||||
import info.bukova.isspst.data.DataModel;
|
||||
import info.bukova.isspst.filters.Filter;
|
||||
import info.bukova.isspst.services.Service;
|
||||
@@ -10,11 +9,15 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.zkoss.bind.BindUtils;
|
||||
import org.zkoss.bind.annotation.BindingParam;
|
||||
import org.zkoss.bind.annotation.Command;
|
||||
import org.zkoss.bind.annotation.GlobalCommand;
|
||||
import org.zkoss.bind.annotation.NotifyChange;
|
||||
import org.zkoss.zk.ui.Executions;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
import org.zkoss.zul.Messagebox;
|
||||
import org.zkoss.zul.Window;
|
||||
|
||||
@@ -125,6 +128,7 @@ public class ListViewModel<T extends DataModel> {
|
||||
@Command
|
||||
public void edit() {
|
||||
int index = dataList.indexOf(dataBean);
|
||||
newRec = false;
|
||||
if (index != -1) {
|
||||
selIndex = index;
|
||||
}
|
||||
@@ -141,20 +145,46 @@ public class ListViewModel<T extends DataModel> {
|
||||
@Command
|
||||
@NotifyChange({"dataList", "dataBean"})
|
||||
public void delete() {
|
||||
Messagebox.show("Opravdu smazat?", "Smazat záznam", Messagebox.YES|Messagebox.NO,
|
||||
Messagebox.QUESTION, new EventListener<Event>() {
|
||||
|
||||
@Override
|
||||
public void onEvent(Event evt) throws Exception {
|
||||
if (((Integer)evt.getData()).intValue() == Messagebox.YES) {
|
||||
try {
|
||||
service.delete(dataBean);
|
||||
dataList.remove(dataBean);
|
||||
dataBean = null;
|
||||
BindUtils.postNotifyChange(null, null, ListViewModel.this, "dataList");
|
||||
BindUtils.postNotifyChange(null, null, ListViewModel.this, "dataBean");
|
||||
} catch (DataIntegrityViolationException e) {
|
||||
Messagebox.show("Chyba při mazání záznamu", "Chyba", Messagebox.OK, Messagebox.ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
confirmDelete = false;
|
||||
}
|
||||
|
||||
@NotifyChange({"dataList", "dataBean"})
|
||||
private void onDelete() {
|
||||
try {
|
||||
service.delete(dataBean);
|
||||
dataList.remove(dataBean);
|
||||
dataBean = null;
|
||||
} catch (IntegrityException e) {
|
||||
Messagebox.show("Error while deleting object", "Error", Messagebox.OK, Messagebox.ERROR);
|
||||
} catch (DataIntegrityViolationException e) {
|
||||
Messagebox.show("Chyba při mazání záznamu", "Chyba", Messagebox.OK, Messagebox.ERROR);
|
||||
}
|
||||
confirmDelete = false;
|
||||
}
|
||||
|
||||
@GlobalCommand
|
||||
@NotifyChange({"dataList", "dataBean"})
|
||||
public void refresh() {
|
||||
if (editBean != null && !editBean.isValid()) {
|
||||
/*if (editBean != null && !editBean.isValid()) {
|
||||
return;
|
||||
}*/
|
||||
if (editBean.getCreated() == null) {
|
||||
return;
|
||||
}
|
||||
if (!filter && newRec) {
|
||||
@@ -220,28 +250,29 @@ public class ListViewModel<T extends DataModel> {
|
||||
}
|
||||
}
|
||||
|
||||
private void loadFromDb() {
|
||||
Thread fillThread = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
tmpList = service.getAll();
|
||||
|
||||
try {
|
||||
Thread.sleep(200);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
fullFill = true;
|
||||
}
|
||||
});
|
||||
|
||||
fillThread.start();
|
||||
}
|
||||
// private void loadFromDb() {
|
||||
// Thread fillThread = new Thread(new Runnable() {
|
||||
//
|
||||
// @Override
|
||||
// public void run() {
|
||||
// tmpList = service.getAll();
|
||||
//
|
||||
// try {
|
||||
// Thread.sleep(200);
|
||||
// } catch (InterruptedException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// fullFill = true;
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// fillThread.start();
|
||||
// }
|
||||
|
||||
private void loadFromDbSync() {
|
||||
dataList.addAll(service.getAll());
|
||||
fullList = dataList;
|
||||
}
|
||||
|
||||
protected void showForm() {
|
||||
|
||||
Reference in New Issue
Block a user