Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug[TW25783]: Fix Filter DateTime Column #585

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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