01: /*
02: * Copyright 2002-2005 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package info.jtrac.wicket;
18:
19: import java.util.Arrays;
20: import org.apache.wicket.markup.html.WebPage;
21: import org.apache.wicket.markup.html.basic.Label;
22: import org.apache.wicket.markup.html.form.Form;
23: import org.apache.wicket.markup.html.link.Link;
24: import org.apache.wicket.markup.html.list.ListItem;
25: import org.apache.wicket.markup.html.list.ListView;
26:
27: /**
28: * reusable confirm / warning dialog page
29: */
30: public abstract class ConfirmPage extends BasePage {
31:
32: private String warning;
33: private String[] lines;
34: private WebPage back;
35:
36: public ConfirmPage(WebPage back, String heading, String warning,
37: String[] lines) {
38: this .back = back;
39: this .warning = warning;
40: this .lines = lines;
41: add(new Label("heading", heading));
42: add(new ConfirmForm("form"));
43: }
44:
45: public abstract void onConfirm();
46:
47: /**
48: * wicket form
49: */
50: private class ConfirmForm extends Form {
51:
52: public ConfirmForm(String id) {
53: super (id);
54: ListView listView = new ListView("lines", Arrays
55: .asList(lines)) {
56: protected void populateItem(ListItem listItem) {
57: String line = (String) listItem.getModelObject();
58: listItem.add(new Label("line", line));
59: }
60: };
61: add(listView);
62: add(new Label("warning", warning));
63: add(new Link("cancel") {
64: public void onClick() {
65: setResponsePage(back);
66: }
67: });
68: }
69:
70: @Override
71: protected void onSubmit() {
72: onConfirm();
73: }
74:
75: }
76:
77: }
|