Skip to content

Commit

Permalink
Merge pull request #585 from vaibhavypatel/master
Browse files Browse the repository at this point in the history
bug[TW25783]: Fix Filter DateTime Column
  • Loading branch information
dondunne authored Apr 10, 2024
2 parents 85a55cd + 1880818 commit 3b7d1fa
Showing 1 changed file with 32 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.nebula.widgets.xviewer;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.jface.viewers.IBaseLabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.nebula.widgets.xviewer.core.model.ColumnDateFilter;
import org.eclipse.nebula.widgets.xviewer.core.model.DateRangeType;
import org.eclipse.nebula.widgets.xviewer.core.model.SortDataType;
import org.eclipse.nebula.widgets.xviewer.core.model.XViewerColumn;
import org.eclipse.nebula.widgets.xviewer.core.util.Strings;

Expand Down Expand Up @@ -131,38 +132,39 @@ public boolean select(Viewer viewer, Object parentElement, Object element) {
}
}
if (colIdToDateFilter.containsKey(xCol.getId())) {
String cellStr =
xViewer.getColumnText(element, xViewer.getCustomizeMgr().getColumnNumFromXViewerColumn(xCol));
if (Strings.isValid(cellStr)) {
Date cellDate = XViewerSorter.parseDatePair(cellStr, "").getFirst();
if (cellDate != null) {
ColumnDateFilter columnDateFilter = colIdToDateFilter.get(xCol.getId());
Calendar cellCal = Calendar.getInstance();
cellCal.setTime(cellDate);
Calendar filterCal = Calendar.getInstance();
Date filterDate1 = columnDateFilter.getDate1();
filterCal.setTime(filterDate1);
DateRangeType rangeType = columnDateFilter.getType();
if (rangeType == DateRangeType.Equals_Date) {
if (cellCal.get(Calendar.YEAR) != filterCal.get(Calendar.YEAR) || cellCal.get(
Calendar.MONTH) != filterCal.get(Calendar.MONTH) || cellCal.get(
Calendar.DAY_OF_MONTH) != filterCal.get(Calendar.DAY_OF_MONTH)) {
return false;
}
} else if (rangeType == DateRangeType.After_Date && cellDate.before(filterDate1)) {
Object obj1 = null;
IBaseLabelProvider labelProvider = xViewer.getLabelProvider();
if (labelProvider instanceof IXViewerLabelProvider) {
try {
obj1 = ((IXViewerLabelProvider) labelProvider).getBackingData(element, xCol,
xViewer.getCustomizeMgr().getColumnNumFromXViewerColumn(xCol));
} catch (Exception ex) {
//Do Nothing
}
}
if (obj1 != null && xCol.getSortDataType() == SortDataType.Date && obj1 instanceof Date) {
Date cellDate = (Date) obj1;
ColumnDateFilter columnDateFilter = colIdToDateFilter.get(xCol.getId());
Date filterDate1 = columnDateFilter.getDate1();
DateRangeType rangeType = columnDateFilter.getType();
if (rangeType == DateRangeType.Equals_Date) {
if (cellDate.getYear() != filterDate1.getYear() || cellDate.getMonth() != filterDate1.getMonth() || cellDate.getDay() != filterDate1.getDay()) {
return false;
} else if (rangeType == DateRangeType.Before_Date && cellDate.after(filterDate1)) {
}
} else if (rangeType == DateRangeType.After_Date && cellDate.before(filterDate1)) {
return false;
} else if (rangeType == DateRangeType.Before_Date && cellDate.after(filterDate1)) {
return false;
} else if (rangeType == DateRangeType.Between_Dates) {
if (cellDate.before(filterDate1)) {
return false;
}
Date filterDate2 = columnDateFilter.getDate2();
if (cellDate.after(filterDate2)) {
return false;
} else if (rangeType == DateRangeType.Between_Dates) {
if (cellDate.before(filterDate1)) {
return false;
}
Date filterDate2 = columnDateFilter.getDate2();
if (cellDate.after(filterDate2)) {
return false;
}
}
}

} else {
// Do not show this row if date filter selected and no date is shown
return false;
Expand Down

0 comments on commit 3b7d1fa

Please sign in to comment.