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.Item;
022: import info.jtrac.domain.ItemSearch;
023: import info.jtrac.wicket.yui.YuiDialog;
024: import java.util.ArrayList;
025: import java.util.HashMap;
026: import java.util.Map;
027: import org.apache.wicket.PageParameters;
028: import org.apache.wicket.ajax.AjaxRequestTarget;
029: import org.apache.wicket.ajax.markup.html.AjaxLink;
030: import org.apache.wicket.markup.html.WebMarkupContainer;
031: import org.apache.wicket.markup.html.basic.Label;
032: import org.apache.wicket.markup.html.form.DropDownChoice;
033: import org.apache.wicket.markup.html.form.Form;
034: import org.apache.wicket.markup.html.form.IChoiceRenderer;
035: import org.apache.wicket.markup.html.form.TextArea;
036: import org.apache.wicket.markup.html.link.Link;
037: import org.apache.wicket.model.BoundCompoundPropertyModel;
038:
039: /**
040: * header that appears only witin relate items use case
041: * containing modal window link
042: */
043: public class ItemRelatePanel extends BasePanel {
044:
045: private String refId;
046:
047: public ItemRelatePanel(String id, boolean isItemViewPage) {
048: super (id);
049: ItemSearch itemSearch = getCurrentItemSearch();
050: refId = itemSearch == null ? null : itemSearch
051: .getRelatingItemRefId();
052: if (refId != null) {
053: final YuiDialog dialog = new YuiDialog("itemWindow");
054: add(dialog);
055: AjaxLink link = new AjaxLink("link") {
056: public void onClick(AjaxRequestTarget target) {
057: Item item = getJtrac().loadItemByRefId(refId);
058: dialog.show(target, refId, new ItemViewPanel(
059: YuiDialog.CONTENT_ID, item, true));
060: }
061: };
062: link.add(new Label("refId", refId));
063: if (isItemViewPage) {
064: add(new WebMarkupContainer("link").setVisible(false));
065: add(new WebMarkupContainer("message").setVisible(false));
066: add(new RelateForm("form").add(link));
067: } else {
068: add(new Label("message",
069: localize("item_list.searchingForRelated")));
070: add(link);
071: add(new WebMarkupContainer("form").setVisible(false));
072: }
073: add(new Link("cancel") {
074: public void onClick() {
075: Item item = getJtrac().loadItemByRefId(refId);
076: setCurrentItemSearch(null);
077: setResponsePage(ItemViewPage.class,
078: new PageParameters("0=" + item.getRefId()));
079: }
080: });
081: } else {
082: setVisible(false);
083: }
084: }
085:
086: /**
087: * wicket form
088: */
089: private class RelateForm extends Form {
090:
091: private int type;
092: private String comment;
093:
094: public RelateForm(String id) {
095: super (id);
096: setModel(new BoundCompoundPropertyModel(this ));
097: final Map<Integer, String> options = new HashMap<Integer, String>(
098: 3);
099: options.put(DUPLICATE_OF,
100: localize("item_view_form.duplicateOf"));
101: options.put(DEPENDS_ON,
102: localize("item_view_form.dependsOn"));
103: options.put(RELATED, localize("item_view_form.relatedTo"));
104: DropDownChoice choice = new DropDownChoice("type",
105: new ArrayList(options.keySet()),
106: new IChoiceRenderer() {
107: public Object getDisplayValue(Object o) {
108: return options.get(o);
109: }
110:
111: public String getIdValue(Object o, int i) {
112: return o.toString();
113: }
114: });
115: add(choice);
116: TextArea commentArea = new TextArea("comment");
117: commentArea.setRequired(true);
118: commentArea.add(new ErrorHighlighter());
119: add(commentArea);
120: }
121:
122: public int getType() {
123: return type;
124: }
125:
126: public void setType(int type) {
127: this .type = type;
128: }
129:
130: public String getComment() {
131: return comment;
132: }
133:
134: public void setComment(String comment) {
135: this .comment = comment;
136: }
137:
138: @Override
139: protected void onSubmit() {
140: Item item = getJtrac().loadItemByRefId(refId);
141: long itemId = ((ItemViewPage) getPage()).getItemId();
142: Item relatedItem = getJtrac().loadItem(itemId);
143: item.addRelated(relatedItem, type);
144: item.setEditReason(comment);
145: getJtrac().updateItem(item, getPrincipal());
146: setCurrentItemSearch(null);
147: setResponsePage(ItemViewPage.class, new PageParameters("0="
148: + item.getRefId()));
149: }
150:
151: }
152:
153: }
|