Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Events to Parts without Focus
Events to Parts without Focus [message #959095] Fri, 26 October 2012 12:58 Go to next message
Michael Behrisch is currently offline Michael BehrischFriend
Messages: 6
Registered: October 2012
Junior Member
Hello,

I have a simple problem with the Eventbroker service:

I have multiple plugins/model fragements (esp. Views/Parts/etc.) in one core model.
Now they all need to communicate. Thus there is a plugin that defines ONLY the String-constants for the Event service:

public class EventConstants {
/**
* Event string published whenever a 
* matrix object, e.g. from the Projection Panel
* should be visualized
*/
public static final String MATRIX_SHOWIMAGE = "MATRIX_SHOWIMAGE";
[...]


Okay now i have one plugin that published the content:

@Override
public void execute(IProgressMonitor monitor) {
   MatrixObject matrix = model.getMatrix(model.getMatrixIDs().get(0));
   eventBroker.post(EventConstants.MATRIX_SHOWIMAGE, matrix);
   [...]
}


Okay up to here NO problem. Now I have the following scenario:

Dependent on the plugin-fragments that are there (all injected into the same content-id as views) only one has the focus and gets the published event (@UIEventTopic(EventConstants.MATRIX_SHOWIMAGE)) from above.
However, I need all of them to visualize the content (independent on the focus status). I played around now with all possible @Optional possibilities and can't make it. How should the handler look like so that every object gets the event?

THANKS in advance!!!


Re: Events to Parts without Focus [message #959195 is a reply to message #959095] Fri, 26 October 2012 14:23 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
You mean parts who have not been activated yet don't receive the event?
That is to be expected because part instances are created lazy (first
time they are shown!).

There was a recent thread here where 2 solutions are mentionned:
* create a renderer that activates views eagerly
* instead of using the event system publish informations e.g. through
the windows/applications IEclipseContext

Tom

Am 26.10.12 15:47, schrieb Michael Behrisch:
> Hello,
>
> I have a simple problem with the Eventbroker service:
>
> I have multiple plugins/model fragements (esp. Views/Parts/etc.) in one
> core model.
> Now they all need to communicate. Thus there is a plugin that defines
> ONLY the String-constants for the Event service:
>
> public class EventConstants {
> /**
> * Event string published whenever a * matrix object, e.g. from the
> Projection Panel
> * should be visualized
> */
> public static final String MATRIX_SHOWIMAGE = "MATRIX_SHOWIMAGE";
> [...]
>
>
> Okay now i have one plugin that published the content:
>
>
> @Override
> public void execute(IProgressMonitor monitor) {
> MatrixObject matrix = model.getMatrix(model.getMatrixIDs().get(0));
> eventBroker.post(EventConstants.MATRIX_SHOWIMAGE, matrix);
> [...]
> }
>
>
> Okay up to here NO problem. Now I have the following scenario:
>
> Dependent on the plugin-fragments that are there (all injected into the
> same content-id as views) only one has the focus and gets the published
> event (@UIEventTopic(EventConstants.MATRIX_SHOWIMAGE)) from above.
> However, I need all of them to visualize the content (independent on the
> focus status). I played around now with all possible @Optional
> possibilities and can't make it. How should the handler look like so
> that every object gets the event?
>
> THANKS in advance!!!
>
>
>
Re: Events to Parts without Focus [message #959218 is a reply to message #959195] Fri, 26 October 2012 14:48 Go to previous messageGo to next message
Michael Behrisch is currently offline Michael BehrischFriend
Messages: 6
Registered: October 2012
Junior Member
Hello and thanks a lot for your answer, but what is the better option of the two mentioned?

The first option is obviously not intended. But why? Okay, reasons such as
the effective usage of resources are obvious. But are there other reasons?

The second option is nearly the same as using the ESelectionService, right?
But, then the Eventbroker is useless... Isn't it a standard scenario that I mention in my post (multiple [maybe not active parts] that are interested
for an event)
?
Wouldn't it be better to couple the EventBroker Service and the Context or do I have a problem in my understanding??

Re: Events to Parts without Focus [message #959297 is a reply to message #959218] Fri, 26 October 2012 15:52 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Am 26.10.12 16:48, schrieb Michael Behrisch:
> Hello and thanks a lot for your answer, but what is the better option of
> the two mentioned?
>

IMHO the context one is the way to go

> The first option is obviously not intended. But why? Okay, reasons such
> as the effective usage of resources are obvious. But are there other
> reasons?
>

No simply resources - think about eclipse where a the editor area has
100 editor activiating them on start up would not make sense.

> The second option is nearly the same as using the ESelectionService, right?

Yes similar but with the selection you can only have one in a
perspective whereas pushing stuff to the IEclipseContext they are bound
to their specific keys.

> But, then the Eventbroker is useless... Isn't it a standard scenario
> that I mention in my post (multiple [maybe not active parts] that are
> interested for an event)?
> Wouldn't it be better to couple the EventBroker Service and the Context
> or do I have a problem in my understanding??
>
>

events are for short lived objects. the context for long living ones.
The event system has also the advantage to send informations in an async
fashion post vs send where as the context is always synchronous!

Tom
Re: Events to Parts without Focus [message #959324 is a reply to message #959297] Fri, 26 October 2012 16:25 Go to previous message
Michael Behrisch is currently offline Michael BehrischFriend
Messages: 6
Registered: October 2012
Junior Member
Hello Tom,

I adapted my code according to your advice. THANK YOU for your expertise!
I close the thread as SOLVED.

For everybody who has interest in context variables and does not know how to do it look here:
http : // workorhobby . blogspot.de/2012/07/eclipse-e4-selections-events-context.html

As a short version here the sender:
private void addMouseListener(Label label, final MyObject myObject) {
  label.addMouseListener(new MouseAdapter() {
     public void mouseDown(MouseEvent e) {
         context.set(EventConstants.MY_EVENT_IDENTIFIER, myObject);
     }
  });
}


Where the context is retrieved for example by:
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;

[...]

@Inject
public MYPart(MWindow window) {
   this.context = window.getContext();
[...]
}


And receiver:
@Inject
@Optional
public void handleEvent(@Named(EventConstants.MY_EVENT_IDENTIFIER) final MyObject myObject) {
[...]
}
Previous Topic:Howto dispose an MWindow?
Next Topic:How to fill Part with Data?
Goto Forum:
  


Current Time: Fri Mar 29 09:39:07 GMT 2024

Powered by FUDForum. Page generated in 0.04024 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top