resty-generators 0.2.0 → 0.3.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/base.rb +33 -5
- data/lib/generators/resty/controller/controller_generator.rb +2 -2
- data/lib/generators/resty/model/model_generator.rb +1 -1
- data/lib/generators/resty/scaffold/scaffold_generator.rb +76 -4
- data/lib/generators/resty/setup/setup_generator.rb +141 -4
- data/lib/generators/resty/setup/templates/ActivityFactory.java +12 -0
- data/lib/generators/resty/setup/templates/ActivityPlace.java +25 -0
- data/lib/generators/resty/setup/templates/ActivityPlaceActivityMapper.java +30 -0
- data/lib/generators/resty/setup/templates/BreadCrumbsPanel.java +80 -0
- data/lib/generators/resty/setup/templates/EntryPoint.java +75 -4
- data/lib/generators/resty/setup/templates/GinModule.java +40 -0
- data/lib/generators/resty/setup/templates/LoginActivity.java +59 -0
- data/lib/generators/resty/setup/templates/LoginPlace.java +20 -0
- data/lib/generators/resty/setup/templates/LoginView.ui.xml +18 -0
- data/lib/generators/resty/setup/templates/LoginViewImpl.java +21 -0
- data/lib/generators/resty/setup/templates/Mavenfile +7 -4
- data/lib/generators/resty/setup/templates/PlaceHistoryMapper.java +8 -0
- data/lib/generators/resty/setup/templates/RestfulPlace.java +24 -0
- data/lib/generators/resty/setup/templates/SessionActivityPlaceActivityMapper.java +71 -0
- data/lib/generators/resty/setup/templates/SessionRestService.java +23 -0
- data/lib/generators/resty/setup/templates/User.java +8 -0
- data/lib/generators/resty/setup/templates/authentication.rb +3 -0
- data/lib/generators/resty/setup/templates/empty.css +17 -0
- data/lib/generators/resty/setup/templates/gitignore +3 -0
- data/lib/generators/resty/setup/templates/group.rb +14 -0
- data/lib/generators/resty/setup/templates/gwt.css +17 -0
- data/lib/generators/resty/setup/templates/module.gwt.xml +9 -2
- data/lib/generators/resty/setup/templates/page.html +1 -1
- data/lib/generators/resty/setup/templates/session.rb +45 -0
- data/lib/generators/resty/setup/templates/sessions_controller.rb +29 -0
- data/lib/generators/resty/setup/templates/user.rb +28 -0
- data/lib/generators/resty/setup/templates/web.xml +50 -0
- data/lib/generators/resty/templates/Activity.java +140 -0
- data/lib/generators/resty/templates/ColumnDefinitionsImpl.java +24 -0
- data/lib/generators/resty/templates/Model.java +13 -7
- data/lib/generators/resty/templates/Place.java +27 -0
- data/lib/generators/resty/templates/PlaceTokenizer.java +25 -0
- data/lib/generators/resty/templates/{Controller.java → RestService.java} +16 -12
- data/lib/generators/resty/templates/View.java +35 -0
- data/lib/generators/resty/templates/View.ui.xml +47 -0
- data/lib/generators/resty/templates/ViewImpl.java +196 -0
- data/lib/resty-generators.rb +1 -0
- data/lib/resty/child_path.rb +17 -4
- data/lib/resty/resty_railtie.rb +4 -5
- metadata +70 -60
@@ -22,12 +22,36 @@ module Resty
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
26
|
-
@
|
25
|
+
def managed_package
|
26
|
+
@managed_package ||= base_package + ".managed"
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
30
|
-
@
|
29
|
+
def models_package
|
30
|
+
@models_package ||= base_package + ".models"
|
31
|
+
end
|
32
|
+
|
33
|
+
def views_package
|
34
|
+
@views_package ||= base_package + ".views"
|
35
|
+
end
|
36
|
+
|
37
|
+
def places_package
|
38
|
+
@places_package ||= base_package + ".places"
|
39
|
+
end
|
40
|
+
|
41
|
+
def activities_package
|
42
|
+
@activities_package ||= base_package + ".activities"
|
43
|
+
end
|
44
|
+
|
45
|
+
def gwt_rails_package
|
46
|
+
'de.mkristian.gwt.rails'
|
47
|
+
end
|
48
|
+
|
49
|
+
def gwt_rails_session_package
|
50
|
+
@gwt_rails_session_package ||= gwt_rails_package + '.session'
|
51
|
+
end
|
52
|
+
|
53
|
+
def restservices_package
|
54
|
+
@restservices_package ||= base_package + ".restservices"
|
31
55
|
end
|
32
56
|
|
33
57
|
def action_map
|
@@ -35,7 +59,11 @@ module Resty
|
|
35
59
|
end
|
36
60
|
|
37
61
|
def type_map
|
38
|
-
@type_map ||= {:integer => 'int', :boolean => 'bool', :string => 'String', :float => '
|
62
|
+
@type_map ||= {:integer => 'int', :boolean => 'bool', :string => 'String', :float => 'double', :date => 'java.util.Date', :datetime => 'java.util.Date', :number => 'long', :fixnum => 'long'}
|
63
|
+
end
|
64
|
+
|
65
|
+
def type_conversion_map
|
66
|
+
@type_conversion_map ||= {:integer => 'Integer.parseInt', :boolean => 'Boolean.parseBoolean', :float => 'Double.parseDouble', :date => 'TODO', :datetime => 'TODO', :number => 'Long.parseLong', :fixnum => 'Long.parseLong'}
|
39
67
|
end
|
40
68
|
|
41
69
|
def find_gwt_xml(basedir)
|
@@ -9,8 +9,8 @@ module Resty
|
|
9
9
|
|
10
10
|
argument :actions, :type => :array, :default => [], :banner => "action action"
|
11
11
|
|
12
|
-
def
|
13
|
-
template '
|
12
|
+
def create_rest_service_file
|
13
|
+
template 'RestService.java', File.join(java_root, rest_services_base_package.gsub(/\./, "/"), class_path, "#{controller_class_name}RestService.java")
|
14
14
|
end
|
15
15
|
|
16
16
|
end
|
@@ -11,7 +11,7 @@ module Resty
|
|
11
11
|
if defined? ::Ixtlan::ModifiedBy
|
12
12
|
class_option :modified_by, :type => :boolean
|
13
13
|
end
|
14
|
-
class_option :timestamps, :type => :boolean
|
14
|
+
class_option :timestamps, :type => :boolean, :default => true
|
15
15
|
class_option :parent, :type => :string, :desc => "The parent class for the generated model"
|
16
16
|
|
17
17
|
def create_model_file
|
@@ -12,16 +12,88 @@ module Resty
|
|
12
12
|
if defined? ::Ixtlan::ModifiedBy
|
13
13
|
class_option :modified_by, :type => :boolean
|
14
14
|
end
|
15
|
-
class_option :timestamps, :type => :boolean
|
15
|
+
class_option :timestamps, :type => :boolean, :default => true
|
16
16
|
class_option :parent, :type => :string, :desc => "The parent class for the generated model"
|
17
17
|
class_option :singleton, :type => :boolean
|
18
18
|
|
19
19
|
def create_model_file
|
20
|
-
template 'Model.java', File.join(java_root,
|
20
|
+
template 'Model.java', File.join(java_root, models_package.gsub(/\./, "/"), class_path, "#{class_name}.java")
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
24
|
-
template '
|
23
|
+
def create_rest_service_file
|
24
|
+
template 'RestService.java', File.join(java_root, restservices_package.gsub(/\./, "/"), class_path, "#{controller_class_name}RestService.java")
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_view_files
|
28
|
+
template 'View.java', File.join(java_root, views_package.gsub(/\./, "/"), class_path, "#{class_name}View.java")
|
29
|
+
template 'View.ui.xml', File.join(java_root, views_package.gsub(/\./, "/"), class_path, "#{class_name}View.ui.xml")
|
30
|
+
template 'ViewImpl.java', File.join(java_root, views_package.gsub(/\./, "/"), class_path, "#{class_name}ViewImpl.java")
|
31
|
+
unless options[:singleton]
|
32
|
+
template 'ColumnDefinitionsImpl.java', File.join(java_root, views_package.gsub(/\./, "/"), class_path, "#{class_name.pluralize}ColumnDefinitionsImpl.java")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_place_files
|
37
|
+
template 'Place.java', File.join(java_root, places_package.gsub(/\./, "/"), class_path, "#{class_name}Place.java")
|
38
|
+
template 'PlaceTokenizer.java', File.join(java_root, places_package.gsub(/\./, "/"), class_path, "#{class_name}PlaceTokenizer.java")
|
39
|
+
end
|
40
|
+
|
41
|
+
def create_activity_file
|
42
|
+
template 'Activity.java', File.join(java_root, activities_package.gsub(/\./, "/"), class_path, "#{class_name}Activity.java")
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_to_activity_factory
|
46
|
+
factory_file = File.join(java_root, managed_package.gsub(/\./, "/"), class_path, "ActivityFactory.java")
|
47
|
+
factory = File.read(factory_file)
|
48
|
+
if factory =~ /@Named\(.#{table_name}.\)/
|
49
|
+
log 'keep', factory_file
|
50
|
+
else
|
51
|
+
factory.sub! /interface\s+ActivityFactory\s+{/, "interface ActivityFactory {\n @Named(\"#{table_name}\") Activity create(#{places_package}.#{class_name}Place place);"
|
52
|
+
File.open(factory_file, 'w') { |f| f.print factory }
|
53
|
+
log "added to", factory_file
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def add_to_place_histroy_mapper
|
58
|
+
file = File.join(java_root, managed_package.gsub(/\./, "/"), class_path, "#{application_name}PlaceHistoryMapper.java")
|
59
|
+
content = File.read(file)
|
60
|
+
if content =~ /#{class_name}PlaceTokenizer.class/
|
61
|
+
log 'keep', file
|
62
|
+
elsif content =~ /@WithTokenizers\({}\)/
|
63
|
+
content.sub! /@WithTokenizers\({}\)/, "@WithTokenizers({#{places_package}.#{class_name}PlaceTokenizer.class})"
|
64
|
+
File.open(file, 'w') { |f| f.print content }
|
65
|
+
log "added to", file
|
66
|
+
else
|
67
|
+
content.sub! /@WithTokenizers\({/, "@WithTokenizers({#{places_package}.#{class_name}PlaceTokenizer.class,\n "
|
68
|
+
File.open(file, 'w') { |f| f.print content }
|
69
|
+
log "added to", file
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def add_to_module
|
74
|
+
file = File.join(java_root, managed_package.gsub(/\./, "/"), class_path, "#{application_name}Module.java")
|
75
|
+
content = File.read(file)
|
76
|
+
if content =~ /#{class_name.pluralize}RestService.class/
|
77
|
+
log 'keep', file
|
78
|
+
else content =~ /super.configure\(\);/
|
79
|
+
content.sub! /super.configure\(\);/, "super.configure();\n bind(#{restservices_package}.#{class_name.pluralize}RestService.class).toProvider(#{class_name.pluralize}RestServiceProvider.class);"
|
80
|
+
|
81
|
+
content.sub! /new GinFactoryModuleBuilder\(\)/, "new GinFactoryModuleBuilder()\n .implement(Activity.class, Names.named(\"#{table_name}\"), #{activities_package}.#{class_name}Activity.class)"
|
82
|
+
|
83
|
+
content.sub! /^}/, <<-EOF
|
84
|
+
|
85
|
+
@Singleton
|
86
|
+
public static class #{class_name.pluralize}RestServiceProvider implements Provider<#{restservices_package}.#{class_name.pluralize}RestService> {
|
87
|
+
private final #{restservices_package}.#{class_name.pluralize}RestService service = GWT.create(#{restservices_package}.#{class_name.pluralize}RestService.class);
|
88
|
+
public #{restservices_package}.#{class_name.pluralize}RestService get() {
|
89
|
+
return service;
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
93
|
+
EOF
|
94
|
+
File.open(file, 'w') { |f| f.print content }
|
95
|
+
log "added to", file
|
96
|
+
end
|
25
97
|
end
|
26
98
|
|
27
99
|
def actions
|
@@ -9,6 +9,8 @@ module Resty
|
|
9
9
|
|
10
10
|
argument :gwt_module_name, :type => :string, :required => true
|
11
11
|
|
12
|
+
class_option :session, :type => :boolean, :default => false
|
13
|
+
|
12
14
|
def name
|
13
15
|
gwt_module_name
|
14
16
|
end
|
@@ -18,26 +20,161 @@ module Resty
|
|
18
20
|
end
|
19
21
|
|
20
22
|
def create_maven_file
|
21
|
-
template 'Mavenfile',
|
23
|
+
template 'Mavenfile', "Mavenfile"
|
24
|
+
unless File.read(".gitignore") =~ /^target/
|
25
|
+
File.open(".gitignore", "a") { |f| f.puts "target/" }
|
26
|
+
end
|
27
|
+
unless File.read(".gitignore") =~ /^*pom/
|
28
|
+
File.open(".gitignore", "a") { |f| f.puts "*pom" }
|
29
|
+
end
|
22
30
|
end
|
23
31
|
|
24
32
|
def create_entry_point_file
|
25
|
-
template 'EntryPoint.java', File.join(java_root, base_package.gsub(/\./, "/"), "#{application_name}.java")
|
33
|
+
template 'EntryPoint.java', File.join(java_root, base_package.gsub(/\./, "/"), "#{application_name}EntryPoint.java")
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_managed_files
|
37
|
+
path = managed_package.gsub(/\./, "/")
|
38
|
+
template 'PlaceHistoryMapper.java',
|
39
|
+
File.join(java_root, path,
|
40
|
+
"#{application_name}PlaceHistoryMapper.java")
|
41
|
+
template 'GinModule.java',
|
42
|
+
File.join(java_root, path,
|
43
|
+
"#{application_name}Module.java")
|
44
|
+
template 'ActivityFactory.java',
|
45
|
+
File.join(java_root, path,
|
46
|
+
"ActivityFactory.java")
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_scaffolded_files
|
50
|
+
path = base_package.gsub(/\./, "/")
|
51
|
+
template 'ActivityPlace.java',
|
52
|
+
File.join(java_root, path,
|
53
|
+
"ActivityPlace.java")
|
54
|
+
template 'ActivityPlaceActivityMapper.java',
|
55
|
+
File.join(java_root, path,
|
56
|
+
"ActivityPlaceActivityMapper.java")
|
57
|
+
if options[:session]
|
58
|
+
template 'SessionActivityPlaceActivityMapper.java',
|
59
|
+
File.join(java_root, path,
|
60
|
+
"SessionActivityPlaceActivityMapper.java")
|
61
|
+
template 'BreadCrumbsPanel.java',
|
62
|
+
File.join(java_root, path,
|
63
|
+
"BreadCrumbsPanel.java")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def create_session_files
|
68
|
+
if options[:session]
|
69
|
+
template 'LoginActivity.java',
|
70
|
+
File.join(java_root, activities_package.gsub(/\./, "/"),
|
71
|
+
"LoginActivity.java")
|
72
|
+
template 'User.java',
|
73
|
+
File.join(java_root, models_package.gsub(/\./, "/"),
|
74
|
+
"User.java")
|
75
|
+
template 'LoginPlace.java',
|
76
|
+
File.join(java_root, places_package.gsub(/\./, "/"),
|
77
|
+
"LoginPlace.java")
|
78
|
+
template 'SessionRestService.java',
|
79
|
+
File.join(java_root, restservices_package.gsub(/\./, "/"),
|
80
|
+
"SessionRestService.java")
|
81
|
+
template 'LoginViewImpl.java',
|
82
|
+
File.join(java_root, views_package.gsub(/\./, "/"),
|
83
|
+
"LoginViewImpl.java")
|
84
|
+
template 'LoginView.ui.xml',
|
85
|
+
File.join(java_root, views_package.gsub(/\./, "/"),
|
86
|
+
"LoginView.ui.xml")
|
87
|
+
end
|
26
88
|
end
|
27
89
|
|
28
90
|
def create_initializers
|
29
|
-
template 'initializer.rb', File.join('config', 'initializers', 'resty.rb')
|
30
91
|
template 'monkey_patch.rb', File.join('config', 'initializers', 'resty_monkey_patch.rb')
|
31
92
|
end
|
32
93
|
|
33
94
|
def create_html
|
34
95
|
template 'page.html', File.join('public', "#{application_name.underscore}.html")
|
35
|
-
template '
|
96
|
+
template 'gwt.css', File.join('public', 'stylesheets', "#{application_name.underscore}.css")
|
36
97
|
end
|
37
98
|
|
99
|
+
def create_web_xml
|
100
|
+
template 'web.xml', File.join('public', 'WEB-INF', 'web.xml')
|
101
|
+
template 'gitignore', File.join('public', 'WEB-INF', '.gitignore')
|
102
|
+
end
|
103
|
+
|
104
|
+
def create_rails_session_files
|
105
|
+
if options[:session]
|
106
|
+
template 'sessions_controller.rb', File.join('app', 'controllers', "sessions_controller.rb")
|
107
|
+
file = File.join('config', 'environments', "development.rb")
|
108
|
+
development = File.read(file)
|
109
|
+
changed = false
|
110
|
+
unless development =~ /config.remote_sso_url/
|
111
|
+
changed = true
|
112
|
+
development.sub! /^end\s*$/, <<ENV
|
113
|
+
|
114
|
+
if ENV['SSO'] == 'true' || ENV['SSO'] == ''
|
115
|
+
config.remote_sso_url = "http://localhost:3000"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
ENV
|
119
|
+
end
|
120
|
+
if changed
|
121
|
+
File.open(file, 'w') { |f| f.print development }
|
122
|
+
log "changed", file
|
123
|
+
else
|
124
|
+
log "unchanged", file
|
125
|
+
end
|
126
|
+
file = File.join('app', 'controllers', "application_controller.rb")
|
127
|
+
app_controller = File.read(file)
|
128
|
+
changed = false
|
129
|
+
unless app_controller =~ /def\s+current_user/
|
130
|
+
changed = true
|
131
|
+
app_controller.sub! /^end\s*$/, <<SESSION
|
132
|
+
|
133
|
+
protected
|
134
|
+
|
135
|
+
def current_user(user = nil)
|
136
|
+
session['user'] = user if user
|
137
|
+
session['user']
|
138
|
+
end
|
139
|
+
end
|
140
|
+
SESSION
|
141
|
+
end
|
142
|
+
unless app_controller =~ /def\s+csrf/
|
143
|
+
changed = true
|
144
|
+
app_controller.sub! /^end\s*$/, <<SESSION
|
145
|
+
|
146
|
+
private
|
147
|
+
|
148
|
+
after_filter :csrf
|
149
|
+
|
150
|
+
def csrf
|
151
|
+
response.header['X-CSRF-Token'] = form_authenticity_token if current_user
|
152
|
+
end
|
153
|
+
end
|
154
|
+
SESSION
|
155
|
+
end
|
156
|
+
if changed
|
157
|
+
File.open(file, 'w') { |f| f.print app_controller }
|
158
|
+
log "changed", file
|
159
|
+
else
|
160
|
+
log "unchanged", file
|
161
|
+
end
|
162
|
+
template 'authentication.rb', File.join('app', 'models', "authentication.rb")
|
163
|
+
template 'group.rb', File.join('app', 'models', "group.rb")
|
164
|
+
template 'session.rb', File.join('app', 'models', "session.rb")
|
165
|
+
template 'user.rb', File.join('app', 'models', "user.rb")
|
166
|
+
route "resource :session"
|
167
|
+
gem 'ixtlan-session-timeout'
|
168
|
+
gem 'ixtlan-guard'
|
169
|
+
# TODO until rmvn uses the right openssl gem
|
170
|
+
gem "jruby-openssl", "~> 0.7.4", :platforms => :jruby
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
38
174
|
def base_package
|
39
175
|
name + ".client"
|
40
176
|
end
|
177
|
+
|
41
178
|
end
|
42
179
|
end
|
43
180
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
package <%= managed_package %>;
|
2
|
+
|
3
|
+
import com.google.gwt.activity.shared.Activity;
|
4
|
+
import com.google.inject.name.Named;
|
5
|
+
<% if options[:session] -%>
|
6
|
+
import <%= places_package %>.LoginPlace;
|
7
|
+
<% end -%>
|
8
|
+
public interface ActivityFactory {
|
9
|
+
<% if options[:session] -%>
|
10
|
+
@Named("login") Activity create(LoginPlace place);
|
11
|
+
<% end -%>
|
12
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
package <%= base_package %>;
|
2
|
+
|
3
|
+
import <%= managed_package %>.ActivityFactory;
|
4
|
+
|
5
|
+
import com.google.gwt.activity.shared.Activity;
|
6
|
+
|
7
|
+
import <%= gwt_rails_package %>.RestfulAction;
|
8
|
+
import <%= gwt_rails_package %>.RestfulPlace;
|
9
|
+
|
10
|
+
public abstract class ActivityPlace extends RestfulPlace {
|
11
|
+
|
12
|
+
protected ActivityPlace(RestfulAction restfulAction) {
|
13
|
+
super(restfulAction);
|
14
|
+
}
|
15
|
+
|
16
|
+
protected ActivityPlace(int id, RestfulAction restfulAction) {
|
17
|
+
super(id, restfulAction);
|
18
|
+
}
|
19
|
+
|
20
|
+
protected ActivityPlace(String id, RestfulAction restfulAction) {
|
21
|
+
super(id, restfulAction);
|
22
|
+
}
|
23
|
+
|
24
|
+
public abstract Activity create(ActivityFactory factory);
|
25
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
package <%= base_package %>;
|
2
|
+
|
3
|
+
import <%= managed_package %>.ActivityFactory;
|
4
|
+
|
5
|
+
import com.google.gwt.activity.shared.Activity;
|
6
|
+
import com.google.gwt.activity.shared.ActivityMapper;
|
7
|
+
import com.google.gwt.place.shared.Place;
|
8
|
+
import com.google.inject.Inject;
|
9
|
+
|
10
|
+
import de.mkristian.gwt.rails.Notice;
|
11
|
+
|
12
|
+
public class ActivityPlaceActivityMapper implements ActivityMapper {
|
13
|
+
protected final ActivityFactory factory;
|
14
|
+
protected final Notice notice;
|
15
|
+
|
16
|
+
@Inject
|
17
|
+
public ActivityPlaceActivityMapper(ActivityFactory factory, Notice notice) {
|
18
|
+
this.notice = notice;
|
19
|
+
this.factory = factory;
|
20
|
+
}
|
21
|
+
|
22
|
+
|
23
|
+
public Activity getActivity(Place place) {
|
24
|
+
if (place instanceof ActivityPlace) {
|
25
|
+
return ((ActivityPlace) place).create(factory);
|
26
|
+
}
|
27
|
+
notice.setText("nothing to see");
|
28
|
+
return null;
|
29
|
+
}
|
30
|
+
}
|
@@ -0,0 +1,80 @@
|
|
1
|
+
package <%= base_package %>;
|
2
|
+
|
3
|
+
import javax.inject.Inject;
|
4
|
+
import javax.inject.Singleton;
|
5
|
+
|
6
|
+
import <%= models_package %>.User;
|
7
|
+
import <%= restservices_package %>.SessionRestService;
|
8
|
+
|
9
|
+
import org.fusesource.restygwt.client.Method;
|
10
|
+
import org.fusesource.restygwt.client.MethodCallback;
|
11
|
+
|
12
|
+
import com.google.gwt.event.dom.client.ClickEvent;
|
13
|
+
import com.google.gwt.event.dom.client.ClickHandler;
|
14
|
+
import com.google.gwt.user.client.History;
|
15
|
+
import com.google.gwt.user.client.ui.Button;
|
16
|
+
import com.google.gwt.user.client.ui.FlowPanel;
|
17
|
+
import com.google.gwt.user.client.ui.Label;
|
18
|
+
|
19
|
+
import de.mkristian.gwt.rails.Notice;
|
20
|
+
import de.mkristian.gwt.rails.session.SessionHandler;
|
21
|
+
import de.mkristian.gwt.rails.session.SessionManager;
|
22
|
+
|
23
|
+
@Singleton
|
24
|
+
public class BreadCrumbsPanel extends FlowPanel {
|
25
|
+
|
26
|
+
private final Button logout;
|
27
|
+
|
28
|
+
@Inject
|
29
|
+
public BreadCrumbsPanel(final SessionManager<User> sessionManager, final SessionRestService service,
|
30
|
+
final Notice notice){
|
31
|
+
setVisible(false);
|
32
|
+
sessionManager.addSessionHandler(new SessionHandler<User>() {
|
33
|
+
|
34
|
+
public void timeout() {
|
35
|
+
notice.setText("timeout");
|
36
|
+
setName(null);
|
37
|
+
History.fireCurrentHistoryState();
|
38
|
+
}
|
39
|
+
|
40
|
+
public void logout() {
|
41
|
+
service.destroy(new MethodCallback<Void>() {
|
42
|
+
public void onSuccess(Method method, Void response) {
|
43
|
+
}
|
44
|
+
public void onFailure(Method method, Throwable exception) {
|
45
|
+
}
|
46
|
+
});
|
47
|
+
setName(null);
|
48
|
+
History.fireCurrentHistoryState();
|
49
|
+
}
|
50
|
+
|
51
|
+
public void login(User user) {
|
52
|
+
setName(user.name);
|
53
|
+
History.fireCurrentHistoryState();
|
54
|
+
}
|
55
|
+
|
56
|
+
public void accessDenied() {
|
57
|
+
notice.setText("access denied");
|
58
|
+
}
|
59
|
+
});
|
60
|
+
logout = new Button("logout");
|
61
|
+
logout.addClickHandler(new ClickHandler() {
|
62
|
+
|
63
|
+
public void onClick(ClickEvent event) {
|
64
|
+
sessionManager.logout();
|
65
|
+
}
|
66
|
+
});
|
67
|
+
}
|
68
|
+
|
69
|
+
private void setName(String name){
|
70
|
+
clear();
|
71
|
+
if(name != null){
|
72
|
+
add(new Label("Welcome " + name));
|
73
|
+
add(logout);
|
74
|
+
setVisible(true);
|
75
|
+
}
|
76
|
+
else {
|
77
|
+
setVisible(false);
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|