Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » Using @ColumnData(SdkColumnCommand.IGNORE)
Using @ColumnData(SdkColumnCommand.IGNORE) [message #1288114] Tue, 08 April 2014 09:38 Go to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 817
Registered: October 2011
Senior Member
Hi,

Bug 403171 introduced the possibility to ignore table columns in the FormData. Example:

@Order(20.0)
@ColumnData(SdkColumnCommand.IGNORE)
public class FirstNameColumn extends AbstractStringColumn {

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


Side note: It seems only to work with bean based TableData and not with array based TableData.

The use case is following:
You have a first not-displayable column, containing a bean with your information and columns that are not contained in the TableData. Here some pseudo code:

MyTable {
    ContentColumn extends AbstractColumn<PersonBean> {
        Displayable property configured to false
    }
    FirstNameColumn extends AbstractStringColumn {
        @ColumnData with value IGNORE on the column
    }
    LastNameColumn extends AbstractStringColumn {
        @ColumnData with value IGNORE on the column
    }
}


Of course the PersonBean contains the first and last name that needs to be displayed in the column.

My question is:
With this pattern, how do you set the value in corresponding column?
Is it with execDecorateRow in the FirstName and LastName column?


.
Re: Using @ColumnData(SdkColumnCommand.IGNORE) [message #1288652 is a reply to message #1288114] Tue, 08 April 2014 19:06 Go to previous message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 817
Registered: October 2011
Senior Member
I spoke with the guys using @ColumnData(IGNORE) in their Scout project.

The Idea is:

The column containing the Bean is not an AbstractColunn<T> but an AbstractContentColunn<T>.
This column has an interceptor on the setValue(..) method:

import org.eclipse.scout.commons.annotations.ColumnData;
import org.eclipse.scout.commons.annotations.ColumnData.SdkColumnCommand;
import org.eclipse.scout.commons.exception.ProcessingException;
import org.eclipse.scout.rt.client.ui.basic.table.ITableRow;
import org.eclipse.scout.rt.client.ui.basic.table.columns.AbstractColumn;

/**
 * This class is intended to be used if some other (or all) columns of a table are depending on values represented by
 * this one. All depending columns should be annotated with {@link ColumnData} using {@link SdkColumnCommand#IGNORE}.
 * <p/>
 * By default, this column is not displayable (i.e. {@link #getConfiguredDisplayable()} returns <code>false</code>).
 * <p/>
 */
public abstract class AbstractContentColumn<T> extends AbstractColumn<T> {

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

  @Override
  public void setValue(ITableRow r, T rawValue) throws ProcessingException {
    T newValue = validateValue(r, rawValue);
    r.setCellValue(getColumnIndex(), newValue);

    // Typically beans used with this column do not implement equals and often the very same
    // instance used to populate an editor (e.g. form) is just updated and set on the cell again.
    // Hence the cell's value as well as its status are not changed. That's what is adjusted here.
    if (r.isStatusNonchanged()) {
      r.setStatusUpdated();
    }

    // always update other table columns.
    updateTableColumns(r, newValue);
  }

  /**
   * Updates all other columns based on this column's value.
   */
  protected abstract void updateTableColumns(ITableRow r, T data) throws ProcessingException;
}


In the table:
- You need to implement updateTableColumns() in the ContentTable and set the ignored column values.
- Nobody should access the ignored columns from the outside (modifier changed from public to protected).

Here the complete example:
@Order(10.0)
@FormData(sdkCommand = SdkCommand.USE, value = AbstractTableFieldBeanData.class, defaultSubtypeSdkCommand = DefaultSubtypeSdkCommand.CREATE)
public class PersonTableField extends AbstractTableField<Table> {

  @Order(10.0)
  public class Table extends AbstractExtensibleTable {

    /**
     * This column is filled with the bean contained in the Content Column (see {@link #getContentColumn()}).
     * @return the FirstNameColumn
     */
    protected FirstNameColumn getFirstNameColumn() {
      return getColumnSet().getColumnByClass(FirstNameColumn.class);
    }

    /**
     * This column is filled with the bean contained in the Content Column (see {@link #getContentColumn()}).
     * @return the LastNameColumn
     */
    protected LastNameColumn getLastNameColumn() {
      return getColumnSet().getColumnByClass(LastNameColumn.class);
    }

    /**
     * @return the ContentColumn
     */
    public ContentColumn getContentColumn() {
      return getColumnSet().getColumnByClass(ContentColumn.class);
    }

    @Order(10.0)
    public class ContentColumn extends AbstractContentColumn<PersonBean> {

      @Override
      protected void updateTableColumns(ITableRow r, PersonBean data) throws ProcessingException {
        getFirstNameColumn().setValue(r, data.getFirstName());
        getLastNameColumn().setValue(r, data.getLastName());
      }
    }

    @Order(20.0)
    @ColumnData(SdkColumnCommand.IGNORE)
    public class FirstNameColumn extends AbstractStringColumn {

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

    @Order(30.0)
    @ColumnData(SdkColumnCommand.IGNORE)
    public class LastNameColumn extends AbstractStringColumn {

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


You do not see a big difference in the UI:

index.php/fa/17898/0/

But in the FormData, if you have a look at the PersonTableRowData, you do not find any getter or setter for FirtName and LastName:

index.php/fa/17899/0/


I hope it can help other scout developers. Do not hesitate to ask if you have questions about this pattern.

.

[Updated on: Wed, 09 April 2014 07:08]

Report message to a moderator

Previous Topic:Preventing a form or page being closed
Next Topic:Create web service consumer on server - timeout
Goto Forum:
  


Current Time: Thu Dec 18 07:22:50 GMT 2014

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

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