Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Scout/Concepts/Extensibility

The Scout documentation has been moved to https://eclipsescout.github.io/.

Overview

Important.png
Required version
The API described here requires version 4.2 or newer.


Since December 2014 and Scout 4.2 or newer a new extensibility concept is available for Scout. This article explains the new features and gives some examples how to use them.

When working with large business applications it is often required to split the application into several modules. Some of those modules may be very basic and can be reused in multiple applications. For those it makes sense to provide them as binary library. But what if you have created great The Scout documentation has been moved to https://eclipsescout.github.io/.s for your applications but in one special case you want to include one more column in a table or want to execute some other code when a pre-defined context menu is pressed? You cannot just modify the code because it is a general library used everywhere. This is where the new extensibility concept helps.

To achieve this two no elements have been introduced:

  • Extension Classes: Contains modifications for a target class. Modifications can be new elements or changed behavior of existing elements.
  • Extension Registry: Service holding all Extensions that should be active in the application.

Extensions - Changing behavior

Extensions contain modifications to a target class. This target class must be extensible. All elements that implement org.eclipse.scout.rt.shared.extension.IExtensibleObject are extensible. And for all extensible elements there exists a corresponding abstract extension class.

Examples:

  • AbstractStringField is extensible. Therefore there is a class AbstractStringFieldExtension.
  • AbstractCodeType is extensible. Therefore there is a class AbstractCodeTypeExtension.

Target classes can be all that are instanceof those extensible elements.This means an AbstractStringFieldExtension can be applied to AbstractStringField and all child classes.

Extensions contain methods for all Scout Operations (The Scout documentation has been moved to https://eclipsescout.github.io/.). Those methods have the same signature except that they have one more input parameter. This method allows you to intercept the given Scout Operation and execute your own code even though the declaring class exists in a binary library. It is then your decision if you call the original code or completely replace it. To achieve this the Chain Pattern is used: All extensions for a target class are called as part of a chain. The order is given by the order in which the extensions are registered. And the original method of the Scout element is an extension as well.

Scout.extensibility.chain.concept.png

The following example changes the initial value of a The Scout documentation has been moved to https://eclipsescout.github.io/. called NameField:

// extension to intercept e.g. execInitField()
public class NameFieldExtension extends AbstractStringFieldExtension<NameField> {
 
  public NameFieldExtension(NameField owner) {
    super(owner);
  }
 
  @Override
  public void execInitField(ExecInitChain chain) {
    chain.execInitField(); // call the original exec init. whatever it may do.
    getOwner().setValue("FirstName LastName");  // overwrite the initial value of the name field
  }
}
 
 
// register extension so that it becomes active
SERVICES.getService(IExtensionRegistry.class).register(NameFieldExtension.class);

The extension registration can be done e.g. in the Activator of your plugin or in the startup of your Application.

Contributions - Add new elements

The section before explained how to modify the behavior of existing Scout elements. This section will describe how to contribute new elements into existing containers.

This is done by using the same mechanism as before. It is required to create an Extension too. But instead of overwriting any Scout Operation we directly define the new elements within the Extension. A lot of new elements can be added this way: The Scout documentation has been moved to https://eclipsescout.github.io/.s, The Scout documentation has been moved to https://eclipsescout.github.io/.s, The Scout documentation has been moved to https://eclipsescout.github.io/.s, The Scout documentation has been moved to https://eclipsescout.github.io/.s, ...

Some new elements may also require a new DTO (The Scout documentation has been moved to https://eclipsescout.github.io/., The Scout documentation has been moved to https://eclipsescout.github.io/., The Scout documentation has been moved to https://eclipsescout.github.io/.) to be filled with data from the server. The corresponding DTO for the extension is automatically created when using the The Scout documentation has been moved to https://eclipsescout.github.io/. 4.2 or newer and having the @Data annotation specified on your extension. As soon as the DTO extension has been registered in the IExtensionRegistry service it is automatically created when the target DTO is created and will also be imported and exported automatically!

The following example adds two new fields for salary and birthday to a PersonForm. Please note the @Data annotation which describes where the DTO for this extension should be created.

// extension for the MainBox of the PersonForm
@Data(PersonFormMainBoxExtensionData.class)
public class PersonFormMainBoxExtension extends AbstractGroupBoxExtension<PersonForm.MainBox>{
 
  public PersonFormMainBoxExtension(MainBox ownerBox) {
    super(ownerBox);
  }
 
  @Order(2000)
  public class SalaryField extends AbstractBigDecimalField {
  }
 
  @Order(3000)
  public class BirthdayField extends AbstractDateField {
  }
}
 
 
// register the extension
SERVICES.getService(IExtensionRegistry.class).register(PersonFormMainBoxExtension.class);

Then the The Scout documentation has been moved to https://eclipsescout.github.io/. automatically creates the extension DTO which could look as follows. Please note: The DTO is generated automatically but you have to register the generated DTO manually!

// automatically generated by the Scout SDK
@Extends(PersonFormData.class)
public class PersonFormMainBoxExtensionData extends AbstractFormFieldData {
 
  public Salary getSalary() {
    return getFieldByClass(Salary.class);
  }
 
  public  getBirthday() {
    return getFieldByClass(Birthday.class);
  }
 
  public static class Salary extends AbstractValueFieldData<BigDecimal> {
  }
 
  public static class Birthday extends AbstractValueFieldData<Date> {
  }
}
 
// The extension data must be registered manually!
SERVICES.getService(IExtensionRegistry.class).register(PersonFormMainBoxExtensionData.class);

Move elements

Migration

Back to the top