View Javadoc

1   /**
2    *
3    */
4   package org.appfuse.webapp.client.ui.users.editUser;
5   
6   import java.util.List;
7   
8   import org.appfuse.webapp.client.application.ApplicationResources;
9   import org.appfuse.webapp.client.application.base.view.ProxyEditView;
10  import org.appfuse.webapp.client.proxies.LabelValueProxy;
11  import org.appfuse.webapp.client.proxies.RoleProxy;
12  import org.appfuse.webapp.client.proxies.UserProxy;
13  
14  import com.github.gwtbootstrap.client.ui.Button;
15  import com.github.gwtbootstrap.client.ui.CheckBox;
16  import com.github.gwtbootstrap.client.ui.IntegerBox;
17  import com.github.gwtbootstrap.client.ui.ListBox;
18  import com.github.gwtbootstrap.client.ui.LongBox;
19  import com.github.gwtbootstrap.client.ui.PasswordTextBox;
20  import com.github.gwtbootstrap.client.ui.TextBox;
21  import com.google.gwt.core.client.GWT;
22  import com.google.gwt.dom.client.Element;
23  import com.google.gwt.editor.client.EditorError;
24  import com.google.gwt.event.dom.client.ClickEvent;
25  import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
26  import com.google.gwt.uibinder.client.UiBinder;
27  import com.google.gwt.uibinder.client.UiField;
28  import com.google.gwt.uibinder.client.UiHandler;
29  import com.google.gwt.user.client.Window;
30  import com.google.gwt.user.client.ui.Anchor;
31  import com.google.gwt.user.client.ui.Composite;
32  import com.google.gwt.user.client.ui.UIObject;
33  import com.google.gwt.user.client.ui.Widget;
34  import com.google.web.bindery.requestfactory.gwt.client.RequestFactoryEditorDriver;
35  
36  /**
37   * @author ivangsa
38   *
39   */
40  public class EditUserViewImpl extends Composite implements EditUserView {
41  
42      interface Binder extends UiBinder<Widget, EditUserViewImpl> {
43      }
44  
45      private static final Binder BINDER = GWT.create(Binder.class);
46  
47      interface Driver extends RequestFactoryEditorDriver<UserProxy, EditUserViewImpl> {
48      }
49  
50      @UiField(provided = true)
51      protected ApplicationResources i18n = GWT.create(ApplicationResources.class);
52  
53      private EditUserView.Delegate delegate;
54  
55      @UiField
56      protected Element subheading;
57  
58      @UiField
59      LongBox id;
60      @UiField
61      IntegerBox version;
62      @UiField
63      TextBox username;
64      @UiField
65      PasswordTextBox password;
66      @UiField
67      Anchor updatePasswordButton;
68      @UiField
69      TextBox passwordHint;
70      @UiField
71      TextBox firstName;
72      @UiField
73      TextBox lastName;
74      @UiField
75      TextBox email;
76      @UiField
77      TextBox phoneNumber;
78      @UiField
79      TextBox website;
80  
81      @UiField
82      UIObject addressFieldset;
83      @UiField
84      @Path("address.address")
85      TextBox address;
86      @UiField
87      @Path("address.city")
88      TextBox city;
89      @UiField
90      @Path("address.province")
91      TextBox province;
92      @UiField
93      @Path("address.country")
94      ListBox country;
95      @UiField
96      @Path("address.postalCode")
97      TextBox postalCode;
98  
99      @UiField(provided = true)
100     protected RolesListBox roles = new RolesListBox();
101 
102     @UiField
103     protected Widget passwordControlGroup;
104     @UiField
105     protected Widget updatePasswordControl;
106     @UiField
107     protected Widget userRoles;// control group for
108     @UiField
109     protected Widget accountSettings;// control group for
110 
111     @UiField
112     CheckBox enabled;
113     @UiField
114     CheckBox accountExpired;
115     @UiField
116     CheckBox accountLocked;
117     @UiField
118     CheckBox credentialsExpired;
119 
120     @UiField
121     Button saveButton;
122     @UiField
123     protected Button deleteButton;
124     @UiField
125     Button cancelButton;
126 
127     /**
128      *
129      */
130     public EditUserViewImpl() {
131         super();
132         initWidget(BINDER.createAndBindUi(this));
133         passwordControlGroup.setVisible(false);
134         updatePasswordControl.setVisible(false);
135     }
136 
137     @Override
138     public <D extends ProxyEditView.Delegate> void setDelegate(D delegate) {
139         this.delegate = (Delegate) delegate;
140     }
141 
142     @Override
143     public RequestFactoryEditorDriver<UserProxy, ? extends EditUserView> createEditorDriver() {
144         final RequestFactoryEditorDriver<UserProxy, EditUserViewImpl> editorDriver = GWT.create(Driver.class);
145         editorDriver.initialize(this);
146         return editorDriver;
147     }
148 
149     @Override
150     public void setCountries(final List<LabelValueProxy> countries) {
151         for (final LabelValueProxy labelValue : countries) {
152             country.addItem(labelValue.getLabel(), labelValue.getValue());
153         }
154     }
155 
156     @Override
157     public void setAvailableRoles(final List<RoleProxy> roles) {
158         this.roles.setRowData(roles);
159     }
160 
161     @Override
162     public void showErrors(final List<EditorError> errors) {
163         if (errors != null && !errors.isEmpty()) {
164             final SafeHtmlBuilder b = new SafeHtmlBuilder();
165             for (final EditorError error : errors) {
166                 if (error.getPath() != null && !"".equals(error.getPath())) {
167                     final Object userData = error.getUserData();
168                     b.appendEscaped(error.getPath()).appendEscaped(": ");
169                 }
170                 b.appendEscaped(error.getMessage()).appendEscaped("\n");
171             }
172             Window.alert(b.toSafeHtml().asString());
173         }
174     }
175 
176     @UiHandler("saveButton")
177     public void onSaveButtonClick(final ClickEvent event) {
178         delegate.saveClicked();
179     }
180 
181     @UiHandler("deleteButton")
182     public void onDeleteButtonClick(final ClickEvent event) {
183         delegate.deleteClicked();
184     }
185 
186     @UiHandler("cancelButton")
187     public void onCancelButtonClick(final ClickEvent event) {
188         delegate.cancelClicked();
189     }
190 
191     @UiHandler("updatePasswordButton")
192     public void onUpdatePasswordClick(final ClickEvent event) {
193         delegate.updatePasswordClicked();
194     }
195 
196     @Override
197     public void setEnabled(final boolean b) {
198         // TODO
199     }
200 
201 }