01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.wicket.examples.repeater;
18:
19: import org.apache.wicket.markup.html.basic.Label;
20: import org.apache.wicket.markup.html.link.Link;
21: import org.apache.wicket.markup.html.panel.FeedbackPanel;
22: import org.apache.wicket.markup.html.panel.Panel;
23: import org.apache.wicket.model.IModel;
24: import org.apache.wicket.model.PropertyModel;
25: import org.apache.wicket.version.undo.Change;
26:
27: /**
28: * Base page for component demo pages.
29: *
30: * @author igor
31: */
32: public class BasePage extends ExamplePage {
33: private Contact selected;
34:
35: /**
36: * Constructor
37: */
38: public BasePage() {
39: add(new Label("selectedLabel", new PropertyModel(this ,
40: "selectedContactLabel")));
41: add(new FeedbackPanel("feedback"));
42: }
43:
44: /**
45: * @return string representation of selceted contact property
46: */
47: public String getSelectedContactLabel() {
48: if (selected == null) {
49: return "No Contact Selected";
50: } else {
51: return selected.getFirstName() + " "
52: + selected.getLastName();
53: }
54: }
55:
56: /**
57: *
58: */
59: class ActionPanel extends Panel {
60: /**
61: * @param id
62: * component id
63: * @param model
64: * model for contact
65: */
66: public ActionPanel(String id, IModel model) {
67: super (id, model);
68: add(new Link("select") {
69: public void onClick() {
70: BasePage.this .selected = (Contact) getParent()
71: .getModelObject();
72: }
73: });
74: }
75: }
76:
77: /**
78: * @return selected contact
79: */
80: public Contact getSelected() {
81: return selected;
82: }
83:
84: /**
85: * sets selected contact
86: * @param selected
87: */
88: public void setSelected(Contact selected) {
89: addStateChange(new Change() {
90: private final Contact old = BasePage.this .selected;
91:
92: public void undo() {
93: BasePage.this.selected = old;
94:
95: }
96: });
97: this.selected = selected;
98: }
99: }
|