001: /*
002: * Copyright 2002-2005 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package info.jtrac.wicket;
018:
019: import info.jtrac.domain.Counts;
020: import info.jtrac.domain.ItemSearch;
021: import info.jtrac.domain.Space;
022: import info.jtrac.domain.State;
023: import info.jtrac.domain.User;
024: import info.jtrac.domain.UserSpaceRole;
025: import java.util.ArrayList;
026: import java.util.List;
027: import java.util.Map;
028: import java.util.TreeMap;
029: import org.apache.wicket.ajax.AjaxRequestTarget;
030: import org.apache.wicket.behavior.SimpleAttributeModifier;
031: import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink;
032: import org.apache.wicket.markup.html.WebMarkupContainer;
033: import org.apache.wicket.markup.html.basic.Label;
034: import org.apache.wicket.markup.html.link.Link;
035: import org.apache.wicket.markup.html.list.ListItem;
036: import org.apache.wicket.markup.html.list.ListView;
037: import org.apache.wicket.model.PropertyModel;
038:
039: /**
040: * panel for expanded view of statistics for a single space
041: */
042: public class DashboardRowExpandedPanel extends BasePanel {
043:
044: public DashboardRowExpandedPanel(String id,
045: final UserSpaceRole usr, final Counts counts) {
046:
047: super (id);
048: setOutputMarkupId(true);
049:
050: final Space space = usr.getSpace();
051: final User user = usr.getUser();
052:
053: final Map<Integer, String> states = new TreeMap(space
054: .getMetadata().getStates());
055: states.remove(State.NEW);
056: int rowspan = states.size() + 1; // add one totals row also
057: final SimpleAttributeModifier sam = new SimpleAttributeModifier(
058: "rowspan", rowspan + "");
059: List<Integer> stateKeys = new ArrayList<Integer>(states
060: .keySet());
061:
062: add(new ListView("rows", stateKeys) {
063:
064: protected void populateItem(ListItem listItem) {
065:
066: if (listItem.getIndex() == 0) { // rowspan output only for first row
067:
068: listItem.add(new Label("space", space.getName())
069: .add(sam));
070:
071: WebMarkupContainer newColumn = new WebMarkupContainer(
072: "new");
073: newColumn.add(sam);
074: listItem.add(newColumn);
075:
076: if (usr.isAbleToCreateNewItem()) {
077: newColumn.add(new Link("new") {
078: public void onClick() {
079: setCurrentSpace(space);
080: setResponsePage(ItemFormPage.class);
081: }
082: });
083:
084: } else {
085: newColumn.add(new WebMarkupContainer("new")
086: .setVisible(false));
087: }
088:
089: listItem.add(new Link("search") {
090: public void onClick() {
091: setCurrentSpace(space);
092: setResponsePage(ItemSearchFormPage.class);
093: }
094: }.add(sam));
095:
096: listItem.add(new IndicatingAjaxLink("link") {
097: public void onClick(AjaxRequestTarget target) {
098: DashboardRowPanel dashboardRow = new DashboardRowPanel(
099: "dashboardRow", usr, counts);
100: DashboardRowExpandedPanel.this
101: .replaceWith(dashboardRow);
102: target.addComponent(dashboardRow);
103: }
104: }.add(sam));
105:
106: } else {
107: listItem.add(new WebMarkupContainer("space")
108: .setVisible(false));
109: listItem.add(new WebMarkupContainer("new")
110: .setVisible(false));
111: listItem.add(new WebMarkupContainer("search")
112: .setVisible(false));
113: listItem.add(new WebMarkupContainer("link")
114: .setVisible(false));
115: }
116:
117: final Integer i = (Integer) listItem.getModelObject();
118: listItem.add(new Label("status", states.get(i)));
119:
120: if (user.getId() > 0) {
121: listItem.add(new Link("loggedByMe") {
122: public void onClick() {
123: setCurrentSpace(space);
124: ItemSearch itemSearch = new ItemSearch(
125: space, this );
126: itemSearch.setLoggedBy(user);
127: itemSearch.setStatus(i);
128: setCurrentItemSearch(itemSearch);
129: setResponsePage(ItemListPage.class);
130: }
131: }.add(new Label("loggedByMe", counts
132: .getLoggedByMeForState(i))));
133:
134: listItem.add(new Link("assignedToMe") {
135: public void onClick() {
136: setCurrentSpace(space);
137: ItemSearch itemSearch = new ItemSearch(
138: space, this );
139: itemSearch.setAssignedTo(user);
140: itemSearch.setStatus(i);
141: setCurrentItemSearch(itemSearch);
142: setResponsePage(ItemListPage.class);
143: }
144: }.add(new Label("assignedToMe", counts
145: .getAssignedToMeForState(i))));
146: } else {
147: listItem.add(new WebMarkupContainer("loggedByMe")
148: .setVisible(false));
149: listItem.add(new WebMarkupContainer("assignedToMe")
150: .setVisible(false));
151: }
152:
153: listItem.add(new Link("total") {
154: public void onClick() {
155: setCurrentSpace(space);
156: ItemSearch itemSearch = new ItemSearch(space,
157: this );
158: itemSearch.setStatus(i);
159: setCurrentItemSearch(itemSearch);
160: setResponsePage(ItemListPage.class);
161: }
162: }.add(new Label("total", counts.getTotalForState(i))));
163: }
164:
165: });
166:
167: // sub totals ==========================================================
168:
169: if (user.getId() > 0) {
170: add(new Link("loggedByMeTotal") {
171: public void onClick() {
172: setCurrentSpace(space);
173: ItemSearch itemSearch = new ItemSearch(space, this );
174: itemSearch.setLoggedBy(user);
175: setCurrentItemSearch(itemSearch);
176: setResponsePage(ItemListPage.class);
177: }
178: }.add(new Label("loggedByMe", new PropertyModel(counts,
179: "loggedByMe"))));
180:
181: add(new Link("assignedToMeTotal") {
182: public void onClick() {
183: setCurrentSpace(space);
184: ItemSearch itemSearch = new ItemSearch(space, this );
185: itemSearch.setAssignedTo(user);
186: setCurrentItemSearch(itemSearch);
187: setResponsePage(ItemListPage.class);
188: }
189: }.add(new Label("assignedToMe", new PropertyModel(counts,
190: "assignedToMe"))));
191: } else {
192: add(new WebMarkupContainer("loggedByMeTotal")
193: .setVisible(false));
194: add(new WebMarkupContainer("assignedToMeTotal")
195: .setVisible(false));
196: }
197:
198: add(new Link("totalTotal") {
199: public void onClick() {
200: setCurrentSpace(space);
201: ItemSearch itemSearch = new ItemSearch(space, this );
202: setCurrentItemSearch(itemSearch);
203: setResponsePage(ItemListPage.class);
204: }
205: }.add(new Label("total", new PropertyModel(counts, "total"))));
206:
207: }
208:
209: }
|