/E4ObjectPassingDemo

A simple example of passing an object between parts via IEclipseBroker in an app built with the Eclipse E4 Rich Client Platform. Created for anyone wanting to implement this functionality in their own apps, but unsure of where to start. Provides a simple hands on example as a jumping off point.

Primary LanguageJava

E4ObjectPassingDemo

A simple example of a passing an object between Parts via the IEventBroker in an app built with the Eclipse E4 RCP.


Main Page

Main Page

Passed Object

Passed Object


Using IEventBroker

Sending

  • Inject IEventBroker in the sending class.
@Inject
IEventBroker eventBroker;
  • Use the IEventBroker object to 'post' an object with an associated 'topic', used for identification by the receiver.
eventBroker.post( "SendingClass/SentObject" , ObjectType object );

--NOTE: The 'topic' format is specific to 'identifier/identifier'. Anything you'd like can be substituted before and after the forward slash '/', but it is required to include SOMETHING. There are of course exceptions to this rule and I am not the expert. Learn more from the Eclipse IEventBroker API, an article on the Eclipse4/RCP/Event Model, this Vogella tutorial on the Eclipse 4 Event System, or of course from checking out this repo.

Receiving

  • Inject IEventBroker in the receiving class.
@Inject
IEventBroker eventBroker;
  • Build a method to listen for/receive the posted object.
@Inject
@Optional
public void receiveEvent( @UIEventTopic ( "SendingClass/SentObject" ) ObjectType object )
{
	this.object = object;
	
	processObject(object);
	object.doAThing();	
}

--NOTE: Notice that the 'topic' ( "SendingClass/SentObject" ) is the same both when the sender posts the object, and when the receiver is listening for it.


Installation

Using the IEventBroker requires installing additional Dependencies:

  1. Navigate to your project hierarchy, open the 'META-INF' folder double click on MANIFEST.MF.

  2. Choose the 'Dependencies' tab at the bottom.

  3. Navigate to the 'Required Plug-ins' section and click 'Add'.

  4. Add the following:

    -org.eclipse.osgi.services
    -org.eclipse.e4.core.services
    -org.eclipse.e4.core.di.extensions
    

This project requires the Eclipse E4 Tools to be installed:

  1. Open the "Install New Software" Window. - Navigate to the far right of the top menu and click on "Help" followed by "Install Software" near the bottom of the drop down menu.

  2. Choose the download site for your version of Eclipse. - In the drop down menu labeled "Works With" at the top of the "Install Software" window, choose the site for your Eclipse Version.

  3. Search for "E4" and install "Eclipse e4 Tools Developer Resources". - Look just below the drop down menu to find the search bar and type in "E4". Click the check box to the left of the package labeled "Eclipse e4 Tools Developer Resources" and click the "Next" button at the bottom of the window.

  4. Follow the Wizard prompts to finish installing the software.

Once the Tools have been installed, you can add this project like you would any other Java Project:

  1. Download the .zip file of this project here.
  2. Import the project. - Navigate to Eclipse, and right click in your Project Explorer, choosing "Import" about halfway down the pop-up menu. - Type "archive" into the search bar to easily locate the option titled "Archive File". Select it and click the "Next" button at the bottom of the window. - Use the "Browse" button at the top right of the next page to locate your .zip file. Select it and click the "Finish" button at the bottom of the window.

Running the Program

  1. Open E4ObjectPassingDemo.product
  2. On the "Overview" tab, in the "Testing" section, under item "2. Test the product by launching a runtime instance of it:", click the first link - "Launch an Eclipse Application".

Motivation

I'm relatively new to Computer Programming and as part of my work have been learning more about building software with the Eclipse E4 Rich Client Platform. There are a number of things I've learned and one of them is how to pass objects within an app. Using the IEventBroker is just one of many ways, but it is the most recent one I've figured out and the simplest in my opinion. This example program exists to provide others a jumping off point for applying this functionality into their own apps.


If you have any questions or need any help please don't hesitate to get a hold of me here, on LinkedIn, or Twitter and I will do the best I can to assist.

-Will