View Javadoc

1   package org.appfuse.webapp.pages;
2   
3   import org.apache.wicket.Page;
4   import org.apache.wicket.markup.html.form.Form;
5   import org.apache.wicket.model.CompoundPropertyModel;
6   import org.apache.wicket.model.IModel;
7   import org.apache.wicket.spring.injection.annot.SpringBean;
8   import org.appfuse.model.User;
9   import org.appfuse.service.RoleManager;
10  import org.appfuse.service.UserManager;
11  import org.appfuse.webapp.pages.components.UserEditPanel;
12  
13  /**
14   * Abstract page for editing users.
15   *
16   * Reusable UserEditPanel allows to simple adjust for user signup and editing: current user, existing user, new user.
17   *
18   * @author Marcin ZajÄ…czkowski, 2011-03-19
19   */
20  public abstract class AbstractUserEdit extends AbstractWebPage {
21  
22      protected static Page NO_RESPONSE_PAGE = null;
23  
24      @SpringBean(name = "userManager")
25      private UserManager userManager;
26  
27      @SpringBean(name = "roleManager")
28      private RoleManager roleManager;
29  
30      private final Page responsePage;
31      private final String propertyPrefix;
32      private final IModel<User> userModel;
33  
34      private Form<User> userEditForm;
35  
36      protected AbstractUserEdit(Page responsePage, String propertyPrefix, IModel<User> userModel) {
37          super();
38          this.responsePage = responsePage;
39          this.propertyPrefix = propertyPrefix;
40          this.userModel = userModel;
41      }
42  
43      @Override
44      protected void onInitialize() {
45          super.onInitialize();
46  
47          add(createPageTitleTag(propertyPrefix + ".title"));
48          add(createPageHeading(propertyPrefix + ".heading"));
49          add(createPageMessage(propertyPrefix + ".message"));
50  
51          add(createFeedbackPanel());
52  
53          CompoundPropertyModel<User> userCompoundPropertyModel = new CompoundPropertyModel<User>(userModel);
54  
55          userEditForm = new Form<User>("userEditForm", userCompoundPropertyModel);
56          add(userEditForm);
57  
58          //TODO: MZA: Extract concrete class and pass interface to avoid Foo.this.on... duplication
59          UserEditPanel userEditPanel = new UserEditPanel("userEditPanel", userCompoundPropertyModel,
60                  roleManager.getAll()) {
61  
62              @Override
63              protected void onSaveButtonSubmit() {
64                  log.info("onSaveButtonSubmit");
65                  AbstractUserEdit.this.onSaveButtonSubmit();
66              }
67  
68              @Override
69              protected void onDeleteButtonSubmit() {
70                  log.info("onDeleteButtonSubmit");
71                  AbstractUserEdit.this.onDeleteButtonSubmit();
72              }
73  
74              @Override
75              protected void onCancelButtonSubmit() {
76                  log.info("onCancelButtonSubmit");
77                  AbstractUserEdit.this.onCancelButtonSubmit();
78              }
79  
80              @Override
81              protected boolean getAccountSettingsGroupVisibility() {
82                  return AbstractUserEdit.this.getAccountSettingsGroupVisibility();
83              }
84  
85              @Override
86              protected boolean getDisplayRolesGroupVisibility() {
87                  return AbstractUserEdit.this.getDisplayRolesGroupVisibility();
88              }
89  
90              @Override
91              protected boolean getDeleteButtonVisibility() {
92                  return AbstractUserEdit.this.getDeleteButtonVisibility();
93              }
94  
95              @Override
96              protected boolean isCollapsedAddressTab() {
97                  return AbstractUserEdit.this.isCollapsedAddressTab();
98              }
99          };
100 
101         userEditForm.add(userEditPanel);
102     }
103 
104     protected void resolveAndSetResponsePage() {
105         if (responsePage == null) {
106             setResponsePage(getApplication().getHomePage());
107         } else {
108             setResponsePage(responsePage);
109         }
110     }
111 
112     protected UserManager getUserManager() {
113         return userManager;
114     }
115 
116     protected RoleManager getRoleManager() {
117         return roleManager;
118     }
119 
120     protected Form<User> getUserEditForm() {
121         return userEditForm;
122     }
123 
124     protected User getUser() {
125         return userModel.getObject();
126     }
127 
128     //required by CurrentUserEdit which cannot lookup current user in a constructor
129     protected void setUser(User user) {
130         userModel.setObject(user);
131     }
132 
133     protected abstract void onSaveButtonSubmit();
134 
135     protected abstract void onDeleteButtonSubmit();
136 
137     /**
138      * A handler for a click on a cancel button.
139      *
140      * Return to a requested response page is usually a good action. Can be overridden if needed.
141      */
142     protected void onCancelButtonSubmit() {
143         resolveAndSetResponsePage();
144     }
145 
146     protected abstract boolean getDisplayRolesGroupVisibility();
147 
148     protected abstract boolean getAccountSettingsGroupVisibility();
149 
150     protected abstract boolean getDeleteButtonVisibility();
151 
152     protected boolean isCollapsedAddressTab() {
153         return true;
154     }
155 }