List<Expression> getValidFilterExpressions() {
return getAsList(EQ, NOT_EQ, GT, LT, BETWEEN);
}
Fragment getFilterUiFragment(MarkupContainer container, User user, Space space, Jtrac jtrac) {
Fragment fragment = new Fragment("fragParent", "dateField", container);
YuiCalendar calendar = new YuiCalendar("value", new PropertyModel(filterCriteria, "value"), false);
fragment.add(calendar);
if(filterCriteria.getExpression() == BETWEEN) {
YuiCalendar calendar2 = new YuiCalendar("value2", new PropertyModel(filterCriteria, "value2"), false);
fragment.add(calendar2);
} else {
fragment.add(new WebMarkupContainer("value2").setVisible(false));
}
return fragment;
}
void addRestrictions(DetachedCriteria criteria) {
if(filterHasValue()) {
Object value = filterCriteria.getValue();
switch(filterCriteria.getExpression()) {
case EQ: criteria.add(Restrictions.eq(getNameText(), value)); break;
case NOT_EQ: criteria.add(Restrictions.not(Restrictions.eq(getNameText(), value))); break;
case GT: criteria.add(Restrictions.gt(getNameText(), value)); break;
case LT: criteria.add(Restrictions.lt(getNameText(), value)); break;
case BETWEEN:
criteria.add(Restrictions.gt(getNameText(), value));
criteria.add(Restrictions.lt(getNameText(), filterCriteria.getValue2()));
break;
default:
}
}
}
String getAsQueryString() {
return getQueryStringFromValue(Date.class);
}
void loadFromQueryString(String s, User user, Jtrac jtrac) {
setValueFromQueryString(s, Date.class);
}
};
//==============================================================
case 5: // free text
return new Processor() {
List<Expression> getValidFilterExpressions() {
return getAsList(CONTAINS);
}
Fragment getFilterUiFragment(MarkupContainer container, User user, Space space, Jtrac jtrac) {
return getTextFieldFragment(container);
}
void addRestrictions(DetachedCriteria criteria) {
if(filterHasValue()) {
criteria.add(Restrictions.ilike(getNameText(),
(String) filterCriteria.getValue(), MatchMode.ANYWHERE));
}
}
String getAsQueryString() {
return getQueryStringFromValue(String.class);
}
void loadFromQueryString(String s, User user, Jtrac jtrac) {
setValueFromQueryString(s, String.class);
}
};
//==============================================================
default:
throw new RuntimeException("Unknown Column Heading " + name);
}
} else { // this is not a custom field but one of the "built-in" columns
switch(name) {
//==============================================================
case ID:
return new Processor() {
List<Expression> getValidFilterExpressions() {
return getAsList(EQ);
}
Fragment getFilterUiFragment(MarkupContainer container, User user, Space space, Jtrac jtrac) {
return getTextFieldFragment(container);
}
void addRestrictions(DetachedCriteria criteria) {
if(filterHasValue()) {
// should never come here for criteria: see ItemSearch#getRefId()
throw new RuntimeException("should not come here for 'id'");
}
}
String getAsQueryString() {
return getQueryStringFromValue(String.class);
}
void loadFromQueryString(String s, User user, Jtrac jtrac) {
setValueFromQueryString(s, String.class);
}
};
//==============================================================
case SUMMARY:
return new Processor() {
List<Expression> getValidFilterExpressions() {
return getAsList(CONTAINS);
}
Fragment getFilterUiFragment(MarkupContainer container, User user, Space space, Jtrac jtrac) {
return getTextFieldFragment(container);
}
void addRestrictions(DetachedCriteria criteria) {
if(filterHasValue()) {
criteria.add(Restrictions.ilike(getNameText(), (String) filterCriteria.getValue(), MatchMode.ANYWHERE));
}
}
String getAsQueryString() {
return getQueryStringFromValue(String.class);
}
void loadFromQueryString(String s, User user, Jtrac jtrac) {
setValueFromQueryString(s, String.class);
}
};
//==============================================================
case DETAIL:
return new Processor() {
List<Expression> getValidFilterExpressions() {
return getAsList(CONTAINS);
}
Fragment getFilterUiFragment(MarkupContainer container, User user, Space space, Jtrac jtrac) {
return getTextFieldFragment(container);
}
void addRestrictions(DetachedCriteria criteria) {
// do nothing, 'detail' already processed, see: ItemSearch#getSearchText()
}
String getAsQueryString() {
return getQueryStringFromValue(String.class);
}
void loadFromQueryString(String s, User user, Jtrac jtrac) {
setValueFromQueryString(s, String.class);
}
};
//==============================================================
case STATUS:
return new Processor() {
List<Expression> getValidFilterExpressions() {
return getAsList(IN);
}
Fragment getFilterUiFragment(MarkupContainer container, User user, Space space, Jtrac jtrac) {
Fragment fragment = new Fragment("fragParent", "multiSelect", container);
// status selectable only when context space is not null
final Map<Integer, String> options = space.getMetadata().getStatesMap();
options.remove(State.NEW);
JtracCheckBoxMultipleChoice choice = new JtracCheckBoxMultipleChoice("values", new ArrayList(options.keySet()), new IChoiceRenderer() {
public Object getDisplayValue(Object o) {
return options.get(o);
}
public String getIdValue(Object o, int i) {
return o.toString();
}
});
fragment.add(choice);
choice.setModel(new PropertyModel(filterCriteria, "values"));
return fragment;
}
void addRestrictions(DetachedCriteria criteria) {
if(filterHasValueList()) {
criteria.add(Restrictions.in(getNameText(), filterCriteria.getValues()));
}
}
String getAsQueryString() {
return getQueryStringFromValueList();
}
void loadFromQueryString(String s, User user, Jtrac jtrac) {
setStatusListFromQueryString(s);
}
};
//==============================================================
case ASSIGNED_TO:
case LOGGED_BY:
return new Processor() {
List<Expression> getValidFilterExpressions() {
return getAsList(IN);
}
Fragment getFilterUiFragment(MarkupContainer container, User user, Space space, Jtrac jtrac) {
Fragment fragment = new Fragment("fragParent", "multiSelect", container);
List<User> users = null;
if(space == null) {
users = jtrac.findUsersForUser(user);
} else {
users = jtrac.findUsersForSpace(space.getId());
}
JtracCheckBoxMultipleChoice choice = new JtracCheckBoxMultipleChoice("values", users, new IChoiceRenderer() {
public Object getDisplayValue(Object o) {
return ((User) o).getName();
}
public String getIdValue(Object o, int i) {
return ((User) o).getId() + "";
}
});
fragment.add(choice);
choice.setModel(new PropertyModel(filterCriteria, "values"));
return fragment;
}
void addRestrictions(DetachedCriteria criteria) {
if(filterHasValueList()) {
criteria.add(Restrictions.in(getNameText(), filterCriteria.getValues()));
}
}
String getAsQueryString() {
return getQueryStringFromUserList();
}
void loadFromQueryString(String s, User user, Jtrac jtrac) {
setUserListFromQueryString(s, jtrac);
}
};
//==============================================================
case TIME_STAMP:
return new Processor() {
List<Expression> getValidFilterExpressions() {
return getAsList(BETWEEN, GT, LT);
}
Fragment getFilterUiFragment(MarkupContainer container, User user, Space space, Jtrac jtrac) {
Fragment fragment = new Fragment("fragParent", "dateField", container);
YuiCalendar calendar = new YuiCalendar("value", new PropertyModel(filterCriteria, "value"), false);
fragment.add(calendar);
if(filterCriteria.getExpression() == BETWEEN) {
YuiCalendar calendar2 = new YuiCalendar("value2", new PropertyModel(filterCriteria, "value2"), false);
fragment.add(calendar2);
} else {
fragment.add(new WebMarkupContainer("value2").setVisible(false));
}
return fragment;