From b3617d6c07d50e2bd929e2951aa640b5a4e139ec Mon Sep 17 00:00:00 2001 From: "Patel (US), Vaibhav Y" Date: Wed, 3 Apr 2024 12:01:11 -0500 Subject: [PATCH] bug[TW25783]: Fix Filter DateTime Column Change-Id: I88e37a6ff8a89fdbaf6a8062327e983e540450b8 --- .../xviewer/IXViewerLabelProvider.java | 75 +++++++++++-------- .../widgets/xviewer/IXViewerValueColumn.java | 5 ++ .../nebula/widgets/xviewer/XViewer.java | 4 + .../widgets/xviewer/XViewerLabelProvider.java | 32 +++++++- .../widgets/xviewer/XViewerTextFilter.java | 51 ++++++------- .../widgets/xviewer/XViewerValueColumn.java | 15 +++- 6 files changed, 117 insertions(+), 65 deletions(-) diff --git a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/IXViewerLabelProvider.java b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/IXViewerLabelProvider.java index 26f4295db..9ad9e5b5e 100644 --- a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/IXViewerLabelProvider.java +++ b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/IXViewerLabelProvider.java @@ -1,5 +1,6 @@ package org.eclipse.nebula.widgets.xviewer; +import java.util.Date; import org.eclipse.nebula.widgets.xviewer.core.model.XViewerColumn; /** @@ -7,34 +8,48 @@ */ public interface IXViewerLabelProvider { - /** - * Returns the label text for the given column of the given element. - */ - public abstract String getColumnText(Object element, int columnIndex); - - /** - * Returns the label text for the given column of the given element. - */ - public abstract String getColumnText(Object element, XViewerColumn xCol, int columnIndex) throws Exception; - - /** - * Returns XViewerColumn of the given index - */ - public abstract XViewerColumn getTreeColumnOffIndex(int columnIndex); - - /** - * Return value between 0..100 and cell will show bar graph shading that portion of the cell - */ - public abstract int getColumnGradient(Object element, XViewerColumn xCol, int columnIndex) throws Exception; - - /** - * Returns the backing data object for operations like sorting - */ - public abstract Object getBackingData(Object element, XViewerColumn xViewerColumn, int columnIndex) throws Exception; - - /** - * When columns get re-ordered, need to clear out this cache so indexing can be re-computed - */ - public abstract void clearXViewerColumnIndexCache(); - + /** + * Returns the label text for the given column of the given element. + */ + public abstract String getColumnText(Object element, int columnIndex); + + /** + * Returns the label date for the given column of the given element. + */ + public default Date getColumnDate(Object element, int columnIndex) { + return null; + }; + + /** + * Returns the label text for the given column of the given element. + */ + public abstract String getColumnText(Object element, XViewerColumn xCol, int columnIndex) throws Exception; + + /** + * Returns the label date for the given column of the given element. + */ + public default Date getColumnDate(Object element, XViewerColumn xCol, int columnIndex) throws Exception { + return null; + }; + + /** + * Returns XViewerColumn of the given index + */ + public abstract XViewerColumn getTreeColumnOffIndex(int columnIndex); + + /** + * Return value between 0..100 and cell will show bar graph shading that portion of the cell + */ + public abstract int getColumnGradient(Object element, XViewerColumn xCol, int columnIndex) throws Exception; + + /** + * Returns the backing data object for operations like sorting + */ + public abstract Object getBackingData(Object element, XViewerColumn xViewerColumn, int columnIndex) throws Exception; + + /** + * When columns get re-ordered, need to clear out this cache so indexing can be re-computed + */ + public abstract void clearXViewerColumnIndexCache(); + } diff --git a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/IXViewerValueColumn.java b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/IXViewerValueColumn.java index 31781b244..acf5c450a 100644 --- a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/IXViewerValueColumn.java +++ b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/IXViewerValueColumn.java @@ -5,6 +5,7 @@ */ package org.eclipse.nebula.widgets.xviewer; +import java.util.Date; import org.eclipse.jface.viewers.StyledString; import org.eclipse.nebula.widgets.xviewer.core.model.XViewerColumn; import org.eclipse.nebula.widgets.xviewer.util.XViewerException; @@ -18,6 +19,10 @@ public interface IXViewerValueColumn { String getColumnText(Object element, XViewerColumn column, int columnIndex) throws XViewerException; + default Date getColumnDate(Object element, XViewerColumn column, int columnIndex) { + return null; + }; + /** * Returns the backing data object for operations like sorting */ diff --git a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewer.java b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewer.java index 351a5c892..ab41b663f 100644 --- a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewer.java +++ b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewer.java @@ -801,6 +801,10 @@ public String getColumnText(Object element, int col) { return ((IXViewerLabelProvider) getLabelProvider()).getColumnText(element, col); } + public Date getColumnDate(Object element, int col) { + return ((IXViewerLabelProvider) getLabelProvider()).getColumnDate(element, col); + } + /** * Mouse clicks can happen in table via XViewerMouseListener or in menu area via XViewerMenuDetectListener. Both are * processed here to use in UI diff --git a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewerLabelProvider.java b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewerLabelProvider.java index e1e6dc1e3..bfe28911c 100644 --- a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewerLabelProvider.java +++ b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewerLabelProvider.java @@ -21,6 +21,7 @@ import java.util.logging.Level; import org.eclipse.jface.viewers.ITableColorProvider; import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.nebula.widgets.xviewer.core.model.SortDataType; import org.eclipse.nebula.widgets.xviewer.core.model.XViewerColumn; import org.eclipse.nebula.widgets.xviewer.util.internal.XViewerLog; import org.eclipse.swt.graphics.Color; @@ -118,7 +119,36 @@ public String getColumnText(Object element, int columnIndex) { } } - public static String getPrecomputedText(Object element, XViewerColumn xViewerColumn, IXViewerPreComputedColumn preComputedColumn, boolean debugLoading) { + @Override + public Date getColumnDate(Object element, int columnIndex) { + try { + XViewerColumn xViewerColumn = getTreeColumnOffIndex(columnIndex); + // First check value column's methods + if (xViewerColumn instanceof IXViewerValueColumn) { + if (xViewerColumn.getSortDataType() == SortDataType.Date) { + Long startTime = viewer.isDebugLoading() ? (new Date()).getTime() : 0L; + IXViewerValueColumn xViewerValueColumn = (IXViewerValueColumn) xViewerColumn; + if (viewer.isDebugLoading()) { + xViewerColumn.addElapsedTime((new Date()).getTime() - startTime); + } + return xViewerValueColumn.getColumnDate(element, xViewerColumn, columnIndex); + } + } + // Return label provider's value + Long startTime = viewer.isDebugLoading() ? (new Date()).getTime() : 0L; + Date value = getColumnDate(element, xViewerColumn, columnIndex); + if (viewer.isDebugLoading()) { + xViewerColumn.addElapsedTime((new Date()).getTime() - startTime); + } + return value; + } catch (Exception ex) { + // do nothing + } + return null; + } + + public static String getPrecomputedText(Object element, XViewerColumn xViewerColumn, + IXViewerPreComputedColumn preComputedColumn, boolean debugLoading) { Long key = preComputedColumn.getKey(element); String cachedValue = xViewerColumn.getPreComputedValue(key); Long startTime = debugLoading ? (new Date()).getTime() : 0L; diff --git a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewerTextFilter.java b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewerTextFilter.java index 38125d2b2..9844c3791 100644 --- a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewerTextFilter.java +++ b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewerTextFilter.java @@ -5,7 +5,7 @@ * 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: @@ -13,7 +13,6 @@ *******************************************************************************/ package org.eclipse.nebula.widgets.xviewer; -import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -131,38 +130,30 @@ 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)) { + Date cellDate = + xViewer.getColumnDate(element, xViewer.getCustomizeMgr().getColumnNumFromXViewerColumn(xCol)); + if (cellDate != null) { + 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; diff --git a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewerValueColumn.java b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewerValueColumn.java index c20f20871..9df4ed392 100644 --- a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewerValueColumn.java +++ b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewerValueColumn.java @@ -5,7 +5,7 @@ * 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: @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.nebula.widgets.xviewer; +import java.util.Date; import org.eclipse.jface.viewers.StyledString; import org.eclipse.nebula.widgets.xviewer.core.model.SortDataType; import org.eclipse.nebula.widgets.xviewer.core.model.XViewerAlign; @@ -39,8 +40,8 @@ public class XViewerValueColumn extends XViewerColumn implements IXViewerValueCo */ @Override public XViewerValueColumn copy() { - XViewerValueColumn copyColumn = new XViewerValueColumn(getId(), getName(), getWidth(), getAlign(), isShow(), getSortDataType(), - isMultiColumnEditable(), getDescription()); + XViewerValueColumn copyColumn = new XViewerValueColumn(getId(), getName(), getWidth(), getAlign(), isShow(), + getSortDataType(), isMultiColumnEditable(), getDescription()); copyColumn.setSortForward(isSortForward()); return copyColumn; } @@ -75,7 +76,8 @@ public Color getForeground(Object element, XViewerColumn xCol, int columnIndex) //This method will only be called be the XViewerStyledTextLabelProvider @Override - public StyledString getStyledText(Object element, XViewerColumn viewerColumn, int columnIndex) throws XViewerException { + public StyledString getStyledText(Object element, XViewerColumn viewerColumn, int columnIndex) + throws XViewerException { return new StyledString(getColumnText(element, viewerColumn, columnIndex)); } @@ -90,4 +92,9 @@ public Object getBackingData(Object element, XViewerColumn xCol, int columnIndex return null; } + @Override + public Date getColumnDate(Object element, XViewerColumn column, int columnIndex) { + return null; + } + }