Adapted exception days controller to BaseCRUDController.
* Also fixed configured properly to show entity name while editing. FEA: ItEr75S13GenericCRUDController
This commit is contained in:
parent
b50921c391
commit
2208f2ac7c
5 changed files with 83 additions and 126 deletions
|
|
@ -32,6 +32,7 @@ import org.hibernate.NonUniqueResultException;
|
|||
import org.hibernate.validator.AssertTrue;
|
||||
import org.hibernate.validator.NotNull;
|
||||
import org.navalplanner.business.calendars.daos.ICalendarExceptionTypeDAO;
|
||||
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;
|
||||
|
|
@ -44,7 +45,8 @@ import org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureExcep
|
|||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public class CalendarExceptionType extends IntegrationEntity {
|
||||
public class CalendarExceptionType extends IntegrationEntity implements
|
||||
IHumanIdentifiable {
|
||||
|
||||
private String name;
|
||||
|
||||
|
|
@ -183,4 +185,9 @@ public class CalendarExceptionType extends IntegrationEntity {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHumanId() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -292,14 +292,20 @@ public abstract class BaseCRUDController<T extends IHumanIdentifiable> extends
|
|||
}
|
||||
|
||||
/**
|
||||
* Shows a dialog asking for confirmation to user and if ok remove entity
|
||||
* passed as parameter. Delegate in {@link #delete(entity)} that should be
|
||||
* implemented in subclasses.
|
||||
* First call {@link #beforeDeleting(entity)} in order to perform some
|
||||
* checkings before trying to delete if needed. Then show a dialog asking
|
||||
* for confirmation to user and if ok remove entity passed as parameter.
|
||||
* Delegate in {@link #delete(entity)} that should be implemented in
|
||||
* subclasses.
|
||||
*
|
||||
* @param entity
|
||||
* Entity to be removed
|
||||
*/
|
||||
public final void confirmDelete(T entity) {
|
||||
if (!beforeDeleting(entity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (Messagebox.show(
|
||||
_("Delete {0} \"{1}\". Are you sure?", getEntityType(),
|
||||
|
|
@ -318,6 +324,21 @@ public abstract class BaseCRUDController<T extends IHumanIdentifiable> extends
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs additional operations before deleting (usually check some wrong
|
||||
* conditions before deleting).
|
||||
*
|
||||
* Default behavior do nothing, however it could be overridden if needed.
|
||||
*
|
||||
* @param entity
|
||||
* Entity to be removed
|
||||
* @return Return true if deletion can carry on
|
||||
*/
|
||||
protected boolean beforeDeleting(T entity) {
|
||||
// Do nothing
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs actions needed to remove entity passed as parameter
|
||||
*
|
||||
|
|
|
|||
|
|
@ -23,16 +23,13 @@ import static org.navalplanner.web.I18nHelper._;
|
|||
import java.util.ConcurrentModificationException;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.navalplanner.business.calendars.entities.CalendarExceptionType;
|
||||
import org.navalplanner.business.calendars.entities.Capacity;
|
||||
import org.navalplanner.business.calendars.entities.PredefinedCalendarExceptionTypes;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
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.Util.Getter;
|
||||
import org.navalplanner.web.common.Util.Setter;
|
||||
|
|
@ -45,33 +42,22 @@ import org.zkoss.zk.ui.Component;
|
|||
import org.zkoss.zk.ui.WrongValueException;
|
||||
import org.zkoss.zk.ui.event.CheckEvent;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.MouseEvent;
|
||||
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
||||
import org.zkoss.zul.Button;
|
||||
import org.zkoss.zul.Checkbox;
|
||||
import org.zkoss.zul.Grid;
|
||||
import org.zkoss.zul.Messagebox;
|
||||
import org.zkoss.zul.Row;
|
||||
import org.zkoss.zul.Textbox;
|
||||
import org.zkoss.zul.Window;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Diego Pino <dpino@igalia.com>
|
||||
*
|
||||
*/
|
||||
public class CalendarExceptionTypeCRUDController extends GenericForwardComposer {
|
||||
|
||||
private static final org.apache.commons.logging.Log LOG = LogFactory
|
||||
.getLog(CalendarExceptionTypeCRUDController.class);
|
||||
public class CalendarExceptionTypeCRUDController extends
|
||||
BaseCRUDController<CalendarExceptionType> {
|
||||
|
||||
@Autowired
|
||||
private ICalendarExceptionTypeModel calendarExceptionTypeModel;
|
||||
|
||||
private Window listWindow;
|
||||
|
||||
private Window editWindow;
|
||||
|
||||
private Textbox tbName;
|
||||
|
||||
private Textbox tbColor;
|
||||
|
|
@ -82,19 +68,10 @@ public class CalendarExceptionTypeCRUDController extends GenericForwardComposer
|
|||
|
||||
private EffortDurationPicker extraEffort;
|
||||
|
||||
private OnlyOneVisible visibility;
|
||||
|
||||
private IMessagesForUser messagesForUser;
|
||||
|
||||
private Component messagesContainer;
|
||||
|
||||
@Override
|
||||
public void doAfterCompose(Component comp) throws Exception {
|
||||
super.doAfterCompose(comp);
|
||||
messagesForUser = new MessagesForUser(messagesContainer);
|
||||
comp.setVariable("controller", this, true);
|
||||
initializeEditWindowComponents();
|
||||
showListWindow();
|
||||
}
|
||||
|
||||
private void initializeCapacityPicker() {
|
||||
|
|
@ -123,37 +100,16 @@ public class CalendarExceptionTypeCRUDController extends GenericForwardComposer
|
|||
extraEffort = Util.findComponentAt(editWindow, "extraEffort");
|
||||
}
|
||||
|
||||
private void showListWindow() {
|
||||
showWindow(listWindow);
|
||||
}
|
||||
|
||||
private void showWindow(Window window) {
|
||||
getVisibility().showOnly(window);
|
||||
}
|
||||
|
||||
private OnlyOneVisible getVisibility() {
|
||||
if (visibility == null) {
|
||||
visibility = new OnlyOneVisible(listWindow, editWindow);
|
||||
}
|
||||
return visibility;
|
||||
}
|
||||
|
||||
private void showEditWindow() {
|
||||
initializeCapacityPicker();
|
||||
editWindow.setTitle(_("Edit Exception Day Type"));
|
||||
showWindow(editWindow);
|
||||
}
|
||||
|
||||
public void goToCreateForm() {
|
||||
@Override
|
||||
protected void initCreate() {
|
||||
calendarExceptionTypeModel.initCreate();
|
||||
showCreateWindow();
|
||||
Util.reloadBindings(editWindow);
|
||||
initializeCapacityPicker();
|
||||
}
|
||||
|
||||
private void showCreateWindow() {
|
||||
@Override
|
||||
protected void initEdit(CalendarExceptionType calendarExceptionType) {
|
||||
calendarExceptionTypeModel.initEdit(calendarExceptionType);
|
||||
initializeCapacityPicker();
|
||||
editWindow.setTitle(_("Create Exception Day Type"));
|
||||
showWindow(editWindow);
|
||||
}
|
||||
|
||||
public CalendarExceptionType getExceptionDayType() {
|
||||
|
|
@ -164,9 +120,9 @@ public class CalendarExceptionTypeCRUDController extends GenericForwardComposer
|
|||
return calendarExceptionTypeModel.getExceptionDayTypes();
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
@Override
|
||||
protected void cancel() {
|
||||
clearFields();
|
||||
showListWindow();
|
||||
}
|
||||
|
||||
private void clearFields() {
|
||||
|
|
@ -174,73 +130,36 @@ public class CalendarExceptionTypeCRUDController extends GenericForwardComposer
|
|||
tbColor.setRawValue("");
|
||||
}
|
||||
|
||||
private boolean save() {
|
||||
try {
|
||||
calendarExceptionTypeModel.confirmSave();
|
||||
messagesForUser.showMessage(Level.INFO, _("Calendar Exception Type saved"));
|
||||
return true;
|
||||
} catch (ValidationException e) {
|
||||
messagesForUser.showInvalidValues(e);
|
||||
@Override
|
||||
protected void save() throws ValidationException {
|
||||
calendarExceptionTypeModel.confirmSave();
|
||||
clearFields();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean beforeDeleting(CalendarExceptionType calendarExceptionType) {
|
||||
if (PredefinedCalendarExceptionTypes.contains(calendarExceptionType)) {
|
||||
messagesForUser
|
||||
.showMessage(
|
||||
Level.ERROR,
|
||||
_("Cannot remove the predefined Exception Day Type \"{0}\"",
|
||||
calendarExceptionType.getHumanId()));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void saveAndExit() {
|
||||
boolean couldSave = save();
|
||||
if (couldSave) {
|
||||
clearFields();
|
||||
showListWindow();
|
||||
Util.reloadBindings(listWindow);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveAndContinue() {
|
||||
boolean couldSave = save();
|
||||
if (couldSave) {
|
||||
calendarExceptionTypeModel.initEdit(calendarExceptionTypeModel
|
||||
.getExceptionDayType());
|
||||
}
|
||||
}
|
||||
|
||||
public void showRemoveConfirmationMessage(MouseEvent event) {
|
||||
Button button = (Button) event.getTarget();
|
||||
Component comp = (Component) event.getTarget();
|
||||
CalendarExceptionType exceptionType = (CalendarExceptionType) ((Row) button
|
||||
.getParent().getParent()).getValue();
|
||||
|
||||
if (PredefinedCalendarExceptionTypes.contains(exceptionType)) {
|
||||
throw new WrongValueException(comp, "Cannot remove a predefined Exception Day Type");
|
||||
} else {
|
||||
showRemoveConfirmationMessage(exceptionType);
|
||||
}
|
||||
}
|
||||
|
||||
public void showRemoveConfirmationMessage(
|
||||
CalendarExceptionType exceptionType) {
|
||||
@Override
|
||||
protected void delete(CalendarExceptionType calendarExceptionType) {
|
||||
try {
|
||||
int status = Messagebox
|
||||
.show(_("Delete item {0}. Are you sure?",
|
||||
exceptionType.getName()), _("Delete"),
|
||||
Messagebox.OK | Messagebox.CANCEL,
|
||||
Messagebox.QUESTION);
|
||||
if (Messagebox.OK == status) {
|
||||
confirmDelete(exceptionType);
|
||||
Util.reloadBindings(listWindow);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
LOG.error(_("Error on showing delete confirm"), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void confirmDelete(CalendarExceptionType exceptionType) {
|
||||
try {
|
||||
calendarExceptionTypeModel.confirmDelete(exceptionType);
|
||||
calendarExceptionTypeModel.confirmDelete(calendarExceptionType);
|
||||
} catch (InstanceNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
} catch (InvalidValueException e) {
|
||||
NewDataSortableGrid listExceptionDayTypes = (NewDataSortableGrid) listWindow
|
||||
.getFellowIfAny("listExceptionDayTypes");
|
||||
Row row = findRowByValue(listExceptionDayTypes, exceptionType);
|
||||
Row row = findRowByValue(listExceptionDayTypes,
|
||||
calendarExceptionType);
|
||||
throw new WrongValueException(row, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
@ -255,12 +174,6 @@ public class CalendarExceptionTypeCRUDController extends GenericForwardComposer
|
|||
return null;
|
||||
}
|
||||
|
||||
public void goToEditForm(CalendarExceptionType exceptionType) {
|
||||
calendarExceptionTypeModel.initEdit(exceptionType);
|
||||
showEditWindow();
|
||||
Util.reloadBindings(editWindow);
|
||||
}
|
||||
|
||||
public void onCheckGenerateCode(Event e) {
|
||||
CheckEvent ce = (CheckEvent) e;
|
||||
if (ce.isChecked()) {
|
||||
|
|
@ -274,4 +187,19 @@ public class CalendarExceptionTypeCRUDController extends GenericForwardComposer
|
|||
Util.reloadBindings(editWindow);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getEntityType() {
|
||||
return "Exception Day Type";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPluralEntityType() {
|
||||
return "Exception Day Types";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CalendarExceptionType getEntityBeingEdited() {
|
||||
return calendarExceptionTypeModel.getExceptionDayType();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,8 @@
|
|||
<label value="${i18n:_('Name')}"/>
|
||||
<textbox id="tbName"
|
||||
value="@{controller.exceptionDayType.name}"
|
||||
width="300px" />
|
||||
width="300px"
|
||||
onBlur="controller.updateWindowTitle()" />
|
||||
</row>
|
||||
<row>
|
||||
<label value="${i18n:_('Color')}" />
|
||||
|
|
@ -82,7 +83,7 @@
|
|||
<button onClick="controller.saveAndContinue()"
|
||||
label="${i18n:_('Save and Continue')}"
|
||||
sclass="save-button global-action"/>
|
||||
<button onClick="controller.cancel()"
|
||||
<button onClick="controller.cancelForm()"
|
||||
label="${i18n:_('Cancel')}"
|
||||
sclass="cancel-button global-action"/>
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@
|
|||
<button sclass="icono" image="/common/img/ico_borrar1.png"
|
||||
hoverImage="/common/img/ico_borrar.png"
|
||||
tooltiptext="${i18n:_('Delete')}"
|
||||
onClick="controller.showRemoveConfirmationMessage(event)"/>
|
||||
onClick="controller.confirmDelete(self.parent.parent.value)"/>
|
||||
</hbox>
|
||||
</row>
|
||||
</rows>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue