Home » Eclipse Projects » Eclipse Scout » Table and GroupBox for details on row selection
| | | | |
Re: Table and GroupBox for details on row selection [message #1297527 is a reply to message #1295233] |
Tue, 15 April 2014 18:53 |
Jeremie Bresson Messages: 1252 Registered: October 2011 |
Senior Member |
|
|
I was asked to present how this pattern is implemented. If you use it, please give us feedback. Maybe support for this pattern (Scout RT and Scout SDK) will be included in the next release of Eclipse Scout.
Because of the lack of support in the current Scout Version, implementing this pattern is not as easy as other task that you can do with the Scout SDK. You should have some experience with Scout and some Java Knowledge.
I have tested this with Scout Luna M6.
1/ Prepare your form:
Like for any other form, you can use the SDK to make your form (MyMasterDetailForm).
You will need at least:
- A Table Field (that will be the master Table).
- A GroupBox containing the detail that will be displayed.
In your table field, you can already create a column called ContentColumn. For the moment this column can have the type ObjectColumn. (I put this column as first column, but this does not maters).
In my example the other columns are simple String Column because I want to handle string fields (first name and last name). It is possible to imagine other types (SmartColumn, IntegerColumn). It is important that the type match the type of the fields in the detail box.
To keep this example simple, the detail box only contains 3 String fields. Create the detail box (in my example it is named SelectedPersonDetailBox) and add the fields
In the detail box you can imagine the content you want. (Multiple group boxes, other fields, even a table...)
2/ Create a template to obtain the DetailBoxData
We need a java object to hold the content of the detail box for each row.
You can work with a plain Java Bean, but in this case, you will need to write the import/export from the bean into the detail box (SelectedPersonDetailBox).
An easiest way is to use the Scout SDK functionality (exactly like for FormData). This way your java object to hold the Data is keep in sync with the detail box.
Select your GroupBox in the Scout Explorer and create a template: AbstractSelectedPersonDetailBox.
Important is to let following options checked:
- "use Template for 'SelectedPersonDetailBox'
- "create external formData".
This way you obtain an "AbstractSelectedPersonDetailBoxData" in the shared plugin. Because this class is created abstract by the SDK you need to create a child class: PersonBoxData
public class PersonBoxData extends AbstractSelectedPersonDetailBoxData {
private static final long serialVersionUID = 1L;
}
In the MyFormData (corresponding to MyForm) you do not want to set data in the server for the SelectedPersonDetailBox (because what will be displayed in the fields comes from the selection in the table field). You can add @FormData(sdkCommand = SdkCommand.IGNORE) on the field :
@Order(20.0)
@FormData(sdkCommand = SdkCommand.IGNORE)
public class SelectedPersonDetailBox extends AbstractSelectedPersonDetailBox {
}
3/ Use @ColumnData(Ignore)
The idea of this pattern is that the data are stored in a not-displayable column (the ContentColumn described in step 1). If you have not created this column, do so now.
We do not want somebody to set a value for the column FirstNameColumn and LastNameColumn in the server.
Do what is described in this forum thread:
- Make the 2 getters for the 2 columns (FirstName and LastName) protected instead of public.
- Add @ColumnData(SdkColumnCommand.IGNORE) on the 2 columns
- Change the type of the ContentColumn: AbstractContentColumn<T> where T is PersonBoxData.
- Implement the requested updateTableColumns(ITableRow, PersonBoxData) method. This method is responsible for the update of the columns that are ignored in the formData.
@Order(10.0)
public class ContentColumn extends AbstractContentColumn<PersonBoxData> {
@Override
protected boolean getConfiguredDisplayable() {
return false;
}
@Override
protected void updateTableColumns(ITableRow r, PersonBoxData data) throws ProcessingException {
getFirstNameColumn().setValue(r, data.getFirstName().getValue());
getLastNameColumn().setValue(r, data.getLastName().getValue());
}
}
4a/ Change the type of AbstractSelectedPersonDetailBox to AbstractSelectedGroupBox<PersonBoxData>
We need to change the type of AbstractSelectedPersonDetailBox: instead of AbstractGroupBox set the type to AbstractSelectedGroupBox<PersonBoxData>
In AbstractSelectedPersonDetailBox you need to implement createEmptyBoxData(). It will be used by the framework to clear the selection in the detail box and for new rows:
@Override
public PersonBoxData createEmptyBoxData() {
PersonBoxData boxData = new PersonBoxData();
boxData.getFirstName().setValue(null);
boxData.getLastName().setValue(null);
boxData.getComments().setValue(null);
return boxData;
}
Notice that you need to set the value to null (or at least setValueSet() with true as parameter). It is possible to use a Utility function to do so on each fieldData instead of having to call them individually.
In SelectedPersonDetailBox in the form you need to implement provideColumn to link the group box with the column.
@Override
public AbstractDetailBoxColumn<PersonBoxData> provideColumn() {
return getPersonTableField().getTable().getContentColumn();
}
NB: FormDataClientUtility is the new name of FormDataUtility2 attached in this forum thread.
4b/ Change the type of the content Column to AbstractDetailBoxColumn<PersonBoxData>
Instead of AbstractContentColumn the ContentColumn needs to be from type AbstractDetailBoxColumn<PersonBoxData>.
To link the column with the group box you need to implement provideGroupBox():
@Override
public AbstractSelectedGroupBox<PersonBoxData> provideGroupBox() {
return getSelectedPersonDetailBox();
}
4c/ Change the type of the Table in the TableField
Instead of AbstractExtensibleTable the Table in the PersonTableField needs tob e from type AbstractTableWithDetailBox. This table will add the new and delete menu and handle the import of the data in the detail GroupBox.
You need to implement provideColumns that need to return the list of the AbstractDetailBoxColumn in the table. These columns will be notified.
@Override
protected List<? extends AbstractDetailBoxColumn<?>> provideColumns() {
return Collections.singletonList(getTable().getContentColumn());
}
4d/ Change the type of the TableField
In order for the Step 3 to work we need to work with bean based table data.
In the step 1 if your table field has the type AbstractTableField (default) change this to AbstractTableWithDetailBoxField. It contains the appropriate @FormData annotation to use bean based table data.
5/ Advanced configuration:
In AbstractSelectedPersonDetailBox you can implement:
* execStartGroupBoxEdit that will be called when a row is selected and the details data have been imported:
@Override
public void execStartGroupBoxEdit() {
getFirstNameField().requestFocus();
}
* execUpdateGroupBoxFields: where you can define your own logic to enable or disable the fields. For example:
@Override
public void execUpdateGroupBoxFields(boolean isEditing) {
getFirstNameField().setEnabled(isEditing);
getFirstNameField().setMandatory(isEditing);
getLastNameField().setEnabled(isEditing);
getLastNameField().setMandatory(isEditing);
getCommentsField().setEnabled(isEditing);
}
NB: you need to have also validation rules on the table. Having them on the field is not enough, because the user can leave the edit mode and the form will be valid even if the values in the different rows are not set.
A/ Appendix: server implementation
I recommend to test step by step your form (between each step). Here is how the server method can looks like at the end:
@Override
public MyMasterDetailFormData load(MyMasterDetailFormData formData) {
addPersonRow(formData, "Bob", "Johnson", "Lorem ipsum");
addPersonRow(formData, "Alan", "Smith", "");
return formData;
}
private void addPersonRow(MyMasterDetailFormData formData, String firstName, String lastName, String comments) {
PersonBoxData personBoxData = new PersonBoxData();
personBoxData.getFirstName().setValue(firstName);
personBoxData.getLastName().setValue(lastName);
personBoxData.getComments().setValue(comments);
PersonTableRowData row = formData.getPersonTable().addRow();
row.setContent(personBoxData);
}
Feel free to ask questions.
[Updated on: Wed, 16 April 2014 07:05] Report message to a moderator
|
|
| | | |
Goto Forum:
Current Time: Mon Sep 23 11:34:27 GMT 2024
Powered by FUDForum. Page generated in 0.03823 seconds
|