|
Lines 23-37
Link Here
|
| 23 |
import org.eclipse.e4.ui.model.application.MUIElement; |
23 |
import org.eclipse.e4.ui.model.application.MUIElement; |
| 24 |
import org.eclipse.e4.ui.model.application.MWindow; |
24 |
import org.eclipse.e4.ui.model.application.MWindow; |
| 25 |
import org.eclipse.e4.ui.services.IServiceConstants; |
25 |
import org.eclipse.e4.ui.services.IServiceConstants; |
|
|
26 |
import org.eclipse.e4.ui.services.events.IEventBroker; |
| 26 |
import org.eclipse.e4.workbench.modeling.EPartService; |
27 |
import org.eclipse.e4.workbench.modeling.EPartService; |
|
|
28 |
import org.eclipse.e4.workbench.ui.UIEvents; |
| 29 |
import org.osgi.service.event.Event; |
| 30 |
import org.osgi.service.event.EventHandler; |
| 27 |
|
31 |
|
| 28 |
public class PartServiceImpl implements EPartService { |
32 |
public class PartServiceImpl implements EPartService { |
|
|
33 |
public static void addListener(IEventBroker broker) { |
| 34 |
EventHandler windowHandler = new EventHandler() { |
| 35 |
public void handleEvent(Event event) { |
| 36 |
Object element = event.getProperty(UIEvents.EventTags.ELEMENT); |
| 37 |
if (element instanceof MWindow) { |
| 38 |
MContext contextAware = (MContext) element; |
| 39 |
IEclipseContext context = contextAware.getContext(); |
| 40 |
if (context != null) { |
| 41 |
context.set(EPartService.PART_SERVICE_ROOT, element); |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
}; |
| 46 |
broker.subscribe(UIEvents.buildTopic(UIEvents.Context.TOPIC, UIEvents.Context.CONTEXT), |
| 47 |
windowHandler); |
| 48 |
} |
| 29 |
|
49 |
|
| 30 |
/** |
50 |
/** |
| 31 |
* This is the specific implementation. TODO: generalize it |
51 |
* This is the specific implementation. TODO: generalize it |
| 32 |
*/ |
52 |
*/ |
| 33 |
@Inject |
53 |
@Inject |
| 34 |
private MWindow windowContainer; |
54 |
@Named(EPartService.PART_SERVICE_ROOT) |
|
|
55 |
private MElementContainer<MUIElement> rootContainer; |
| 35 |
|
56 |
|
| 36 |
@Inject |
57 |
@Inject |
| 37 |
void setPart(@Optional @Named(IServiceConstants.ACTIVE_PART) MPart p) { |
58 |
void setPart(@Optional @Named(IServiceConstants.ACTIVE_PART) MPart p) { |
|
Lines 86-96
Link Here
|
| 86 |
} |
107 |
} |
| 87 |
|
108 |
|
| 88 |
public MPart findPart(String id) { |
109 |
public MPart findPart(String id) { |
| 89 |
return findPart(windowContainer, id); |
110 |
return findPart(rootContainer, id); |
| 90 |
} |
111 |
} |
| 91 |
|
112 |
|
| 92 |
public Collection<MPart> getParts() { |
113 |
public Collection<MPart> getParts() { |
| 93 |
return getParts(new ArrayList<MPart>(), windowContainer); |
114 |
return getParts(new ArrayList<MPart>(), rootContainer); |
| 94 |
} |
115 |
} |
| 95 |
|
116 |
|
| 96 |
private Collection<MPart> getParts(Collection<MPart> parts, |
117 |
private Collection<MPart> getParts(Collection<MPart> parts, |
|
Lines 132-138
Link Here
|
| 132 |
} |
153 |
} |
| 133 |
|
154 |
|
| 134 |
private boolean isInContainer(MPart part) { |
155 |
private boolean isInContainer(MPart part) { |
| 135 |
return isInContainer(windowContainer, part); |
156 |
return isInContainer(rootContainer, part); |
| 136 |
} |
157 |
} |
| 137 |
|
158 |
|
| 138 |
private boolean isInContainer(MElementContainer<?> container, MPart part) { |
159 |
private boolean isInContainer(MElementContainer<?> container, MPart part) { |