0

I want to publish an event in my RCP project when I press a JButton. For that I am trying to use the IEventBroker.

I followed the tutorial from vogella.com here.

 @Inject
 private IEventBroker eventBroker; 

 @Override
    public void actionPerformed(ActionEvent arg0) {

        // THE UPDATE BUTTON
        if (arg0.getSource()== update) {

            System.out.println("Button Pressed");

            eventBroker.post("test", "New data"); // generates a null point exception
            .....
            .....

Unfortunately this generates a null point exception.

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at chipcoach.tableviewerDMA.GanttFrame.actionPerformed(GanttFrame.java:522)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

In the later part of the tutorial, it also did not state where the @EventTopic and @UIEventTopic annotations are defined.

greg-449
  • 109,219
  • 232
  • 102
  • 145
2c00L
  • 495
  • 12
  • 29
  • Well presumably injection isn't working to populate `eventBroker`. Have you used the debugger to verify that? – Jon Skeet Oct 29 '14 at 17:32
  • How are you creating this class? Eclipse only does injection on objects it creates from the application model. – greg-449 Oct 29 '14 at 17:35
  • How do I verify that the injection is not working? Please excuse my lack of knowledge. :) This class is used to draw a Gannt chart : public class GanttFrame extends ApplicationFrame implements MouseWheelListener, ChangeListener, AxisChangeListener,ActionListener{ . Then added to the view composite via an AWT frame Composite composite = new Composite(scrolledComposite, SWT.EMBEDDED | SWT.NO_BACKGROUND); frame = SWT_AWT.new_Frame(composite); – 2c00L Oct 29 '14 at 17:40
  • Essentially only classes mentioned directly in the Application.e4xmi are injected. For anything else you need to use `ContextInjectionFactory`. So if you are using `new` to create your class it is not injected. – greg-449 Oct 29 '14 at 18:10
  • See my answer to http://stackoverflow.com/q/25759291/2670892 – greg-449 Oct 29 '14 at 18:12

1 Answers1

0

The absolutely brilliant tutorial on Event Broker by Christian solved my problem on how to use the Event Broker in my RCP project.

The following dependencies need to be added:

org.eclipse.e4.core.services 
org.eclipse.osgi.services 
2c00L
  • 495
  • 12
  • 29