|
Lines 8-13
Link Here
|
| 8 |
import org.eclipse.e4.core.services.events.IEventBroker; |
8 |
import org.eclipse.e4.core.services.events.IEventBroker; |
| 9 |
import org.eclipse.e4.ui.di.UIEventTopic; |
9 |
import org.eclipse.e4.ui.di.UIEventTopic; |
| 10 |
import org.eclipse.e4.ui.di.UISynchronize; |
10 |
import org.eclipse.e4.ui.di.UISynchronize; |
|
|
11 |
import org.eclipse.e4.ui.workbench.UIEvents; |
| 12 |
import org.eclipse.jface.dialogs.MessageDialog; |
| 11 |
import org.eclipse.jface.viewers.ListViewer; |
13 |
import org.eclipse.jface.viewers.ListViewer; |
| 12 |
import org.eclipse.swt.SWT; |
14 |
import org.eclipse.swt.SWT; |
| 13 |
import org.eclipse.swt.events.SelectionAdapter; |
15 |
import org.eclipse.swt.events.SelectionAdapter; |
|
Lines 17-33
Link Here
|
| 17 |
import org.eclipse.swt.widgets.Button; |
19 |
import org.eclipse.swt.widgets.Button; |
| 18 |
import org.eclipse.swt.widgets.Composite; |
20 |
import org.eclipse.swt.widgets.Composite; |
| 19 |
import org.eclipse.swt.widgets.Group; |
21 |
import org.eclipse.swt.widgets.Group; |
|
|
22 |
import org.eclipse.swt.widgets.MessageBox; |
| 23 |
import org.osgi.service.event.Event; |
| 24 |
import org.osgi.service.event.EventHandler; |
| 20 |
|
25 |
|
| 21 |
@SuppressWarnings("restriction") |
26 |
@SuppressWarnings("restriction") |
| 22 |
public class EventSamplePart { |
27 |
public class EventSamplePart { |
|
|
28 |
|
| 29 |
private static int counter = 0; |
| 30 |
|
| 23 |
@Inject |
31 |
@Inject |
| 24 |
IEventBroker broker; |
32 |
IEventBroker broker; |
| 25 |
|
33 |
|
| 26 |
@Inject |
34 |
@Inject |
| 27 |
UISynchronize uiSync; |
35 |
UISynchronize uiSync; |
| 28 |
|
36 |
|
| 29 |
private ListViewer listViewer; |
37 |
private ListViewer listViewer; |
| 30 |
|
38 |
|
| 31 |
@PostConstruct |
39 |
@PostConstruct |
| 32 |
void init(Composite parent) { |
40 |
void init(Composite parent) { |
| 33 |
parent.setLayout(new GridLayout()); |
41 |
parent.setLayout(new GridLayout()); |
|
Lines 35-43
Link Here
|
| 35 |
listViewer = new ListViewer(parent); |
43 |
listViewer = new ListViewer(parent); |
| 36 |
listViewer.getControl().setLayoutData( |
44 |
listViewer.getControl().setLayoutData( |
| 37 |
new GridData(GridData.FILL_BOTH)); |
45 |
new GridData(GridData.FILL_BOTH)); |
| 38 |
|
46 |
|
| 39 |
createSendGroup(parent, "EventTopic"); |
47 |
createSendGroup(parent, "EventTopic"); |
| 40 |
createSendGroup(parent, "UIEventTopic"); |
48 |
createSendGroup(parent, "UIEventTopic"); |
|
|
49 |
|
| 50 |
broker.subscribe(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE, new EventHandler() { |
| 51 |
@Override |
| 52 |
public void handleEvent(Event event) { |
| 53 |
System.out.println(event); |
| 54 |
broker.unsubscribe(this); |
| 55 |
if( counter == 0 ) { |
| 56 |
counter++; |
| 57 |
MessageDialog.openInformation(parent.getShell(), "Blocking dialog", "Blocked!"); |
| 58 |
} |
| 59 |
} |
| 60 |
}); |
| 41 |
} |
61 |
} |
| 42 |
|
62 |
|
| 43 |
private void createSendGroup(Composite parent, final String topicType) { |
63 |
private void createSendGroup(Composite parent, final String topicType) { |
|
Lines 45-51
Link Here
|
| 45 |
g.setText("@" + topicType); |
65 |
g.setText("@" + topicType); |
| 46 |
g.setLayout(new GridLayout(2, true)); |
66 |
g.setLayout(new GridLayout(2, true)); |
| 47 |
g.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
67 |
g.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 48 |
|
68 |
|
| 49 |
Button b = new Button(g, SWT.PUSH); |
69 |
Button b = new Button(g, SWT.PUSH); |
| 50 |
b.setText("Sync sending"); |
70 |
b.setText("Sync sending"); |
| 51 |
b.addSelectionListener(new SelectionAdapter() { |
71 |
b.addSelectionListener(new SelectionAdapter() { |
|
Lines 55-61
Link Here
|
| 55 |
} |
75 |
} |
| 56 |
}); |
76 |
}); |
| 57 |
b.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
77 |
b.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 58 |
|
78 |
|
| 59 |
b = new Button(g, SWT.PUSH); |
79 |
b = new Button(g, SWT.PUSH); |
| 60 |
b.setText("Async sending"); |
80 |
b.setText("Async sending"); |
| 61 |
b.addSelectionListener(new SelectionAdapter() { |
81 |
b.addSelectionListener(new SelectionAdapter() { |
|
Lines 66-72
Link Here
|
| 66 |
}); |
86 |
}); |
| 67 |
b.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
87 |
b.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 68 |
} |
88 |
} |
| 69 |
|
89 |
|
| 70 |
@Inject |
90 |
@Inject |
| 71 |
@Optional |
91 |
@Optional |
| 72 |
void receiveEvent(@EventTopic("rape4/EventTopic") final String eventData) { |
92 |
void receiveEvent(@EventTopic("rape4/EventTopic") final String eventData) { |
|
Lines 74-88
Link Here
|
| 74 |
listViewer.add(eventData); |
94 |
listViewer.add(eventData); |
| 75 |
} else { |
95 |
} else { |
| 76 |
uiSync.syncExec(new Runnable() { |
96 |
uiSync.syncExec(new Runnable() { |
| 77 |
|
97 |
|
| 78 |
@Override |
98 |
@Override |
| 79 |
public void run() { |
99 |
public void run() { |
| 80 |
listViewer.add(eventData); |
100 |
listViewer.add(eventData); |
| 81 |
} |
101 |
} |
| 82 |
}); |
102 |
}); |
| 83 |
} |
103 |
} |
| 84 |
} |
104 |
} |
| 85 |
|
105 |
|
| 86 |
@Inject |
106 |
@Inject |
| 87 |
@Optional |
107 |
@Optional |
| 88 |
void receiveUIEvent(@UIEventTopic("rape4/UIEventTopic") final String eventData) { |
108 |
void receiveUIEvent(@UIEventTopic("rape4/UIEventTopic") final String eventData) { |