resty-generators 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/generators/resty/model/model_generator.rb +1 -1
- data/lib/generators/resty/scaffold/scaffold_generator.rb +47 -30
- data/lib/generators/resty/setup/setup_generator.rb +11 -0
- data/lib/generators/resty/setup/templates/ActivityPlace.java +8 -4
- data/lib/generators/resty/setup/templates/ActivityPlaceActivityMapper.java +3 -3
- data/lib/generators/resty/setup/templates/BreadCrumbsPanel.java +3 -6
- data/lib/generators/resty/setup/templates/EntryPoint.java +22 -17
- data/lib/generators/resty/setup/templates/LoginPlace.java +3 -3
- data/lib/generators/resty/setup/templates/LoginView.ui.xml +1 -1
- data/lib/generators/resty/setup/templates/Mavenfile +1 -1
- data/lib/generators/resty/setup/templates/MenuPanel.java +27 -0
- data/lib/generators/resty/setup/templates/PlaceHistoryMapper.java +37 -4
- data/lib/generators/resty/setup/templates/SessionActivityPlaceActivityMapper.java +10 -10
- data/lib/generators/resty/setup/templates/authentication.rb +1 -1
- data/lib/generators/resty/templates/Activity.java +63 -17
- data/lib/generators/resty/templates/Model.java +2 -2
- data/lib/generators/resty/templates/Place.java +7 -2
- data/lib/generators/resty/templates/PlaceTokenizer.java +3 -8
- data/lib/generators/resty/templates/RestService.java +4 -2
- data/lib/generators/resty/templates/View.java +16 -2
- data/lib/generators/resty/templates/View.ui.xml +31 -19
- data/lib/generators/resty/templates/ViewImpl.java +131 -28
- data/lib/resty-generators.rb +1 -1
- metadata +9 -12
- data/lib/generators/resty/setup/templates/monkey_patch.rb +0 -47
- data/lib/generators/resty/templates/ColumnDefinitionsImpl.java +0 -24
- data/lib/resty/child_path.rb +0 -31
@@ -1,14 +1,14 @@
|
|
1
1
|
package <%= activities_package %>;
|
2
|
+
<% unless options[:singleton] -%>
|
2
3
|
|
4
|
+
import java.util.List;
|
5
|
+
<% end -%>
|
3
6
|
|
4
7
|
import <%= models_package %>.<%= class_name %>;
|
5
8
|
import <%= places_package %>.<%= class_name %>Place;
|
6
9
|
import <%= restservices_package %>.<%= class_name.pluralize %>RestService;
|
7
10
|
import <%= views_package %>.<%= class_name %>View;
|
8
11
|
|
9
|
-
import <%= gwt_rails_package %>.Notice;
|
10
|
-
import <%= gwt_rails_package %>.RestfulActionEnum;
|
11
|
-
|
12
12
|
import org.fusesource.restygwt.client.Method;
|
13
13
|
import org.fusesource.restygwt.client.MethodCallback;
|
14
14
|
|
@@ -20,6 +20,11 @@ import com.google.gwt.user.client.ui.AcceptsOneWidget;
|
|
20
20
|
import com.google.inject.Inject;
|
21
21
|
import com.google.inject.assistedinject.Assisted;
|
22
22
|
|
23
|
+
import <%= gwt_rails_package %>.Notice;
|
24
|
+
<% unless options[:singleton] -%>
|
25
|
+
import <%= gwt_rails_package %>.places.RestfulActionEnum;
|
26
|
+
<% end -%>
|
27
|
+
|
23
28
|
public class <%= class_name %>Activity extends AbstractActivity implements <%= class_name %>View.Presenter{
|
24
29
|
|
25
30
|
private final <%= class_name %>Place place;
|
@@ -31,7 +36,7 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c
|
|
31
36
|
@Inject
|
32
37
|
public <%= class_name %>Activity(@Assisted <%= class_name %>Place place, Notice notice, <%= class_name %>View view,
|
33
38
|
<%= class_name.pluralize %>RestService service, PlaceController placeController) {
|
34
|
-
|
39
|
+
this.place = place;
|
35
40
|
this.notice = notice;
|
36
41
|
this.view = view;
|
37
42
|
this.service = service;
|
@@ -42,20 +47,21 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c
|
|
42
47
|
display.setWidget(view.asWidget());
|
43
48
|
view.setPresenter(this);
|
44
49
|
<% if options[:singleton] -%>
|
45
|
-
|
50
|
+
load();
|
46
51
|
<% else -%>
|
47
52
|
switch(RestfulActionEnum.valueOf(place.action.name())){
|
48
53
|
case EDIT:
|
49
54
|
case SHOW:
|
50
|
-
load(place.id);
|
55
|
+
load(place.model == null ? place.id : place.model.id);
|
51
56
|
break;
|
52
|
-
case
|
53
|
-
//TODO
|
54
|
-
default:
|
55
|
-
case NEW:
|
57
|
+
case NEW:
|
56
58
|
notice.setText(null);
|
57
59
|
view.reset(new <%= class_name %>());
|
58
60
|
break;
|
61
|
+
case INDEX:
|
62
|
+
default:
|
63
|
+
load();
|
64
|
+
break;
|
59
65
|
}
|
60
66
|
<% end -%>
|
61
67
|
view.reset(place.action);
|
@@ -64,6 +70,29 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c
|
|
64
70
|
public void goTo(Place place) {
|
65
71
|
placeController.goTo(place);
|
66
72
|
}
|
73
|
+
<% unless options[:singleton] -%>
|
74
|
+
|
75
|
+
public void load(){
|
76
|
+
view.setEnabled(false);
|
77
|
+
service.index(new MethodCallback<List<<%= class_name %>>>() {
|
78
|
+
|
79
|
+
public void onFailure(Method method, Throwable exception) {
|
80
|
+
notice.setText("error loading list of <%= class_name.underscore.humanize %>: "
|
81
|
+
+ exception.getMessage());
|
82
|
+
view.reset(place.action);
|
83
|
+
}
|
84
|
+
|
85
|
+
public void onSuccess(Method method, List<<%= class_name %>> response) {
|
86
|
+
view.reset(response);
|
87
|
+
notice.setText(null);
|
88
|
+
view.reset(place.action);
|
89
|
+
}
|
90
|
+
});
|
91
|
+
if(!notice.isVisible()){
|
92
|
+
notice.setText("loading list of <%= class_name.underscore.humanize %> . . .");
|
93
|
+
}
|
94
|
+
}
|
95
|
+
<% end -%>
|
67
96
|
|
68
97
|
public void load(<% unless options[:singleton] -%>int id<% end -%>) {
|
69
98
|
view.setEnabled(false);
|
@@ -76,8 +105,8 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c
|
|
76
105
|
}
|
77
106
|
|
78
107
|
public void onSuccess(Method method, <%= class_name %> response) {
|
79
|
-
view.reset(response);
|
80
108
|
notice.setText(null);
|
109
|
+
view.reset(response);
|
81
110
|
view.reset(place.action);
|
82
111
|
}
|
83
112
|
});
|
@@ -94,9 +123,12 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c
|
|
94
123
|
public void onFailure(Method method, Throwable exception) {
|
95
124
|
notice.setText("error creating <%= class_name.underscore.humanize %>: "
|
96
125
|
+ exception.getMessage());
|
126
|
+
view.reset(place.action);
|
97
127
|
}
|
98
128
|
|
99
129
|
public void onSuccess(Method method, <%= class_name %> response) {
|
130
|
+
notice.setText(null);
|
131
|
+
view.addToList(response);
|
100
132
|
goTo(new <%= class_name %>Place(response.id,
|
101
133
|
RestfulActionEnum.EDIT));
|
102
134
|
}
|
@@ -104,36 +136,50 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c
|
|
104
136
|
notice.setText("creating <%= class_name.underscore.humanize %> . . .");
|
105
137
|
}
|
106
138
|
|
107
|
-
public void delete()
|
108
|
-
<%= class_name %> model = view.retrieve<%= class_name %>();
|
139
|
+
public void delete(final <%= class_name %> model){
|
109
140
|
view.setEnabled(false);
|
110
141
|
service.destroy(model, new MethodCallback<Void>() {
|
111
142
|
|
112
143
|
public void onFailure(Method method, Throwable exception) {
|
113
144
|
notice.setText("error deleting <%= class_name.underscore.humanize %>: "
|
114
145
|
+ exception.getMessage());
|
146
|
+
view.reset(place.action);
|
115
147
|
}
|
116
148
|
|
117
149
|
public void onSuccess(Method method, Void response) {
|
118
|
-
|
150
|
+
notice.setText(null);
|
151
|
+
view.removeFromList(model);
|
152
|
+
<%= class_name %>Place next = new <%= class_name %>Place(RestfulActionEnum.INDEX);
|
153
|
+
if(placeController.getWhere().equals(next)){
|
154
|
+
view.reset(place.action);
|
155
|
+
}
|
156
|
+
else{
|
157
|
+
goTo(next);
|
158
|
+
}
|
119
159
|
}
|
120
160
|
});
|
121
161
|
notice.setText("deleting <%= class_name.underscore.humanize %> . . .");
|
122
162
|
}
|
123
163
|
<% end -%>
|
164
|
+
|
124
165
|
public void save() {
|
125
166
|
<%= class_name %> model = view.retrieve<%= class_name %>();
|
126
167
|
view.setEnabled(false);
|
127
168
|
service.update(model, new MethodCallback<<%= class_name %>>() {
|
128
169
|
|
129
170
|
public void onFailure(Method method, Throwable exception) {
|
130
|
-
notice.setText("error
|
171
|
+
notice.setText("error saving <%= class_name.underscore.humanize %>: "
|
131
172
|
+ exception.getMessage());
|
173
|
+
view.reset(place.action);
|
132
174
|
}
|
133
175
|
|
134
176
|
public void onSuccess(Method method, <%= class_name %> response) {
|
135
|
-
|
136
|
-
|
177
|
+
notice.setText(null);
|
178
|
+
<% unless options[:singleton] -%>
|
179
|
+
view.updateInList(response);
|
180
|
+
<% end -%>
|
181
|
+
view.reset(response);
|
182
|
+
view.reset(place.action);
|
137
183
|
}
|
138
184
|
});
|
139
185
|
notice.setText("saving <%= class_name.underscore.humanize %> . . .");
|
@@ -14,12 +14,12 @@ public class <%= class_name %> {
|
|
14
14
|
public int id;
|
15
15
|
<% end -%>
|
16
16
|
<% for attribute in attributes -%>
|
17
|
-
<% name = attribute.name.
|
17
|
+
<% name = attribute.name.camelcase.sub(/^(.)/) {$1.downcase} -%>
|
18
18
|
|
19
19
|
<% if name != name.underscore -%> @Json(name = "<%= name.underscore %>")
|
20
20
|
<% end -%>
|
21
21
|
<% if attribute.type == :has_one -%>
|
22
|
-
public <%= attribute.name.
|
22
|
+
public <%= attribute.name.camelcase %> <%= name %>;
|
23
23
|
<% elsif attribute.type == :has_many -%>
|
24
24
|
public java.util.List<<%= attribute.name.classify %>> <%= name %>;
|
25
25
|
<% else -%>
|
@@ -1,13 +1,14 @@
|
|
1
1
|
package <%= places_package %>;
|
2
2
|
|
3
|
-
import <%= gwt_rails_package %>.RestfulAction;
|
3
|
+
import <%= gwt_rails_package %>.places.RestfulAction;
|
4
4
|
|
5
5
|
import <%= managed_package %>.ActivityFactory;
|
6
|
+
import <%= models_package %>.<%= class_name %>;
|
6
7
|
import <%= base_package %>.ActivityPlace;
|
7
8
|
|
8
9
|
import com.google.gwt.activity.shared.Activity;
|
9
10
|
|
10
|
-
public class <%= class_name %>Place extends ActivityPlace {
|
11
|
+
public class <%= class_name %>Place extends ActivityPlace<<%= class_name %>> {
|
11
12
|
|
12
13
|
public Activity create(ActivityFactory factory){
|
13
14
|
return factory.create(this);
|
@@ -17,6 +18,10 @@ public class <%= class_name %>Place extends ActivityPlace {
|
|
17
18
|
super(restfulAction, "<%= table_name %>");
|
18
19
|
}
|
19
20
|
|
21
|
+
public <%= class_name %>Place(<%= class_name %> model, RestfulAction restfulAction) {
|
22
|
+
super(model, restfulAction, "<%= table_name %>");
|
23
|
+
}
|
24
|
+
|
20
25
|
public <%= class_name %>Place(int id, RestfulAction restfulAction) {
|
21
26
|
super(id, restfulAction, "<%= table_name %>");
|
22
27
|
}
|
@@ -1,17 +1,12 @@
|
|
1
1
|
package <%= places_package %>;
|
2
2
|
|
3
|
-
import
|
4
|
-
import com.google.gwt.place.shared.Prefix;
|
3
|
+
import <%= gwt_rails_package %>.places.RestfulPlaceTokenizer;
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
@Prefix("<% if options[:singleton] -%><%= singular_table_name %><% else -%><%= table_name %><% end -%>")
|
9
|
-
public class <%= class_name %>PlaceTokenizer extends RestfulPlaceTokenizer<<%= class_name %>Place>
|
10
|
-
implements PlaceTokenizer<<%= class_name %>Place> {
|
5
|
+
public class <%= class_name %>PlaceTokenizer extends RestfulPlaceTokenizer<<%= class_name %>Place> {
|
11
6
|
|
12
7
|
public <%= class_name %>Place getPlace(String token) {
|
13
8
|
<% if options[:singleton] -%>
|
14
|
-
|
9
|
+
return new <%= class_name %>Place(toSingletonToken(token).action);
|
15
10
|
<% else -%>
|
16
11
|
Token t = toToken(token);
|
17
12
|
if(t.identifier == null){
|
@@ -1,10 +1,12 @@
|
|
1
1
|
package <%= restservices_package %>;
|
2
2
|
|
3
|
-
import <%= gwt_rails_package %>.RestfulDispatcherSingleton;
|
3
|
+
import <%= gwt_rails_package %>.dispatchers.RestfulDispatcherSingleton;
|
4
|
+
<% unless options[:singleton] -%>
|
4
5
|
<% if action_map.values.member? :get_all -%>
|
5
|
-
import <%= gwt_rails_package %>.DefaultDispatcherSingleton;
|
6
|
+
import <%= gwt_rails_package %>.dispatchers.DefaultDispatcherSingleton;
|
6
7
|
import java.util.List;
|
7
8
|
<% end -%>
|
9
|
+
<% end -%>
|
8
10
|
|
9
11
|
import javax.ws.rs.*;
|
10
12
|
|
@@ -1,14 +1,16 @@
|
|
1
1
|
package <%= views_package %>;
|
2
2
|
|
3
|
+
<% unless options[:singleton] -%>
|
3
4
|
import java.util.List;
|
4
5
|
|
6
|
+
<% end -%>
|
5
7
|
import <%= models_package %>.<%= class_name %>;
|
6
8
|
|
7
9
|
import com.google.gwt.place.shared.Place;
|
8
10
|
import com.google.gwt.user.client.ui.IsWidget;
|
9
11
|
import com.google.inject.ImplementedBy;
|
10
12
|
|
11
|
-
import <%= gwt_rails_package %>.RestfulAction;
|
13
|
+
import <%= gwt_rails_package %>.places.RestfulAction;
|
12
14
|
|
13
15
|
@ImplementedBy(<%= class_name %>ViewImpl.class)
|
14
16
|
public interface <%= class_name %>View extends IsWidget {
|
@@ -19,17 +21,29 @@ public interface <%= class_name %>View extends IsWidget {
|
|
19
21
|
<% end -%>
|
20
22
|
void save();
|
21
23
|
<% unless options[:singleton] -%>
|
22
|
-
void delete();
|
24
|
+
void delete(<%= class_name %> model);
|
23
25
|
<% end -%>
|
24
26
|
void goTo(Place place);
|
25
27
|
}
|
26
28
|
void setPresenter(Presenter presenter);
|
27
29
|
|
28
30
|
void reset(<%= class_name %> model);
|
31
|
+
<% unless options[:singleton] -%>
|
32
|
+
|
33
|
+
void reset(List<<%= class_name %>> models);
|
34
|
+
<% end -%>
|
29
35
|
|
30
36
|
void reset(RestfulAction action);
|
31
37
|
|
32
38
|
void setEnabled(boolean enabled);
|
33
39
|
|
34
40
|
<%= class_name %> retrieve<%= class_name %>();
|
41
|
+
<% unless options[:singleton] -%>
|
42
|
+
|
43
|
+
void updateInList(<%= class_name %> model);
|
44
|
+
|
45
|
+
void removeFromList(<%= class_name %> model);
|
46
|
+
|
47
|
+
void addToList(<%= class_name %> model);
|
48
|
+
<% end -%>
|
35
49
|
}
|
@@ -5,43 +5,55 @@
|
|
5
5
|
|
6
6
|
<ui:style>
|
7
7
|
.buttons {}
|
8
|
-
.
|
9
|
-
.
|
8
|
+
.signature { float: left; }
|
9
|
+
.signature * { display: inline; margin-right: 1em; font-size: 0.8em;}
|
10
10
|
.fields { clear: both;}
|
11
11
|
.field { }
|
12
12
|
</ui:style>
|
13
13
|
|
14
|
-
<g:FlowPanel>
|
14
|
+
<g:FlowPanel styleName="display">
|
15
15
|
<g:FlowPanel styleName="{style.buttons}">
|
16
16
|
<% unless options[:singleton] -%>
|
17
17
|
<g:Button ui:field="newButton">New</g:Button>
|
18
|
-
<g:Button ui:field="createButton">Create</g:Button>
|
19
18
|
<% end -%>
|
20
19
|
<g:Button ui:field="editButton">Edit</g:Button>
|
21
|
-
<g:Button ui:field="saveButton">Save</g:Button>
|
22
|
-
<% unless options[:singleton] -%>
|
23
|
-
<g:Button ui:field="deleteButton">Delete</g:Button>
|
24
|
-
<% end -%>
|
25
20
|
</g:FlowPanel>
|
26
|
-
<g:FlowPanel styleName="
|
21
|
+
<g:FlowPanel ui:field="form" styleName="form">
|
22
|
+
<g:FlowPanel styleName="{style.signature}" ui:field="signature">
|
27
23
|
<% unless options[:singleton] -%>
|
28
|
-
|
24
|
+
<g:Label>id: </g:Label>
|
25
|
+
<g:NumberLabel ui:field="id" />
|
29
26
|
<% end -%>
|
30
27
|
<% if options[:timestamps] %>
|
31
|
-
|
32
|
-
|
28
|
+
<g:Label>created at: </g:Label>
|
29
|
+
<g:DateLabel ui:field="createdAt" predefinedFormat="DATE_TIME_MEDIUM"/>
|
30
|
+
<g:Label>updated at: </g:Label>
|
31
|
+
<g:DateLabel ui:field="updatedAt" predefinedFormat="DATE_TIME_MEDIUM" />
|
33
32
|
<% end -%>
|
34
|
-
|
35
|
-
|
33
|
+
</g:FlowPanel>
|
34
|
+
<g:FlowPanel styleName="{style.fields}">
|
36
35
|
<% for attribute in attributes -%>
|
37
36
|
<% if attribute.type != :has_one && attribute.type != :has_many -%>
|
38
|
-
<% name = attribute.name.
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
<% name = attribute.name.camelcase.sub(/^(.)/){ $1.downcase } -%>
|
38
|
+
<g:FlowPanel styleName="{style.field}">
|
39
|
+
<g:HTML><label name="<%= name %>"><%= name.underscore.humanize %></label></g:HTML>
|
40
|
+
<g:TextBox ui:field="<%= name %>" name="<%= name %>"/>
|
41
|
+
</g:FlowPanel>
|
43
42
|
<% end -%>
|
44
43
|
<% end -%>
|
44
|
+
</g:FlowPanel>
|
45
|
+
<g:FlowPanel styleName="{style.buttons}">
|
46
|
+
<% unless options[:singleton] -%>
|
47
|
+
<g:Button ui:field="createButton">Create</g:Button>
|
48
|
+
<% end -%>
|
49
|
+
<g:Button ui:field="saveButton">Save</g:Button>
|
50
|
+
<% unless options[:singleton] -%>
|
51
|
+
<g:Button ui:field="deleteButton">Delete</g:Button>
|
52
|
+
<% end -%>
|
53
|
+
</g:FlowPanel>
|
45
54
|
</g:FlowPanel>
|
55
|
+
<% unless options[:singleton] -%>
|
56
|
+
<g:FlexTable ui:field="list" styleName="list"/>
|
57
|
+
<% end -%>
|
46
58
|
</g:FlowPanel>
|
47
59
|
</ui:UiBinder>
|
@@ -1,20 +1,27 @@
|
|
1
1
|
package <%= views_package %>;
|
2
2
|
|
3
|
-
<%
|
4
|
-
import java.util.
|
3
|
+
<% unless options[:singleton] -%>
|
4
|
+
import java.util.List;
|
5
|
+
|
5
6
|
<% end -%>
|
6
7
|
<% if options[:timestamps] -%>
|
7
|
-
import <%= gwt_rails_package
|
8
|
-
import <%= gwt_rails_package %>.IdentifyableView;<% end -%><% end -%>
|
8
|
+
import <%= gwt_rails_package %>.views.<% unless options[:singleton] -%>Identifyable<% end -%>TimestampedView;<% else -%><% unless options[:singleton] -%>
|
9
|
+
import <%= gwt_rails_package %>.views.IdentifyableView;<% end -%><% end -%>
|
9
10
|
|
10
|
-
|
11
|
-
import <%= gwt_rails_package %>.
|
11
|
+
<% unless options[:singleton] -%>
|
12
|
+
import <%= gwt_rails_package %>.views.ModelButton;
|
13
|
+
<% end -%>
|
14
|
+
import <%= gwt_rails_package %>.places.RestfulAction;
|
15
|
+
import <%= gwt_rails_package %>.places.RestfulActionEnum;
|
12
16
|
|
13
17
|
import <%= models_package %>.<%= class_name %>;
|
14
18
|
import <%= places_package %>.<%= class_name %>Place;
|
15
19
|
|
16
20
|
import com.google.gwt.core.client.GWT;
|
17
21
|
import com.google.gwt.event.dom.client.ClickEvent;
|
22
|
+
<% unless options[:singleton] -%>
|
23
|
+
import com.google.gwt.event.dom.client.ClickHandler;
|
24
|
+
<% end -%>
|
18
25
|
import com.google.gwt.uibinder.client.UiBinder;
|
19
26
|
import com.google.gwt.uibinder.client.UiField;
|
20
27
|
import com.google.gwt.uibinder.client.UiHandler;
|
@@ -52,14 +59,21 @@ public class <%= class_name %>ViewImpl extends <% if options[:timestamps] -%><%
|
|
52
59
|
<% end -%>
|
53
60
|
<% for attribute in attributes -%>
|
54
61
|
<% if attribute.type == :has_one -%>
|
55
|
-
// TODO <%= attribute.name.
|
62
|
+
// TODO <%= attribute.name.camelcase %> <%= attribute.name %>;
|
56
63
|
<% elsif attribute.type == :has_many -%>
|
57
|
-
// TODO public java.util.List<<%= attribute.name.
|
64
|
+
// TODO public java.util.List<<%= attribute.name.camelcase %>> <%= attribute.name %>;
|
58
65
|
<% else -%>
|
59
66
|
@UiField
|
60
|
-
TextBox <%= attribute.name.
|
67
|
+
TextBox <%= attribute.name.camelcase.sub(/^(.)/){ $1.downcase } %>;
|
61
68
|
<% end -%>
|
62
69
|
|
70
|
+
<% end -%>
|
71
|
+
<% unless options[:singleton] -%>
|
72
|
+
@UiField
|
73
|
+
Panel form;
|
74
|
+
|
75
|
+
@UiField
|
76
|
+
FlexTable list;
|
63
77
|
<% end -%>
|
64
78
|
|
65
79
|
private Presenter presenter;
|
@@ -78,21 +92,24 @@ public class <%= class_name %>ViewImpl extends <% if options[:timestamps] -%><%
|
|
78
92
|
void onClickCreate(ClickEvent e) {
|
79
93
|
presenter.create();
|
80
94
|
}
|
95
|
+
|
81
96
|
<% end -%>
|
82
97
|
@UiHandler("editButton")
|
83
98
|
void onClickEdit(ClickEvent e) {
|
84
|
-
presenter.goTo(new <%= class_name %>Place(<% unless options[:singleton] -%>
|
99
|
+
presenter.goTo(new <%= class_name %>Place(<% unless options[:singleton] -%>id.getValue(), <% end -%>RestfulActionEnum.EDIT));
|
85
100
|
}
|
86
101
|
|
87
102
|
@UiHandler("saveButton")
|
88
103
|
void onClickSave(ClickEvent e) {
|
89
104
|
presenter.save();
|
90
105
|
}
|
106
|
+
|
91
107
|
<% unless options[:singleton] -%>
|
92
108
|
@UiHandler("deleteButton")
|
93
109
|
void onClickDelete(ClickEvent e) {
|
94
|
-
presenter.delete();
|
110
|
+
presenter.delete(retrieve<%= class_name %>());
|
95
111
|
}
|
112
|
+
|
96
113
|
<% end -%>
|
97
114
|
<% end -%>
|
98
115
|
public void setPresenter(Presenter presenter) {
|
@@ -111,43 +128,54 @@ public class <%= class_name %>ViewImpl extends <% if options[:timestamps] -%><%
|
|
111
128
|
<% end -%>
|
112
129
|
<% for attribute in attributes -%>
|
113
130
|
<% if attribute.type != :has_one && attribute.type != :has_many -%>
|
114
|
-
<% name = attribute.name.
|
131
|
+
<% name = attribute.name.camelcase.sub(/^(.)/){ $1.downcase } -%>
|
115
132
|
<%= name %>.setText(model.<%= name %><% if type_conversion_map[attribute.type] -%> + ""<% end -%>);
|
116
133
|
<% end -%>
|
117
134
|
<% end -%>
|
118
135
|
}
|
119
136
|
|
120
137
|
public void reset(RestfulAction action) {
|
121
|
-
|
122
|
-
|
123
|
-
|
138
|
+
<% if options[:singleton] -%>
|
139
|
+
editButton.setVisible(action.name().equals(RestfulActionEnum.SHOW.name()) ||
|
140
|
+
action.name().equals(RestfulActionEnum.INDEX.name()));
|
141
|
+
saveButton.setVisible(action.name().equals(RestfulActionEnum.EDIT.name()));
|
142
|
+
setEnabled(!action.viewOnly());
|
124
143
|
<% else -%>
|
125
|
-
<% unless options[:singleton] -%>
|
126
144
|
newButton.setVisible(!action.name().equals(RestfulActionEnum.NEW.name()));
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
145
|
+
if(action.name().equals(RestfulActionEnum.INDEX.name())){
|
146
|
+
editButton.setVisible(false);
|
147
|
+
list.setVisible(true);
|
148
|
+
form.setVisible(false);
|
149
|
+
}
|
150
|
+
else {
|
151
|
+
<% if options[:readonly] -%>
|
152
|
+
setEnabled(false);
|
153
|
+
<% else -%>
|
154
|
+
createButton.setVisible(action.name().equals(RestfulActionEnum.NEW.name()));
|
155
|
+
editButton.setVisible(action.name().equals(RestfulActionEnum.SHOW.name()));
|
156
|
+
saveButton.setVisible(action.name().equals(RestfulActionEnum.EDIT.name()));
|
157
|
+
deleteButton.setVisible(action.name().equals(RestfulActionEnum.EDIT.name()));
|
133
158
|
<% end -%>
|
134
|
-
|
159
|
+
setEnabled(!action.viewOnly());
|
160
|
+
list.setVisible(false);
|
161
|
+
form.setVisible(true);
|
162
|
+
}
|
135
163
|
<% end -%>
|
136
164
|
}
|
137
165
|
|
138
166
|
public <%= class_name %> retrieve<%= class_name %>() {
|
139
167
|
<%= class_name %> model = new <%= class_name %>();
|
140
168
|
<% unless options[:singleton] -%>
|
141
|
-
model.id =
|
169
|
+
model.id = id.getValue() == null ? 0 : id.getValue();
|
142
170
|
<% end -%>
|
143
171
|
<% if options[:timestamps] %>
|
144
|
-
model.createdAt =
|
145
|
-
model.updatedAt =
|
172
|
+
model.createdAt = createdAt.getValue();
|
173
|
+
model.updatedAt = updatedAt.getValue();
|
146
174
|
<% end -%>
|
147
175
|
|
148
176
|
<% for attribute in attributes -%>
|
149
177
|
<% if attribute.type != :has_one && attribute.type != :has_many -%>
|
150
|
-
<% name = attribute.name.
|
178
|
+
<% name = attribute.name.camelcase.sub(/^(.)/){ $1.downcase } -%>
|
151
179
|
model.<%= name %> = <% if (conv = type_conversion_map[attribute.type]).nil? -%><%= name %>.getText()<% else -%><%= conv %>(<%= name %>.getText())<% end -%>;
|
152
180
|
<% end -%>
|
153
181
|
|
@@ -158,9 +186,84 @@ public class <%= class_name %>ViewImpl extends <% if options[:timestamps] -%><%
|
|
158
186
|
public void setEnabled(boolean enabled) {
|
159
187
|
<% for attribute in attributes -%>
|
160
188
|
<% if attribute.type != :has_one && attribute.type != :has_many -%>
|
161
|
-
<% name = attribute.name.
|
189
|
+
<% name = attribute.name.camelcase.sub(/^(.)/){ $1.downcase } -%>
|
162
190
|
<%= name %>.setEnabled(enabled);
|
163
191
|
<% end -%>
|
164
192
|
<% end -%>
|
165
193
|
}
|
194
|
+
<% unless options[:singleton] -%>
|
195
|
+
|
196
|
+
private final ClickHandler clickHandler = new ClickHandler() {
|
197
|
+
|
198
|
+
@SuppressWarnings("unchecked")
|
199
|
+
public void onClick(ClickEvent event) {
|
200
|
+
ModelButton<<%= class_name %>> button = (ModelButton<<%= class_name %>>)event.getSource();
|
201
|
+
switch(button.action){
|
202
|
+
case DESTROY:
|
203
|
+
presenter.delete(button.model);
|
204
|
+
break;
|
205
|
+
default:
|
206
|
+
presenter.goTo(new <%= class_name %>Place(button.model, button.action));
|
207
|
+
}
|
208
|
+
}
|
209
|
+
};
|
210
|
+
|
211
|
+
private Button newButton(RestfulActionEnum action, <%= class_name %> model){
|
212
|
+
ModelButton<<%= class_name %>> button = new ModelButton<<%= class_name %>>(action, model);
|
213
|
+
button.addClickHandler(clickHandler);
|
214
|
+
return button;
|
215
|
+
}
|
216
|
+
|
217
|
+
public void reset(List<<%= class_name %>> models) {
|
218
|
+
list.removeAllRows();
|
219
|
+
list.setText(0, 0, "Id");
|
220
|
+
<% attributes.each_with_index do |attribute, index| -%>
|
221
|
+
list.setText(0, <%= index + 1 %>, "<%= attribute.name.humanize -%>");
|
222
|
+
<% end -%>
|
223
|
+
list.getRowFormatter().addStyleName(0, "model-list-header");
|
224
|
+
int row = 1;
|
225
|
+
for(<%= class_name %> model: models){
|
226
|
+
setRow(row, model);
|
227
|
+
row++;
|
228
|
+
}
|
229
|
+
}
|
230
|
+
|
231
|
+
private void setRow(int row, <%= class_name %> model) {
|
232
|
+
list.setText(row, 0, model.id + "");
|
233
|
+
<% attributes.each_with_index do |attribute, index| -%>
|
234
|
+
<% if attribute.type != :has_one && attribute.type != :has_many -%>
|
235
|
+
<% name = attribute.name.camelcase.sub(/^(.)/){ $1.downcase } -%>
|
236
|
+
list.setText(row, <%= index + 1 %>, model.<%= name %> + "");
|
237
|
+
<% end -%>
|
238
|
+
|
239
|
+
<% end -%>
|
240
|
+
list.setWidget(row, <%= attributes.size + 1 %>, newButton(RestfulActionEnum.SHOW, model));
|
241
|
+
list.setWidget(row, <%= attributes.size + 2 %>, newButton(RestfulActionEnum.EDIT, model));
|
242
|
+
list.setWidget(row, <%= attributes.size + 3 %>, newButton(RestfulActionEnum.DESTROY, model));
|
243
|
+
}
|
244
|
+
|
245
|
+
public void updateInList(<%= class_name %> model) {
|
246
|
+
String id = model.id + "";
|
247
|
+
for(int i = 0; i < list.getRowCount(); i++){
|
248
|
+
if(list.getText(i, 0).equals(id)){
|
249
|
+
setRow(i, model);
|
250
|
+
return;
|
251
|
+
}
|
252
|
+
}
|
253
|
+
}
|
254
|
+
|
255
|
+
public void removeFromList(<%= class_name %> model) {
|
256
|
+
String id = model.id + "";
|
257
|
+
for(int i = 0; i < list.getRowCount(); i++){
|
258
|
+
if(list.getText(i, 0).equals(id)){
|
259
|
+
list.removeRow(i);
|
260
|
+
return;
|
261
|
+
}
|
262
|
+
}
|
263
|
+
}
|
264
|
+
|
265
|
+
public void addToList(<%= class_name %> model) {
|
266
|
+
setRow(list.getRowCount(), model);
|
267
|
+
}
|
268
|
+
<% end -%>
|
166
269
|
}
|
data/lib/resty-generators.rb
CHANGED