Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » Summary row in table
Summary row in table [message #717030] Fri, 19 August 2011 05:55 Go to next message
Adrian Moser
Messages: 67
Registered: March 2011
Member
I have a scout table page with numeric column data.
What is the preferred way to create a summary row? (e.g. avg, sum, min, max)

Is there an automatic way? How can I make sure the summary row stays always at the same position (bottom) when sorting?

Kind regards
Adrian
Re: Summary row in table [message #717571 is a reply to message #717030] Sun, 21 August 2011 12:43 Go to previous messageGo to next message
Claudio Guglielmo is currently offline Claudio Guglielmo
Messages: 127
Registered: March 2010
Senior Member
Hi Adrian

To make sure the summary row always stays at the bottom of the table I suggest to create an invisible column and set the property AlwaysIncludeSortAtBegin to true. This makes sure the sort order of this column is always considered first when sorting any column. So the sort order of this column is important which means the value of the summary row needs to be greater than the other values.

Here is an example of the data. The first column is the invisible sort column:

   
@Override
protected Object[][] execLoadTableData(SearchFilter filter) throws ProcessingException {
  return new Object[][]{
      {0, "Company A", 50000},
      {0, "Company B", 10000},
      {1, "Total", 60000},
  };
}


The invisible sort column could look like this:

@Order(10.0)
public class SortColumn extends AbstractIntegerColumn {

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

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

  @Override
  protected int getConfiguredSortIndex() {  
    return 0;
  }

}


To group the data (sum, avg) etc. I suggest to do this directly in the sql code when selecting the data.

SELECT 0, name, value from company
UNION
SELECT 1, 'Total', sum(value) from company


Best regards
Claudio
Re: Summary row in table [message #717701 is a reply to message #717571] Mon, 22 August 2011 06:57 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie Bresson
Messages: 118
Registered: November 2010
Senior Member
@Claudio Guglielmo

I think you wanted to say that the sort Column should not be Displayable
   @Override
   protected boolean getConfiguredDisplayable() {
     return false;
  }



I think there wasn't the need to compute a Summary Row in Java, but I could be added to the framework... (in a generalized way). This is something I find very comfortable in JasperReport where you can add this kind of operation in a group-band.

To my mind support for tree-table in scout is also missing and it would go in the same direction.



Here some input on the configuration of a the sorting properties in a column:

* SortIndex: configure the sorting priority of the column (the smallest the better).

* SortAscending: if true the rows are sorted in the ascending order (from A to Z or 0 to 9). if false the rows are sorted in the descending order.

* AlwaysIncludeSortAtBegin: if true, the column is always sorted before the user configuration. (priority between all columns Included at begin is still defined with the SortIndex)

* AlwaysIncludeSortAtEnd: if true, the column is always sorted after the user configuration. (priority between all columns Included at end is still defined with the SortIndex)


Please tell me if this is clear enough. I will put this in our wiki.

I have a draft of an "how to" article to explain how sorting is working in scout. I never took time to publish it.
Re: Summary row in table [message #717847 is a reply to message #717701] Mon, 22 August 2011 14:09 Go to previous messageGo to next message
Claudio Guglielmo is currently offline Claudio Guglielmo
Messages: 127
Registered: March 2010
Senior Member
Hi Jeremie

That's ok for me. If you miss any feature please open a change request ticket in bugzilla. Otherwise your idea will be forgotten soon.

Regards
Claudiot
Re: Summary row in table [message #718598 is a reply to message #717847] Wed, 24 August 2011 19:49 Go to previous messageGo to next message
Adrian Moser
Messages: 67
Registered: March 2011
Member
Thanks for your feedback, and the pattern with the sort column.
But, I don't like the idea using SQL for calculation, since you are duplicating code in the where clause.

I tried creating an AbstractSummaryTable, which handles creating the row and doing the calculation. If I need to have a summary row, basically I just need to add the sort column and replace the default AbstractTable with the AbstractSummaryTable.

Any suggestions?

import org.eclipse.scout.commons.BooleanUtility;
import org.eclipse.scout.commons.NumberUtility;
import org.eclipse.scout.commons.exception.ProcessingException;
import org.eclipse.scout.rt.client.ui.basic.table.AbstractTable;
import org.eclipse.scout.rt.client.ui.basic.table.ITableRow;
import org.eclipse.scout.rt.client.ui.basic.table.columns.AbstractBooleanColumn;
import org.eclipse.scout.rt.client.ui.basic.table.columns.AbstractDoubleColumn;
import org.eclipse.scout.rt.client.ui.basic.table.columns.AbstractLongColumn;
import org.eclipse.scout.rt.client.ui.basic.table.columns.AbstractStringColumn;
import org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn;
import org.eclipse.scout.rt.shared.data.basic.FontSpec;

public abstract class AbstractSummaryTable extends AbstractTable {

  protected abstract Class<? extends AbstractBooleanColumn> getConfiguredSummaryOrderColumn();

  protected abstract Class<? extends AbstractStringColumn> getConfiguredSummaryTotalColumn();

  @Override
  protected final void execDecorateRow(ITableRow row) throws ProcessingException {

    // create summary row
    if ((getTableData().length - 1) == row.getRowIndex() &&
        !BooleanUtility.nvl(getColumnSet().getColumnByClass(getConfiguredSummaryOrderColumn()).getValue(row), false)) {
      ITableRow newRow = createRow();
      getColumnSet().getColumnByClass(getConfiguredSummaryOrderColumn()).setValue(newRow, true);
      addRow(newRow);
    }

    // populate summary row
    if (BooleanUtility.nvl(getColumnSet().getColumnByClass(getConfiguredSummaryOrderColumn()).getValue(row), false)) {
      // bold
      row.setFont(FontSpec.parse("bold"));
      row.setIconId(null);

      // label
      getColumnSet().getColumnByClass(getConfiguredSummaryTotalColumn()).setValue(row, Texts.get("Total"));

      // summary
      int dataColCount = getRowCount() - 1;
      for (IColumn column : getColumnSet().getColumns()) {

        // Long
        if (column instanceof AbstractLongColumn) {
          Long sum = 0L;
          for (int k = 0; k < dataColCount; k++) {
            sum += NumberUtility.nvl((Long) getTableData()[k][column.getColumnIndex()], 0);
          }
          ((AbstractLongColumn) column).setValue(dataColCount, sum);
        }

        // Double
        if (column instanceof AbstractDoubleColumn) {
          Double sum = 0D;
          for (int k = 0; k < dataColCount; k++) {
            sum = sum + NumberUtility.nvl((Double) getTableData()[k][column.getColumnIndex()], 0D);
          }
          ((AbstractDoubleColumn) column).setValue(dataColCount, sum);
        }
      }
    }
  }

}

Re: Summary row in table [message #1404220 is a reply to message #718598] Wed, 30 July 2014 14:29 Go to previous messageGo to next message
Lukas Steigerwald is currently offline Lukas Steigerwald
Messages: 47
Registered: July 2014
Member
I know the last post in this thread has been a while ago, but I am currently working on exactly the same problem. I would like to put two lines at the bottom of my table. For that reason I added a sort colum. All the content get a 0 as value for this column, the last two rows get 1 and 2. "Always include sort at begin" is checked and the sort index is set to 0. Exactly as told in the posts above. However when now clicking on one of the column headers to sort, this setup seems to have no effect at all. Has there been a change to scout to disable this feature, or am I missing something?
Re: Summary row in table [message #1404242 is a reply to message #1404220] Wed, 30 July 2014 15:27 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie Bresson
Messages: 757
Registered: October 2011
Senior Member
No problem to ask, even if the thread is old.

Just tested with Luna, SWT UI.
It works as expected:

Ascending sort of the Text Column
index.php/fa/18710/0/

Descending sort of the Text Column
index.php/fa/18709/0/


In a normal application the SortColumn should be "displayable = false" in order to hide it for the user. I let it visible for debug purpose.

@Order(10.0)
public class SortColumn extends AbstractIntegerColumn {

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

  @Override
  protected String getConfiguredHeaderText() {
    return TEXTS.get("Sort");
  }

  @Override
  protected int getConfiguredSortIndex() {
    return 0;
  }
}


Can you provide more details (Scout Version, UI, Eclipse platform version, ...)?
Re: Summary row in table [message #1404302 is a reply to message #1404242] Thu, 31 July 2014 06:47 Go to previous messageGo to next message
Lukas Steigerwald is currently offline Lukas Steigerwald
Messages: 47
Registered: July 2014
Member
This is how my SortColum looks like:

  @Order(10.0)
        public class SortColumn extends AbstractIntegerColumn {

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

          @Override
          protected int getConfiguredSortIndex() {
            return 0;
          }

        }

In my opinion no difference to your code. Do I have to setup something else for the other columns that are not the summary column maybe?


Regarding my setup (same as we had during my last issue):
Scout Version: 4.0
UI: same result in all three clients (focus on RAP and SWT)
Eclipse Platform: 4.4

[Updated on: Thu, 31 July 2014 06:48]

Report message to a moderator

Re: Summary row in table [message #1404328 is a reply to message #1404302] Thu, 31 July 2014 09:23 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie Bresson
Messages: 757
Registered: October 2011
Senior Member
I think your problem is somewhere else. I tried my code with Swing and RAP and it works. (I have also Scout 4.0.0 - aka Luna Release)

Are you sure your Sort Column contains Data?

.
Re: Summary row in table [message #1404337 is a reply to message #1404328] Thu, 31 July 2014 10:21 Go to previous messageGo to next message
Lukas Steigerwald is currently offline Lukas Steigerwald
Messages: 47
Registered: July 2014
Member
Yes, I am sure that there is data in it:
index.php/fa/18722/0/
index.php/fa/18723/0/

And I have no idea what could be wrong with the table. It is a table in a TableField of a Form. Maybe that does make a difference? The other columns have no sortIndex enabled. Do I need to enable the sortIndex in every column?
Re: Summary row in table [message #1404356 is a reply to message #1404337] Thu, 31 July 2014 13:23 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie Bresson
Messages: 757
Registered: October 2011
Senior Member
I have also a Table Field in a Form.

What occures when you call "Reset columns > Sorting" in the context menu in the Table header.
You can also call table.sort() in your code.

I have manage to produce a situation where this is not working:
@Order(10.0)
public class Table extends AbstractExtensibleTable {

  @Override
  protected boolean getConfiguredSortEnabled() {
    return false;
  }

  //rest of the table.

}


can you check the "Sort Enabled" property in your table?
(maybe it is not set with the getConfiguredSortEnabled() method but later with setSortEnabled(..)?)

You should debug: AbstractTable#sort().

From what I can tell, every thing works by design.

We should probably contribute some unit test for sorting in
org.eclipse.scout.rt.client.ui.basic.table.TableTest


Are you interested in contributing tests for the framework?

.

[Updated on: Thu, 31 July 2014 13:23]

Report message to a moderator

Re: Summary row in table [message #1404402 is a reply to message #1404356] Fri, 01 August 2014 06:42 Go to previous messageGo to next message
Lukas Steigerwald is currently offline Lukas Steigerwald
Messages: 47
Registered: July 2014
Member
Reset columns > Sorting brings the table back to the default like shown in the first screenshot of my last post. Except that in the header column the arrow for sort ascending is shown. And neither in the form nor in the Page opening the form there is any getConfiguredSortEnabled() or setSortEnabled method. Will try to debug the sort() method of AbstractTable() next and hope to find something there. Thank you for your time and suggestions until now.

EDIT: debuggin sort() I noticed that getColumnSet().getSortColumns() only returns the column that I have clicked on in the UI. Where should the sort() method get to know about the "always Include Sort at Begin"-column?

[Updated on: Fri, 01 August 2014 07:04]

Report message to a moderator

Re: Summary row in table [message #1404404 is a reply to message #1404402] Fri, 01 August 2014 07:05 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie Bresson
Messages: 757
Registered: October 2011
Senior Member
SortEnabled is a property of the Table (inside you TablePage or TableField in your Form). You should override getConfiguredSortEnabled() in the Table inner-class.

Edit: In my case when I click on the Text column to sort "getColumnSet().getSortColumns()" return:
- [0] MyForm$MainBox$MyTableField$Table$SortColumn
- [1] MyForm$MainBox$MyTableField$Table$TextColumn
I have 2 columns in this list...

Can you inspect table.getColumnSet()?

I have:
* m_permanentHeadSortColumns ArrayList<E> (size 1)
- [0] DesktopForm$MainBox$MyTableField$Table$SortColumn
* m_permanentTailSortColumns ArrayList<E> (size 0)
* m_userSortColumns ArrayList<E> (size 1)
- [0] DesktopForm$MainBox$MyTableField$Table$TextColumn

.

[Updated on: Fri, 01 August 2014 07:15]

Report message to a moderator

Re: Summary row in table [message #1404408 is a reply to message #1404404] Fri, 01 August 2014 07:35 Go to previous messageGo to next message
Lukas Steigerwald is currently offline Lukas Steigerwald
Messages: 47
Registered: July 2014
Member
Ok...I discovered the following: When starting the form by opening the page there is first no ascending arrow for the sort column. When I hit another column to sort the sort-column is ignored (and the m_permanentHeadSortColumns-Array is empty). However after resetting the columns with the menu I get the ascending arrow on the sort-column. When now sorting another column by clicking on its header everything works as it should ( and table.getColumnSet() has the expected array content, as described in your previous post)

EDIT: Only sorting by the sort column has not the same effect as getting the ascending-arrow by resetting sort; Furthermore after resetting the sort the other column to sort has not the ascending/descending arrow when sorted but [a-z]/[z-a].

[Updated on: Fri, 01 August 2014 07:47]

Report message to a moderator

Re: Summary row in table [message #1404413 is a reply to message #1404408] Fri, 01 August 2014 08:10 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie Bresson
Messages: 757
Registered: October 2011
Senior Member
Interresting... This might be a cause.

Do you know how you manage to produce a case where you have no arrow? I have cleared the user preferences and I still have the arrow when I open the form.

I continue to investigate, I do no understand why you have something else.

.
Re: Summary row in table [message #1404415 is a reply to message #1404413] Fri, 01 August 2014 08:28 Go to previous messageGo to next message
Lukas Steigerwald is currently offline Lukas Steigerwald
Messages: 47
Registered: July 2014
Member
The case with no arrows is when I navigate to the page. The page has its own table disabled and opens a layoutForm. In this layoutForm the tableForm is included with setInnerClass of a AbstractWrappedFormField<AbstractForm>. The layoutForm and tableForm are both initialised in the execPageActivated() method of the page.
Re: Summary row in table [message #1404424 is a reply to message #1404415] Fri, 01 August 2014 09:47 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie Bresson
Messages: 757
Registered: October 2011
Senior Member
Is it possible for you to attach some code in the forum (for example a zip containing the Page, the LayoutForm and the TableForm classes)? [do not post confidential/closed source code on the forum. See Terms of use].

What is different in your case (in comparison to what happens in the normal case)?

.
Re: Summary row in table [message #1404428 is a reply to message #1404424] Fri, 01 August 2014 10:08 Go to previous messageGo to next message
Lukas Steigerwald is currently offline Lukas Steigerwald
Messages: 47
Registered: July 2014
Member
I will check with the responsible people on monday and then provide some source code.
Re: Summary row in table [message #1404429 is a reply to message #1404428] Fri, 01 August 2014 10:49 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie Bresson
Messages: 757
Registered: October 2011
Senior Member
An alternative is also to reproduce the behaviour in a small "Hello-World" scout project with different names... This way you are sure to be the author of the code you share.
Re: Summary row in table [message #1404471 is a reply to message #1404429] Fri, 01 August 2014 15:04 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie Bresson
Messages: 757
Registered: October 2011
Senior Member
Ok I spend time on writing Unit tests in org.eclipse.scout.rt.client.ui.basic.table.TableTest (diff) to ensure that table-ordering works as I told.

I managed to reproduce the symptoms you are describing (m_permanentHeadSortColumns empty, sort order not considered...).

Is it possible that the Table where you have your sort problem is also the same table that you have also mentioned in this thread: Saving users table customisation?

The fix for my unit tests was to add table.initTable() at the beginning of my unit test. I do not know why but looking at the code, it seems to be necessary. (see as example: TableRowInsertOrderTest)

Can you add a breakpoint in AbstractTable#initTable() and see if you are called? I guess not. It is probably related to your other problem.

Without seeing your code, I can not tell what is wrong.

.

PS: I will be on holidays the major part of august and will not be able to reply.

[Updated on: Fri, 01 August 2014 16:00]

Report message to a moderator

Re: Summary row in table [message #1404552 is a reply to message #1404471] Mon, 04 August 2014 07:32 Go to previous message
Lukas Steigerwald is currently offline Lukas Steigerwald
Messages: 47
Registered: July 2014
Member
Adding the initTable() directly after creating the TableForm did it. Now the sorting works as expected and the summary row and the empty row stay where they should. And yes, the table is the same one mentioned in my other question. Thank you very much and enjoy your holiday.
EDIT: It seems the initTable() solved the issue with saving a changed order of colums as described in my other question as well. I will add a link to this thread as a solution.

[Updated on: Mon, 04 August 2014 07:40]

Report message to a moderator

Previous Topic:Deploy scout application in Apache ServiceMix
Next Topic:Highlight default button?
Goto Forum:
  


Current Time: Tue Oct 21 13:43:22 GMT 2014

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

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