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

Difference between revisions of "Scout/Concepts/Extensibility"

(Replaced content with "{{ScoutPage|cat=Concepts}} Moved to new Scout documentation at http://eclipsescout.github.io/6.0/technical-guide.html#texts")
(12 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{ScoutPage|cat=Concepts}}
 
{{ScoutPage|cat=Concepts}}
  
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.
+
Moved to new Scout documentation at http://eclipsescout.github.io/6.0/technical-guide.html#texts
 
+
== Overview ==
+
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 {{ScoutLink|Concepts|Template}}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 <code>org.eclipse.scout.rt.shared.extension.IExtensibleObject</code> are extensible.
+
And for all extensible elements there exists a corresponding abstract extension class.
+
 
+
Examples:
+
* <code>AbstractStringField</code> is extensible. Therefore there is a class <code>AbstractStringFieldExtension</code>.
+
* <code>AbstractCodeType</code> is extensible. Therefore there is a class <code>AbstractCodeTypeExtension</code>.
+
 
+
Target classes can be all that are <code>instanceof</code> those extensible elements.This means an <code>AbstractStringFieldExtension</code> can be applied to <code>AbstractStringField</code> and all child classes.
+
 
+
Extensions contain methods for all Scout Operations ({{ScoutLink|Concepts|Exec_Methods}}). 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 [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern 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.
+
 
+
[[Image:Scout.extensibility.chain.concept.png|600px]]
+
 
+
The following example changes the initial value of a {{ScoutLink|Concepts|StringField}} called <code>NameField</code>:
+
 
+
<source lang="java">
+
// 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);
+
 
+
</source >
+
== Contributions - Add new elements ==
+
 
+
== Move elements ==
+
 
+
== Migration ==
+

Revision as of 11:02, 29 June 2016

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

Moved to new Scout documentation at http://eclipsescout.github.io/6.0/technical-guide.html#texts

Back to the top