Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Using EventBroker in composites
Using EventBroker in composites [message #1744511] Tue, 27 September 2016 15:15 Go to next message
Dimg Cim is currently offline Dimg CimFriend
Messages: 31
Registered: December 2015
Member
Hi together,

I have a Problem to use IEventBroker injection in not ViewParts. Are there anyway to use this in Composites.

E.g. I Have two Views with 1 nested Composites, when I click in the first View I want to Change data in the second view nested composite.

I tried this

View 1
[code][
import javax.inject.Inject;

import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;

public class View1 {

@Inject
IEventBroker broker;

@Inject
public View1(Composite parent) {
Button button = new Button(parent, SWT.PUSH);
button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
button.setText("Ahhh");
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
broker.post("SEND", "TEST WORLD");
}
});

}
}
/code]

View2
public class View2 {

    @Inject
    IEventBroker broker;

    @Inject
    public View2(Composite parent) {
        new TestComposite(parent);
    }

}


Nested Composite TestComposite.java
public class TestComposite extends Composite {

    public TestComposite(Composite parent) {
        super(parent, 0);
        Button button = new Button(parent, SWT.PUSH);
        button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
        button.setText("Beeeh");
        button.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {

            }
        });
    }

    @Inject
    public void get(@UIEventTopic("SEND") String value) {
        System.out.println(value);
    }

}


The subribe method in the TestComposite won't be used.
How can I do this?

Many thanks
Dim
Re: Using EventBroker in composites [message #1744520 is a reply to message #1744511] Tue, 27 September 2016 16:24 Go to previous messageGo to next message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 653
Registered: January 2012
Senior Member

As you're controlling your TestComposite's lifecycle, *you* need to inject your TestComposite (and uninject on dispose/termination). See the ContextInjectionFactory class.

Maybe we should have a helper for creating and injecting classes that uses the without having to specify the PrimaryObjectSupplier or an IEclipseContext like Injector and EclipseContextFactory.

Brian.


Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Re: Using EventBroker in composites [message #1749428 is a reply to message #1744520] Tue, 06 December 2016 15:34 Go to previous message
Dimg Cim is currently offline Dimg CimFriend
Messages: 31
Registered: December 2015
Member
So the composites can be injected by the viewpart?
class ViewPart{

@PostConstruct
private void create(){
...
ContextInjectionFactory.inject(composite, context);
...
}

}


So there is an EclipseContext, where I can put in.
When I want to inject a composite in a Dialog, where should I get the EclipseContext?
Previous Topic:Neon: leak in menus ActionContributionItem
Next Topic:Using EventBroker in composites
Goto Forum:
  


Current Time: Fri Sep 22 22:38:41 GMT 2017

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

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