Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Apply DateColumnFilter(Cant apply a dateFrom - dateTo Filter to a Table.)
Apply DateColumnFilter [message #1763157] Fri, 12 May 2017 08:25 Go to next message
Janosh Suter is currently offline Janosh SuterFriend
Messages: 5
Registered: April 2017
Junior Member
Hello,

I got a problem with the ColumnUserFilterState, that seems to not work with Dates.

I have a Column "SollAnColumn" with Dates in it and on this column I want to set a filter whitch excludes all rows of the Table with their Date outside of the given Range (Date fromDate, date toDate).

I would be very grateful for your help.

Here is a Snippet of the Column, where I want to apply a filter:

  @Order(30.0)
  public class SollAnColumn extends AbstractCockpitCisDateTimeColumn {

    @Override
    public int compareTableRows(ITableRow r1, ITableRow r2) {
      return compareRowZeitBySort(r1, r2, SortMode.SOLL);
    }

    @Override
    protected void execDecorateCell(Cell cell, ITableRow row) throws ProcessingException {
      super.execDecorateCell(cell, row);

      ZugfahrtAmBetriebspunktDTO model = (ZugfahrtAmBetriebspunktDTO) row.getCellValue(getZugfahrtAmBetriebspunktModelColumn().getColumnIndex());
      if (!Objects.equals(model.getZugfahrtPunkt().getAnZeit().getSoll(), cell.getValue())) {
        cell.setFont(ITALIC_FONT);
      } else {
        cell.setFont(NORMAL_FONT);
      }
    }

  }


The Abstract Column with the correct Date Format:

public class AbstractCockpitCisDateTimeColumn extends AbstractDateColumn {

  private static final String DATE_TIME_FORMAT = "HH:mm dd.MM.yyyy";
  private static final String TIME_FORMAT = "HH:mm";

  @Override
  protected Date execParseValue(ITableRow row, Object rawValue) {
    CisDateTime timeValue;
    if (rawValue instanceof CisDateTime) {
      timeValue = (CisDateTime) rawValue;
    } else {
      timeValue = CisDateTime.createCisDateTime((Date) rawValue);
    }
      return super.execParseValue(row, timeValue.getDate());
  }

  @Override
  protected void execDecorateCell(Cell cell, ITableRow row) throws ProcessingException {
    super.execDecorateCell(cell, row);
    CisDateTime value = CisDateTime.createCisDateTime(getValue(row));
    cell.setText(formatCisDateTime(value));
  }

  private String formatCisDateTime(CisDateTime value) {
    if (value == null) {
      return null;
    }

    int today = new DateTime().getDayOfYear();
    if (value.getDateTime().getDayOfYear() != today) {
      return value.toString(DATE_TIME_FORMAT);
    }

    return value.toString(TIME_FORMAT);
  }
}


The Filtermananger applys when RadioButtonValue has changed:
        @Order(10.0)
        public class ZeitraumStundenGroup extends AbstractZugfahrtPunktZeitraumGroup {

          @Override
          protected boolean getConfiguredEnabled() {
            return true;
          }

          @Override
          protected void execChangedValue() {
            Zeitraum zeitraum = getValue();

            ZugfahrtPunktTableColumnFilterManager filterManager = getFilterManager();

            if (filterManager != null) {
              filterManager.applyCisDateComparableFilter(getTable().getSollAnColumn(), zeitraum);
            }
          }
        }


The TableFilterManager how should apply the Filter to the Table, but doesnt seem to work:
public class ZugfahrtPunktTableColumnFilterManager extends TableUserFilterManager {
  private AbstractTable table;

  public ZugfahrtPunktTableColumnFilterManager(AbstractTable table) {
    super(table);
    this.table = table;
  }

  public void applyCisDateComparableFilter(IColumn filterCol, Zeitraum zeitraum) {
    TableUserFilterManager filterManager = table.getUserFilterManager();
    DateTimeColumnUserFilterState comparableFilter = (DateTimeColumnUserFilterState) getFilter(filterCol);
    if (comparableFilter == null) {
      comparableFilter = new DateTimeColumnUserFilterState(filterCol);
    }

    comparableFilter.setDateFrom(zeitraum.getZeitVon().getDate());
    comparableFilter.setDateTo(zeitraum.getZeitBis().getDate());

    if (filterManager.getFilter(filterCol.getColumnId()) != null) {
      filterManager.removeFilterByKey(filterCol.getColumnId());
    }
    filterManager.addFilter(comparableFilter);
  }
}


If you need more information just ask.

best regards,
Joshi
Re: Apply DateColumnFilter [message #1763693 is a reply to message #1763157] Thu, 18 May 2017 15:52 Go to previous messageGo to next message
Claudio Guglielmo is currently offline Claudio GuglielmoFriend
Messages: 256
Registered: March 2010
Senior Member
Hi Janosh,

you probably don't have to use the UserFilterState and TableUserFilterManager. These classes are mainly necessary to save the current state of the filters visible in the UI (column filter, text filter), so that the filters survive a page reload or even a logout/login. But the actual filtering of the table rows happens in the UI. So if the user enters some text in the text filter (on the bottom of the table), the browser filters the rows and then notifies the server about the new visible rows and the current filter state. The only filter active on server side is the UserTableRowFilter, which contains the currently visible rows.

I think you don't need all of this. You can just implement an ITableRowFilter and add it to the table using table.addRowFilter().

Hope it helps.
Claudio
Re: Apply DateColumnFilter [message #1763981 is a reply to message #1763693] Tue, 23 May 2017 15:19 Go to previous message
Janosh Suter is currently offline Janosh SuterFriend
Messages: 5
Registered: April 2017
Junior Member
Hei Claudio

Alriight, i thought this is how you should define a filter in Java scout specific.

But you were right, there is no need for those TableUserFilterManager in this case.

Thank you for your help.
Joshi
Previous Topic:Scout Application on Openshift
Next Topic:Scout paid support?
Goto Forum:
  


Current Time: Fri Apr 26 03:37:40 GMT 2024

Powered by FUDForum. Page generated in 0.03194 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top