Using EventBroker in composites [message #1744511] |
Tue, 27 September 2016 15:15 |
Dimg Cim Messages: 59 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 |
Eclipse User |
|
|
|
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.
|
|
|
|
Powered by
FUDForum. Page generated in 0.04641 seconds