Using @ColumnData(SdkColumnCommand.IGNORE) [message #1288114] |
Tue, 08 April 2014 05:38  |
Eclipse User |
|
|
|
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 15:06  |
Eclipse User |
|
|
|
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:

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

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 03:08] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.09669 seconds