resty-generators 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -62,6 +62,10 @@ module Resty
62
62
  @restservices_package ||= base_package + ".restservices"
63
63
  end
64
64
 
65
+ def caches_package
66
+ @caches_package ||= base_package + ".caches"
67
+ end
68
+
65
69
  def action_map
66
70
  @action_map ||= {'index' => :get_all, 'show' => :get_single, 'create' => :post, 'update' => :put, 'destroy' => :delete}
67
71
  end
@@ -19,6 +19,12 @@ module Resty
19
19
  template 'Model.java', File.join(java_root, models_package.gsub(/\./, "/"), class_path, "#{class_name}.java")
20
20
  end
21
21
 
22
+ def create_cache_file
23
+ if !options[:singleton] && !options[:read_only]
24
+ template 'Cache.java', File.join(java_root, caches_package.gsub(/\./, "/"), class_path, "#{class_name.pluralize}Cache.java")
25
+ end
26
+ end
27
+
22
28
  def create_event_files
23
29
  template 'Event.java', File.join(java_root, events_package.gsub(/\./, "/"), class_path, "#{class_name}Event.java")
24
30
  template 'EventHandler.java', File.join(java_root, events_package.gsub(/\./, "/"), class_path, "#{class_name}EventHandler.java")
@@ -82,13 +88,13 @@ end
82
88
  file = File.join(java_root, managed_package.gsub(/\./, "/"), class_path, "#{application_name}MenuPanel.java")
83
89
  if File.exists?(file)
84
90
  content = File.read(file)
85
- if content =~ /#{class_name}Place\(RestfulActionEnum/
91
+ if content =~ /#{class_name}Place\(/
86
92
  log 'keep', file
87
93
  else
88
94
  # TODO non session case !!!
89
95
  t_name = options[:singleton] ? singular_table_name : table_name
90
- content.sub! /super\(\s*sessionManager\s*\)\s*;/, "super(sessionManager);\n addButton(\"#{t_name.underscore.humanize}\").addClickHandler(new ClickHandler() {\n public void onClick(ClickEvent event) {\n placeController.goTo(new #{places_package}.#{class_name}Place(RestfulActionEnum.#{options[:singleton] ? 'SHOW' : 'INDEX'}));\n }\n });"
91
- content.sub! /super\(\s*\)\s*;/, "super();\n addButton(\"#{t_name.underscore.humanize}\").addClickHandler(new ClickHandler() {\n public void onClick(ClickEvent event) {\n placeController.goTo(new #{places_package}.#{class_name}Place(RestfulActionEnum.#{options[:singleton] ? 'SHOW' : 'INDEX'}));\n }\n });"
96
+ content.sub! /super\(\s*sessionManager\s*,\s*placeController\s*\)\s*;/, "super(sessionManager, placeController);\n addButton(\"#{t_name.underscore.humanize}\", new #{places_package}.#{class_name}Place(#{options[:singleton] ? 'SHOW' : 'INDEX'}));"
97
+ content.sub! /super\(\s*placeController\s*\)\s*;/, "super(placeController);\n addButton(\"#{t_name.underscore.humanize}\", new #{places_package}.#{class_name}Place(#{options[:singleton] ? 'SHOW' : 'INDEX'}));"
92
98
  File.open(file, 'w') { |f| f.print content }
93
99
  log "added to", file
94
100
  end
@@ -55,9 +55,9 @@ module Resty
55
55
 
56
56
  def create_scaffolded_files
57
57
  path = base_package.gsub(/\./, "/")
58
- template 'ActivityPlace.java',
59
- File.join(java_root, path,
60
- "ActivityPlace.java")
58
+ #template 'ActivityPlace.java',
59
+ # File.join(java_root, path,
60
+ # "ActivityPlace.java")
61
61
  template 'ActivityPlaceActivityMapper.java',
62
62
  File.join(java_root, path,
63
63
  "ActivityPlaceActivityMapper.java")
@@ -4,10 +4,12 @@ import <%= managed_package %>.ActivityFactory;
4
4
 
5
5
  import com.google.gwt.activity.shared.Activity;
6
6
  import com.google.gwt.activity.shared.ActivityMapper;
7
+ import com.google.gwt.core.client.GWT;
7
8
  import com.google.gwt.place.shared.Place;
8
9
  import com.google.inject.Inject;
9
10
 
10
- import de.mkristian.gwt.rails.Notice;
11
+ import <%= gwt_rails_package %>.Notice;
12
+ import <%= gwt_rails_package %>.places.RestfulPlace;
11
13
 
