View Javadoc

1   package org.appfuse.webapp.client.application.base.view;
2   
3   import java.util.HashSet;
4   import java.util.Set;
5   
6   import javax.validation.ConstraintViolation;
7   
8   import org.appfuse.webapp.client.application.ApplicationResources;
9   
10  import com.github.gwtbootstrap.client.ui.DataGrid;
11  import com.google.gwt.core.client.GWT;
12  import com.google.gwt.editor.client.SimpleBeanEditorDriver;
13  import com.google.gwt.uibinder.client.UiField;
14  import com.google.gwt.user.cellview.client.CellTable;
15  import com.google.gwt.user.cellview.client.ColumnSortEvent.Handler;
16  import com.google.gwt.user.cellview.client.ColumnSortList;
17  import com.google.gwt.user.client.ui.Composite;
18  import com.google.gwt.view.client.HasData;
19  import com.google.web.bindery.requestfactory.shared.BaseProxy;
20  import com.google.web.bindery.requestfactory.shared.EntityProxy;
21  
22  /**
23   * Abstract implementation of ProxyListView.
24   *
25   * @param <P>
26   *            the type of the proxy
27   */
28  public abstract class AbstractProxySearchView<P extends EntityProxy, S> extends Composite implements ProxySearchView<P, S> {
29  
30      public @UiField(provided = true) ApplicationResources i18n = GWT.create(ApplicationResources.class);
31      protected ProxySearchView.Delegate<P> delegate;
32  
33      @UiField(provided = true)
34      public Integer pageSize = 25;
35  
36      @UiField
37      public CellTable<P> table;
38  
39      public Set<String> paths = new HashSet<String>();
40  
41      protected abstract SimpleBeanEditorDriver<S, ?> getEditorDriver();
42  
43      @Override
44      public S getSearchCriteria() {
45          return getEditorDriver() != null ? getEditorDriver().flush() : null;
46      }
47  
48      @Override
49      public void setSearchCriteria(S searchCriteria) {
50          if (getEditorDriver() != null) {
51              getEditorDriver().edit(searchCriteria);
52          }
53      }
54  
55      @Override
56      public boolean setConstraintViolations(Iterable<ConstraintViolation<S>> violations) {
57          return getEditorDriver() != null ?
58                  getEditorDriver().setConstraintViolations((Set) violations) : false;
59      }
60  
61      @Override
62      public HasData<P> asHasData() {
63          return table;
64      }
65  
66      @Override
67      public ColumnSortList getColumnSortList() {
68          return table.getColumnSortList();
69      }
70  
71      @Override
72      public void addColumnSortHandler(Handler clientSideSortHandler) {
73          table.addColumnSortHandler(clientSideSortHandler);
74      }
75  
76      @Override
77      public String[] getPaths() {
78          return paths.toArray(new String[paths.size()]);
79      }
80  
81      @Override
82      public AbstractProxySearchView<P, S> asWidget() {
83          return this;
84      }
85  
86      @Override
87      public void setDelegate(final Delegate<P> delegate) {
88          this.delegate = delegate;
89      }
90  
91      @Override
92      public void setPageSize(Integer pageSize) {
93          asHasData().setVisibleRange(asHasData().getVisibleRange().getStart(), pageSize);
94      }
95  
96  }