How to use Extension [message #1847598] |
Tue, 02 November 2021 08:36 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 #1847823 is a reply to message #1847820] |
Tue, 09 November 2021 11:51 |
Matthias Villiger 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 |
|
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 |
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.05917 seconds