Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Scout/Concepts/Template"
(→Form Field template) |
(add Form template) |
||
Line 16: | Line 16: | ||
=== Example === | === Example === | ||
Consider the following example: A group box for the billing address containing some fields. | Consider the following example: A group box for the billing address containing some fields. | ||
+ | |||
+ | <source lang="java"> | ||
@Order(10.0) | @Order(10.0) | ||
public class BillingAddressBox extends AbstractGroupBox { | public class BillingAddressBox extends AbstractGroupBox { | ||
Line 41: | Line 43: | ||
} | } | ||
} | } | ||
+ | </source> | ||
Now let's assume you would like to create a similar box for the correspondence address without copying the code. This is possible by selecting "Create template..." on the group box. | Now let's assume you would like to create a similar box for the correspondence address without copying the code. This is possible by selecting "Create template..." on the group box. | ||
Line 49: | Line 52: | ||
A new abstract class is created containing the code of BillingAddressBox. To make the AddressBox template more useful, we move the configured label code to the BillingAddressBox. | A new abstract class is created containing the code of BillingAddressBox. To make the AddressBox template more useful, we move the configured label code to the BillingAddressBox. | ||
− | ... | + | <source lang="java"> |
+ | //... | ||
@FormData(value = AbstractAddressBoxData.class, sdkCommand = SdkCommand.CREATE, defaultSubtypeSdkCommand = DefaultSubtypeSdkCommand.CREATE) | @FormData(value = AbstractAddressBoxData.class, sdkCommand = SdkCommand.CREATE, defaultSubtypeSdkCommand = DefaultSubtypeSdkCommand.CREATE) | ||
public abstract class AbstractAddressBox extends AbstractGroupBox { | public abstract class AbstractAddressBox extends AbstractGroupBox { | ||
− | + | /* @Override | |
protected String getConfiguredLabel() { | protected String getConfiguredLabel() { | ||
return TEXTS.get("BillingAddress"); | return TEXTS.get("BillingAddress"); | ||
Line 59: | Line 63: | ||
return getFieldByClass(CityField.class); | return getFieldByClass(CityField.class); | ||
} | } | ||
− | ... | + | //... |
− | + | </source> | |
− | + | The commented getConfiguredLabel is moved in the concrete class: | |
+ | <source lang="java"> | ||
@Order(10.0) | @Order(10.0) | ||
public class BillingAddressBox extends AbstractAddressBox { | public class BillingAddressBox extends AbstractAddressBox { | ||
Line 69: | Line 74: | ||
} | } | ||
} | } | ||
− | + | </source> | |
Now the correspondance address field can be created by choosing the template as type for the new field. | Now the correspondance address field can be created by choosing the template as type for the new field. | ||
+ | <source lang="java"> | ||
@Order(20.0) | @Order(20.0) | ||
public class CorrespondanceAddressBox extends AbstractAddressBox { | public class CorrespondanceAddressBox extends AbstractAddressBox { | ||
Line 80: | Line 86: | ||
} | } | ||
} | } | ||
+ | </source> | ||
<!-- | <!-- | ||
Line 89: | Line 96: | ||
{{note|TODO|Template and SQL binding (in Process Service). Merge with this post: [http://www.eclipse.org/forums/index.php/t/261235/ Process Service and Templates]}} | {{note|TODO|Template and SQL binding (in Process Service). Merge with this post: [http://www.eclipse.org/forums/index.php/t/261235/ Process Service and Templates]}} | ||
+ | |||
+ | == Form template == | ||
+ | |||
+ | A form template is nothing more than an Abstract class extending {{ScoutJavadoc|org.eclipse.scout.rt.client.ui.form.AbstractForm|C}}. Your template can be located where you want (where it makes sense, depending on your code organization). Possible package: <tt><your_app>.client.ui.template.form</tt> | ||
+ | |||
+ | There isn't any support yet in the Scout Perspective to create a form template. You need to use the Java tooling from the IDE. | ||
+ | |||
+ | This is a minimal example: | ||
+ | |||
+ | <source lang="java"> | ||
+ | import org.eclipse.scout.commons.exception.ProcessingException; | ||
+ | import org.eclipse.scout.rt.client.ui.form.AbstractForm; | ||
+ | |||
+ | public abstract class AbstractMyForm extends AbstractForm { | ||
+ | |||
+ | /** | ||
+ | * @throws ProcessingException | ||
+ | */ | ||
+ | public AbstractMyForm() throws ProcessingException { | ||
+ | super(); | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
== See also == | == See also == | ||
* {{ScoutLink|SDK|Explorer View|Explorer View}} | * {{ScoutLink|SDK|Explorer View|Explorer View}} |
Revision as of 08:26, 19 September 2014
The Scout documentation has been moved to https://eclipsescout.github.io/.
A template is some portion of code (a class) that is defined to be used many times in the The Scout documentation has been moved to https://eclipsescout.github.io/..
Overview
The templates are visible in the The Scout documentation has been moved to https://eclipsescout.github.io/. under your scout project > Client > Templates
Form Field template
An easy way to reuse form field code is to use templates. Templates are implemented as abstract classes that may be extended by form fields. Creation and usage of templates is supported by the Scout SDK.
Templates may be extracted from existing fields or other templates. The Scout SDK template support allows for quite powerful refactorings and helps keeping your code clean and DRY with little effort.
Example
Consider the following example: A group box for the billing address containing some fields.
@Order(10.0) public class BillingAddressBox extends AbstractGroupBox { @Override protected String getConfiguredLabel() { return TEXTS.get("BillingAddress"); } @Order(10.0) public class StreetField extends AbstractStringField { @Override protected String getConfiguredLabel() { return TEXTS.get("Street"); } } @Order(20.0) public class CityField extends AbstractSmartField<Long> { @Override protected Class<? extends ICodeType<?>> getConfiguredCodeType() { return CityCodeType.class; } @Override protected String getConfiguredLabel() { return TEXTS.get("City"); } } }
Now let's assume you would like to create a similar box for the correspondence address without copying the code. This is possible by selecting "Create template..." on the group box.
A new abstract class is created containing the code of BillingAddressBox. To make the AddressBox template more useful, we move the configured label code to the BillingAddressBox.
//... @FormData(value = AbstractAddressBoxData.class, sdkCommand = SdkCommand.CREATE, defaultSubtypeSdkCommand = DefaultSubtypeSdkCommand.CREATE) public abstract class AbstractAddressBox extends AbstractGroupBox { /* @Override protected String getConfiguredLabel() { return TEXTS.get("BillingAddress"); } */ public CityField getCityField() { return getFieldByClass(CityField.class); } //...
The commented getConfiguredLabel is moved in the concrete class:
@Order(10.0) public class BillingAddressBox extends AbstractAddressBox { @Override protected String getConfiguredLabel() { return TEXTS.get("BillingAddress"); } }
Now the correspondance address field can be created by choosing the template as type for the new field.
@Order(20.0) public class CorrespondanceAddressBox extends AbstractAddressBox { @Override protected String getConfiguredLabel() { return TEXTS.get("Correspondance"); } }
Form template
A form template is nothing more than an Abstract class extending The Scout documentation has been moved to https://eclipsescout.github.io/.. Your template can be located where you want (where it makes sense, depending on your code organization). Possible package: <your_app>.client.ui.template.form
There isn't any support yet in the Scout Perspective to create a form template. You need to use the Java tooling from the IDE.
This is a minimal example:
import org.eclipse.scout.commons.exception.ProcessingException; import org.eclipse.scout.rt.client.ui.form.AbstractForm; public abstract class AbstractMyForm extends AbstractForm { /** * @throws ProcessingException */ public AbstractMyForm() throws ProcessingException { super(); } }
See also
- The Scout documentation has been moved to https://eclipsescout.github.io/.