View Javadoc

1   package org.appfuse.webapp.client.ui.users.active;
2   
3   import java.util.HashSet;
4   import java.util.Set;
5   
6   import org.appfuse.webapp.client.application.ApplicationResources;
7   import org.appfuse.webapp.client.application.utils.tables.CustomColumn;
8   import org.appfuse.webapp.client.proxies.UserProxy;
9   
10  import com.github.gwtbootstrap.client.ui.Button;
11  import com.google.gwt.cell.client.Cell.Context;
12  import com.google.gwt.core.client.GWT;
13  import com.google.gwt.event.dom.client.ClickEvent;
14  import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
15  import com.google.gwt.safehtml.shared.SafeHtmlUtils;
16  import com.google.gwt.uibinder.client.UiBinder;
17  import com.google.gwt.uibinder.client.UiField;
18  import com.google.gwt.uibinder.client.UiHandler;
19  import com.google.gwt.user.cellview.client.CellTable;
20  import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
21  import com.google.gwt.user.client.ui.Composite;
22  import com.google.gwt.user.client.ui.Widget;
23  
24  public class ActiveUsersViewImpl extends Composite implements ActiveUsersView {
25  
26      interface Binder extends UiBinder<Widget, ActiveUsersViewImpl> {
27      }
28  
29      private static final Binder uiBinder = GWT.create(Binder.class);
30  
31      private Delegate delegate;
32  
33      @UiField(provided = true)
34      ApplicationResources i18n = GWT.create(ApplicationResources.class);
35  
36      @UiField
37      Button doneButton;
38  
39      @UiField
40      CellTable<UserProxy> table;
41      Set<String> paths = new HashSet<String>();
42  
43      public ActiveUsersViewImpl() {
44          initWidget(uiBinder.createAndBindUi(this));
45          table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
46          createTableColumns();
47      }
48  
49      @Override
50      public void setDelegate(final Delegate delegate) {
51          this.delegate = delegate;
52      }
53  
54      @Override
55      public CellTable<UserProxy> getCellTable() {
56          return table;
57      }
58  
59      @Override
60      public String[] getPaths() {
61          return paths.toArray(new String[paths.size()]);
62      }
63  
64      @UiHandler("doneButton")
65      public void doneClicked(final ClickEvent event) {
66          delegate.cancelClicked();
67      }
68  
69      public void createTableColumns() {
70  
71          int columnNumber = 0;
72          paths.add("username");
73          table.addColumn(new CustomColumn<UserProxy, String>("username", true) {
74              @Override
75              public String getValue(final UserProxy user) {
76                  return user.getUsername();
77              }
78          }, i18n.user_username());
79          table.setColumnWidth(columnNumber++, "30%");
80  
81          paths.add("email");
82          paths.add("firstName");
83          paths.add("lastName");
84          table.addColumn(new CustomColumn<UserProxy, String>("firstName", true) {
85  
86              @Override
87              public String getValue(final UserProxy user) {
88                  return user.getFirstName() + " " + user.getLastName();
89              }
90  
91              @Override
92              public void render(final Context context, final UserProxy object, final SafeHtmlBuilder sb) {
93                  final String template =
94                          SafeHtmlUtils.htmlEscape(getValue(object)) + " " +
95                                  "<a href=\"mailto:" + SafeHtmlUtils.htmlEscape(object.getEmail()) + "\">\n" +
96                                  "	<img class=\"icon\" alt=\"E-Mail\" src=\"images/iconEmail.gif\">\n" +
97                                  "</a>";
98                  sb.append(SafeHtmlUtils.fromTrustedString(template));
99              };
100         }, i18n.activeUsers_fullName());
101 
102     }
103 
104 }