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 static info.jtrac.domain.ItemItem.*;
020:
021: import info.jtrac.domain.Field;
022: import info.jtrac.domain.History;
023: import info.jtrac.domain.Item;
024: import info.jtrac.domain.ItemItem;
025: import info.jtrac.domain.ItemSearch;
026: import info.jtrac.util.DateUtils;
027: import info.jtrac.util.ItemUtils;
028: import java.util.ArrayList;
029: import java.util.List;
030: import java.util.Map;
031: import org.apache.wicket.PageParameters;
032: import org.apache.wicket.behavior.SimpleAttributeModifier;
033: import org.apache.wicket.markup.html.WebMarkupContainer;
034: import org.apache.wicket.markup.html.basic.Label;
035: import org.apache.wicket.markup.html.link.Link;
036: import org.apache.wicket.markup.html.list.ListItem;
037: import org.apache.wicket.markup.html.list.ListView;
038: import org.apache.wicket.model.PropertyModel;
039:
040: /**
041: * panel for showing the item read-only view
042: */
043: public class ItemViewPanel extends BasePanel {
044:
045: private boolean hideLinks;
046:
047: public ItemViewPanel(String id, long itemId) {
048: super (id);
049: addComponents(getJtrac().loadItem(itemId));
050: }
051:
052: public ItemViewPanel(String id, final Item item, boolean hideLinks) {
053: super (id);
054: this .hideLinks = hideLinks;
055: addComponents(item);
056: }
057:
058: private void addComponents(final Item item) {
059:
060: add(new Label("refId", new PropertyModel(item, "refId")));
061:
062: add(new Link("relate") {
063: public void onClick() {
064: // TODO choose specific space for search
065: ItemSearch itemSearch = new ItemSearch(getPrincipal(),
066: ItemViewPanel.this );
067: itemSearch.setRelatingItemRefId(item.getRefId());
068: setResponsePage(new ItemSearchFormPage(itemSearch));
069: }
070: }.setVisible(!hideLinks));
071:
072: if (item.getRelatedItems() != null) {
073: add(new ListView("relatedItems", new ArrayList(item
074: .getRelatedItems())) {
075: protected void populateItem(ListItem listItem) {
076: final ItemItem itemItem = (ItemItem) listItem
077: .getModelObject();
078: String message = null;
079: if (itemItem.getType() == DUPLICATE_OF) {
080: message = localize("item_view.duplicateOf");
081: } else if (itemItem.getType() == DEPENDS_ON) {
082: message = localize("item_view.dependsOn");
083: } else if (itemItem.getType() == RELATED) {
084: message = localize("item_view.relatedTo");
085: }
086: final String refId = itemItem.getRelatedItem()
087: .getRefId();
088: if (hideLinks) {
089: message = message + " " + refId;
090: }
091: listItem.add(new Label("message", message));
092: Link link = new Link("link") {
093: public void onClick() {
094: setResponsePage(ItemViewPage.class,
095: new PageParameters("0=" + refId));
096: }
097: };
098: link.add(new Label("refId", refId));
099: link.setVisible(!hideLinks);
100: listItem.add(link);
101: listItem.add(new Link("remove") {
102: public void onClick() {
103: setResponsePage(new ItemRelateRemovePage(
104: item.getId(), itemItem));
105: }
106: }.setVisible(!hideLinks));
107: }
108: });
109: } else {
110: add(new WebMarkupContainer("relatedItems")
111: .setVisible(false));
112: }
113:
114: if (item.getRelatingItems() != null) {
115: add(new ListView("relatingItems", new ArrayList(item
116: .getRelatingItems())) {
117: protected void populateItem(ListItem listItem) {
118: final ItemItem itemItem = (ItemItem) listItem
119: .getModelObject();
120: // this looks very similar to related items block above
121: // but the display strings could be different and in future handling of the
122: // inverse of the bidirectional link could be different as well
123: String message = null;
124: if (itemItem.getType() == DUPLICATE_OF) {
125: message = localize("item_view.duplicateOfThis");
126: } else if (itemItem.getType() == DEPENDS_ON) {
127: message = localize("item_view.dependsOnThis");
128: } else if (itemItem.getType() == RELATED) {
129: message = localize("item_view.relatedToThis");
130: }
131: final String refId = itemItem.getItem().getRefId();
132: if (hideLinks) {
133: message = refId + " " + message;
134: }
135: listItem.add(new Label("message", message));
136: Link link = new Link("link") {
137: public void onClick() {
138: setResponsePage(ItemViewPage.class,
139: new PageParameters("0=" + refId));
140: }
141: };
142: link.add(new Label("refId", refId));
143: link.setVisible(!hideLinks);
144: listItem.add(link);
145: listItem.add(new Link("remove") {
146: public void onClick() {
147: setResponsePage(new ItemRelateRemovePage(
148: item.getId(), itemItem));
149: }
150: }.setVisible(!hideLinks));
151: }
152: });
153: } else {
154: add(new WebMarkupContainer("relatingItems")
155: .setVisible(false));
156: }
157:
158: add(new Label("status", new PropertyModel(item, "statusValue")));
159: add(new Label("loggedBy", new PropertyModel(item,
160: "loggedBy.name")));
161: add(new Label("assignedTo", new PropertyModel(item,
162: "assignedTo.name")));
163: add(new Label("summary", new PropertyModel(item, "summary")));
164: add(new Label("detail", ItemUtils.fixWhiteSpace(item
165: .getDetail())).setEscapeModelStrings(false));
166:
167: final SimpleAttributeModifier sam = new SimpleAttributeModifier(
168: "class", "alt");
169: final Map<Field.Name, Field> fields = item.getSpace()
170: .getMetadata().getFields();
171: add(new ListView("fields", item.getSpace().getMetadata()
172: .getFieldOrder()) {
173: protected void populateItem(ListItem listItem) {
174: if (listItem.getIndex() % 2 == 0) {
175: listItem.add(sam);
176: }
177: Field.Name fieldName = (Field.Name) listItem
178: .getModelObject();
179: Field field = fields.get(fieldName);
180: listItem.add(new Label("label", field.getLabel()));
181: listItem.add(new Label("value", item
182: .getCustomValue(fieldName)));
183: }
184: });
185:
186: final List<Field> editable = item.getSpace().getMetadata()
187: .getEditableFields();
188: add(new ListView("labels", editable) {
189: protected void populateItem(ListItem listItem) {
190: Field field = (Field) listItem.getModelObject();
191: listItem.add(new Label("label", field.getLabel()));
192: }
193: });
194:
195: if (item.getHistory() != null) {
196: List<History> history = new ArrayList(item.getHistory());
197: add(new ListView("history", history) {
198: protected void populateItem(ListItem listItem) {
199: if (listItem.getIndex() % 2 != 0) {
200: listItem.add(sam);
201: }
202: final History h = (History) listItem
203: .getModelObject();
204: listItem.add(new Label("loggedBy",
205: new PropertyModel(h, "loggedBy.name")));
206: listItem.add(new Label("status", new PropertyModel(
207: h, "statusValue")));
208: listItem.add(new Label("assignedTo",
209: new PropertyModel(h, "assignedTo.name")));
210:
211: WebMarkupContainer comment = new WebMarkupContainer(
212: "comment");
213: comment.add(new AttachmentLinkPanel("attachment", h
214: .getAttachment()));
215: comment.add(new Label("comment", ItemUtils
216: .fixWhiteSpace(h.getComment()))
217: .setEscapeModelStrings(false));
218: listItem.add(comment);
219:
220: listItem.add(new Label("timeStamp", DateUtils
221: .formatTimeStamp(h.getTimeStamp())));
222: listItem.add(new ListView("fields", editable) {
223: protected void populateItem(ListItem listItem) {
224: Field field = (Field) listItem
225: .getModelObject();
226: listItem.add(new Label("field", h
227: .getCustomValue(field.getName())));
228: }
229: });
230: }
231: });
232: }
233:
234: }
235:
236: }
|