final Form form = new Form("form");
add(form);
form.add(new FeedbackPanel("feedback"));
form.setModel(new CompoundPropertyModel(itemSearch));
List<Integer> sizes = Arrays.asList(new Integer[] {5, 10, 15, 25, 50, 100, -1});
DropDownChoice pageSizeChoice = new DropDownChoice("pageSize", sizes, new IChoiceRenderer() {
public Object getDisplayValue(Object o) {
return ((Integer) o) == -1 ? localize("item_search_form.noLimit") : o.toString();
}
public String getIdValue(Object o, int i) {
return o.toString();
}
});
form.add(pageSizeChoice);
form.add(new CheckBox("showHistory"));
form.add(new Button("search") {
@Override
public void onSubmit() {
String refId = itemSearch.getRefId();
if(refId != null) {
if(getCurrentSpace() != null) {
// user can save typing by entering the refId number without the space prefixCode
try {
long id = Long.parseLong(refId);
refId = getCurrentSpace().getPrefixCode() + "-" + id;
} catch(Exception e) {
// oops that didn't work, continue
}
}
try {
new ItemRefId(refId);
} catch(InvalidRefIdException e) {
form.error(localize("item_search_form.error.refId.invalid"));
return;
}
Item item = getJtrac().loadItemByRefId(refId);
if(item == null) {
form.error(localize("item_search_form.error.refId.notFound"));
return;
}
JtracSession.get().setItemSearch(itemSearch);
setResponsePage(ItemViewPage.class, new PageParameters("0=" + item.getRefId()));
return;
}
String searchText = itemSearch.getSearchText();
if(searchText != null) {
if(!getJtrac().validateTextSearchQuery(searchText)) {
form.error(localize("item_search_form.error.summary.invalid"));
return;
}
}
setResponsePage(ItemListPage.class, itemSearch.getAsQueryString());
}
});
form.add(new Link("expandAll") {
public void onClick() {
expandAll = true;
}
@Override
public boolean isVisible() {
return !expandAll;
}
});
form.add(new ListView("columns", itemSearch.getColumnHeadings()) {
protected void populateItem(final ListItem listItem) {
final ColumnHeading ch = (ColumnHeading) listItem.getModelObject();
String label = ch.isField() ? ch.getLabel() : localize("item_list." + ch.getName());
listItem.add(new Label("columnName", label));
listItem.add(new CheckBox("visible", new PropertyModel(ch, "visible")));
List<Expression> validExpressions = ch.getValidFilterExpressions();
DropDownChoice expressionChoice = new IndicatingDropDownChoice("expression", validExpressions, new IChoiceRenderer() {
public Object getDisplayValue(Object o) {
String key = ((Expression) o).getKey();
return localize("item_filter." + key);
}
public String getIdValue(Object o, int i) {