Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This tutorial introduces the IGB platform by demonstrating a very simple IGB App that adds a new entry to the IGB Tools menu. 

 

Info

See Setting up your Development Environment for recommendations on how to set up your machine to be more compatible with IGB Development practices.

Clone IGB Hello World App

...

Code Block
git clone https://bitbucket.org/lorainelab/igb-app-hello-world.git

 

MenuBarEntryProvider interface

Once you have compiled the App and installed it in IGB, you'll see a new menu item - "Hello World App" in the IGB Tools menu, as show below: 

Image Removed

The Hello World App contains a class that implements the MenuBarEntryProvider interface, show below 

...

Compile the App

To build your App, open the igb-app-hello-world project into Netbeans, select it project in the Projects tab, and then select Run > Build.

Alternatively, you can build it from the command line by entering:

Code Block
languagejava
titleMenuBarEntryProvider interface
public interface MenuBarEntryProvider {
    public Optional<List<MenuItem>> getMenuItems();
	public MenuBarParentMenu getMenuExtensionParent();
 }

 

To add a new menu item to IGB, you create a class that implements this interface. When you install the App in IGB, the OSGi run-time then adds it to whichever IGB menu is specified in the code.

 

Compile the App

To build your App, open the igb-app-hello-world project into Netbeans, select it project in the Projects tab, and then select Run > Build.

Alternatively, you can build it from the command line by entering:

Code Block
languagebash
mvn clean install

Building the App will create a new directory named "target" which can serve as a new App repository. This new directory contains compiled code as well as a meta-data about the App it contains.

Add target directory as new App repository

Normally, Apps are deployed on-line via an App Store or your own on-line App repository.

However, you can also deploy an App Store on your local computer - useful for developing and testing new Apps.

To add your target directory as a local App Store:

...

bash
mvn clean install

Building the App will create a new directory named "target" which can serve as a new App repository. This new directory contains compiled code as well as a meta-data about the App it contains.

Add target directory as new App repository

Normally, Apps are deployed on-line via an App Store or your own on-line App repository.

However, you can also deploy an App Store on your local computer - useful for developing and testing new Apps.

To add your target directory as a local App Store:

  1. Start IGB
  2. Select Tools > Open App Manager
  3. Click Manage Repositories... button (opens Plug-in Repositories tab in Preferences window)
  4. Click Add... button (opens Plugin Repository dialog)
  5. Enter a name for your repository (can be anything)
  6. Click Choose local folder button
  7. Select "target" in your igb-app-hello-world project folder

Once you add "target" as a new local App store, you should see the Hello World App added as a new App in the IGB App Manager window, as show below;

Image Added

Install App

To install the hello world App:

Once you add "target" as a new local App store, you should see the Hello World App added as a new App in the IGB App Manager window, as show below;

Image Removed

Install App

To install the hello world App:

  • Select Tools > Open App Manager
  • Select the App
  • Click Install

To check that installation worked correctly, select the Tools menu. Check that there is  now a new menu item named Hello World App.

Run App

To run the App:

  • Select Tools > Hello World App
  • Observe a dialog appears containing the message "Hello IGB World!"

Image Removed

 

Observe the message that appears:

Image Removed

 

Next step: Modify your code

...

  • Select Tools > Open App Manager

...

  • Select the App
  • Click Install

To check that installation worked correctly, select the Tools menu. Check that there is  now a new menu item named Hello World App.

Run App

To run the App:

  • Select Tools > Hello World App
  • Observe a dialog appears containing the message "Hello IGB World!"

Image Added

 

Observe the message that appears:

Image Added

 

Next step: Modify your code

Re-open your IGB App project. Edit the message your IGB App prints and re-build your App. Then, return to the IGB App Manager, un-install and then re-install your App. When you select the the menu item again, the new message will print instead of the old one.

Note that you can rapidly repeat this edit-build-uninstall-install cycle. You don't have to re-build IGB or even restart it, which makes development much faster than if you had to modify the IGB code directly.

Next step: Make README.md for your App (optional)

It's not enough to create and deploy an App; you should also provide an easy-to-understand README.md file suitable for display in the IGB App Manager. See Create Markdown to display in IGB App Manager

How this works

-install cycle. You don't have to re-build IGB or even restart it, which makes development much faster than if you had to modify the IGB code directly.

Next step: Make README.md for your App (optional)

It's not enough to create and deploy an App; you should also provide an easy-to-understand README.md file suitable for display in the IGB App Manager. See Create Markdown to display in IGB App Manager

...

How this works

Apps can interact with and add new functionality to IGB by implementing services defined by the 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 users.

The Hello World App contains a class that implements the MenuBarEntryProvider interface:


Code Block
languagejava
titleMenuBarEntryProvider interface
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

The Maven build system assumes that every Java project conforms to an expected directory structure. Here, the maven project includes

...