View Javadoc

1   package org.appfuse.webapp.client.ui.users.search;
2   
3   import java.util.Set;
4   
5   import javax.validation.ConstraintViolation;
6   
7   import org.appfuse.webapp.client.application.base.view.AbstractProxySearchView;
8   import org.appfuse.webapp.client.application.utils.tables.CustomColumn;
9   import org.appfuse.webapp.client.proxies.UserProxy;
10  import org.appfuse.webapp.client.proxies.UsersSearchCriteriaProxy;
11  
12  import com.github.gwtbootstrap.client.ui.Button;
13  import com.github.gwtbootstrap.client.ui.TextBox;
14  import com.google.gwt.cell.client.Cell.Context;
15  import com.google.gwt.cell.client.FieldUpdater;
16  import com.google.gwt.core.client.GWT;
17  import com.google.gwt.editor.client.Editor;
18  import com.google.gwt.editor.client.SimpleBeanEditorDriver;
19  import com.google.gwt.event.dom.client.ClickEvent;
20  import com.google.gwt.event.dom.client.KeyCodes;
21  import com.google.gwt.event.dom.client.KeyDownEvent;
22  import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
23  import com.google.gwt.safehtml.shared.SafeHtmlUtils;
24  import com.google.gwt.uibinder.client.UiBinder;
25  import com.google.gwt.uibinder.client.UiField;
26  import com.google.gwt.uibinder.client.UiHandler;
27  import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
28  import com.google.gwt.user.client.ui.Anchor;
29  import com.google.gwt.user.client.ui.CheckBox;
30  import com.google.gwt.user.client.ui.Widget;
31  
32  public class UsersSearchViewImpl extends AbstractProxySearchView<UserProxy, UsersSearchCriteriaProxy> implements UsersSearchView, Editor<UsersSearchCriteriaProxy> {
33  
34      interface Binder extends UiBinder<Widget, UsersSearchViewImpl> {
35      }
36  
37      private static final Binder uiBinder = GWT.create(Binder.class);
38  
39      interface Driver extends SimpleBeanEditorDriver<UsersSearchCriteriaProxy, UsersSearchViewImpl> {
40      }
41  
42      private Driver editorDriver = GWT.create(Driver.class);
43  
44      @UiField
45      TextBox searchTerm;
46  
47      @UiField
48      Button addButton;
49      @UiField
50      Button doneButton;
51      @UiField
52      com.google.gwt.user.client.ui.Button searchButton;
53  
54      public UsersSearchViewImpl() {
55          initWidget(uiBinder.createAndBindUi(this));
56          getEditorDriver().initialize(this);
57          table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
58          createTableColumns();
59      }
60  
61      @UiHandler("addButton")
62      public void addButtonClicked(ClickEvent event) {
63          delegate.addClicked();
64      }
65  
66      @UiHandler("doneButton")
67      public void doneClicked(ClickEvent event) {
68          delegate.cancelClicked();
69      }
70  
71      @UiHandler("searchButton")
72      public void searchButtonClicked(ClickEvent event) {
73          delegate.searchClicked();
74      }
75  
76      @UiHandler("searchTerm")
77      void defaultAction(KeyDownEvent event) {
78          if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
79              delegate.searchClicked();
80          }
81      }
82  
83      public void createTableColumns() {
84          FieldUpdater<UserProxy, String> showDetails = new FieldUpdater<UserProxy, String>() {
85              @Override
86              public void update(int index, UserProxy object, String value) {
87                  delegate.showDetails(UserProxy.class, object.getId().toString());
88              }
89          };
90  
91          int columnNumber = 0;
92          paths.add("username");
93          table.addColumn(new CustomColumn<UserProxy, String>("username", true, showDetails) {
94              @Override
95              public String getValue(UserProxy user) {
96                  return user.getUsername();
97              }
98  
99              @Override
100             public void render(Context context, UserProxy object, SafeHtmlBuilder sb) {
101                 Anchor anchor = new Anchor(SafeHtmlUtils.htmlEscape(getValue(object)));
102                 sb.append(SafeHtmlUtils.fromTrustedString(anchor.toString()));
103             };
104         }, i18n.user_username());
105         table.setColumnWidth(columnNumber++, "25%");
106 
107         paths.add("firstName");
108         paths.add("lastName");
109         table.addColumn(new CustomColumn<UserProxy, String>("firstName", true) {
110 
111             @Override
112             public String getValue(UserProxy user) {
113                 return user.getFirstName() + " " + user.getLastName();
114             }
115         }, i18n.activeUsers_fullName());
116         table.setColumnWidth(columnNumber++, "34%");
117 
118         paths.add("email");
119         table.addColumn(new CustomColumn<UserProxy, String>("email", true) {
120 
121             @Override
122             public String getValue(UserProxy user) {
123                 return user.getEmail();
124             }
125 
126             @Override
127             public void render(Context context, UserProxy object, SafeHtmlBuilder sb) {
128                 String email = object.getEmail();
129                 Anchor anchor = new Anchor(SafeHtmlUtils.htmlEscape(email), "mailto:" + email);
130                 sb.append(SafeHtmlUtils.fromTrustedString(anchor.toString()));
131             };
132         }, i18n.user_email());
133         table.setColumnWidth(columnNumber++, "25%");
134 
135         paths.add("enabled");
136         table.addColumn(new CustomColumn<UserProxy, Boolean>("enabled", true) {
137             @Override
138             public Boolean getValue(UserProxy user) {
139                 return user.isEnabled();
140             }
141 
142             @Override
143             public void render(Context context, UserProxy object, SafeHtmlBuilder sb) {
144                 boolean isEnabled = object.isEnabled();
145                 CheckBox checkBox = new CheckBox();
146                 checkBox.setValue(isEnabled);
147                 checkBox.setEnabled(false);
148                 sb.append(SafeHtmlUtils.fromTrustedString(checkBox.toString()));
149             };
150         }, i18n.user_enabled());
151         table.setColumnWidth(columnNumber++, "16%");
152 
153     }
154 
155     /**
156      * @return the editorDriver
157      */
158     @Override
159     protected Driver getEditorDriver() {
160         return editorDriver;
161     }
162 
163 }