-
Notifications
You must be signed in to change notification settings - Fork 58
/
FormWindow.java
221 lines (191 loc) · 5.07 KB
/
FormWindow.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.googlecode.wicket.kendo.ui.widget.window;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.core.request.handler.IPartialPageRequestHandler;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import com.googlecode.wicket.jquery.core.resource.StyleSheetPackageHeaderItem;
import com.googlecode.wicket.kendo.ui.panel.KendoFeedbackPanel;
/**
* Provides a Kendo UI base Window containing a {@link Form}, a {@link KendoFeedbackPanel}, a {@value Window#OK} and a {@value Window#CANCEL} button<br>
* <br>
* Implementation may look like:
*
* <pre>
* <code>
* final Form<?> form = this.getForm();
* form.add(new TextField("myId", this.getModel()));
* </code>
* </pre>
*
* @param <T> the type of the model object
* @author Sebastien Briquet - sebfz1
* @since 8.0.0
*/
public abstract class FormWindow<T> extends Window<T> // NOSONAR
{
private static final long serialVersionUID = 1L;
private final Form<?> form;
private KendoFeedbackPanel feedback;
/**
* Constructor
*
* @param id the markup id, an html div suffice to host a window.
* @param title the title of the window
*/
public FormWindow(String id, String title)
{
this(id, Model.of(title), null);
}
/**
* Constructor
*
* @param id the markup id, an html div suffice to host a window.
* @param title the title of the window
* @param model the model to be used in the window
*/
public FormWindow(String id, String title, IModel<T> model)
{
this(id, Model.of(title), model);
}
/**
* Constructor
*
* @param id the markup id, an html div suffice to host a window.
* @param title the title of the window
*/
public FormWindow(String id, IModel<String> title)
{
this(id, title, null);
}
/**
* Constructor
*
* @param id the markup id, an html div suffice to host a window.
* @param title the title of the window
* @param model the model to be used in the window
*/
public FormWindow(String id, IModel<String> title, IModel<T> model)
{
super(id, title, model, WindowButtons.OK_CANCEL);
// form //
this.form = FormWindow.newForm("form");
this.add(this.form);
}
// Methods //
@Override
public void renderHead(IHeaderResponse response)
{
super.renderHead(response);
response.render(new StyleSheetPackageHeaderItem(FormWindow.class));
}
// Events //
@Override
protected void onInitialize()
{
super.onInitialize();
// feedback //
this.feedback = this.newFeedbackPanel("feedback");
this.form.add(this.feedback);
// buttons //
this.form.add(this.newButtonPanel("buttons", this.getButtons()));
}
@Override
protected void onOpen(IPartialPageRequestHandler handler)
{
super.onOpen(handler);
handler.add(this.form);
}
@Override
protected void onError(AjaxRequestTarget target, WindowButton button)
{
super.onError(target, button);
target.add(this.feedback);
}
@Override
protected void onSubmit(AjaxRequestTarget target, WindowButton button)
{
if (button != null)
{
if (button.match(OK))
{
this.onSubmit(target);
}
else if (button.match(CANCEL))
{
this.onCancel(target);
}
}
}
/**
* Triggered when the 'submit' button is clicked, and the validation succeed
*
* @param target the {@link AjaxRequestTarget}
*/
protected abstract void onSubmit(AjaxRequestTarget target);
/**
* Triggered when the 'cancel' button is clicked
*
* @param target the {@link AjaxRequestTarget}
*/
protected void onCancel(AjaxRequestTarget target)
{
// noop
}
// Properties //
/**
* Gets the inner {@link Form}
*
* @return the form
*/
@Override
public Form<?> getForm()
{
return this.form;
}
// Factories //
/**
* Gets a new {@link Form}
*
* @param id the markup id
* @return the new form
*/
private static Form<Void> newForm(String id)
{
return new Form<Void>(id) {
private static final long serialVersionUID = 1L;
@Override
protected boolean wantSubmitOnParentFormSubmit()
{
return false;
}
};
}
/**
* Gets a new {@link KendoFeedbackPanel}
*
* @param id the markup id
* @return a new {@code KendoFeedbackPanel}
*/
protected KendoFeedbackPanel newFeedbackPanel(String id)
{
return new KendoFeedbackPanel(id, this);
}
}