Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 295003 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/e4/ui/tests/application/EPartServiceTest.java (+9 lines)
Lines 27-32 Link Here
27
import org.eclipse.e4.ui.workbench.swt.internal.E4Application;
27
import org.eclipse.e4.ui.workbench.swt.internal.E4Application;
28
import org.eclipse.e4.workbench.modeling.EPartService;
28
import org.eclipse.e4.workbench.modeling.EPartService;
29
import org.eclipse.e4.workbench.ui.IPresentationEngine;
29
import org.eclipse.e4.workbench.ui.IPresentationEngine;
30
import org.eclipse.e4.workbench.ui.internal.UIEventPublisher;
31
import org.eclipse.e4.workbench.ui.internal.Workbench;
32
import org.eclipse.emf.common.notify.Notifier;
30
33
31
public class EPartServiceTest extends TestCase {
34
public class EPartServiceTest extends TestCase {
32
35
Lines 649-654 Link Here
649
		// setup the context
652
		// setup the context
650
		applicationContext.set(MApplication.class.getName(), application);
653
		applicationContext.set(MApplication.class.getName(), application);
651
		application.setContext(applicationContext);
654
		application.setContext(applicationContext);
655
		Workbench.processHierarchy(application);
656
		((Notifier) application).eAdapters().add(
657
				new UIEventPublisher(applicationContext));
652
658
653
		// render the windows
659
		// render the windows
654
		engine.createGui(window1);
660
		engine.createGui(window1);
Lines 721-726 Link Here
721
727
722
		applicationContext.set(MApplication.class.getName(), application);
728
		applicationContext.set(MApplication.class.getName(), application);
723
		application.setContext(applicationContext);
729
		application.setContext(applicationContext);
730
		Workbench.processHierarchy(application);
731
		((Notifier) application).eAdapters().add(
732
				new UIEventPublisher(applicationContext));
724
733
725
		return application;
734
		return application;
726
	}
735
	}
(-)src/org/eclipse/e4/workbench/modeling/EPartService.java (+1 lines)
Lines 14-19 Link Here
14
import org.eclipse.e4.ui.model.application.MPart;
14
import org.eclipse.e4.ui.model.application.MPart;
15
15
16
public interface EPartService {
16
public interface EPartService {
17
	public static final String PART_SERVICE_ROOT = "partServiceRoot"; //$NON-NLS-1$
17
18
18
	public void activate(MPart part);
19
	public void activate(MPart part);
19
20
(-)src/org/eclipse/e4/workbench/ui/internal/PartServiceImpl.java (-4 / +25 lines)
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) {
(-)src/org/eclipse/e4/workbench/ui/internal/Workbench.java (+15 lines)
Lines 57-62 Link Here
57
import org.eclipse.e4.ui.model.application.MWindow;
57
import org.eclipse.e4.ui.model.application.MWindow;
58
import org.eclipse.e4.ui.services.IServiceConstants;
58
import org.eclipse.e4.ui.services.IServiceConstants;
59
import org.eclipse.e4.ui.services.IStylingEngine;
59
import org.eclipse.e4.ui.services.IStylingEngine;
60
import org.eclipse.e4.ui.services.events.IEventBroker;
61
import org.eclipse.e4.workbench.modeling.EPartService;
60
import org.eclipse.e4.workbench.ui.IExceptionHandler;
62
import org.eclipse.e4.workbench.ui.IExceptionHandler;
61
import org.eclipse.e4.workbench.ui.IPresentationEngine;
63
import org.eclipse.e4.workbench.ui.IPresentationEngine;
62
import org.eclipse.e4.workbench.ui.IWorkbench;
64
import org.eclipse.e4.workbench.ui.IWorkbench;
Lines 403-408 Link Here
403
	}
405
	}
404
406
405
	public static void processHierarchy(Object me) {
407
	public static void processHierarchy(Object me) {
408
		if (me instanceof MApplication) {
409
			MContext contextAware = (MContext) me;
410
			IEclipseContext c = contextAware.getContext();
411
			IEventBroker broker = (IEventBroker) c.get(IEventBroker.class.getName());
412
			PartServiceImpl.addListener(broker);
413
		}
406
414
407
		if (me instanceof MHandlerContainer) {
415
		if (me instanceof MHandlerContainer) {
408
			MContext contextModel = (MContext) me;
416
			MContext contextModel = (MContext) me;
Lines 450-455 Link Here
450
				}
458
				}
451
			}
459
			}
452
		}
460
		}
461
		if (me instanceof MWindow) {
462
			MContext contextAware = (MContext) me;
463
			IEclipseContext c = contextAware.getContext();
464
			if (c != null) {
465
				c.set(EPartService.PART_SERVICE_ROOT, me);
466
			}
467
		}
453
		if (me instanceof MElementContainer<?>) {
468
		if (me instanceof MElementContainer<?>) {
454
			EList children = ((MElementContainer) me).getChildren();
469
			EList children = ((MElementContainer) me).getChildren();
455
			Iterator i = children.iterator();
470
			Iterator i = children.iterator();

Return to bug 295003