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; package info.bukova.isspst.services;
import static ch.lambdaj.Lambda.filter; 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.Date;
import java.util.List; import java.util.List;
@ -9,16 +12,10 @@ import java.util.Set;
import javax.validation.ConstraintViolation; import javax.validation.ConstraintViolation;
import javax.validation.Validator; import javax.validation.Validator;
import org.hibernate.HibernateException;
import org.hibernate.NonUniqueResultException; import org.hibernate.NonUniqueResultException;
import org.hibernate.Query; import org.hibernate.Query;
import org.springframework.transaction.annotation.Transactional; 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> { public abstract class AbstractService<T extends DataModel> implements Service<T> {
protected BaseDao<T> dao; protected BaseDao<T> dao;
@ -34,22 +31,22 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
entity.setCreated(new Date()); entity.setCreated(new Date());
dao.add(entity); dao.add(entity);
} }
@Override @Override
@Transactional @Transactional
public void update(T entity) { public void update(T entity) {
entity.setModified(new Date()); if (entity.getCreated() == null) {
dao.modify(entity); add(entity);
} else {
entity.setModified(new Date());
dao.modify(entity);
}
} }
@Override @Override
@Transactional @Transactional
public void delete(T entity) { public void delete(T entity) {
try { dao.delete(entity);
dao.delete(entity);
} catch (HibernateException e) {
throw new IntegrityException(e);
}
} }
@Override @Override

@ -1,11 +1,12 @@
package info.bukova.isspst.ui; 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.Service;
import info.bukova.isspst.services.ValidationException; import info.bukova.isspst.services.ValidationException;
import java.util.Map; import java.util.Map;
import org.springframework.dao.DataIntegrityViolationException;
import org.zkoss.bind.annotation.BindingParam; import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.ExecutionArgParam; 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.Messagebox;
import org.zkoss.zul.Window; import org.zkoss.zul.Window;
public class FormViewModel<T> { public class FormViewModel<T extends DataModel> {
private T dataBean; private T dataBean;
private Map<String, String> errMessages; private Map<String, String> errMessages;
@ -34,7 +35,7 @@ public class FormViewModel<T> {
@NotifyChange("errMessages") @NotifyChange("errMessages")
public void save(@BindingParam("window") Window win) { public void save(@BindingParam("window") Window win) {
try { try {
service.update(dataBean); doSave();
win.detach(); win.detach();
} catch (ValidationException e) { } catch (ValidationException e) {
errMessages = e.getMessages(); errMessages = e.getMessages();
@ -44,9 +45,11 @@ public class FormViewModel<T> {
classErr = ""; classErr = "";
} }
Messagebox.show("Chyba validace", "Error", Messagebox.OK, Messagebox.ERROR); Messagebox.show("Chyba validace", "Chyba", Messagebox.OK, Messagebox.ERROR);
} catch (IntegrityException e) { } catch (DataIntegrityViolationException e) {
dataBean.setCreated(null);
e.printStackTrace(); 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) { protected void setErrMesages(Map<String, String> msgs) {
this.errMessages = msgs; this.errMessages = msgs;
} }
protected void doSave() {
service.update(dataBean);
}
public boolean isCanSave() {
return true;
}
} }

@ -1,6 +1,5 @@
package info.bukova.isspst.ui; package info.bukova.isspst.ui;
import info.bukova.isspst.dao.IntegrityException;
import info.bukova.isspst.data.DataModel; import info.bukova.isspst.data.DataModel;
import info.bukova.isspst.filters.Filter; import info.bukova.isspst.filters.Filter;
import info.bukova.isspst.services.Service; import info.bukova.isspst.services.Service;
@ -10,11 +9,15 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; 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.BindingParam;
import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.GlobalCommand; import org.zkoss.bind.annotation.GlobalCommand;
import org.zkoss.bind.annotation.NotifyChange; import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zk.ui.Executions; 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.Messagebox;
import org.zkoss.zul.Window; import org.zkoss.zul.Window;
@ -125,6 +128,7 @@ public class ListViewModel<T extends DataModel> {
@Command @Command
public void edit() { public void edit() {
int index = dataList.indexOf(dataBean); int index = dataList.indexOf(dataBean);
newRec = false;
if (index != -1) { if (index != -1) {
selIndex = index; selIndex = index;
} }
@ -141,20 +145,46 @@ public class ListViewModel<T extends DataModel> {
@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.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 { try {
service.delete(dataBean); service.delete(dataBean);
dataList.remove(dataBean); dataList.remove(dataBean);
dataBean = null; dataBean = null;
} catch (IntegrityException e) { } catch (DataIntegrityViolationException e) {
Messagebox.show("Error while deleting object", "Error", Messagebox.OK, Messagebox.ERROR); Messagebox.show("Chyba při mazání záznamu", "Chyba", Messagebox.OK, Messagebox.ERROR);
} }
confirmDelete = false;
} }
@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;
}*/
if (editBean.getCreated() == null) {
return; return;
} }
if (!filter && newRec) { if (!filter && newRec) {
@ -220,28 +250,29 @@ public class ListViewModel<T extends DataModel> {
} }
} }
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;
} }
protected void showForm() { protected void showForm() {

@ -1,5 +1,5 @@
jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.dialect=org.hibernate.dialect.MySQLDialect 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.username=root
jdbc.password=xsacfgd 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> <toolbar>
<toolbarbutton image="/img/add.png" tooltiptext="Nový" id="btnNew" onClick="@command('addNew')" disabled="@load(vm.filter)" /> <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/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')" /> <toolbarbutton image="/img/funnel.png" tooltiptext="Filtr" id="btnFilter" onClick="@command('filter')" />
</toolbar> </toolbar>
</zk> </zk>

Binary file not shown.

After

Width:  |  Height:  |  Size: 719 B

Loading…
Cancel
Save