12
14
  public class ActivityPlaceActivityMapper implements ActivityMapper {
13
15
  protected final ActivityFactory factory;
@@ -19,10 +21,11 @@ public class ActivityPlaceActivityMapper implements ActivityMapper {
19
21
  this.factory = factory;
20
22
  }
21
23
 
22
-
24
+ @SuppressWarnings("unchecked")
23
25
  public Activity getActivity(Place place) {
24
- if (place instanceof ActivityPlace<?>) {
25
- return ((ActivityPlace<?>) place).create(factory);
26
+ if (place instanceof RestfulPlace<?, ?>) {
27
+ GWT.log(place.toString());
28
+ return ((RestfulPlace<?, ActivityFactory>) place).create(factory);
26
29
  }
27
30
  notice.setText("nothing to see");
28
31
  return null;
@@ -1,11 +1,12 @@
1
1
  package <%= places_package %>;
2
2
 
3
- import <%= base_package %>.ActivityPlace;
4
3
  import <%= managed_package %>.ActivityFactory;
5
4
 
5
+ import <%= gwt_rails_package %>.places.RestfulPlace;
6
+
6
7
  import com.google.gwt.activity.shared.Activity;
7
8
 
8
- public class LoginPlace extends ActivityPlace<Void> {
9
+ public class LoginPlace extends RestfulPlace<Void, ActivityFactory> {
9
10
 
10
11
  public static final LoginPlace LOGIN = new LoginPlace();
11
12
 
@@ -1,6 +1,6 @@
1
1
  #-*- mode: ruby -*-
2
2
  GWT_VERSION = '2.4.0'
3
- jar('de.mkristian.gwt:rails-gwt', '0.6.0').scope :provided
3
+ jar('de.mkristian.gwt:rails-gwt', '0.7.0').scope :provided
4
4
  jar('org.fusesource.restygwt:restygwt', '1.2').scope :provided
5
5
  jar('javax.ws.rs:jsr311-api', '1.1').scope :provided
6
6
  jar('com.google.gwt:gwt-user', GWT_VERSION).scope :provided
@@ -11,7 +11,7 @@ import com.google.gwt.event.dom.client.ClickEvent;
11
11
  import com.google.gwt.event.dom.client.ClickHandler;
12
12
  import com.google.gwt.place.shared.PlaceController;
13
13
 
14
- import <%= gwt_rails_package %>.places.RestfulActionEnum;
14
+ import static <%= gwt_rails_package %>.places.RestfulActionEnum.*;
15
15
  <% if options[:session] -%>
16
16
  import <%= gwt_rails_package %>.session.SessionManager;
17
17
  <% end -%>
@@ -32,7 +32,7 @@ public class <%= application_name %>PlaceHistoryMapper extends RestfulPlaceHisto
32
32
 
33
33
  @Override
34
34
  public Place getPlace(String token) {
35
- RestfulPlace<?> place = (RestfulPlace<?>) super.getPlace(token);
35
+ RestfulPlace<?, ?> place = (RestfulPlace<?, ?>) super.getPlace(token);
36
36
  // place needs to be different on the level of equals in order to trigger an activity
37
37
  place.hasSession = manager.hasSession();
38
38
  return place;
@@ -36,7 +36,7 @@ public class SessionActivityPlaceActivityMapper extends ActivityPlaceActivityMap
36
36
  protected Activity pessimisticGetActivity(Place place) {
37
37
  if (!(place instanceof NoAuthorization)) {
38
38
  if(manager.hasSession()){
39
- if(!manager.isAllowed((RestfulPlace<?>)place)){
39
+ if(!manager.isAllowed((RestfulPlace<?,?>)place)){
40
40
  notice.setText("nothing to see");
41
41
  return null;
42
42
  }
@@ -57,7 +57,7 @@ public class SessionActivityPlaceActivityMapper extends ActivityPlaceActivityMap
57
57
  protected Activity optimisticGetActivity(Place place) {
58
58
  if (place instanceof NeedsAuthorization) {
59
59
  if(manager.hasSession()){
60
- if(!manager.isAllowed((RestfulPlace<?>)place)){
60
+ if(!manager.isAllowed((RestfulPlace<?,?>)place)){
61
61
  notice.setText("nothing to see");
62
62
  return null;
63
63
  }
@@ -5,6 +5,12 @@ import java.util.List;
5
5
  <% end -%>
6
6
 
7
7
  import <%= events_package %>.<%= class_name %>Event;
8
+ <% if !options[:singleton] && !options[:read_only] -%>
9
+ import <%= events_package %>.<%= class_name %>EventHandler;
10
+ <% end -%>
11
+ <% if !options[:singleton] && !options[:read_only] -%>
12
+ import <%= caches_package %>.<%= class_name.pluralize %>Cache;
13
+ <% end -%>
8
14
  <% for attribute in attributes -%>
9
15
  <% if attribute.type == :belongs_to -%>
10
16
  import <%= models_package %>.<%= attribute.name.classify %>;
@@ -14,7 +20,9 @@ import <%= models_package %>.<%= class_name %>;
14
20
  import <%= places_package %>.<%= class_name %>Place;
15
21
  <% for attribute in attributes -%>
16
22
  <% if attribute.type == :belongs_to -%>
17
- import <%= restservices_package %>.<%= attribute.name.classify.to_s.pluralize %>RestService;
23
+ import <%= caches_package %>.<%= attribute.name.classify.to_s.pluralize %>Cache;
24
+ import <%= events_package %>.<%= attribute.name.classify %>Event;
25
+ import <%= events_package %>.<%= attribute.name.classify %>EventHandler;
18
26
  <% end -%>
19
27
  <% end -%>
20
28
  import <%= restservices_package %>.<%= class_name.pluralize %>RestService;
@@ -32,6 +40,9 @@ import com.google.inject.Inject;
32
40
  import com.google.inject.assistedinject.Assisted;
33
41
 
34
42
  import <%= gwt_rails_package %>.Notice;
43
+ <% if !options[:singleton] && !options[:read_only] -%>
44
+ import <%= gwt_rails_package %>.events.ModelEvent;
45
+ <% end -%>
35
46
  import <%= gwt_rails_package %>.events.ModelEvent.Action;
36
47
  <% unless options[:singleton] -%>
37
48
  import <%= gwt_rails_package %>.places.RestfulActionEnum;
@@ -39,25 +50,46 @@ import <%= gwt_rails_package %>.places.RestfulActionEnum;
39
50
 
40
51
  public class <%= class_name %>Activity extends AbstractActivity implements <%= class_name %>View.Presenter{
41
52
 
53
+ <% if !options[:singleton] -%>
42
54
  private final <%= class_name %>Place place;
55
+ <% end -%>
43
56
  private final <%= class_name.pluralize %>RestService service;
44
57
  private final Notice notice;
45
58
  private final PlaceController placeController;
46
59
  private final <%= class_name %>View view;
60
+ <% if !options[:singleton] && !options[:read_only] -%>
61
+ private final <%= class_name.pluralize %>Cache cache;
62
+ <% end -%>
63
+ <% attributes.select { |a| a.type == :belongs_to }.each do |attribute| -%>
64
+ private final <%= attribute.name.classify.to_s.pluralize %>Cache <%= attribute.name.pluralize %>Cache;
65
+ <% end -%>
47
66
  private EventBus eventBus;
48
67
 
49
68
  @Inject
50
69
  public <%= class_name %>Activity(@Assisted <%= class_name %>Place place, final Notice notice, final <%= class_name %>View view,
51
- <%= class_name.pluralize %>RestService service, PlaceController placeController<% for attribute in attributes -%>
70
+ <%= class_name.pluralize %>RestService service, PlaceController placeController<% if !options[:singleton] && !options[:read_only] -%>,
71
+ <%= class_name.pluralize %>Cache cache<% for attribute in attributes -%>
72
+ <% end -%>
52
73
  <% if attribute.type == :belongs_to -%>
53
- , <%= attribute.name.classify.to_s.pluralize %>RestService <%= attribute.name %>RestService<% end -%><% end -%>) {
74
+ , <%= attribute.name.classify.to_s.pluralize %>Cache <%= attribute.name.pluralize %>Cache<% end -%><% end -%>) {
75
+ <% if !options[:singleton] -%>
54
76
  this.place = place;
77
+ <% end -%>
55
78
  this.notice = notice;
56
79
  this.view = view;
57
80
  this.service = service;
58
81
  this.placeController = placeController;
82
+ <% if !options[:singleton] && !options[:read_only] -%>
83
+ this.cache = cache;
84
+ <% end -%>
85
+ <% attributes.select { |a| a.type == :belongs_to }.each do |attribute| -%>
86
+ this.<%= attribute.name.pluralize %>Cache = <%= attribute.name.pluralize %>Cache;
87
+ <% end -%>
88
+
89
+ notice.hide();
90
+ view.setup(this, place.action);
59
91
  <% for attribute in attributes -%>
60
- <% if attribute.type == :belongs_to -%>
92
+ <% if attribute.type == :belongsss_to -%>
61
93
 
62
94
  view.reset<%= attribute.name.classify.to_s.pluralize %>(null);
63
95
  <%= attribute.name %>RestService.index(new MethodCallback<List<<%= attribute.name.classify %>>>() {
@@ -67,7 +99,7 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c
67
99
  }
68
100
 
69
101
  public void onFailure(Method method, Throwable exception) {
70
- notice.setText("failed to load <%= attribute.name.pluralize %>");
102
+ notice.error("failed to load <%= attribute.name.pluralize %>");
71
103
  }
72
104
  });
73
105
  <% end -%>
@@ -76,27 +108,57 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c
76
108
 
77
109
  public void start(AcceptsOneWidget display, EventBus eventBus) {
78
110
  this.eventBus = eventBus;
111
+ <% attributes.select { |a| a.type == :belongs_to }.each do |attribute| -%>
112
+
113
+ this.eventBus.addHandler(<%= attribute.name.classify %>Event.TYPE, new <%= attribute.name.classify %>EventHandler() {
114
+
115
+ public void onModelEvent(ModelEvent<<%= attribute.name.classify %>> event) {
116
+ if(event.getModels() != null) {
117
+ view.reset<%= attribute.name.classify.to_s.pluralize %>(event.getModels());
118
+ }
119
+ }
120
+ });
121
+ view.reset<%= attribute.name.classify.to_s.pluralize %>(<%= attribute.name.pluralize %>Cache.getOrLoadModels());
122
+ <% end -%>
123
+ <% if !options[:singleton] && !options[:read_only]-%>
124
+
125
+ this.eventBus.addHandler(<%= class_name %>Event.TYPE, new <%= class_name %>EventHandler() {
126
+
127
+ public void onModelEvent(ModelEvent<<%= class_name %>> event) {
128
+ notice.finishLoading();
129
+ if (event.getModels() != null) {
130
+ view.reset(event.getModels());
131
+ } else if (event.getModel() == null) {
132
+ // TODO maybe error message ?
133
+ notice.error("error loading list of <%= class_name.underscore.humanize %>");
134
+ }
135
+ }
136
+ });
137
+ <% end -%>
138
+
79
139
  display.setWidget(view.asWidget());
80
- view.setPresenter(this);
140
+
81
141
  <% if options[:singleton] -%>
82
142
  load();
83
143
  <% else -%>
84
- switch(RestfulActionEnum.valueOf(place.action.name())){
85
- case EDIT:
144
+ switch(RestfulActionEnum.valueOf(place.action)){
145
+ <% unless options[:read_only] -%>
146
+ case EDIT:
147
+ <% end -%>
86
148
  case SHOW:
87
- load(place.model == null ? place.id : place.model.getId());
149
+ load(place.id);
88
150
  break;
151
+ <% unless options[:read_only] -%>
89
152
  case NEW:
90
- notice.setText(null);
91
153
  view.edit(new <%= class_name %>());
92
154
  break;
155
+ <% end -%>
93
156
  case INDEX:
94
157
  default:
95
158
  load();
96
159
  break;
97
160
  }
98
161
  <% end -%>
99
- view.reset(place.action);
100
162
  }
101
163
 
102
164
  public void goTo(Place place) {
@@ -104,123 +166,129 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c
104
166
  }
105
167
  <% unless options[:singleton] -%>
106
168
 
107
- public void load(){
108
- view.setEnabled(false);
169
+ public void load(){
170
+ <% if options[:read_only] -%>
109
171
  service.index(new MethodCallback<List<<%= class_name %>>>() {
110
172
 
111
173
  public void onFailure(Method method, Throwable exception) {
112
- notice.setText("error loading list of <%= class_name.underscore.humanize %>: "
113
- + exception.getMessage());
114
- view.reset(place.action);
174
+ notice.finishLoading();
175
+ notice.error("error loading list of <%= class_name.underscore.humanize %>", exception);
115
176
  }
116
177
 
117
178
  public void onSuccess(Method method, List<<%= class_name %>> response) {
179
+ notice.finishLoading();
118
180
  eventBus.fireEvent(new <%= class_name %>Event(response, Action.LOAD));
119
- notice.setText(null);
120
181
  view.reset(response);
121
- view.reset(place.action);
122
182
  }
123
183
  });
124
- if(!notice.isVisible()){
125
- notice.setText("loading list of <%= class_name.underscore.humanize %> . . .");
184
+ notice.loading();
185
+ <% else -%>
186
+ List<<%= class_name %>> models = cache.getOrLoadModels();
187
+ if (models != null){
188
+ view.reset(models);
126
189
  }
190
+ else {
191
+ // loading the event callback fills the resets the models
192
+ notice.loading();
193
+ }
194
+ <% end -%>
127
195
  }
128
196
  <% end -%>
129
- <% unless options[:singleton] -%>
197
+ <% if !options[:singleton] && !options[:read_only] -%>
130
198
 
131
199
  public void create() {
132
200
  <%= class_name %> model = view.flush();
133
- view.setEnabled(false);
134
201
  service.create(model<% if attributes.detect{|a| a.type == :belongs_to} -%>.minimalClone()<% end -%>, new MethodCallback<<%= class_name %>>() {
135
202
 
136
203
  public void onFailure(Method method, Throwable exception) {
137
- notice.setText("error creating <%= class_name.underscore.humanize %>: "
138
- + exception.getMessage());
139
- view.reset(place.action);
204
+ notice.finishLoading();
205
+ notice.error("error creating <%= class_name.underscore.humanize %>", exception);
140
206
  }
141
207
 
142
208
  public void onSuccess(Method method, <%= class_name %> response) {
209
+ notice.finishLoading();
143
210
  eventBus.fireEvent(new <%= class_name %>Event(response, Action.CREATE));
144
- notice.setText(null);
145
- view.addToList(response);
146
211
  goTo(new <%= class_name %>Place(response.getId(), RestfulActionEnum.EDIT));
147
212
  }
148
213
  });
149
- notice.setText("creating <%= class_name.underscore.humanize %> . . .");
214
+ notice.loading();
150
215
  }
151
216
  <% end -%>
152
217
 
153
218
  public void load(<% unless options[:singleton] -%>int id<% end -%>) {
154
- view.setEnabled(false);
155
- service.show(<% unless options[:singleton] -%>id, <% end -%>new MethodCallback<<%= class_name %>>() {
219
+ <% if !options[:singleton] && !options[:read_only] -%>
220
+ <%= class_name %> model = cache.getModel(id);
221
+ view.edit(model);
222
+ <% elsif options[:read_only] -%>
223
+ view.edit(new <%= class_name %>()); // clear the form
224
+ <% end -%>
225
+ <% if !options[:singleton] && !options[:read_only] && (options[:timestamps] || options[:modified_by]) -%>
226
+ if (model == null || model.get<% if options[:timestamps] -%>CreatedAt()<% else -%>ModifiedBy()<% end -%> == null) {
227
+ <% indent = ' ' -%>
228
+ <% else -%>
229
+ <% indent = '' -%>
230
+ <% end -%>
231
+ <%= indent %> service.show(<% unless options[:singleton] -%>id, <% end -%>new MethodCallback<<%= class_name %>>() {
156
232
 
157
- public void onFailure(Method method, Throwable exception) {
158
- notice.setText("error loading <%= class_name.underscore.humanize %>: "
159
- + exception.getMessage());
160
- view.reset(place.action);
161
- }
233
+ <%= indent %> public void onFailure(Method method, Throwable exception) {
234
+ <%= indent %> notice.finishLoading();
235
+ <%= indent %> notice.error("error loading <%= class_name.underscore.humanize %>", exception);
236
+ <%= indent %> }
162
237
 
163
- public void onSuccess(Method method, <%= class_name %> response) {
164
- eventBus.fireEvent(new <%= class_name %>Event(response, Action.LOAD));
165
- notice.setText(null);
166
- view.edit(response);
167
- view.reset(place.action);
168
- }
169
- });
170
- if(!notice.isVisible()){
171
- notice.setText("loading <%= class_name.underscore.humanize %> . . .");
238
+ <%= indent %> public void onSuccess(Method method, <%= class_name %> response) {
239
+ <%= indent %> notice.finishLoading();
240
+ <%= indent %> eventBus.fireEvent(new <%= class_name %>Event(response, Action.LOAD));
241
+ <%= indent %> view.edit(response);
242
+ <%= indent %> }
243
+ <%= indent %> });
244
+ <%= indent %> notice.loading();
245
+ <% if !options[:singleton] && !options[:read_only] && (options[:timestamps] || options[:modified_by]) -%>
172
246
  }
247
+ <% end -%>
173
248
  }
249
+ <% unless options[:read_only] -%>
174
250
 
175
251
  public void save() {
176
252
  <%= class_name %> model = view.flush();
177
- view.setEnabled(false);
178
253
  service.update(model<% if attributes.detect{|a| a.type == :belongs_to} -%>.minimalClone()<% end -%>, new MethodCallback<<%= class_name %>>() {
179
254
 
180
255
  public void onFailure(Method method, Throwable exception) {
181
- notice.setText("error saving <%= class_name.underscore.humanize %>: "
182
- + exception.getMessage());
183
- view.reset(place.action);
256
+ notice.finishLoading();
257
+ notice.error("error saving <%= class_name.underscore.humanize %>", exception);
184
258
  }
185
259
 
186
260
  public void onSuccess(Method method, <%= class_name %> response) {
261
+ notice.finishLoading();
187
262
  eventBus.fireEvent(new <%= class_name %>Event(response, Action.UPDATE));
188
- notice.setText(null);
189
- <% unless options[:singleton] -%>
190
- view.updateInList(response);
191
- <% end -%>
192
263
  view.edit(response);
193
- view.reset(place.action);
194
264
  }
195
265
  });
196
- notice.setText("saving <%= class_name.underscore.humanize %> . . .");
266
+ notice.loading();
197
267
  }
198
268
  <% unless options[:singleton] -%>
199
269
 
200
270
  public void delete(final <%= class_name %> model){
201
- view.setEnabled(false);
202
271
  service.destroy(model, new MethodCallback<Void>() {
203
272
 
204
273
  public void onFailure(Method method, Throwable exception) {
205
- notice.setText("error deleting <%= class_name.underscore.humanize %>: "
206
- + exception.getMessage());
207
- view.reset(place.action);
274
+ notice.finishLoading();
275
+ notice.error("error deleting <%= class_name.underscore.humanize %>", exception);
208
276
  }
209
277
 
210
278
  public void onSuccess(Method method, Void response) {
279
+ notice.finishLoading();
211
280
  eventBus.fireEvent(new <%= class_name %>Event(model, Action.DESTROY));
212
- notice.setText(null);
213
- view.removeFromList(model);
214
281
  <%= class_name %>Place next = new <%= class_name %>Place(RestfulActionEnum.INDEX);
215
282
  if(placeController.getWhere().equals(next)){
216
- view.reset(place.action);
283
+ view.removeFromList(model);
217
284
  }
218
285
  else{
219
286
  goTo(next);
220
287
  }
221
288
  }
222
289
  });
223
- notice.setText("deleting <%= class_name.underscore.humanize %> . . .");
290
+ notice.loading();
224
291
  }
225
292
  <% end -%>
293
+ <% end -%>
226
294
  }
@@ -0,0 +1,51 @@
1
+ package <%= caches_package %>;
2
+
3
+ import java.util.List;
4
+
5
+ import javax.inject.Inject;
6
+ import javax.inject.Singleton;
7
+
8
+ import <%= events_package %>.<%= class_name %>Event;
9
+ import <%= events_package %>.<%= class_name %>EventHandler;
10
+ import <%= models_package %>.<%= class_name %>;
11
+ import <%= models_package %>.User;
12
+ import <%= restservices_package %>.<%= class_name.pluralize %>RestService;
13
+
14
+ import com.google.gwt.event.shared.EventBus;
15
+ import com.google.gwt.event.shared.GwtEvent;
16
+
17
+ import <%= gwt_rails_package %>.caches.AbstractModelCache;
18
+ import <%= gwt_rails_package %>.events.ModelEvent;
19
+ import <%= gwt_rails_package %>.events.ModelEvent.Action;
20
+ import <%= gwt_rails_package %>.session.SessionManager;
21
+
22
+ @Singleton
23
+ public class <%= class_name.pluralize %>Cache extends AbstractModelCache<<%= class_name %>>{
24
+
25
+ private final <%= class_name.pluralize %>RestService restService;
26
+
27
+ @Inject
28
+ <%= class_name.pluralize %>Cache(SessionManager<User> manager, EventBus eventBus, <%= class_name.pluralize %>RestService restService) {
29
+ super(manager, eventBus);
30
+ this.restService = restService;
31
+ eventBus.addHandler(<%= class_name %>Event.TYPE, new <%= class_name %>EventHandler() {
32
+
33
+ public void onModelEvent(ModelEvent<<%= class_name %>> event) {
34
+ <%= class_name.pluralize %>Cache.this.onModelEvent(event);
35
+ }
36
+ });
37
+ }
38
+
39
+ protected void loadModels() {
40
+ restService.index(newMethodCallback());
41
+ }
42
+
43
+ protected <%= class_name %> newModel() {
44
+ return new <%= class_name %>();
45
+ }
46
+
47
+ @Override
48
+ protected GwtEvent<?> newEvent(List<<%= class_name %>> response) {
49
+ return new <%= class_name %>Event(response, Action.LOAD);
50
+ }
51
+ }
@@ -0,0 +1,34 @@
1
+ package <%= places_package %>;
2
+
3
+ import <%= gwt_rails_package %>.places.RestfulAction;
4
+ import <%= gwt_rails_package %>.places.RestfulPlace;
5
+
6
+ import <%= managed_package %>.ActivityFactory;
7
+ import <%= models_package %>.<%= class_name %>;
8
+
9
+ import com.google.gwt.activity.shared.Activity;
10
+
11
+ public class <%= class_name %>Place extends RestfulPlace<<%= class_name %>, ActivityFactory> {
12
+
13
+ public static final String NAME = "<%= table_name %>";
14
+
15
+ public Activity create(ActivityFactory factory){
16
+ return factory.create(this);
17
+ }
18
+
19
+ public <%= class_name %>Place(RestfulAction restfulAction) {
20
+ super(restfulAction, NAME);
21
+ }
22
+
23
+ public <%= class_name %>Place(<%= class_name %> model, RestfulAction restfulAction) {
24
+ super(<% unless options[:singleton] -%>model.getId(), <% end -%>model, restfulAction, NAME);
25
+ }
26
+
27
+ public <%= class_name %>Place(int id, RestfulAction restfulAction) {
28
+ super(id, restfulAction, NAME);
29
+ }
30
+
31
+ public <%= class_name %>Place(String id, RestfulAction restfulAction) {
32
+ super(id, restfulAction, NAME);
33
+ }
34
+ }
@@ -32,13 +32,25 @@ import com.google.gwt.user.client.ui.NumberLabel;
32
32
  <% end -%>
33
33
  import com.google.gwt.user.client.ui.*;
34
34
  import com.google.gwt.user.client.ui.Widget;
35
+ <% if attributes.detect {|a| [:datetime, :date, :time].member? a.type } -%>
35
36
  import com.google.gwt.user.datepicker.client.DateBox;
37
+ <% end -%>
36
38
 
39
+ <% if options[:modified_by] -%>
37
40
  import de.mkristian.gwt.rails.editors.UserLabel;
41
+ <% end -%>
42
+ <% if attributes.detect {|a| a.type == :number } -%>
38
43
  import de.mkristian.gwt.rails.editors.DoubleBox;
44
+ <% end -%>
45
+ <% if attributes.detect {|a| a.type == :integer } -%>
39
46
  import de.mkristian.gwt.rails.editors.IntegerBox;
47
+ <% end -%>
48
+ <% if attributes.detect {|a| a.type == :number || a.type == :fixnum } -%>
40
49
  import de.mkristian.gwt.rails.editors.LongBox;
50
+ <% end -%>
51
+ <% if attributes.detect {|a| a.type == :belongs_to } -%>
41
52
  import de.mkristian.gwt.rails.editors.IdentifyableListBox;
53
+ <% end -%>
42
54
 
43
55
  public class <%= class_name %>Editor extends Composite implements Editor<<%= class_name %>>{
44
56
 
@@ -70,6 +82,8 @@ public class <%= class_name %>Editor extends Composite implements Editor<<%= cla
70
82
  // TODO public java.util.List<<%= attribute.name.camelcase %>> <%= attribute.name %>;
71
83
  <% elsif attribute.type == :belongs_to -%>
72
84
  @UiField IdentifyableListBox<<%= attribute.name.classify %>> <%= attribute.name.camelcase.sub(/^(.)/){ $1.downcase } %>;
85
+ <% elsif attribute.type == :text && options[:read_only] -%>
86
+ @UiField Label <%= attribute.name.camelcase.sub(/^(.)/){ $1.downcase } %>;
73
87
  <% else -%>
74
88
  @UiField <%= type_widget_map[attribute.type][2..-1] %> <%= attribute.name.camelcase.sub(/^(.)/){ $1.downcase } %>;
75
89
  <% end -%>
@@ -102,7 +116,7 @@ public class <%= class_name %>Editor extends Composite implements Editor<<%= cla
102
116
 
103
117
  <% end -%>
104
118
  <% end -%>
105
- public void setEnabled(boolean enabled) {
119
+ public void resetVisibility() {
106
120
  <% if !options[:singleton] -%>
107
121
  this.signature.setVisible(id.getValue() != null && id.getValue() > 0);
108
122
  <% elsif options[:timestamps] -%>
@@ -110,14 +124,18 @@ public class <%= class_name %>Editor extends Composite implements Editor<<%= cla
110
124
  <% elsif options[:modified_by] -%>
111
125
  this.signature.setVisible(modifiedBy.getValue() != null);
112
126
  <% end -%>
127
+ }
128
+
129
+ public void setEnabled(boolean enabled) {
130
+ resetVisibility();
113
131
  <% for attribute in attributes -%>
114
132
  <% if attribute.type == :has_one -%>
115
133
  // TODO <%= attribute.name.camelcase %> <%= attribute.name %>;
116
134
  <% elsif attribute.type == :has_many -%>
117
135
  // TODO public java.util.List<<%= attribute.name.camelcase %>> <%= attribute.name %>;
118
- <% else -%>
136
+ <% elsif !(attribute.type == :text && options[:read_only]) -%>
119
137
  this.<%= attribute.name.camelcase.sub(/^(.)/){ $1.downcase } %>.setEnabled(enabled);
120
138
  <% end -%>
121
139
  <% end -%>
122
140
  }
123
- }
141
+ }
@@ -30,7 +30,11 @@
30
30
  <% name = attribute.name.camelcase.sub(/^(.)/){ $1.downcase } -%>
31
31
  <g:HTMLPanel>
32
32
  <label name="<%= name %>"><%= name.underscore.humanize %></label>
33
+ <% if options[:read_only] && attribute.type == :text -%>
34
+ <pre><g:Label ui:field="<%= name %>"/></pre>
35
+ <% else -%>
33
36
  <<%= type_widget_map[attribute.type] || 'r:IdentifyableListBox' %> ui:field="<%= name %>"/>
37
+ <% end -%>
34
38
  </g:HTMLPanel>
35
39
  <% end -%>
36
40
  <% end -%>
@@ -1,32 +1,34 @@
1
1
  package <%= places_package %>;
2
2
 
3
3
  import <%= gwt_rails_package %>.places.RestfulAction;
4
+ import <%= gwt_rails_package %>.places.RestfulPlace;
4
5
 
5
6
  import <%= managed_package %>.ActivityFactory;
6
7
  import <%= models_package %>.<%= class_name %>;
7
- import <%= base_package %>.ActivityPlace;
8
8
 
9
9
  import com.google.gwt.activity.shared.Activity;
10
10
 
11
- public class <%= class_name %>Place extends ActivityPlace<<%= class_name %>> {
11
+ public class <%= class_name %>Place extends RestfulPlace<<%= class_name %>, ActivityFactory> {
12
12
 
13
+ public static final String NAME = "<%= table_name %>";
14
+
13
15
  public Activity create(ActivityFactory factory){
14
16
  return factory.create(this);
15
17
  }
16
18
 
17
19
  public <%= class_name %>Place(RestfulAction restfulAction) {
18
- super(restfulAction, "<%= table_name %>");
20
+ super(restfulAction, NAME);
19
21
  }
20
22
 
21
23
  public <%= class_name %>Place(<%= class_name %> model, RestfulAction restfulAction) {
22
- super(<% unless options[:singleton] -%>model.getId(), <% end -%>model, restfulAction, "<%= table_name %>");
24
+ super(<% unless options[:singleton] -%>model.getId(), <% end -%>model, restfulAction, NAME);
23
25
  }
24
26
 
25
27
  public <%= class_name %>Place(int id, RestfulAction restfulAction) {
26
- super(id, restfulAction, "<%= table_name %>");
28
+ super(id, restfulAction, NAME);
27
29
  }
28
30
 
29
31
  public <%= class_name %>Place(String id, RestfulAction restfulAction) {
30
- super(id, restfulAction, "<%= table_name %>");
32
+ super(id, restfulAction, NAME);
31
33
  }
32
34
  }
@@ -1,35 +1,42 @@
1
1
  package <%= restservices_package %>;
2
2
 
3
+ <% if options[:singleton] -%>
3
4
  import <%= gwt_rails_package %>.dispatchers.RestfulDispatcherSingleton;
4
- <% unless options[:singleton] -%>
5
- <% if action_map.values.member? :get_all -%>
5
+ <% else -%>
6
6
  import <%= gwt_rails_package %>.dispatchers.DefaultDispatcherSingleton;
7
+ <% if action_map.values.member? :get_all -%>
8
+
7
9
  import java.util.List;
8
10
  <% end -%>
9
11
  <% end -%>
10
12
 
11
13
  import javax.ws.rs.*;
12
14
 
13
- import org.fusesource.restygwt.client.*;
15
+ <% unless options[:singleton] -%>
16
+ import org.fusesource.restygwt.client.Attribute;
17
+ <% end -%>
18
+ import org.fusesource.restygwt.client.MethodCallback;
19
+ import org.fusesource.restygwt.client.Options;
20
+ import org.fusesource.restygwt.client.RestService;
14
21
 
15
22
  <% if name -%>
23
+ import <%= models_package %>.<%= class_name %>;
16
24
  import <%= models_package %>.*;
17
25
  <% end -%>
18
26
 
19
- <% if options[:singleton] -%>@Path("/<%= singular_table_name %>")<% end %>
27
+ <% if options[:singleton] -%>@Path("/<%= singular_table_name %>")
20
28
  @Options(dispatcher = RestfulDispatcherSingleton.class)
29
+ <% else -%>
30
+ @Options(dispatcher = DefaultDispatcherSingleton.class)
31
+ <% end -%>
21
32
  public interface <%= controller_class_name %>RestService extends RestService {
22
33
 
23
34
  <% actions.each do |action|
24
35
  case action_map[action]
25
36
  when :get_all -%>
26
37
  @GET @Path("/<%= table_name %>")
27
- @Options(dispatcher = DefaultDispatcherSingleton.class)
28
38
  void <%= action %>(MethodCallback<List<<%= class_name %>>> callback);
29
39
 
30
- // @GET @Path("/<%= table_name %>")
31
- // void <%= action %>(MethodCallback<List<<%= class_name %>>> callback, @QueryParam("limit") int limit, @QueryParam("offset") int offset);
32
- //
33
40
  <% when :get_single -%>
34
41
  @GET<% unless options[:singleton] -%> @Path("/<%= table_name %>/{id}")<% end %>
35
42
  void <%= action %>(<% unless options[:singleton] -%>@PathParam("id") int id, <% end -%>MethodCallback<<%= class_name %>> callback);
@@ -21,40 +21,37 @@ import <%= gwt_rails_package %>.places.RestfulAction;
21
21
  public interface <%= class_name %>View extends IsWidget {
22
22
 
23
23
  public interface Presenter {
24
+ <% unless options[:read_only] -%>
24
25
  <% unless options[:singleton] -%>
25
26
  void create();
26
- <% end -%>
27
+ <% end -%>
27
28
  void save();
28
29
  <% unless options[:singleton] -%>
29
30
  void delete(<%= class_name %> model);
31
+ <% end -%>
30
32
  <% end -%>
31
33
  void goTo(Place place);
32
34
  }
33
- void setPresenter(Presenter presenter);
34
35
 
35
- void edit(<%= class_name %> model);
36
-
37
- <%= class_name %> flush();
36
+ void setup(Presenter presenter, RestfulAction action);
38
37
  <% unless options[:singleton] -%>
39
38
 
40
39
  void reset(List<<%= class_name %>> models);
41
40
  <% end -%>
42
-
43
- void reset(RestfulAction action);
44
-
45
- void setEnabled(boolean enabled);
46
- <% unless options[:singleton] -%>
47
-
48
- void updateInList(<%= class_name %> model);
49
-
50
- void removeFromList(<%= class_name %> model);
51
-
52
- void addToList(<%= class_name %> model);
53
- <% end -%>
54
41
  <% for attribute in attributes -%>
55
42
  <% if attribute.type == :belongs_to -%>
56
43
 
57
44
  void reset<%= attribute.name.classify.to_s.pluralize %>(List<<%= attribute.name.classify %>> list);
58
45
  <% end -%>
46
+ <% end -%>
47
+
48
+ void edit(<%= class_name %> model);
49
+ <% unless options[:read_only] -%>
50
+
51
+ <%= class_name %> flush();
52
+ <% end -%>
53
+ <% if !options[:singleton] && !options[:read_only] -%>
54
+
55
+ void removeFromList(<%= class_name %> model);
59
56
  <% end -%>
60
57
  }
@@ -4,10 +4,11 @@
4
4
  xmlns:g="urn:import:com.google.gwt.user.client.ui"
5
5
  xmlns:t="urn:import:<%= editors_package %>">
6
6
 
7
- <g:FlowPanel styleName="gwt-rails-display">
7
+ <g:FlowPanel styleName="gwt-rails-display <%= application_name.downcase %>-<%= table_name %>">
8
8
 
9
9
  <g:Label><%if options[:singleton] -%><%= class_name.underscore.singularize.humanize %><% else -%><%= class_name.underscore.pluralize.humanize %><% end -%></g:Label>
10
10
 
11
+ <% unless options[:read_only] -%>
11
12
  <g:FlowPanel styleName="gwt-rails-buttons">
12
13
  <% unless options[:singleton] -%>
13
14
  <g:Button ui:field="newButton">New</g:Button>
@@ -16,10 +17,12 @@
16
17
  <g:Button ui:field="showButton">Show</g:Button>
17
18
  </g:FlowPanel>
18
19
 
20
+ <% end -%>
19
21
  <g:FlowPanel ui:field="model" styleName="gwt-rails-model">
20
22
 
21
23
  <t:<%= class_name %>Editor ui:field="editor" styleName="gwt-rails-model-editor" />
22
24
 
25
+ <% unless options[:read_only] -%>
23
26
  <g:FlowPanel styleName="gwt-rails-buttons">
24
27
  <% unless options[:singleton] -%>
25
28
  <g:Button ui:field="createButton">Create</g:Button>
@@ -30,6 +33,7 @@
30
33
  <% end -%>
31
34
  </g:FlowPanel>
32
35
 
36
+ <% end -%>
33
37
  </g:FlowPanel>
34
38
  <% unless options[:singleton] -%>
35
39
 
@@ -4,12 +4,21 @@ package <%= views_package %>;
4
4
  import java.util.List;
5
5
 
6
6
  <% end -%>
7
+ <% unless options[:read_only] -%>
8
+ import javax.inject.Inject;
9
+ <% end -%>
10
+
7
11
  import <%= editors_package %>.<%= class_name %>Editor;
8
12
  <% for attribute in attributes -%>
9
13
  <% if attribute.type == :belongs_to -%>
10
14
  import <%= models_package %>.<%= attribute.name.classify %>;
11
15
  <% end -%>
12
16
  <% end -%>
17
+ <% unless options[:read_only] -%>
18
+ <% unless class_name == 'User' -%>
19
+ import <%= models_package %>.User;
20
+ <% end -%>
21
+ <% end -%>
13
22
  import <%= models_package %>.<%= class_name %>;
14
23
  import <%= places_package %>.<%= class_name %>Place;
15
24
 
@@ -21,7 +30,9 @@ import com.google.gwt.event.dom.client.ClickHandler;
21
30
  <% end -%>
22
31
  import com.google.gwt.uibinder.client.UiBinder;
23
32
  import com.google.gwt.uibinder.client.UiField;
33
+ <% unless options[:read_only] -%>
24
34
  import com.google.gwt.uibinder.client.UiHandler;
35
+ <% end -%>
25
36
  import com.google.gwt.uibinder.client.UiTemplate;
26
37
  import com.google.gwt.user.client.ui.Button;
27
38
  import com.google.gwt.user.client.ui.Composite;
@@ -34,6 +45,10 @@ import com.google.inject.Singleton;
34
45
 
35
46
  import <%= gwt_rails_package %>.places.RestfulAction;
36
47
  import <%= gwt_rails_package %>.places.RestfulActionEnum;
48
+ import static <%= gwt_rails_package %>.places.RestfulActionEnum.*;
49
+ <% unless options[:read_only] -%>
50
+ import <%= gwt_rails_package %>.session.SessionManager;
51
+ <% end -%>
37
52
  <% unless options[:singleton] -%>
38
53
  import <%= gwt_rails_package %>.views.ModelButton;
39
54
  <% end -%>
@@ -50,15 +65,13 @@ public class <%= class_name %>ViewImpl extends Composite implements <%= class_na
50
65
 
51
66
  private final EditorDriver editorDriver = GWT.create(EditorDriver.class);
52
67
 
53
- <% unless options[:readonly] -%>
68
+ <% unless options[:read_only] -%>
54
69
  <% unless options[:singleton] -%>
55
70
  @UiField Button newButton;
56
71
  <% end -%>
57
72
  @UiField Button editButton;
58
- <% end -%>
59
73
  @UiField Button showButton;
60
74
 
61
- <% unless options[:readonly] -%>
62
75
  <% unless options[:singleton] -%>
63
76
  @UiField Button createButton;
64
77
  <% end -%>
@@ -76,12 +89,32 @@ public class <%= class_name %>ViewImpl extends Composite implements <%= class_na
76
89
  @UiField <%= class_name %>Editor editor;
77
90
 
78
91
  private Presenter presenter;
92
+ <% unless options[:read_only] -%>
93
+
94
+ private final SessionManager<User> session;
95
+ <% end -%>
79
96
 
80
97
  public <%= class_name %>ViewImpl() {
98
+ <% unless options[:read_only] -%>
99
+ this(null);
100
+ }
101
+
102
+ @Inject
103
+ public <%= class_name %>ViewImpl(SessionManager<User> session) {
104
+ <% end -%>
81
105
  initWidget(BINDER.createAndBindUi(this));
82
106
  editorDriver.initialize(editor);
107
+ <% unless options[:read_only] -%>
108
+ this.session = session;
109
+ <% end -%>
110
+ }
111
+ <% unless options[:read_only] -%>
112
+
113
+ private boolean isAllowed(RestfulActionEnum action){
114
+ return session == null || session.isAllowed(<%= class_name %>Place.NAME, action);
83
115
  }
84
- <% unless options[:readonly] -%>
116
+ <% end -%>
117
+ <% unless options[:read_only] -%>
85
118
  <% unless options[:singleton] -%>
86
119
 
87
120
  @UiHandler("newButton")
@@ -117,56 +150,52 @@ public class <%= class_name %>ViewImpl extends Composite implements <%= class_na
117
150
  void onClickDelete(ClickEvent e) {
118
151
  presenter.delete(flush());
119
152
  }
120
-
121
153
  <% end -%>
122
154
  <% end -%>
123
- public void setPresenter(Presenter presenter) {
124
- this.presenter = presenter;
125
- }
126
-
127
- public void edit(<%= class_name %> model) {
128
- this.editorDriver.edit(model);
129
- }
130
155
 
131
- public <%= class_name %> flush() {
132
- return editorDriver.flush();
133
- }
134
-
135
- public void setEnabled(boolean enabled) {
136
- editor.setEnabled(enabled);
137
- }
138
-
139
- public void reset(RestfulAction action) {
156
+ public void setup(Presenter presenter, RestfulAction a) {
157
+ RestfulActionEnum action = RestfulActionEnum.valueOf(a);
158
+ this.presenter = presenter;
140
159
  <% if options[:singleton] -%>
141
- editButton.setVisible(action.name().equals(RestfulActionEnum.SHOW.name()) ||
142
- action.name().equals(RestfulActionEnum.INDEX.name()));
143
- saveButton.setVisible(action.name().equals(RestfulActionEnum.EDIT.name()));
144
- showButton.setVisible(action.name().equals(RestfulActionEnum.EDIT.name()));
145
- setEnabled(!action.viewOnly());
160
+ editButton.setVisible((action == SHOW || action == INDEX) && isAllowed(EDIT));
161
+ saveButton.setVisible(action == EDIT);
162
+ showButton.setVisible(action == EDIT);
163
+ editor.setEnabled(!action.viewOnly());
146
164
  <% else -%>
147
- newButton.setVisible(!action.name().equals(RestfulActionEnum.NEW.name()));
148
- if(action.name().equals(RestfulActionEnum.INDEX.name())){
165
+ <% unless options[:read_only] -%>
166
+ newButton.setVisible(action != NEW && isAllowed(NEW));
167
+ <% end -%>
168
+ if(action == INDEX){
169
+ <% unless options[:read_only] -%>
149
170
  editButton.setVisible(false);
150
171
  showButton.setVisible(false);
172
+ <% end -%>
151
173
  list.setVisible(true);
152
174
  model.setVisible(false);
153
175
  }
154
176
  else {
155
- <% if options[:readonly] -%>
156
- setEnabled(false);
157
- <% else -%>
158
- createButton.setVisible(action.name().equals(RestfulActionEnum.NEW.name()));
159
- editButton.setVisible(action.name().equals(RestfulActionEnum.SHOW.name()));
160
- showButton.setVisible(action.name().equals(RestfulActionEnum.EDIT.name()));
161
- saveButton.setVisible(action.name().equals(RestfulActionEnum.EDIT.name()));
162
- deleteButton.setVisible(action.name().equals(RestfulActionEnum.EDIT.name()));
177
+ <% unless options[:read_only] -%>
178
+ createButton.setVisible(action == NEW);
179
+ editButton.setVisible(action == SHOW && isAllowed(EDIT));
180
+ showButton.setVisible(action == EDIT);
181
+ saveButton.setVisible(action == EDIT);
182
+ deleteButton.setVisible(action == EDIT && isAllowed(DESTROY));
163
183
  <% end -%>
164
- setEnabled(!action.viewOnly());
165
184
  list.setVisible(false);
166
185
  model.setVisible(true);
167
186
  }
187
+ editor.setEnabled(!action.viewOnly());
168
188
  <% end -%>
169
189
  }
190
+
191
+ public void edit(<%= class_name %> model) {
192
+ this.editorDriver.edit(model);
193
+ this.editor.resetVisibility();
194
+ }
195
+
196
+ public <%= class_name %> flush() {
197
+ return editorDriver.flush();
198
+ }
170
199
  <% unless options[:singleton] -%>
171
200
 
172
201
  private final ClickHandler clickHandler = new ClickHandler() {
@@ -175,9 +204,11 @@ public class <%= class_name %>ViewImpl extends Composite implements <%= class_na
175
204
  public void onClick(ClickEvent event) {
176
205
  ModelButton<<%= class_name %>> button = (ModelButton<<%= class_name %>>)event.getSource();
177
206
  switch(button.action){
207
+ <% unless options[:read_only] -%>
178
208
  case DESTROY:
179
209
  presenter.delete(button.model);
180
210
  break;
211
+ <% end -%>
181
212
  default:
182
213
  presenter.goTo(new <%= class_name %>Place(button.model, button.action));
183
214
  }
@@ -193,10 +224,14 @@ public class <%= class_name %>ViewImpl extends Composite implements <%= class_na
193
224
  public void reset(List<<%= class_name %>> models) {
194
225
  list.removeAllRows();
195
226
  list.setText(0, 0, "Id");
196
- <% attributes.each_with_index do |attribute, index| -%>
197
- list.setText(0, <%= index + 1 %>, "<%= attribute.name.humanize -%>");
227
+ <% index = 0 -%>
228
+ <% attributes.each do |attribute| -%>
229
+ <% if !(attribute.type == :text && options[:read_only]) -%>
230
+ <% index = index + 1 -%>
231
+ list.setText(0, <%= index %>, "<%= attribute.name.humanize -%>");
232
+ <% end -%>
198
233
  <% end -%>
199
- list.getRowFormatter().addStyleName(0, "model-list-header");
234
+ list.getRowFormatter().addStyleName(0, "gwt-rails-model-list-header");
200
235
  int row = 1;
201
236
  for(<%= class_name %> model: models){
202
237
  setRow(row, model);
@@ -206,27 +241,24 @@ public class <%= class_name %>ViewImpl extends Composite implements <%= class_na
206
241
 
207
242
  private void setRow(int row, <%= class_name %> model) {
208
243
  list.setText(row, 0, model.getId() + "");
209
- <% attributes.each_with_index do |attribute, index| -%>
244
+ <% index = 0 -%>
245
+ <% attributes.each do |attribute| -%>
210
246
  <% if attribute.type != :has_one && attribute.type != :has_many -%>
211
247
  <% name = attribute.name.camelcase.sub(/^(.)/){ $1.downcase } -%>
212
- list.setText(row, <%= index + 1 %>, model.get<%= name.camelcase %>()<%= attribute.type == :has_one || attribute.type == :belongs_to ? ' == null ? "-" : model.get' + name.camelcase + '().toDisplay()' : ' + ""' %>);
248
+ <% if !(attribute.type == :text && options[:read_only]) -%>
249
+ <% index = index + 1 -%>
250
+ list.setText(row, <%= index %>, model.get<%= name.camelcase %>()<%= attribute.type == :has_one || attribute.type == :belongs_to ? ' == null ? "-" : model.get' + name.camelcase + '().toDisplay()' : ' + ""' %>);
251
+ <% end -%>
213
252
  <% end -%>
214
-
215
253
  <% end -%>
216
- list.setWidget(row, <%= attributes.size + 1 %>, newButton(RestfulActionEnum.SHOW, model));
217
- list.setWidget(row, <%= attributes.size + 2 %>, newButton(RestfulActionEnum.EDIT, model));
218
- list.setWidget(row, <%= attributes.size + 3 %>, newButton(RestfulActionEnum.DESTROY, model));
219
- }
220
254
 
221
- public void updateInList(<%= class_name %> model) {
222
- String id = model.getId() + "";
223
- for(int i = 0; i < list.getRowCount(); i++){
224
- if(list.getText(i, 0).equals(id)){
225
- setRow(i, model);
226
- return;
227
- }
228
- }
255
+ list.setWidget(row, <%= index + 1 %>, newButton(RestfulActionEnum.SHOW, model));
256
+ <% unless options[:read_only] -%>
257
+ list.setWidget(row, <%= index + 2 %>, newButton(RestfulActionEnum.EDIT, model));
258
+ list.setWidget(row, <%= index + 3 %>, newButton(RestfulActionEnum.DESTROY, model));
259
+ <% end -%>
229
260
  }
261
+ <% unless options[:read_only] -%>
230
262
 
231
263
  public void removeFromList(<%= class_name %> model) {
232
264
  String id = model.getId() + "";
@@ -237,10 +269,7 @@ public class <%= class_name %>ViewImpl extends Composite implements <%= class_na
237
269
  }
238
270
  }
239
271
  }
240
-
241
- public void addToList(<%= class_name %> model) {
242
- setRow(list.getRowCount(), model);
243
- }
272
+ <% end -%>
244
273
  <% end -%>
245
274
  <% for attribute in attributes -%>
246
275
  <% if attribute.type == :belongs_to -%>
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: resty-generators
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.6.0
5
+ version: 0.7.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - mkristian
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-10-15 00:00:00 +05:30
13
+ date: 2011-11-04 00:00:00 +05:30
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -21,7 +21,7 @@ dependencies:
21
21
  requirements:
22
22
  - - ~>
23
23
  - !ruby/object:Gem::Version
24
- version: 0.1.2
24
+ version: 0.1.3
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
27
  - !ruby/object:Gem::Dependency
@@ -150,6 +150,7 @@ files:
150
150
  - lib/generators/resty/setup/templates/empty.css~
151
151
  - lib/generators/resty/scaffold/scaffold_generator.rb
152
152
  - lib/generators/resty/templates/PlaceTokenizer.java
153
+ - lib/generators/resty/templates/Cache.java~
153
154
  - lib/generators/resty/templates/ViewImpl.java~
154
155
  - lib/generators/resty/templates/EventHandler.java~
155
156
  - lib/generators/resty/templates/Model.java
@@ -164,6 +165,7 @@ files:
164
165
  - lib/generators/resty/templates/ActivityPlace.java~
165
166
  - lib/generators/resty/templates/Controller.java~
166
167
  - lib/generators/resty/templates/RestService.java
168
+ - lib/generators/resty/templates/Cache.java
167
169
  - lib/generators/resty/templates/Activity.java
168
170
  - lib/generators/resty/templates/RestService.java~
169
171
  - lib/generators/resty/templates/Editor.ui.xml~