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 info.jtrac.domain.Space;
20: import org.apache.wicket.behavior.SimpleAttributeModifier;
21: import org.apache.wicket.markup.html.basic.Label;
22: import org.apache.wicket.markup.html.link.Link;
23: import org.apache.wicket.markup.html.list.ListItem;
24: import org.apache.wicket.markup.html.list.ListView;
25: import org.apache.wicket.model.LoadableDetachableModel;
26: import org.apache.wicket.model.PropertyModel;
27:
28: /**
29: * space management page
30: */
31: public class SpaceListPage extends BasePage {
32:
33: private long selectedSpaceId;
34:
35: public void setSelectedSpaceId(long selectedSpaceId) {
36: this .selectedSpaceId = selectedSpaceId;
37: }
38:
39: public SpaceListPage() {
40:
41: add(new Link("create") {
42: public void onClick() {
43: SpaceFormPage page = new SpaceFormPage();
44: page.setPrevious(SpaceListPage.this );
45: setResponsePage(page);
46: }
47: });
48:
49: LoadableDetachableModel spaceListModel = new LoadableDetachableModel() {
50: protected Object load() {
51: logger.debug("loading space list from database");
52: return getJtrac().findAllSpaces();
53: }
54: };
55:
56: final SimpleAttributeModifier sam = new SimpleAttributeModifier(
57: "class", "alt");
58:
59: ListView listView = new ListView("spaces", spaceListModel) {
60: protected void populateItem(ListItem listItem) {
61: final Space space = (Space) listItem.getModelObject();
62: if (selectedSpaceId == space.getId()) {
63: listItem.add(new SimpleAttributeModifier("class",
64: "selected"));
65: } else if (listItem.getIndex() % 2 == 1) {
66: listItem.add(sam);
67: }
68: listItem.add(new Label("prefixCode", new PropertyModel(
69: space, "prefixCode")));
70: listItem.add(new Label("name", new PropertyModel(space,
71: "name")));
72: Link edit = new Link("edit") {
73: public void onClick() {
74: Space temp = getJtrac()
75: .loadSpace(space.getId());
76: temp.getMetadata().getXmlString(); // hack to override lazy loading
77: SpaceFormPage page = new SpaceFormPage(temp);
78: page.setPrevious(SpaceListPage.this );
79: setResponsePage(page);
80: }
81: };
82: listItem.add(edit);
83: listItem.add(new Label("description",
84: new PropertyModel(space, "description")));
85: listItem.add(new Link("allocate") {
86: public void onClick() {
87: setResponsePage(new SpaceAllocatePage(space
88: .getId(), SpaceListPage.this));
89: }
90: });
91: }
92: };
93:
94: add(listView);
95:
96: }
97:
98: }
|