diff --git a/common/source/java/ch/systemsx/cisd/common/shared/basic/AlternativesStringFilter.java b/common/source/java/ch/systemsx/cisd/common/shared/basic/AlternativesStringFilter.java index ff84a61b54dd4d182fc4610c4395b3a42b1a84a0..98e697897b34f88aa4accc3f191fabe66ef3cc7f 100644 --- a/common/source/java/ch/systemsx/cisd/common/shared/basic/AlternativesStringFilter.java +++ b/common/source/java/ch/systemsx/cisd/common/shared/basic/AlternativesStringFilter.java @@ -212,6 +212,48 @@ public class AlternativesStringFilter } } + static class DateMatcher implements Matcher + { + private String filter; + + private ComparisonKind comparisonKind; + + DateMatcher(String filter, ComparisonKind comparison) + { + this.filter = filter; + this.comparisonKind = comparison; + } + + @Override + public boolean matches(String value) + { + if (value == null) + { + return false; + } + + if (comparisonKind == null || ComparisonKind.EQ.equals(this.comparisonKind)) + { + return value.startsWith(filter); + } else + { + switch (this.comparisonKind) + { + case LT: + return value.compareTo(this.filter) < 0; + case LE: + return value.compareTo(this.filter) <= 0; + case GT: + return value.compareTo(this.filter) > 0; + case GE: + return value.compareTo(this.filter) >= 0; + default: + return false; + } + } + } + } + static class NumericMatcher implements Matcher { protected final double filterValue; @@ -316,6 +358,23 @@ public class AlternativesStringFilter } } + public void setDateFilterValue(String value) + { + alternatives.clear(); + + String filterValue = value; + ComparisonKind comparisonKindOrNull = null; + if (value != null && value.length() >= 2 && "<>=".indexOf(value.charAt(0)) > -1) + { + int operatorLength = (value.charAt(1) == '=') ? 2 : 1; + String operator = value.substring(0, operatorLength); + filterValue = value.substring(operatorLength); + comparisonKindOrNull = tryGetComparisonKind(operator); + } + Matcher matcher = new DateMatcher(filterValue, comparisonKindOrNull); + alternatives.add(matcher); + } + private Matcher tryGetNumericMatcher(String s) { if (s.length() < 2) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/resultset/CachedResultSetManager.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/resultset/CachedResultSetManager.java index 5048ff8a934b761f53c91fb512f74b06d145172e..abc775d0bdd11c8cd446006729803e6aaf28ab3d 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/resultset/CachedResultSetManager.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/resultset/CachedResultSetManager.java @@ -17,9 +17,12 @@ package ch.systemsx.cisd.openbis.generic.client.web.server.resultset; import java.io.Serializable; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -62,6 +65,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.GridRowModel; import ch.systemsx.cisd.openbis.generic.shared.basic.IColumnDefinition; import ch.systemsx.cisd.openbis.generic.shared.basic.PrimitiveValue; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataTypeCode; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DateTableCell; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GridCustomColumn; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SortInfo; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SortInfo.SortDir; @@ -96,6 +100,14 @@ public final class CachedResultSetManager<K> implements IResultSetManager<K>, Se final GridRowModel<T> row) { Comparable<?> value = definition.tryGetComparableValue(row); + + if (value != null && value instanceof DateTableCell) + { + final DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date d = ((DateTableCell) value).getDateTime(); + return df.format(d); + } + return value == null ? "" : value.toString(); } @@ -509,7 +521,14 @@ public final class CachedResultSetManager<K> implements IResultSetManager<K>, Se { final AlternativesStringFilter result = new AlternativesStringFilter(); final String pattern = gridFilterInfo.tryGetFilterPattern().toLowerCase(); - result.setFilterValue(pattern); + + if (DataTypeCode.TIMESTAMP.equals(gridFilterInfo.getFilteredField().tryToGetDataType())) + { + result.setDateFilterValue(pattern); + } else + { + result.setFilterValue(pattern); + } return result; }