Opravy bázových tříd. Toolbar v samostatném souboru.

multitenant
Josef Rokos 11 years ago
parent 9abe1ab6a4
commit 202825322a

@ -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;
@ -38,18 +35,18 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
@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);
}
}
@ -58,4 +61,12 @@ public class FormViewModel<T> {
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() {

@ -1,5 +1,5 @@
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.dialect=org.hibernate.dialect.MySQLDialect
jdbc.databaseurl=jdbc:mysql://127.0.0.1:3306/isspst
jdbc.databaseurl=jdbc:mysql://127.0.0.1:3306/isspst?characterEncoding=utf8
jdbc.username=root
jdbc.password=xsacfgd

@ -0,0 +1,51 @@
.nicebutton {
font-family: Arial;
color: #050005;
font-size: 12px;
padding-top: 3px;
padding-right: 10px;
padding-bottom: 3px;
padding-left: 10px;
margin: 4px;
text-decoration: none;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: 0px 1px 3px #666666;
-moz-box-shadow: 0px 1px 3px #666666;
box-shadow: 0px 1px 3px #666666;
text-shadow: 1px 1px 2px #666666;
border: solid #8abaed 1px;
background: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#efefef));
background: -moz-linear-gradient(top, #ffffff, #efefef);
-ms-filter: progid:DXImageTransform.Microsoft.gradient(startColorStr=#ffffff, endColorStr=#efefef);
filter: progid:DXImageTransform.Microsoft.gradient(startColorStr=#ffffff, endColorStr=#efefef);
display:inline-block; /* IE is so silly */
}
.nicebutton:hover {
background: #c5e8fa;
}
.nicebutton:disabled {
font-family: Arial;
color: #c4c4c4;
font-size: 12px;
padding-top: 3px;
padding-right: 10px;
padding-bottom: 3px;
padding-left: 10px;
margin: 5px;
text-decoration: none;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: 0px 1px 3px #666666;
-moz-box-shadow: 0px 1px 3px #666666;
text-shadow: 0px 0px 0px #9e9e9e;
box-shadow: 0px 1px 3px #666666;
border: solid #d91c71 0px;
background: #ebebeb;
}
.error {
color: red;
}

@ -3,7 +3,7 @@
<toolbar>
<toolbarbutton image="/img/add.png" tooltiptext="Nový" id="btnNew" onClick="@command('addNew')" disabled="@load(vm.filter)" />
<toolbarbutton image="/img/edit.png" tooltiptext="Upravit" id="btnEdit" onClick="@command('edit')" disabled="@load(empty vm.dataBean ? 'true' : 'false')"/>
<toolbarbutton image="/img/delete.png" tooltiptext="Smazat" id="btnDelete" onClick="@command('delObject')" disabled="@load(empty vm.dataBean ? 'true' : 'false')"/>
<toolbarbutton image="/img/delete.png" tooltiptext="Smazat" id="btnDelete" onClick="@command('delete')" disabled="@load(empty vm.dataBean ? 'true' : 'false')"/>
<toolbarbutton image="/img/funnel.png" tooltiptext="Filtr" id="btnFilter" onClick="@command('filter')" />
</toolbar>
</zk>

Binary file not shown.

After

Width:  |  Height:  |  Size: 719 B

Loading…
Cancel
Save