Adapted TypeofWorkHoursCRUDController in order to extend BaseCRUDController
FEA: ItEr75S14ShowInformationEditedEntity
This commit is contained in:
parent
0ada9ca1e2
commit
07d38e90c5
4 changed files with 50 additions and 97 deletions
|
|
@ -26,6 +26,7 @@ import java.math.BigDecimal;
|
|||
import org.apache.commons.lang.StringUtils;
|
||||
import org.hibernate.validator.AssertTrue;
|
||||
import org.hibernate.validator.NotEmpty;
|
||||
import org.navalplanner.business.common.IHumanIdentifiable;
|
||||
import org.navalplanner.business.common.IntegrationEntity;
|
||||
import org.navalplanner.business.common.Registry;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
|
|
@ -35,7 +36,7 @@ import org.navalplanner.business.costcategories.daos.ITypeOfWorkHoursDAO;
|
|||
* @author Jacobo Aragunde Perez <jaragunde@igalia.com>
|
||||
* @author Diego Pino García <dpino@igalia.com>
|
||||
*/
|
||||
public class TypeOfWorkHours extends IntegrationEntity {
|
||||
public class TypeOfWorkHours extends IntegrationEntity implements IHumanIdentifiable {
|
||||
|
||||
private String name;
|
||||
|
||||
|
|
@ -144,4 +145,9 @@ public class TypeOfWorkHours extends IntegrationEntity {
|
|||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHumanId() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -27,104 +27,42 @@ import java.util.ConcurrentModificationException;
|
|||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.costcategories.entities.TypeOfWorkHours;
|
||||
import org.navalplanner.web.common.ConstraintChecker;
|
||||
import org.navalplanner.web.common.IMessagesForUser;
|
||||
import org.navalplanner.web.common.BaseCRUDController;
|
||||
import org.navalplanner.web.common.Level;
|
||||
import org.navalplanner.web.common.MessagesForUser;
|
||||
import org.navalplanner.web.common.OnlyOneVisible;
|
||||
import org.navalplanner.web.common.Util;
|
||||
import org.navalplanner.web.common.components.NewDataSortableGrid;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.event.CheckEvent;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
||||
import org.zkoss.zul.Messagebox;
|
||||
import org.zkoss.zul.api.Window;
|
||||
|
||||
/**
|
||||
* Controller for CRUD actions over a {@link TypeOfWorkHours}
|
||||
*
|
||||
* @author Jacobo Aragunde Perez <jaragunde@igalia.com>
|
||||
* @author Cristina Alvarino Pereza <cristina.alvarino@comtecsf.es>
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class TypeOfWorkHoursCRUDController extends GenericForwardComposer {
|
||||
public class TypeOfWorkHoursCRUDController extends BaseCRUDController<TypeOfWorkHours> {
|
||||
|
||||
private static final org.apache.commons.logging.Log LOG = LogFactory
|
||||
.getLog(TypeOfWorkHoursCRUDController.class);
|
||||
|
||||
private Window createWindow;
|
||||
|
||||
private Window listWindow;
|
||||
|
||||
private ITypeOfWorkHoursModel typeOfWorkHoursModel;
|
||||
|
||||
private OnlyOneVisible visibility;
|
||||
|
||||
private IMessagesForUser messagesForUser;
|
||||
|
||||
private Component messagesContainer;
|
||||
|
||||
private NewDataSortableGrid listing;
|
||||
|
||||
@Override
|
||||
public void doAfterCompose(Component comp) throws Exception {
|
||||
super.doAfterCompose(comp);
|
||||
comp.setVariable("controller", this, true);
|
||||
messagesForUser = new MessagesForUser(messagesContainer);
|
||||
listing = (NewDataSortableGrid) listWindow.getFellowIfAny("listing");
|
||||
getVisibility().showOnly(listWindow);
|
||||
}
|
||||
|
||||
public void goToCreateForm() {
|
||||
typeOfWorkHoursModel.initCreate();
|
||||
createWindow.setTitle(_("Create Work Hours Type"));
|
||||
getVisibility().showOnly(createWindow);
|
||||
Util.reloadBindings(createWindow);
|
||||
}
|
||||
|
||||
public void goToEditForm(TypeOfWorkHours typeOfWorkHours) {
|
||||
typeOfWorkHoursModel.initEdit(typeOfWorkHours);
|
||||
createWindow.setTitle(_("Edit Work Hours Type"));
|
||||
getVisibility().showOnly(createWindow);
|
||||
Util.reloadBindings(createWindow);
|
||||
}
|
||||
|
||||
public void goToList() {
|
||||
getVisibility().showOnly(listWindow);
|
||||
Util.reloadBindings(listWindow);
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
goToList();
|
||||
}
|
||||
|
||||
public void saveAndExit() {
|
||||
if (save()) {
|
||||
goToList();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveAndContinue() {
|
||||
if (save()) {
|
||||
goToEditForm(getTypeOfWorkHours());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean save() {
|
||||
if(!ConstraintChecker.isValid(createWindow)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
typeOfWorkHoursModel.confirmSave();
|
||||
messagesForUser.showMessage(Level.INFO,
|
||||
_("Type of work hours saved"));
|
||||
return true;
|
||||
} catch (ValidationException e) {
|
||||
messagesForUser.showInvalidValues(e);
|
||||
}
|
||||
return false;
|
||||
protected void save() throws ValidationException {
|
||||
typeOfWorkHoursModel.confirmSave();
|
||||
}
|
||||
|
||||
public List<TypeOfWorkHours> getTypesOfWorkHours() {
|
||||
|
|
@ -135,12 +73,6 @@ public class TypeOfWorkHoursCRUDController extends GenericForwardComposer {
|
|||
return typeOfWorkHoursModel.getTypeOfWorkHours();
|
||||
}
|
||||
|
||||
private OnlyOneVisible getVisibility() {
|
||||
return (visibility == null) ? new OnlyOneVisible(createWindow,
|
||||
listWindow)
|
||||
: visibility;
|
||||
}
|
||||
|
||||
public void onCheckGenerateCode(Event e) {
|
||||
CheckEvent ce = (CheckEvent) e;
|
||||
if (ce.isChecked()) {
|
||||
|
|
@ -151,17 +83,7 @@ public class TypeOfWorkHoursCRUDController extends GenericForwardComposer {
|
|||
messagesForUser.showMessage(Level.ERROR, err.getMessage());
|
||||
}
|
||||
}
|
||||
Util.reloadBindings(createWindow);
|
||||
}
|
||||
|
||||
public void confirmDelete(TypeOfWorkHours typeOfWorkHours) {
|
||||
if (!isReferencedByOtherEntities(typeOfWorkHours)) {
|
||||
int result = showConfirmDeleteWorkHoursType(typeOfWorkHours);
|
||||
if (result == Messagebox.OK) {
|
||||
typeOfWorkHoursModel.confirmRemove(typeOfWorkHours);
|
||||
Util.reloadBindings(listing);
|
||||
}
|
||||
}
|
||||
Util.reloadBindings(editWindow);
|
||||
}
|
||||
|
||||
private boolean isReferencedByOtherEntities(TypeOfWorkHours typeOfWorkHours) {
|
||||
|
|
@ -185,14 +107,38 @@ public class TypeOfWorkHoursCRUDController extends GenericForwardComposer {
|
|||
}
|
||||
}
|
||||
|
||||
private int showConfirmDeleteWorkHoursType(TypeOfWorkHours typeOfWorkHours) {
|
||||
try {
|
||||
return Messagebox.show(_("Delete item. Are you sure?"), _("Confirm"),
|
||||
Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION);
|
||||
} catch (InterruptedException e) {
|
||||
LOG.error(_("Error on removing typeOfWorkHours: ", typeOfWorkHours.getId()), e);
|
||||
}
|
||||
return Messagebox.CANCEL;
|
||||
@Override
|
||||
protected String getEntityType() {
|
||||
return _("Type of hours");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPluralEntityType() {
|
||||
return _("Types of hours");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initCreate() {
|
||||
typeOfWorkHoursModel.initCreate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initEdit(TypeOfWorkHours typeOfWorkHours) {
|
||||
typeOfWorkHoursModel.initEdit(typeOfWorkHours);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeOfWorkHours getEntityBeingEdited() {
|
||||
return typeOfWorkHoursModel.getTypeOfWorkHours();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void delete(TypeOfWorkHours typeOfWorkHours)
|
||||
throws InstanceNotFoundException {
|
||||
typeOfWorkHoursModel.confirmRemove(typeOfWorkHours);
|
||||
}
|
||||
|
||||
protected boolean beforeDeleting(TypeOfWorkHours typeOfWorkHours) {
|
||||
return !isReferencedByOtherEntities(typeOfWorkHours);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@
|
|||
<label value="${i18n:_('Name')}:" />
|
||||
<textbox id="name"
|
||||
value="@{controller.typeOfWorkHours.name}" width="300px"
|
||||
constraint="no empty:${i18n:_('cannot be null or empty')}"/>
|
||||
constraint="no empty:${i18n:_('cannot be null or empty')}"
|
||||
onBlur="controller.updateWindowTitle()" />
|
||||
</row>
|
||||
<row>
|
||||
<label value="${i18n:_('Default price')}:" />
|
||||
|
|
@ -73,7 +74,7 @@
|
|||
label="${i18n:_('Save')}" sclass="save-button global-action" />
|
||||
<button onClick="controller.saveAndContinue();"
|
||||
label="${i18n:_('Save & Continue')}" sclass="saveandcontinue-button global-action" />
|
||||
<button onClick="controller.cancel();"
|
||||
<button onClick="controller.cancelForm();"
|
||||
label="${i18n:_('Cancel')}" sclass="cancel-button global-action" />
|
||||
|
||||
</window>
|
||||
|
|
|
|||
|
|
@ -34,6 +34,6 @@
|
|||
<vbox id="messagesContainer"></vbox>
|
||||
|
||||
<list top_id="listWindow" />
|
||||
<edition top_id="createWindow" />
|
||||
<edition top_id="editWindow" />
|
||||
</window>
|
||||
</zk>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue