View Javadoc

1   package org.appfuse.webapp.client.application.base.activity;
2   
3   import javax.validation.Validator;
4   import javax.validation.ValidatorFactory;
5   
6   import org.appfuse.webapp.client.application.Application;
7   import org.appfuse.webapp.client.application.ApplicationProxyFactory;
8   import org.appfuse.webapp.client.application.ApplicationResources;
9   import org.appfuse.webapp.client.requests.ApplicationRequestFactory;
10  import org.appfuse.webapp.client.ui.Shell;
11  
12  import com.google.gwt.activity.shared.AbstractActivity;
13  import com.google.gwt.dom.client.Document;
14  import com.google.gwt.place.shared.Place;
15  import com.google.gwt.place.shared.PlaceController;
16  import com.google.web.bindery.event.shared.EventBus;
17  
18  public abstract class AbstractBaseActivity extends AbstractActivity {
19  
20      protected final Place currentPlace;
21      protected final Shell shell;
22      protected final Application application;
23      protected final EventBus eventBus;
24      protected final ApplicationRequestFactory requests;
25      protected final PlaceController placeController;
26      protected final ApplicationProxyFactory proxyFactory;
27      protected final ValidatorFactory validatorFactory;
28      protected final ApplicationResources i18n;
29  
30      private String title;
31      private String bodyId;
32      private String bodyClassname;
33  
34      /**
35       */
36      public AbstractBaseActivity(final Application application) {
37          super();
38          this.application = application;
39          this.shell = application.getShell();
40          this.eventBus = application.getEventBus();
41          this.requests = application.getRequestFactory();
42          this.placeController = application.getPlaceController();
43          this.currentPlace = placeController.getWhere();
44          this.proxyFactory = application.getProxyFactory();
45          this.validatorFactory = application.getValidatorFactory();
46          this.i18n = application.getI18n();
47      }
48  
49      protected void setDocumentTitleAndBodyAttributtes() {
50          // set document title and body class/id
51          if (getTitle() != null) {
52              Document.get().setTitle(getTitle() + " | " + application.getI18n().webapp_name());
53          } else {
54              Document.get().setTitle(application.getI18n().webapp_name());
55          }
56  
57          if (getBodyId() != null) {
58              Document.get().getBody().setId(getBodyId());
59          } else {
60              Document.get().getBody().removeAttribute("id");
61          }
62  
63          if (getBodyClassName() != null) {
64              Document.get().getBody().setClassName(getBodyClassName());
65          } else {
66              Document.get().getBody().removeAttribute("class");
67          }
68      }
69  
70      public String getTitle() {
71          return title;
72      }
73  
74      public String getBodyId() {
75          return bodyId;
76      }
77  
78      public String getBodyClassName() {
79          return bodyClassname;
80      }
81  
82      public String getBodyClassname() {
83          return bodyClassname;
84      }
85  
86      public void setBodyClassname(final String bodyClassname) {
87          this.bodyClassname = bodyClassname;
88      }
89  
90      public void setTitle(final String title) {
91          this.title = title;
92      }
93  
94      public void setBodyId(final String bodyId) {
95          this.bodyId = bodyId;
96      }
97  
98      /**
99       * 
100      * @return
101      */
102     protected Validator getValidator() {
103         return validatorFactory.getValidator();
104     }
105 
106     // Mobile interface
107 
108     protected Place getBackButtonPlace() {
109         return null;
110     }
111 
112     protected String getBackButtonText() {
113         return null;
114     }
115 
116     protected Place getEditButtonPlace() {
117         return null;
118     }
119 
120     protected boolean hasEditButton() {
121         return false;
122     }
123 
124 }