...
Apps can interact with and add new functionality to IGB by implementing services defined controlled by the OSGi container that runs IGB API. In other words, Apps that implement services recognized by the IGB API, then IGB can automatically consume those services and provide them as new functionality for usersadd new functionality to IGB by implementing services that IGB can consume as services controlled and instantiated by the OSGi run-time.
...
The Hello World App contains a class that implements the MenuBarEntryProvider interface:
...
adds a new menu item to the Tools menu by implementing the MenuBarEntryProvider interface, defined in org.lorainelab.igb.menu.api, which is part of the Menu API module in the IGB code base.
Code Block | ||||
---|---|---|---|---|
| ||||
public interface MenuBarEntryProvider {
public Optional<List<MenuItem>> getMenuItems();
public MenuBarParentMenu getMenuExtensionParent();
} |
The Hello World App uses a specialization of the maven build system to package the Hello World App as a so-called "OSGi" bundle that can be added or removed dynamically from the OGSi run-time that runs IGB.
When you compile the App and add its "target" directory as a new local App store (plug-in repository) to IGB, the OSGi run-time detects the repository and adds all its Apps as optional Apps to the IGB App Manager interface. Then, when you install the App, the OSGi runtime then exposes its services to IGB.
The MenuBarEntryProvider is one such service; any App that provides this service - by implementing this interface - can therefore add new menus to IGB once they are installed into the run-time.
Using maven to develop Apps - the App directory structure
...
MenuBarParentMenu getMenuExtensionParent();
} |
The Hello World App uses maven to build and deploy the App for consumption as an OSGi bundle in IGB.
Maven build system assumes that every Java project conforms to an expected directory structure. Here, the maven project includes:
- pom.xml - located at the top level of the project. In An IGB , an App's pom.xml file specifies which services the App needs to import from the IGB code base as well as any 3rd party libraries used by your App.
- src - contains source code, organized as shown. Every maven project contains src/main/java, which contains java packages organized as directories in the usual way. The example shows a single Java source code file/
To see the directory structure for your project in NetBeans, select the Files tab (next to the Projects tab).
HelloWorld pom.xml
...
pom
...
.xml
The pom.xml contains information about the project and configuration details used by Maven to build the project. Here is the pom.xml file for the Hello World App:
...
Code Block |
---|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.affymetrix</groupId> <artifactId>igb-project</artifactId> <version>9.0.0</version> </parent> <groupId>org.lorainelab.igb</groupId> <artifactId>org.lorainelab.igb.menu.api.example</artifactId> <version>1.0.0</version> <packaging>bundle</packaging> <name>IGB Menubar Extension</name> <dependencies> <dependency> <groupId>biz.aQute.bnd</groupId> <artifactId>bndlib</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.lorainelab.igb</groupId> <artifactId>org.lorainelab.igb.menu.api</artifactId> <scope>provided</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <extensions>true</extensions> <executions> <execution> <id>build plugin repository</id> <goals> <goal> index </goal> </goals> <phase>package</phase> <configuration> <obrRepository>${project.build.directory}</obrRepository> <mavenRepository>${project.build.directory}</mavenRepository> </configuration> </execution> </executions> <configuration> <instructions> <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> <Import-Package>*</Import-Package> <Export-Package/> <Service-Component>*</Service-Component> </instructions> </configuration> </plugin> </plugins> </build> </project> |
parent tag
The parent tag specifies which version of IGB your new App is compatible with. It also enables your project to inherit configurations from the parent pom.xml file, which will save you time and effort.
Code Block | ||
---|---|---|
| ||
<parent> <groupId>com.affymetrix</groupId> <artifactId>igb-project</artifactId> <version>9.0.0</version> </parent> |
In the image below, you can see that the IGB version of 9.0.0 is seen in the app's pom.xml.
packaging tag
...
Code Block | ||||
---|---|---|---|---|
| ||||
package org.lorainelab.igb.menu.api.example; import aQute.bnd.annotation.component.Component; import java.util.Arrays; import java.util.List; import java.util.Optional; import javax.swing.JOptionPane; import org.lorainelab.igb.menu.api.MenuBarEntryProvider; import org.lorainelab.igb.menu.api.model.MenuBarParentMenu; import org.lorainelab.igb.menu.api.model.MenuItem; @Component(immediate = true) public class MenuBarExtensionExample implements MenuBarEntryProvider { @Override public Optional<List<MenuItem>> getMenuItems() { MenuItem menuItem = new MenuItem("Hello World App", (Void t) -> { JOptionPane.showMessageDialog(null, "Hello IGB World!"); return t; }); menuItem.setWeight(1000000000); return Optional.ofNullable(Arrays.asList(menuItem)); } @Override public MenuBarParentMenu getMenuExtensionParent() { return MenuBarParentMenu.TOOLS; } } |
If you need help with this process or wish to discuss any other issues with the IGB team, please do not hesitate to contact us.