Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » How to use Extension(Modular Application)
How to use Extension [message #1847598] Tue, 02 November 2021 08:36 Go to next message
Oueslati Anis is currently offline Oueslati AnisFriend
Messages: 134
Registered: June 2014
Location: Paris
Senior Member
Hello,
I would like to use the Extensions to transform my application into a modular application. There fore I created a core scout project containing a Main Outline that implementes the IExtensibleObject Interface

I created a second scout projetct that represents the extension where Destktop, client and outline are AbstractExtensions

I thought that SDK will detext this and activate the extension plugins
but in in the injectExtension method in the core application I do not get the extension desktop ot the extension outline

Can any one explain how to make modular applications ?

Kind Regards
Re: How to use Extension [message #1847711 is a reply to message #1847598] Thu, 04 November 2021 10:23 Go to previous messageGo to next message
Oueslati Anis is currently offline Oueslati AnisFriend
Messages: 134
Registered: June 2014
Location: Paris
Senior Member
Hello

In this thread https://www.eclipse.org/forums/index.php/t/463108/, some steps were described , but what is not clear for me is that the extension or even contribution is made to add new module to application at runtime not compiling the core module with dependencies ( new module as a binary )
What I would like to achieve is the following :
Create an application that is splitted on several modules and I only have to install ( remove ) modules depending on the needed business needs.
Is this possible or not, thank you for your answer.

Kind Regards
Re: How to use Extension [message #1847779 is a reply to message #1847711] Mon, 08 November 2021 08:06 Go to previous messageGo to next message
Beat Schwarzentrub is currently offline Beat SchwarzentrubFriend
Messages: 214
Registered: November 2010
Senior Member
Modular applications are certainly possible.

The easiest way to get an adjustable application is to include every aspect in the same build. Only the relevant parts are then activated on a specific instance either using different sets of permissions or some sort of configuration (e.g. config.properties or in-app settings).
The advantage is that you don't need to worry too much about different modules and dependencies in your code and you only need a single build. Whether this model is suitable depends very much on how different the various business needs are and how much they overlap.

For a true modularization you need separate modules (Maven and/or NPM) in addition to the core modules. During the building process of your application you have to include or exclude them depending on the target. This gives you great flexibility but also adds complexity to the build process. In any case you have to make sure that the relevant modules are all included on the resulting runtime classpath.

There are various sorts of "extensions" in Scout. The easiest ist the desktop extension. Simply create a class that extends from AbstractDesktopExtension and define new ViewButtons as inner classes or add outlines via getConfiguredOutlines(). During execInit(), you may also alter existing outlines or pages (e.g. change labels, add new pages, add menus etc.). Since this extension is a @Bean, it will be registered automatically.

To not only add or remove elements to the desktop, but change the behavior of existing elements, subclasses of IExtension can be used. Unlike desktop extensions, these have to registered manually with the extension registry, e.g. in a platform listener:
public class MyPlatformListener implements IPlatformListener {
  @Override
  public void stateChanged(PlatformEvent event) {
    if (event.getState() == State.PlatformStarted) {
      BEANS.get(IExtensionRegistry.class).register(MyExtension.class);
    }
  }
}


Regards,
Beat
Re: How to use Extension [message #1847787 is a reply to message #1847779] Mon, 08 November 2021 10:29 Go to previous messageGo to next message
Oueslati Anis is currently offline Oueslati AnisFriend
Messages: 134
Registered: June 2014
Location: Paris
Senior Member
Hello Schwarzentrub,
thank you for your answer, It is clear now that the extension does not work like the plugin way for eclipse RCP ( you can add new module at runtime by copying the plugins and features in the relevant directories and restart the application.


So if I understood :

For example if you want to add a new module we have to make a new build to the hole application ( core + modules ) and redeploy them again to tomcat ?

I want to make a kind of repository when a bunch of modules are available then if someone needs a module he will download it and restart the server to enable it and make needed changes to the database. => this is not possible with the actual way of extensions ?


The code :

public class MyPlatformListener implements IPlatformListener {
@Override
public void stateChanged(PlatformEvent event) {
if (event.getState() == State.PlatformStarted) {
BEANS.get(IExtensionRegistry.class).register(MyExtension.class);
}
}
}

is in the core server, so all module have to be built with core prior to deploy, and core has a dependency to all modules ?

Kind Regards

[Updated on: Mon, 08 November 2021 10:31]

Report message to a moderator

Re: How to use Extension [message #1847793 is a reply to message #1847787] Mon, 08 November 2021 15:20 Go to previous messageGo to next message
Beat Schwarzentrub is currently offline Beat SchwarzentrubFriend
Messages: 214
Registered: November 2010
Senior Member
Yes this is possible, at least for Java code. Scout contains a CDI-like dependency injection mechanism to resolve instances at runtime that are not known at compile time. These instances are called "beans" and are simpliy classes annotated with @Bean or @ApplicationScoped. You can use this mechanism to change the behavior of your application depending on which JAR files are deployed. The bean manager will only "see" beans on the class path.

Example:

base.jar
@ApplicationScoped
public interface IElement { ... }
...
List<Element> elements = BEANS.all(IElement.class);
...

ext1.jar
public class RedElement implements IElement { ... }

ext2.jar
public class BlueElement implements IElement { ... }

If you deploy base.jar only, "elements" will be empty.
If you deploy base.jar and ext1.jar, "elements" will contain one element.
If you deploy base.jar and ext2.jar, "elements" will contain one element (but a different one).
If you deploy base.jar, ext1.jar, ext2.jar, "elements" will contain two elements.

Documentation

IDesktopExtension is a @Bean, and can therefore be used to contribute elements to the desktop without the core desktop needing a dependency on all your extension modules.

Usually, there is a *.app.war module with dependencies to all modules, but this just simplifies the build process. You can also assemble all required JARs manually.

Regards,
Beat
Re: How to use Extension [message #1847820 is a reply to message #1847793] Tue, 09 November 2021 10:16 Go to previous messageGo to next message
Oueslati Anis is currently offline Oueslati AnisFriend
Messages: 134
Registered: June 2014
Location: Paris
Senior Member
Hello Beat,
I tried to re implement what you discribed to get more knowledge on this topic, so this is what I have done :

1 - Create a new helloworld scout project :

This project is going to be the core project, it contains the three outlines on the helloworld project.

index.php/fa/41286/0/


2 - Then create a second scout project named helloworld.module

index.php/fa/41287/0/

This second project is going to add a new outline to the first one

I replaced the Desktop and ClientSession with Extensions


index.php/fa/41288/0/

Code for Desktop Extension

index.php/fa/41289/0/

Please not here there is 2 IDesktopExtension
Witch one should be used :


org.eclipse.scout.rt.client.ui.desktop.IDesktopExtension;
org.eclipse.scout.rt.client.extension.ui.desktop.IDesktopExtension




Since it implements the Idesktopextension it should be loaded automatically in the core as it is a @Bean


Same think fot ClientSession

index.php/fa/41290/0/



Now my problem is that when running the core project

I do not get the third outline appearing

I am sure I missed something :) but I do not know what exactely.

it may be totally wrong and should be implemented in an other way.

Please help :)

Kind Regards

[Updated on: Tue, 09 November 2021 10:20]

Report message to a moderator

Re: How to use Extension [message #1847823 is a reply to message #1847820] Tue, 09 November 2021 11:51 Go to previous messageGo to next message
Matthias Villiger is currently offline Matthias VilligerFriend
Messages: 235
Registered: September 2011
Senior Member
Hi

When starting your helloworld, do you have the helloworld.module on the classpath as well? Your launch config uses the classpath of which module?

There is also a sample application for your usecase. Please have a look at the 'contacts' demo application: There is a core named "contacts" and an extra module named "contacts.events". This extra module also adds an outline using an outline-extension. Maybe you can have a look at this sample.

Hope this helps
Mat

[Updated on: Tue, 09 November 2021 11:52]

Report message to a moderator

Re: How to use Extension [message #1847834 is a reply to message #1847820] Tue, 09 November 2021 19:53 Go to previous messageGo to next message
Beat Schwarzentrub is currently offline Beat SchwarzentrubFriend
Messages: 214
Registered: November 2010
Senior Member
I think you are on the right track.

Everything depends on the correct class path (a list of locations where the JVM will look for classes). This path is usually set when launching the application. From inside Eclipse, the classpath is defined in your launch config (I think it defaults to all modules listed as dependencies in the pom.xml). When run standalone, the class path must be passed as an argument to the JVM executable. When deployed as a *.war to an applicatoin server, the necessary JARs must be included inside (something like WEB-INF/lib, if I remember correctly). This is not specific to Scout, it's pure Java.

To check if your class is on the class path, you can try loading it by name:
Class.forName("com.helloworld.module.client.DesktopExtension")

If this works, the class is present. Otherwise, you'll get a ClassNotFoundException.

If you think your bean class is at the correct location, but is still not found by Scout's bean manager, check that your module is marked as a Scout module. To do so, you simply have to add an empty file called scout.xml at your.module/src/main/resources/META-INFO. The Scout SDK should normally generate this file for you.


Regarding the extension interface: You probably want org.eclipse.scout.rt.client.ui.desktop.IDesktopExtension, since it is a @Bean. All other interfaces with ".extension." in the package name are the other kind of extension that has to be manually registered in the extension registry (as described above).

Regards,
Beat
Re: How to use Extension [message #1847852 is a reply to message #1847834] Wed, 10 November 2021 12:59 Go to previous messageGo to next message
Oueslati Anis is currently offline Oueslati AnisFriend
Messages: 134
Registered: June 2014
Location: Paris
Senior Member
Hello,
Thank you for your answers :

I was able to reproduce the same think as contact, but I have a few questions :

In contact demo application the EventOutline is extending the ContactOutline so why we do have an EventOutline and also an EventOutlineExtension class ? ( I think that EventOutlineExtension is that what we need to add the extension and not the basic Outline ( I hope I am clear on this )

In order to extend the Desktop and add a complete new Outline How Can I perform this when I have to add a new Outline and OutlineExtension that extends an already existing Outline in the core => in order to add a new Outline I have to add it in core ( rebuild it and then extend it the extension module ?

Kind Regards
Anis
Re: How to use Extension [message #1847853 is a reply to message #1847852] Wed, 10 November 2021 13:20 Go to previous message
Matthias Villiger is currently offline Matthias VilligerFriend
Messages: 235
Registered: September 2011
Senior Member
Hi

I understand your confusion. The naming is indeed very confusing here.
Because of historical reasons there are two different types of extensions:

1. Subclasses of org.eclipse.scout.rt.client.ui.desktop.IDesktopExtension
They are used to add new elements to a desktop only (e.g. new outlines or outline buttons).
For this you have a sample in the contacts app: The EventOutline, which is a normal outline extending AbstractOutline (not ContactOutline as you stated) is added to the desktop using class org.eclipse.scout.contacts.events.client.DesktopExtension (which is an IDesktopExtension).
You don't need to register such IDesktopExtensions, you just have to add them to the Java classpath and Scout will find them automatically (as already explained by Beat).

2. All other Extensions (sub classes of org.eclipse.scout.rt.shared.extension.IExtension)
Such extensions are used to modify the behavior of or add new elements to various Scout objects (like Forms, FormFields, Pages, etc.). So they are not limited to desktops. Such extensions must be registered using the IExtensionRegistry (as already explained by Beat).
You have a sample for this in the contacts app too (including the registration): org.eclipse.scout.contacts.events.client.event.EventOutlineExtension. The purpose of this extension is to add a new child page to the ContactOutline from the core module. So this has nothing to do with the EventOutline.

Hope this helps

Kind regards
Mat
Previous Topic:App in Scout 11 not working when scout.devMode=false
Next Topic:Classic field style for all fields
Goto Forum:
  


Current Time: Sun Dec 01 20:49:45 GMT 2024

Powered by FUDForum. Page generated in 0.03702 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top