From 0ada9ca1e28c9d8cd6e35c8636303f3e82a871d2 Mon Sep 17 00:00:00 2001 From: Cristina Alvarino Date: Fri, 15 Jul 2011 12:11:55 +0200 Subject: [PATCH] Adapted ProfileCRUDController in order to extend BaseCRUDController FEA: ItEr75S14ShowInformationEditedEntity --- .../business/users/entities/Profile.java | 8 +- .../web/users/ProfileCRUDController.java | 142 +++++------------- .../src/main/webapp/users/_editProfile.zul | 5 +- .../src/main/webapp/users/_listProfiles.zul | 2 +- .../src/main/webapp/users/profiles.zul | 2 +- 5 files changed, 48 insertions(+), 111 deletions(-) diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/Profile.java b/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/Profile.java index 799cc428b..942af8569 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/Profile.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/Profile.java @@ -27,6 +27,7 @@ import java.util.Set; import org.hibernate.validator.AssertTrue; import org.hibernate.validator.NotEmpty; import org.navalplanner.business.common.BaseEntity; +import org.navalplanner.business.common.IHumanIdentifiable; import org.navalplanner.business.common.Registry; import org.navalplanner.business.common.exceptions.InstanceNotFoundException; import org.navalplanner.business.users.daos.IProfileDAO; @@ -36,7 +37,7 @@ import org.navalplanner.business.users.daos.IProfileDAO; * * @author Jacobo Aragunde Perez */ -public class Profile extends BaseEntity { +public class Profile extends BaseEntity implements IHumanIdentifiable{ private String profileName = ""; @@ -103,4 +104,9 @@ public class Profile extends BaseEntity { } } + + @Override + public String getHumanId() { + return profileName; + } } diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/users/ProfileCRUDController.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/users/ProfileCRUDController.java index 0be76c3e3..d51310638 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/users/ProfileCRUDController.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/users/ProfileCRUDController.java @@ -30,18 +30,12 @@ import org.navalplanner.business.common.exceptions.InstanceNotFoundException; import org.navalplanner.business.common.exceptions.ValidationException; import org.navalplanner.business.users.entities.Profile; import org.navalplanner.business.users.entities.UserRole; -import org.navalplanner.web.common.ConstraintChecker; -import org.navalplanner.web.common.IMessagesForUser; -import org.navalplanner.web.common.Level; -import org.navalplanner.web.common.MessagesForUser; -import org.navalplanner.web.common.OnlyOneVisible; +import org.navalplanner.web.common.BaseCRUDController; import org.navalplanner.web.common.Util; import org.zkoss.zk.ui.Component; -import org.zkoss.zk.ui.util.GenericForwardComposer; import org.zkoss.zul.Combobox; import org.zkoss.zul.Comboitem; import org.zkoss.zul.Messagebox; -import org.zkoss.zul.api.Window; /** * Controller for CRUD actions over a {@link Profile} @@ -50,31 +44,18 @@ import org.zkoss.zul.api.Window; * @author Diego Pino GarcĂ­a */ @SuppressWarnings("serial") -public class ProfileCRUDController extends GenericForwardComposer { +public class ProfileCRUDController extends BaseCRUDController { private static final org.apache.commons.logging.Log LOG = LogFactory.getLog(ProfileCRUDController.class); - private Window createWindow; - - private Window listWindow; - private IProfileModel profileModel; - private OnlyOneVisible visibility; - - private IMessagesForUser messagesForUser; - - private Component messagesContainer; - private Combobox userRolesCombo; @Override public void doAfterCompose(Component comp) throws Exception { super.doAfterCompose(comp); - comp.setVariable("controller", this, true); - messagesForUser = new MessagesForUser(messagesContainer); - userRolesCombo = (Combobox) createWindow.getFellowIfAny("userRolesCombo"); - getVisibility().showOnly(listWindow); + userRolesCombo = (Combobox) editWindow.getFellowIfAny("userRolesCombo"); appendAllUserRoles(userRolesCombo); } @@ -89,54 +70,8 @@ public class ProfileCRUDController extends GenericForwardComposer { } } - public void goToCreateForm() { - profileModel.initCreate(); - createWindow.setTitle(_("Create Profile")); - getVisibility().showOnly(createWindow); - Util.reloadBindings(createWindow); - } - - public void goToEditForm(Profile profile) { - profileModel.initEdit(profile); - createWindow.setTitle(_("Edit Profile")); - 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(getProfile()); - } - } - - public boolean save() { - if(!ConstraintChecker.isValid(createWindow)) { - return false; - } - try { - profileModel.confirmSave(); - messagesForUser.showMessage(Level.INFO, - _("Profile saved")); - return true; - } catch (ValidationException e) { - messagesForUser.showInvalidValues(e); - } - return false; + protected void save() throws ValidationException{ + profileModel.confirmSave(); } public List getProfiles() { @@ -164,30 +99,37 @@ public class ProfileCRUDController extends GenericForwardComposer { public void addRole(UserRole role) { profileModel.addRole(role); - Util.reloadBindings(createWindow); + Util.reloadBindings(editWindow); } public void removeRole(UserRole role) { profileModel.removeRole(role); - Util.reloadBindings(createWindow); + Util.reloadBindings(editWindow); } - public void removeProfile(Profile profile) { - if (!isReferencedByOtherEntities(profile)) { - int result = showConfirmDeleteProfile(profile); - if (result == Messagebox.OK) { - try { - profileModel.confirmRemove(profile); - goToList(); - } catch (InstanceNotFoundException e) { - messagesForUser - .showMessage( - Level.ERROR, - _("Cannot delete profile: it does not exist anymore")); - LOG.error(_("Error removing element: ", profile.getId()), e); - } - } - } + @Override + protected String getEntityType() { + return _("Profile"); + } + + @Override + protected String getPluralEntityType() { + return _("Profiles"); + } + + @Override + protected void initCreate() { + profileModel.initCreate(); + } + + @Override + protected void initEdit(Profile profile) { + profileModel.initEdit(profile); + } + + @Override + protected Profile getEntityBeingEdited() { + return profileModel.getProfile(); } private boolean isReferencedByOtherEntities(Profile profile) { @@ -211,25 +153,13 @@ public class ProfileCRUDController extends GenericForwardComposer { profile.getId()), e); } } - - private int showConfirmDeleteProfile(Profile profile) { - try { - return Messagebox.show( - _("Confirm deleting this profile. Are you sure?"), - _("Delete"), Messagebox.OK | Messagebox.CANCEL, - Messagebox.QUESTION); - } catch (InterruptedException e) { - LOG.error( - _("Error on showing removing element: ", profile.getId()), - e); - } - return Messagebox.CANCEL; + @Override + protected boolean beforeDeleting(Profile profile){ + return !isReferencedByOtherEntities(profile); } - private OnlyOneVisible getVisibility() { - return (visibility == null) ? new OnlyOneVisible(createWindow, - listWindow) - : visibility; + @Override + protected void delete(Profile profile) throws InstanceNotFoundException { + profileModel.confirmRemove(profile); } - } diff --git a/navalplanner-webapp/src/main/webapp/users/_editProfile.zul b/navalplanner-webapp/src/main/webapp/users/_editProfile.zul index a37d7bdc4..b31b62e96 100644 --- a/navalplanner-webapp/src/main/webapp/users/_editProfile.zul +++ b/navalplanner-webapp/src/main/webapp/users/_editProfile.zul @@ -39,7 +39,8 @@