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 (-63 / +427 lines)
Lines 43-57 Link Here
43
	protected void setUp() throws Exception {
43
	protected void setUp() throws Exception {
44
		applicationContext = E4Application.createDefaultContext();
44
		applicationContext = E4Application.createDefaultContext();
45
45
46
		IContributionFactory contributionFactory = (IContributionFactory) applicationContext
47
				.get(IContributionFactory.class.getName());
48
		Object newEngine = contributionFactory.create(getEngineURI(),
49
				applicationContext);
50
		assertTrue(newEngine instanceof IPresentationEngine);
51
		applicationContext.set(IPresentationEngine.class.getName(), newEngine);
52
53
		engine = (IPresentationEngine) newEngine;
54
55
		super.setUp();
46
		super.setUp();
56
	}
47
	}
57
48
Lines 67-77 Link Here
67
		}
58
		}
68
	}
59
	}
69
60
61
	private IPresentationEngine getEngine() {
62
		if (engine == null) {
63
			IContributionFactory contributionFactory = (IContributionFactory) applicationContext
64
					.get(IContributionFactory.class.getName());
65
			Object newEngine = contributionFactory.create(getEngineURI(),
66
					applicationContext);
67
			assertTrue(newEngine instanceof IPresentationEngine);
68
			applicationContext.set(IPresentationEngine.class.getName(),
69
					newEngine);
70
71
			engine = (IPresentationEngine) newEngine;
72
		}
73
74
		return engine;
75
	}
76
70
	public void testFindPart_PartInWindow() {
77
	public void testFindPart_PartInWindow() {
71
		MApplication application = createApplication("partId");
78
		MApplication application = createApplication("partId");
72
79
73
		MWindow window = application.getChildren().get(0);
80
		MWindow window = application.getChildren().get(0);
74
		engine.createGui(window);
81
		getEngine().createGui(window);
75
82
76
		EPartService partService = (EPartService) window.getContext().get(
83
		EPartService partService = (EPartService) window.getContext().get(
77
				EPartService.class.getName());
84
				EPartService.class.getName());
Lines 89-95 Link Here
89
		MApplication application = createApplication("partId");
96
		MApplication application = createApplication("partId");
90
97
91
		MWindow window = application.getChildren().get(0);
98
		MWindow window = application.getChildren().get(0);
92
		engine.createGui(window);
99
		getEngine().createGui(window);
93
100
94
		EPartService partService = (EPartService) window.getContext().get(
101
		EPartService partService = (EPartService) window.getContext().get(
95
				EPartService.class.getName());
102
				EPartService.class.getName());
Lines 105-112 Link Here
105
		MWindow window1 = application.getChildren().get(0);
112
		MWindow window1 = application.getChildren().get(0);
106
		MWindow window2 = application.getChildren().get(1);
113
		MWindow window2 = application.getChildren().get(1);
107
114
108
		engine.createGui(window1);
115
		getEngine().createGui(window1);
109
		engine.createGui(window2);
116
		getEngine().createGui(window2);
110
117
111
		EPartService partService = (EPartService) window1.getContext().get(
118
		EPartService partService = (EPartService) window1.getContext().get(
112
				EPartService.class.getName());
119
				EPartService.class.getName());
Lines 137-143 Link Here
137
		MPart partFront = partStack.getChildren().get(0);
144
		MPart partFront = partStack.getChildren().get(0);
138
		partStack.setActiveChild(partFront);
145
		partStack.setActiveChild(partFront);
139
146
140
		engine.createGui(window);
147
		getEngine().createGui(window);
141
148
142
		EPartService partService = (EPartService) window.getContext().get(
149
		EPartService partService = (EPartService) window.getContext().get(
143
				EPartService.class.getName());
150
				EPartService.class.getName());
Lines 154-160 Link Here
154
		MPart partFront = partStack.getChildren().get(0);
161
		MPart partFront = partStack.getChildren().get(0);
155
		partStack.setActiveChild(partFront);
162
		partStack.setActiveChild(partFront);
156
163
157
		engine.createGui(window);
164
		getEngine().createGui(window);
158
165
159
		EPartService partService = (EPartService) partFront.getContext().get(
166
		EPartService partService = (EPartService) partFront.getContext().get(
160
				EPartService.class.getName());
167
				EPartService.class.getName());
Lines 172-178 Link Here
172
		MPart partBack = partStack.getChildren().get(1);
179
		MPart partBack = partStack.getChildren().get(1);
173
		partStack.setActiveChild(partFront);
180
		partStack.setActiveChild(partFront);
174
181
175
		engine.createGui(window);
182
		getEngine().createGui(window);
176
183
177
		EPartService partService = (EPartService) window.getContext().get(
184
		EPartService partService = (EPartService) window.getContext().get(
178
				EPartService.class.getName());
185
				EPartService.class.getName());
Lines 190-196 Link Here
190
		MPart partBack = partStack.getChildren().get(1);
197
		MPart partBack = partStack.getChildren().get(1);
191
		partStack.setActiveChild(partFront);
198
		partStack.setActiveChild(partFront);
192
199
193
		engine.createGui(window);
200
		getEngine().createGui(window);
194
201
195
		EPartService partService = (EPartService) partFront.getContext().get(
202
		EPartService partService = (EPartService) partFront.getContext().get(
196
				EPartService.class.getName());
203
				EPartService.class.getName());
Lines 216-223 Link Here
216
		MPart partBackB = partStackB.getChildren().get(1);
223
		MPart partBackB = partStackB.getChildren().get(1);
217
		partStackB.setActiveChild(partFrontB);
224
		partStackB.setActiveChild(partFrontB);
218
225
219
		engine.createGui(windowA);
226
		getEngine().createGui(windowA);
220
		engine.createGui(windowB);
227
		getEngine().createGui(windowB);
221
228
222
		EPartService partServiceA = (EPartService) windowA.getContext().get(
229
		EPartService partServiceA = (EPartService) windowA.getContext().get(
223
				EPartService.class.getName());
230
				EPartService.class.getName());
Lines 258-269 Link Here
258
		MPart partBackB = partStackB.getChildren().get(1);
265
		MPart partBackB = partStackB.getChildren().get(1);
259
		partStackB.setActiveChild(partFrontB);
266
		partStackB.setActiveChild(partFrontB);
260
267
261
		engine.createGui(windowA);
268
		getEngine().createGui(windowA);
262
		engine.createGui(windowB);
269
		getEngine().createGui(windowB);
263
270
264
		EPartService partServiceA = (EPartService) partFrontA.getContext().get(
271
		EPartService partServiceA = (EPartService) partFrontA.getContext().get(
265
				EPartService.class.getName());
272
				EPartService.class.getName());
266
		EPartService partServiceB = (EPartService) partBackB.getContext().get(
273
		EPartService partServiceB = (EPartService) partFrontB.getContext().get(
267
				EPartService.class.getName());
274
				EPartService.class.getName());
268
275
269
		partServiceA.bringToTop(partBackB);
276
		partServiceA.bringToTop(partBackB);
Lines 287-293 Link Here
287
		MApplication application = createApplication(1, new String[1][0]);
294
		MApplication application = createApplication(1, new String[1][0]);
288
		MWindow window = application.getChildren().get(0);
295
		MWindow window = application.getChildren().get(0);
289
296
290
		engine.createGui(window);
297
		getEngine().createGui(window);
291
298
292
		EPartService partService = (EPartService) window.getContext().get(
299
		EPartService partService = (EPartService) window.getContext().get(
293
				EPartService.class.getName());
300
				EPartService.class.getName());
Lines 301-307 Link Here
301
		MWindow window = application.getChildren().get(0);
308
		MWindow window = application.getChildren().get(0);
302
		MPartStack partStack = (MPartStack) window.getChildren().get(0);
309
		MPartStack partStack = (MPartStack) window.getChildren().get(0);
303
310
304
		engine.createGui(window);
311
		getEngine().createGui(window);
305
312
306
		EPartService partService = (EPartService) window.getContext().get(
313
		EPartService partService = (EPartService) window.getContext().get(
307
				EPartService.class.getName());
314
				EPartService.class.getName());
Lines 318-325 Link Here
318
		MWindow windowA = application.getChildren().get(0);
325
		MWindow windowA = application.getChildren().get(0);
319
		MWindow windowB = application.getChildren().get(1);
326
		MWindow windowB = application.getChildren().get(1);
320
327
321
		engine.createGui(windowA);
328
		getEngine().createGui(windowA);
322
		engine.createGui(windowB);
329
		getEngine().createGui(windowB);
323
330
324
		EPartService partServiceA = (EPartService) windowA.getContext().get(
331
		EPartService partServiceA = (EPartService) windowA.getContext().get(
325
				EPartService.class.getName());
332
				EPartService.class.getName());
Lines 353-359 Link Here
353
		MPart part = partStack.getChildren().get(0);
360
		MPart part = partStack.getChildren().get(0);
354
		partStack.setActiveChild(part);
361
		partStack.setActiveChild(part);
355
362
356
		engine.createGui(window);
363
		getEngine().createGui(window);
357
364
358
		EPartService partService = (EPartService) window.getContext().get(
365
		EPartService partService = (EPartService) window.getContext().get(
359
				EPartService.class.getName());
366
				EPartService.class.getName());
Lines 368-374 Link Here
368
		MPart part = partStack.getChildren().get(0);
375
		MPart part = partStack.getChildren().get(0);
369
		partStack.setActiveChild(part);
376
		partStack.setActiveChild(part);
370
377
371
		engine.createGui(window);
378
		getEngine().createGui(window);
372
379
373
		EPartService partService = (EPartService) part.getContext().get(
380
		EPartService partService = (EPartService) part.getContext().get(
374
				EPartService.class.getName());
381
				EPartService.class.getName());
Lines 382-388 Link Here
382
		MPartStack partStack = (MPartStack) window.getChildren().get(0);
389
		MPartStack partStack = (MPartStack) window.getChildren().get(0);
383
		partStack.setActiveChild(partStack.getChildren().get(0));
390
		partStack.setActiveChild(partStack.getChildren().get(0));
384
391
385
		engine.createGui(window);
392
		getEngine().createGui(window);
386
393
387
		MPart part = partStack.getChildren().get(1);
394
		MPart part = partStack.getChildren().get(1);
388
395
Lines 398-410 Link Here
398
		MPartStack partStack = (MPartStack) window.getChildren().get(0);
405
		MPartStack partStack = (MPartStack) window.getChildren().get(0);
399
		partStack.setActiveChild(partStack.getChildren().get(0));
406
		partStack.setActiveChild(partStack.getChildren().get(0));
400
407
401
		engine.createGui(window);
408
		getEngine().createGui(window);
402
409
403
		MPart part = partStack.getChildren().get(1);
410
		MPart part1 = partStack.getChildren().get(0);
411
		MPart part2 = partStack.getChildren().get(1);
404
412
405
		EPartService partService = (EPartService) part.getContext().get(
413
		EPartService partService1 = (EPartService) part1.getContext().get(
406
				EPartService.class.getName());
414
				EPartService.class.getName());
407
		assertFalse(partService.isPartVisible(part));
415
		assertTrue(partService1.isPartVisible(part1));
416
		assertFalse(partService1.isPartVisible(part2));
417
418
		partService1.activate(part2);
419
420
		EPartService partService2 = (EPartService) part2.getContext().get(
421
				EPartService.class.getName());
422
		assertFalse(partService1.isPartVisible(part1));
423
		assertTrue(partService1.isPartVisible(part2));
424
		assertFalse(partService2.isPartVisible(part1));
425
		assertTrue(partService2.isPartVisible(part2));
408
	}
426
	}
409
427
410
	public void testIsVisible_ViewInAnotherWindow() {
428
	public void testIsVisible_ViewInAnotherWindow() {
Lines 424-431 Link Here
424
		MPart partBackB = partStackB.getChildren().get(1);
442
		MPart partBackB = partStackB.getChildren().get(1);
425
		partStackB.setActiveChild(partFrontB);
443
		partStackB.setActiveChild(partFrontB);
426
444
427
		engine.createGui(windowA);
445
		getEngine().createGui(windowA);
428
		engine.createGui(windowB);
446
		getEngine().createGui(windowB);
429
447
430
		EPartService partServiceA = (EPartService) windowA.getContext().get(
448
		EPartService partServiceA = (EPartService) windowA.getContext().get(
431
				EPartService.class.getName());
449
				EPartService.class.getName());
Lines 460-467 Link Here
460
		MPart partBackB = partStackB.getChildren().get(1);
478
		MPart partBackB = partStackB.getChildren().get(1);
461
		partStackB.setActiveChild(partFrontB);
479
		partStackB.setActiveChild(partFrontB);
462
480
463
		engine.createGui(windowA);
481
		getEngine().createGui(windowA);
464
		engine.createGui(windowB);
482
		getEngine().createGui(windowB);
465
483
466
		EPartService partServiceA = (EPartService) partFrontA.getContext().get(
484
		EPartService partServiceA = (EPartService) partFrontA.getContext().get(
467
				EPartService.class.getName());
485
				EPartService.class.getName());
Lines 486-502 Link Here
486
		MPartStack partStack = (MPartStack) window.getChildren().get(0);
504
		MPartStack partStack = (MPartStack) window.getChildren().get(0);
487
		partStack.setActiveChild(partStack.getChildren().get(0));
505
		partStack.setActiveChild(partStack.getChildren().get(0));
488
506
489
		engine.createGui(window);
507
		getEngine().createGui(window);
490
508
491
		MPart part = partStack.getChildren().get(1);
509
		MPart part1 = partStack.getChildren().get(0);
510
		MPart part2 = partStack.getChildren().get(1);
492
511
493
		EPartService partService = (EPartService) part.getContext().get(
512
		EPartService partService1 = (EPartService) part1.getContext().get(
494
				EPartService.class.getName());
513
				EPartService.class.getName());
495
		assertFalse(partService.isPartVisible(part));
514
		assertTrue(partService1.isPartVisible(part1));
515
		assertFalse(partService1.isPartVisible(part2));
496
516
497
		partService.activate(part);
517
		partService1.activate(part2);
498
		assertTrue(partService.isPartVisible(part));
518
499
		assertEquals(part, partService.getActivePart());
519
		EPartService partService2 = (EPartService) part2.getContext().get(
520
				EPartService.class.getName());
521
		assertFalse(partService1.isPartVisible(part1));
522
		assertTrue(partService1.isPartVisible(part2));
523
		assertFalse(partService2.isPartVisible(part1));
524
		assertTrue(partService2.isPartVisible(part2));
500
	}
525
	}
501
526
502
	public void testActivate_partService_twoWindows() {
527
	public void testActivate_partService_twoWindows() {
Lines 509-523 Link Here
509
		MPart partFrontA = partStackA.getChildren().get(0);
534
		MPart partFrontA = partStackA.getChildren().get(0);
510
		MPart partBackA = partStackA.getChildren().get(1);
535
		MPart partBackA = partStackA.getChildren().get(1);
511
		partStackA.setActiveChild(partFrontA);
536
		partStackA.setActiveChild(partFrontA);
537
		windowA.setActiveChild(partStackA);
512
538
513
		MWindow windowB = application.getChildren().get(1);
539
		MWindow windowB = application.getChildren().get(1);
514
		MPartStack partStackB = (MPartStack) windowB.getChildren().get(0);
540
		MPartStack partStackB = (MPartStack) windowB.getChildren().get(0);
515
		MPart partFrontB = partStackB.getChildren().get(0);
541
		MPart partFrontB = partStackB.getChildren().get(0);
516
		MPart partBackB = partStackB.getChildren().get(1);
542
		MPart partBackB = partStackB.getChildren().get(1);
517
		partStackB.setActiveChild(partFrontB);
543
		partStackB.setActiveChild(partFrontB);
544
		windowB.setActiveChild(partStackB);
545
546
		application.setActiveChild(windowA);
518
547
519
		engine.createGui(windowA);
548
		getEngine().createGui(windowA);
520
		engine.createGui(windowB);
549
		getEngine().createGui(windowB);
521
550
522
		EPartService partServiceA = (EPartService) partFrontA.getContext().get(
551
		EPartService partServiceA = (EPartService) partFrontA.getContext().get(
523
				EPartService.class.getName());
552
				EPartService.class.getName());
Lines 570-577 Link Here
570
		MPart partBackB = partStackB.getChildren().get(1);
599
		MPart partBackB = partStackB.getChildren().get(1);
571
		partStackB.setActiveChild(partFrontB);
600
		partStackB.setActiveChild(partFrontB);
572
601
573
		engine.createGui(windowA);
602
		getEngine().createGui(windowA);
574
		engine.createGui(windowB);
603
		getEngine().createGui(windowB);
575
604
576
		EPartService partServiceA = (EPartService) partFrontA.getContext().get(
605
		EPartService partServiceA = (EPartService) partFrontA.getContext().get(
577
				EPartService.class.getName());
606
				EPartService.class.getName());
Lines 618-625 Link Here
618
		MPart partFrontB = partStackB.getChildren().get(0);
647
		MPart partFrontB = partStackB.getChildren().get(0);
619
		MPart partBackB = partStackB.getChildren().get(1);
648
		MPart partBackB = partStackB.getChildren().get(1);
620
649
621
		engine.createGui(windowA);
650
		getEngine().createGui(windowA);
622
		engine.createGui(windowB);
651
		getEngine().createGui(windowB);
623
652
624
		EPartService partServiceA = (EPartService) partFrontA.getContext().get(
653
		EPartService partServiceA = (EPartService) partFrontA.getContext().get(
625
				EPartService.class.getName());
654
				EPartService.class.getName());
Lines 650-656 Link Here
650
		partDescriptor.setId("partId");
679
		partDescriptor.setId("partId");
651
		application.getDescriptors().add(partDescriptor);
680
		application.getDescriptors().add(partDescriptor);
652
681
653
		engine.createGui(window);
682
		getEngine().createGui(window);
654
683
655
		EPartService partService = (EPartService) window.getContext().get(
684
		EPartService partService = (EPartService) window.getContext().get(
656
				EPartService.class.getName());
685
				EPartService.class.getName());
Lines 669-675 Link Here
669
		partDescriptor.setId("partId");
698
		partDescriptor.setId("partId");
670
		application.getDescriptors().add(partDescriptor);
699
		application.getDescriptors().add(partDescriptor);
671
700
672
		engine.createGui(window);
701
		getEngine().createGui(window);
673
702
674
		EPartService partService = (EPartService) window.getContext().get(
703
		EPartService partService = (EPartService) window.getContext().get(
675
				EPartService.class.getName());
704
				EPartService.class.getName());
Lines 706-712 Link Here
706
		((Notifier) application).eAdapters().add(
735
		((Notifier) application).eAdapters().add(
707
				new UIEventPublisher(applicationContext));
736
				new UIEventPublisher(applicationContext));
708
737
709
		engine.createGui(window);
738
		getEngine().createGui(window);
710
739
711
		EPartService partService = (EPartService) window.getContext().get(
740
		EPartService partService = (EPartService) window.getContext().get(
712
				EPartService.class.getName());
741
				EPartService.class.getName());
Lines 756-762 Link Here
756
		((Notifier) application).eAdapters().add(
785
		((Notifier) application).eAdapters().add(
757
				new UIEventPublisher(applicationContext));
786
				new UIEventPublisher(applicationContext));
758
787
759
		engine.createGui(window);
788
		getEngine().createGui(window);
760
789
761
		EPartService partService = (EPartService) window.getContext().get(
790
		EPartService partService = (EPartService) window.getContext().get(
762
				EPartService.class.getName());
791
				EPartService.class.getName());
Lines 772-782 Link Here
772
		assertEquals(part2, stack.getActiveChild());
801
		assertEquals(part2, stack.getActiveChild());
773
	}
802
	}
774
803
804
	public void testShowPart_CREATE() {
805
		MApplication application = MApplicationFactory.eINSTANCE
806
				.createApplication();
807
		MWindow window = MApplicationFactory.eINSTANCE.createWindow();
808
		application.getChildren().add(window);
809
810
		MPartStack partStackA = MApplicationFactory.eINSTANCE.createPartStack();
811
		MPartStack partStackB = MApplicationFactory.eINSTANCE.createPartStack();
812
		window.getChildren().add(partStackA);
813
		window.getChildren().add(partStackB);
814
815
		MPart partA1 = MApplicationFactory.eINSTANCE.createPart();
816
		MPart partA2 = MApplicationFactory.eINSTANCE.createPart();
817
		partA1.setId("partA1");
818
		partA2.setId("partA2");
819
		partStackA.getChildren().add(partA1);
820
		partStackA.getChildren().add(partA2);
821
822
		MPart partB1 = MApplicationFactory.eINSTANCE.createPart();
823
		MPart partB2 = MApplicationFactory.eINSTANCE.createPart();
824
		partB1.setId("partB1");
825
		partB2.setId("partB2");
826
		partStackB.getChildren().add(partB1);
827
		partStackB.getChildren().add(partB2);
828
829
		partStackA.setActiveChild(partA1);
830
		partStackB.setActiveChild(partB1);
831
		window.setActiveChild(partStackA);
832
833
		applicationContext.set(MApplication.class.getName(), application);
834
		application.setContext(applicationContext);
835
		Workbench.processHierarchy(application);
836
		((Notifier) application).eAdapters().add(
837
				new UIEventPublisher(applicationContext));
838
839
		getEngine().createGui(window);
840
841
		EPartService partService = (EPartService) window.getContext().get(
842
				EPartService.class.getName());
843
		partService.activate(partA1);
844
		assertEquals(partA1, partService.getActivePart());
845
846
		assertEquals(null, partA2.getContext());
847
		assertEquals(null, partB2.getContext());
848
849
		MPart shownPart = partService.showPart("partA2",
850
				EPartService.PartState.CREATE);
851
		assertTrue(partService.isPartVisible(partA1));
852
		assertTrue(partService.isPartVisible(partB1));
853
		assertEquals(partA1, partService.getActivePart());
854
		assertEquals(shownPart, partA2);
855
		assertNotNull(
856
				"The part should have been created so it should have a context",
857
				partA2.getContext());
858
		assertEquals(
859
				"This part has not been instantiated yet, it should have no context",
860
				null, partB2.getContext());
861
862
		shownPart = partService.showPart("partB2",
863
				EPartService.PartState.CREATE);
864
		assertTrue(partService.isPartVisible(partA1));
865
		assertTrue(partService.isPartVisible(partB1));
866
		assertEquals(partA1, partService.getActivePart());
867
		assertEquals(shownPart, partB2);
868
		assertNotNull(
869
				"The part should have been created so it should have a context",
870
				partA2.getContext());
871
		assertNotNull(
872
				"The part should have been created so it should have a context",
873
				partB2.getContext());
874
	}
875
876
	public void testShowPart_CREATE2() {
877
		MApplication application = MApplicationFactory.eINSTANCE
878
				.createApplication();
879
		MWindow window = MApplicationFactory.eINSTANCE.createWindow();
880
		application.getChildren().add(window);
881
882
		MPartDescriptor partDescriptor = MApplicationFactory.eINSTANCE
883
				.createPartDescriptor();
884
		partDescriptor.setId("partB");
885
		partDescriptor.setCategory("aCategory");
886
		application.getDescriptors().add(partDescriptor);
887
888
		MPartStack partStack = MApplicationFactory.eINSTANCE.createPartStack();
889
		partStack.setId("aCategory");
890
		window.getChildren().add(partStack);
891
892
		MPart partA = MApplicationFactory.eINSTANCE.createPart();
893
		partA.setId("partA");
894
		partStack.getChildren().add(partA);
895
896
		partStack.setActiveChild(partA);
897
		window.setActiveChild(partStack);
898
		application.setActiveChild(window);
899
900
		applicationContext.set(MApplication.class.getName(), application);
901
		application.setContext(applicationContext);
902
		Workbench.processHierarchy(application);
903
		((Notifier) application).eAdapters().add(
904
				new UIEventPublisher(applicationContext));
905
906
		getEngine().createGui(window);
907
908
		EPartService partService = (EPartService) window.getContext().get(
909
				EPartService.class.getName());
910
		partService.activate(partA);
911
		assertEquals(partA, partService.getActivePart());
912
913
		MPart partB = partService.showPart("partB",
914
				EPartService.PartState.CREATE);
915
916
		assertEquals(2, partStack.getChildren().size());
917
		assertEquals(
918
				"Only creating the part, the active part should not have changed",
919
				partA, partService.getActivePart());
920
		assertNotNull("The shown part should have a context", partB
921
				.getContext());
922
		assertFalse(partService.isPartVisible(partB));
923
	}
924
925
	public void testShowPart_CREATE3() {
926
		MApplication application = MApplicationFactory.eINSTANCE
927
				.createApplication();
928
		MWindow window = MApplicationFactory.eINSTANCE.createWindow();
929
		application.getChildren().add(window);
930
931
		MPartDescriptor partDescriptor = MApplicationFactory.eINSTANCE
932
				.createPartDescriptor();
933
		partDescriptor.setId("partB");
934
		partDescriptor.setCategory("aCategory");
935
		application.getDescriptors().add(partDescriptor);
936
937
		MPartStack partStackA = MApplicationFactory.eINSTANCE.createPartStack();
938
		window.getChildren().add(partStackA);
939
		MPartStack partStackB = MApplicationFactory.eINSTANCE.createPartStack();
940
		partStackB.setId("aCategory");
941
		window.getChildren().add(partStackB);
942
943
		MPart partA = MApplicationFactory.eINSTANCE.createPart();
944
		partA.setId("partA");
945
		partStackA.getChildren().add(partA);
946
947
		partStackA.setActiveChild(partA);
948
		window.setActiveChild(partStackA);
949
		application.setActiveChild(window);
950
951
		applicationContext.set(MApplication.class.getName(), application);
952
		application.setContext(applicationContext);
953
		Workbench.processHierarchy(application);
954
		((Notifier) application).eAdapters().add(
955
				new UIEventPublisher(applicationContext));
956
957
		getEngine().createGui(window);
958
959
		EPartService partService = (EPartService) window.getContext().get(
960
				EPartService.class.getName());
961
		partService.activate(partA);
962
		assertEquals(partA, partService.getActivePart());
963
964
		MPart partB = partService.showPart("partB",
965
				EPartService.PartState.CREATE);
966
967
		assertEquals(1, partStackA.getChildren().size());
968
		assertEquals(
969
				"Only creating the part, the active part should not have changed",
970
				partA, partService.getActivePart());
971
		assertNotNull("The shown part should have a context", partB
972
				.getContext());
973
		assertTrue(
974
				"The part is the only one in the stack, it should be visible",
975
				partService.isPartVisible(partB));
976
	}
977
978
	public void testShowPart_VISIBLE() {
979
		MApplication application = MApplicationFactory.eINSTANCE
980
				.createApplication();
981
		MWindow window = MApplicationFactory.eINSTANCE.createWindow();
982
		application.getChildren().add(window);
983
984
		MPartStack partStackA = MApplicationFactory.eINSTANCE.createPartStack();
985
		MPartStack partStackB = MApplicationFactory.eINSTANCE.createPartStack();
986
		window.getChildren().add(partStackA);
987
		window.getChildren().add(partStackB);
988
989
		MPart partA1 = MApplicationFactory.eINSTANCE.createPart();
990
		MPart partA2 = MApplicationFactory.eINSTANCE.createPart();
991
		partA1.setId("partA1");
992
		partA2.setId("partA2");
993
		partStackA.getChildren().add(partA1);
994
		partStackA.getChildren().add(partA2);
995
996
		MPart partB1 = MApplicationFactory.eINSTANCE.createPart();
997
		MPart partB2 = MApplicationFactory.eINSTANCE.createPart();
998
		partB1.setId("partB1");
999
		partB2.setId("partB2");
1000
		partStackB.getChildren().add(partB1);
1001
		partStackB.getChildren().add(partB2);
1002
1003
		partStackA.setActiveChild(partA1);
1004
		partStackB.setActiveChild(partB1);
1005
		window.setActiveChild(partStackA);
1006
1007
		applicationContext.set(MApplication.class.getName(), application);
1008
		application.setContext(applicationContext);
1009
		Workbench.processHierarchy(application);
1010
		((Notifier) application).eAdapters().add(
1011
				new UIEventPublisher(applicationContext));
1012
1013
		getEngine().createGui(window);
1014
1015
		EPartService partService = (EPartService) window.getContext().get(
1016
				EPartService.class.getName());
1017
		partService.activate(partA1);
1018
		assertEquals(partA1, partService.getActivePart());
1019
1020
		MPart shownPart = partService.showPart("partB1",
1021
				EPartService.PartState.VISIBLE);
1022
		assertTrue(partService.isPartVisible(partA1));
1023
		assertTrue(partService.isPartVisible(partB1));
1024
		assertEquals(partA1, partService.getActivePart());
1025
		assertEquals(partB1, shownPart);
1026
1027
		shownPart = partService.showPart("partB2",
1028
				EPartService.PartState.VISIBLE);
1029
		assertTrue(partService.isPartVisible(partA1));
1030
		assertTrue(partService.isPartVisible(partB2));
1031
		assertEquals(partA1, partService.getActivePart());
1032
		assertEquals(partB2, shownPart);
1033
	}
1034
1035
	public void testShowPart_VISIBLE2() {
1036
		MApplication application = MApplicationFactory.eINSTANCE
1037
				.createApplication();
1038
		MWindow window = MApplicationFactory.eINSTANCE.createWindow();
1039
		application.getChildren().add(window);
1040
1041
		MPartDescriptor partDescriptor = MApplicationFactory.eINSTANCE
1042
				.createPartDescriptor();
1043
		partDescriptor.setId("partB");
1044
		partDescriptor.setCategory("aCategory");
1045
		application.getDescriptors().add(partDescriptor);
1046
1047
		MPartStack partStack = MApplicationFactory.eINSTANCE.createPartStack();
1048
		partStack.setId("aCategory");
1049
		window.getChildren().add(partStack);
1050
1051
		MPart partA = MApplicationFactory.eINSTANCE.createPart();
1052
		partA.setId("partA");
1053
		partStack.getChildren().add(partA);
1054
1055
		partStack.setActiveChild(partA);
1056
		window.setActiveChild(partStack);
1057
		application.setActiveChild(window);
1058
1059
		applicationContext.set(MApplication.class.getName(), application);
1060
		application.setContext(applicationContext);
1061
		Workbench.processHierarchy(application);
1062
		((Notifier) application).eAdapters().add(
1063
				new UIEventPublisher(applicationContext));
1064
1065
		getEngine().createGui(window);
1066
1067
		EPartService partService = (EPartService) window.getContext().get(
1068
				EPartService.class.getName());
1069
		partService.activate(partA);
1070
		assertEquals(partA, partService.getActivePart());
1071
1072
		MPart partB = partService.showPart("partB",
1073
				EPartService.PartState.VISIBLE);
1074
1075
		assertEquals(2, partStack.getChildren().size());
1076
		assertEquals(
1077
				"The part is in the same stack as the active part, so the active part should change",
1078
				partB, partService.getActivePart());
1079
		assertNotNull("The shown part should have a context", partB
1080
				.getContext());
1081
		assertTrue(partService.isPartVisible(partB));
1082
	}
1083
1084
	public void testShowPart_VISIBLE3() {
1085
		MApplication application = MApplicationFactory.eINSTANCE
1086
				.createApplication();
1087
		MWindow window = MApplicationFactory.eINSTANCE.createWindow();
1088
		application.getChildren().add(window);
1089
1090
		MPartDescriptor partDescriptor = MApplicationFactory.eINSTANCE
1091
				.createPartDescriptor();
1092
		partDescriptor.setId("partB");
1093
		partDescriptor.setCategory("aCategory");
1094
		application.getDescriptors().add(partDescriptor);
1095
1096
		MPartStack partStackA = MApplicationFactory.eINSTANCE.createPartStack();
1097
		window.getChildren().add(partStackA);
1098
		MPartStack partStackB = MApplicationFactory.eINSTANCE.createPartStack();
1099
		partStackB.setId("aCategory");
1100
		window.getChildren().add(partStackB);
1101
1102
		MPart partA = MApplicationFactory.eINSTANCE.createPart();
1103
		partA.setId("partA");
1104
		partStackA.getChildren().add(partA);
1105
1106
		partStackA.setActiveChild(partA);
1107
		window.setActiveChild(partStackA);
1108
		application.setActiveChild(window);
1109
1110
		applicationContext.set(MApplication.class.getName(), application);
1111
		application.setContext(applicationContext);
1112
		Workbench.processHierarchy(application);
1113
		((Notifier) application).eAdapters().add(
1114
				new UIEventPublisher(applicationContext));
1115
1116
		getEngine().createGui(window);
1117
1118
		EPartService partService = (EPartService) window.getContext().get(
1119
				EPartService.class.getName());
1120
		partService.activate(partA);
1121
		assertEquals(partA, partService.getActivePart());
1122
1123
		MPart partB = partService.showPart("partB",
1124
				EPartService.PartState.VISIBLE);
1125
1126
		assertEquals(1, partStackA.getChildren().size());
1127
		assertEquals(
1128
				"Only creating the part, the active part should not have changed",
1129
				partA, partService.getActivePart());
1130
		assertNotNull("The shown part should have a context", partB
1131
				.getContext());
1132
		assertTrue(
1133
				"The part is the only one in the stack, it should be visible",
1134
				partService.isPartVisible(partB));
1135
	}
1136
775
	public void testGetSaveableParts() {
1137
	public void testGetSaveableParts() {
776
		MApplication application = createApplication(1, new String[1][0]);
1138
		MApplication application = createApplication(1, new String[1][0]);
777
		MWindow window = application.getChildren().get(0);
1139
		MWindow window = application.getChildren().get(0);
778
1140
779
		engine.createGui(window);
1141
		getEngine().createGui(window);
780
1142
781
		EPartService partService = (EPartService) window.getContext().get(
1143
		EPartService partService = (EPartService) window.getContext().get(
782
				EPartService.class.getName());
1144
				EPartService.class.getName());
Lines 790-796 Link Here
790
		MApplication application = createApplication("partId");
1152
		MApplication application = createApplication("partId");
791
		MWindow window = application.getChildren().get(0);
1153
		MWindow window = application.getChildren().get(0);
792
1154
793
		engine.createGui(window);
1155
		getEngine().createGui(window);
794
1156
795
		EPartService partService = (EPartService) window.getContext().get(
1157
		EPartService partService = (EPartService) window.getContext().get(
796
				EPartService.class.getName());
1158
				EPartService.class.getName());
Lines 817-823 Link Here
817
		((Notifier) application).eAdapters().add(
1179
		((Notifier) application).eAdapters().add(
818
				new UIEventPublisher(applicationContext));
1180
				new UIEventPublisher(applicationContext));
819
1181
820
		engine.createGui(window);
1182
		getEngine().createGui(window);
821
1183
822
		EPartService partService = (EPartService) window.getContext().get(
1184
		EPartService partService = (EPartService) window.getContext().get(
823
				EPartService.class.getName());
1185
				EPartService.class.getName());
Lines 831-837 Link Here
831
		MApplication application = createApplication(1, new String[1][0]);
1193
		MApplication application = createApplication(1, new String[1][0]);
832
		MWindow window = application.getChildren().get(0);
1194
		MWindow window = application.getChildren().get(0);
833
1195
834
		engine.createGui(window);
1196
		getEngine().createGui(window);
835
1197
836
		EPartService partService = (EPartService) window.getContext().get(
1198
		EPartService partService = (EPartService) window.getContext().get(
837
				EPartService.class.getName());
1199
				EPartService.class.getName());
Lines 844-850 Link Here
844
		MApplication application = createApplication("partId");
1206
		MApplication application = createApplication("partId");
845
		MWindow window = application.getChildren().get(0);
1207
		MWindow window = application.getChildren().get(0);
846
1208
847
		engine.createGui(window);
1209
		getEngine().createGui(window);
848
1210
849
		EPartService partService = (EPartService) window.getContext().get(
1211
		EPartService partService = (EPartService) window.getContext().get(
850
				EPartService.class.getName());
1212
				EPartService.class.getName());
Lines 871-877 Link Here
871
		((Notifier) application).eAdapters().add(
1233
		((Notifier) application).eAdapters().add(
872
				new UIEventPublisher(applicationContext));
1234
				new UIEventPublisher(applicationContext));
873
1235
874
		engine.createGui(window);
1236
		getEngine().createGui(window);
875
1237
876
		EPartService partService = (EPartService) window.getContext().get(
1238
		EPartService partService = (EPartService) window.getContext().get(
877
				EPartService.class.getName());
1239
				EPartService.class.getName());
Lines 920-929 Link Here
920
		MWindow window2 = MApplicationFactory.eINSTANCE.createWindow();
1282
		MWindow window2 = MApplicationFactory.eINSTANCE.createWindow();
921
		application.getChildren().add(window1);
1283
		application.getChildren().add(window1);
922
		application.getChildren().add(window2);
1284
		application.getChildren().add(window2);
1285
		application.setActiveChild(window1);
923
1286
924
		// place a part in the first window
1287
		// place a part in the first window
925
		MPart part = MApplicationFactory.eINSTANCE.createPart();
1288
		MPart part = MApplicationFactory.eINSTANCE.createPart();
926
		window1.getChildren().add(part);
1289
		window1.getChildren().add(part);
1290
		window1.setActiveChild(part);
927
1291
928
		// setup the context
1292
		// setup the context
929
		applicationContext.set(MApplication.class.getName(), application);
1293
		applicationContext.set(MApplication.class.getName(), application);
Lines 933-940 Link Here
933
				new UIEventPublisher(applicationContext));
1297
				new UIEventPublisher(applicationContext));
934
1298
935
		// render the windows
1299
		// render the windows
936
		engine.createGui(window1);
1300
		getEngine().createGui(window1);
937
		engine.createGui(window2);
1301
		getEngine().createGui(window2);
938
1302
939
		EPartService windowService1 = (EPartService) window1.getContext().get(
1303
		EPartService windowService1 = (EPartService) window1.getContext().get(
940
				EPartService.class.getName());
1304
				EPartService.class.getName());
Lines 964-970 Link Here
964
		// activate the part
1328
		// activate the part
965
		windowService2.activate(part);
1329
		windowService2.activate(part);
966
1330
967
		assertNull("No parts in this window, this should be null",
1331
		assertEquals("No parts in this window, this should be null", null,
968
				windowService1.getActivePart());
1332
				windowService1.getActivePart());
969
		assertEquals("We activated it just now, this should be active", part,
1333
		assertEquals("We activated it just now, this should be active", part,
970
				windowService2.getActivePart());
1334
				windowService2.getActivePart());
(-)src/org/eclipse/e4/ui/tests/application/HeadlessApplicationTest.java (-42 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
2
 * Copyright (c) 2009, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 33-41 Link Here
33
import org.eclipse.e4.ui.model.application.MUIElement;
33
import org.eclipse.e4.ui.model.application.MUIElement;
34
import org.eclipse.e4.ui.model.application.MWindow;
34
import org.eclipse.e4.ui.model.application.MWindow;
35
import org.eclipse.e4.ui.services.IServiceConstants;
35
import org.eclipse.e4.ui.services.IServiceConstants;
36
import org.eclipse.e4.ui.services.events.IEventBroker;
37
import org.eclipse.e4.workbench.ui.IPresentationEngine;
36
import org.eclipse.e4.workbench.ui.IPresentationEngine;
38
import org.eclipse.e4.workbench.ui.UIEvents;
39
import org.eclipse.e4.workbench.ui.internal.Workbench;
37
import org.eclipse.e4.workbench.ui.internal.Workbench;
40
import org.eclipse.emf.common.util.EList;
38
import org.eclipse.emf.common.util.EList;
41
import org.eclipse.emf.common.util.TreeIterator;
39
import org.eclipse.emf.common.util.TreeIterator;
Lines 44-51 Link Here
44
import org.eclipse.emf.ecore.resource.Resource;
42
import org.eclipse.emf.ecore.resource.Resource;
45
import org.eclipse.emf.ecore.resource.ResourceSet;
43
import org.eclipse.emf.ecore.resource.ResourceSet;
46
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
44
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
47
import org.osgi.service.event.Event;
48
import org.osgi.service.event.EventHandler;
49
45
50
public abstract class HeadlessApplicationTest extends
46
public abstract class HeadlessApplicationTest extends
51
		HeadlessApplicationElementTest {
47
		HeadlessApplicationElementTest {
Lines 54-89 Link Here
54
50
55
	protected IPresentationEngine renderer;
51
	protected IPresentationEngine renderer;
56
52
57
	private EventHandler eventHandler = new EventHandler() {
58
		public void handleEvent(Event event) {
59
			if (event.getProperty(UIEvents.EventTags.ATTNAME).equals(
60
					UIEvents.ElementContainer.ACTIVECHILD)) {
61
				Object oldPart = event
62
						.getProperty(UIEvents.EventTags.OLD_VALUE);
63
				Object newPart = event
64
						.getProperty(UIEvents.EventTags.NEW_VALUE);
65
				if (oldPart instanceof MContext) {
66
					IEclipseContext context = (IEclipseContext) ((MContext) oldPart)
67
							.getContext().get(IContextConstants.PARENT);
68
					context.set(IContextConstants.ACTIVE_CHILD,
69
							newPart == null ? null : ((MContext) newPart)
70
									.getContext());
71
				} else if (newPart instanceof MContext) {
72
					IEclipseContext context = (IEclipseContext) ((MContext) newPart)
73
							.getContext().get(IContextConstants.PARENT);
74
					context.set(IContextConstants.ACTIVE_CHILD,
75
							((MContext) newPart).getContext());
76
				}
77
			}
78
		}
79
	};
80
81
	@Override
53
	@Override
82
	protected void setUp() throws Exception {
54
	protected void setUp() throws Exception {
83
		super.setUp();
55
		super.setUp();
84
56
85
		application = (MApplication) applicationElement;
57
		application = (MApplication) applicationElement;
86
58
59
		for (MWindow wbw : application.getChildren()) {
60
			createGUI(wbw);
61
		}
62
87
		if (needsActiveChildEventHandling()) {
63
		if (needsActiveChildEventHandling()) {
88
			addActiveChildEventHandling();
64
			addActiveChildEventHandling();
89
		}
65
		}
Lines 91-100 Link Here
91
67
92
	@Override
68
	@Override
93
	protected void tearDown() throws Exception {
69
	protected void tearDown() throws Exception {
94
		IEventBroker eventBroker = (IEventBroker) application.getContext().get(
95
				IEventBroker.class.getName());
96
		eventBroker.unsubscribe(eventHandler);
97
98
		for (MWindow window : application.getChildren()) {
70
		for (MWindow window : application.getChildren()) {
99
			renderer.removeGui(window);
71
			renderer.removeGui(window);
100
		}
72
		}
Lines 107-117 Link Here
107
	}
79
	}
108
80
109
	private void addActiveChildEventHandling() {
81
	private void addActiveChildEventHandling() {
110
		IEventBroker eventBroker = (IEventBroker) application.getContext().get(
111
				IEventBroker.class.getName());
112
		eventBroker.subscribe(UIEvents
113
				.buildTopic(UIEvents.ElementContainer.TOPIC), null,
114
				eventHandler, true);
115
	}
82
	}
116
83
117
	public void testGet_ActiveContexts() throws Exception {
84
	public void testGet_ActiveContexts() throws Exception {
Lines 349-358 Link Here
349
316
350
		renderer = createPresentationEngine(getEngineURI());
317
		renderer = createPresentationEngine(getEngineURI());
351
318
352
		for (MWindow wbw : windows) {
353
			createGUI(wbw);
354
		}
355
356
		return application;
319
		return application;
357
	}
320
	}
358
321
(-)src/org/eclipse/e4/ui/tests/application/HeadlessContextPresentationEngine.java (-16 / +61 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
2
 * Copyright (c) 2009, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-16 Link Here
11
11
12
package org.eclipse.e4.ui.tests.application;
12
package org.eclipse.e4.ui.tests.application;
13
13
14
import java.util.List;
15
14
import javax.inject.Inject;
16
import javax.inject.Inject;
15
17
16
import org.eclipse.e4.core.services.IDisposable;
18
import org.eclipse.e4.core.services.IDisposable;
Lines 21-26 Link Here
21
import org.eclipse.e4.ui.model.application.MApplicationElement;
23
import org.eclipse.e4.ui.model.application.MApplicationElement;
22
import org.eclipse.e4.ui.model.application.MContext;
24
import org.eclipse.e4.ui.model.application.MContext;
23
import org.eclipse.e4.ui.model.application.MElementContainer;
25
import org.eclipse.e4.ui.model.application.MElementContainer;
26
import org.eclipse.e4.ui.model.application.MPart;
27
import org.eclipse.e4.ui.model.application.MPartStack;
24
import org.eclipse.e4.ui.model.application.MUIElement;
28
import org.eclipse.e4.ui.model.application.MUIElement;
25
import org.eclipse.e4.ui.services.events.IEventBroker;
29
import org.eclipse.e4.ui.services.events.IEventBroker;
26
import org.eclipse.e4.workbench.ui.IPresentationEngine;
30
import org.eclipse.e4.workbench.ui.IPresentationEngine;
Lines 35-40 Link Here
35
	@Inject
39
	@Inject
36
	private IEventBroker eventBroker;
40
	private IEventBroker eventBroker;
37
41
42
	private EventHandler childHandler;
43
	private EventHandler activeChildHandler;
44
38
	private static IEclipseContext getParentContext(MUIElement element) {
45
	private static IEclipseContext getParentContext(MUIElement element) {
39
		MElementContainer<MUIElement> parent = element.getParent();
46
		MElementContainer<MUIElement> parent = element.getParent();
40
		IEclipseContext context = null;
47
		IEclipseContext context = null;
Lines 62-70 Link Here
62
69
63
	@PostConstruct
70
	@PostConstruct
64
	void postConstruct() {
71
	void postConstruct() {
72
		childHandler = new EventHandler() {
73
			public void handleEvent(Event event) {
74
				if (UIEvents.EventTypes.ADD.equals(event
75
						.getProperty(UIEvents.EventTags.TYPE))) {
76
					Object element = event
77
							.getProperty(UIEvents.EventTags.NEW_VALUE);
78
					if (element instanceof MUIElement) {
79
						Object parent = event
80
								.getProperty(UIEvents.EventTags.ELEMENT);
81
						createGui((MUIElement) element, parent);
82
83
						if (parent instanceof MPartStack) {
84
							MPartStack stack = (MPartStack) parent;
85
							List<MPart> children = stack.getChildren();
86
							if (children.size() == 1) {
87
								stack.setActiveChild((MPart) element);
88
							}
89
						}
90
					}
91
				}
92
			}
93
		};
94
65
		eventBroker.subscribe(UIEvents.buildTopic(
95
		eventBroker.subscribe(UIEvents.buildTopic(
66
				UIEvents.ElementContainer.TOPIC,
96
				UIEvents.ElementContainer.TOPIC,
67
				UIEvents.ElementContainer.CHILDREN), new EventHandler() {
97
				UIEvents.ElementContainer.CHILDREN), childHandler);
98
99
		activeChildHandler = new EventHandler() {
68
			public void handleEvent(Event event) {
100
			public void handleEvent(Event event) {
69
				Object element = event
101
				Object element = event
70
						.getProperty(UIEvents.EventTags.NEW_VALUE);
102
						.getProperty(UIEvents.EventTags.NEW_VALUE);
Lines 74-80 Link Here
74
					createGui((MUIElement) element, parent);
106
					createGui((MUIElement) element, parent);
75
				}
107
				}
76
			}
108
			}
77
		});
109
		};
110
111
		eventBroker.subscribe(UIEvents.buildTopic(
112
				UIEvents.ElementContainer.TOPIC,
113
				UIEvents.ElementContainer.ACTIVECHILD), activeChildHandler);
78
	}
114
	}
79
115
80
	/*
116
	/*
Lines 103-124 Link Here
103
139
104
			mcontext.setContext(createdContext);
140
			mcontext.setContext(createdContext);
105
		}
141
		}
106
		if (element instanceof MElementContainer<?>) {
142
107
			boolean active = false;
143
		if (element instanceof MPartStack) {
144
			MPartStack container = (MPartStack) element;
145
			MPart active = container.getActiveChild();
146
			if (active != null) {
147
				createGui(active, container);
148
				IEclipseContext childContext = ((MContext) active).getContext();
149
				IEclipseContext parentContext = getParentContext(active);
150
				parentContext.set(IContextConstants.ACTIVE_CHILD, childContext);
151
			} else {
152
				List<MPart> children = container.getChildren();
153
				if (!children.isEmpty()) {
154
					container.setActiveChild(children.get(0));
155
				}
156
			}
157
		} else if (element instanceof MElementContainer<?>) {
108
			for (Object child : ((MElementContainer<?>) element).getChildren()) {
158
			for (Object child : ((MElementContainer<?>) element).getChildren()) {
109
				if (child instanceof MUIElement) {
159
				if (child instanceof MUIElement) {
110
					createGui((MUIElement) child, element);
160
					createGui((MUIElement) child, element);
111
					if (!active) {
161
					if (child instanceof MContext) {
112
						active = true;
162
						IEclipseContext childContext = ((MContext) child)
113
						((MElementContainer) element)
163
								.getContext();
114
								.setActiveChild((MUIElement) child);
164
						IEclipseContext parentContext = getParentContext((MUIElement) child);
115
						if (child instanceof MContext) {
165
						parentContext.set(IContextConstants.ACTIVE_CHILD,
116
							IEclipseContext childContext = ((MContext) child)
166
								childContext);
117
									.getContext();
118
							IEclipseContext parentContext = getParentContext((MUIElement) child);
119
							parentContext.set(IContextConstants.ACTIVE_CHILD,
120
									childContext);
121
						}
122
					}
167
					}
123
				}
168
				}
124
			}
169
			}
(-)src/org/eclipse/e4/ui/tests/application/HeadlessPhotoDemoTest.java (-3 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
2
 * Copyright (c) 2009, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 22-33 Link Here
22
22
23
	@Override
23
	@Override
24
	protected MPart getFirstPart() {
24
	protected MPart getFirstPart() {
25
		return (MPart) findElement("ExifView");
25
		return (MPart) findElement("ThumbnailsView");
26
	}
26
	}
27
27
28
	@Override
28
	@Override
29
	protected MPart getSecondPart() {
29
	protected MPart getSecondPart() {
30
		return (MPart) findElement("ThumbnailsView");
30
		return (MPart) findElement("ExifView");
31
	}
31
	}
32
32
33
}
33
}
(-)src/org/eclipse/e4/ui/tests/application/UIPhotoDemoTest.java (-3 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
2
 * Copyright (c) 2009, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 22-33 Link Here
22
22
23
	@Override
23
	@Override
24
	protected MPart getFirstPart() {
24
	protected MPart getFirstPart() {
25
		return (MPart) findElement("ExifView");
25
		return (MPart) findElement("ThumbnailsView");
26
	}
26
	}
27
27
28
	@Override
28
	@Override
29
	protected MPart getSecondPart() {
29
	protected MPart getSecondPart() {
30
		return (MPart) findElement("ThumbnailsView");
30
		return (MPart) findElement("ExifView");
31
	}
31
	}
32
32
33
}
33
}
(-)src/org/eclipse/e4/workbench/modeling/EPartService.java (+51 lines)
Lines 14-20 Link Here
14
import org.eclipse.e4.ui.model.application.MPart;
14
import org.eclipse.e4.ui.model.application.MPart;
15
import org.eclipse.e4.ui.model.application.MSaveablePart;
15
import org.eclipse.e4.ui.model.application.MSaveablePart;
16
16
17
/**
18
 * The part service provides clients with the functionalities of showing and hiding parts. Part
19
 * events can also be tracked via the part service.
20
 * 
21
 * @since 1.0
22
 */
17
public interface EPartService {
23
public interface EPartService {
24
25
	/**
26
	 * Applicable states that a part can be in. This will be used in conjunction with
27
	 * {@link EPartService#showPart(String, PartState)}.
28
	 */
29
	public enum PartState {
30
31
		/**
32
		 * Part state that indicates the part should be made visible and activated.
33
		 */
34
		ACTIVATE,
35
36
		/**
37
		 * Part state that indicates the part should be made visible though it may not necessarily
38
		 * be granted focus.
39
		 */
40
		VISIBLE,
41
42
		/**
43
		 * Part state that indicates the part should be created but not necessarily made visible.
44
		 */
45
		CREATE
46
	}
47
18
	public static final String PART_SERVICE_ROOT = "partServiceRoot"; //$NON-NLS-1$
48
	public static final String PART_SERVICE_ROOT = "partServiceRoot"; //$NON-NLS-1$
19
49
20
	public void activate(MPart part);
50
	public void activate(MPart part);
Lines 25-38 Link Here
25
55
26
	public MPart findPart(String id);
56
	public MPart findPart(String id);
27
57
58
	/**
59
	 * Returns a collection of all the parts that are being managed by this part service.
60
	 * 
61
	 * @return a collection of parts that are being managed by this service, never <code>null</code>
62
	 */
28
	public Collection<MPart> getParts();
63
	public Collection<MPart> getParts();
29
64
65
	/**
66
	 * Returns the active part.
67
	 * 
68
	 * @return an active part within the scope of this service, or <code>null</code> if no part is
69
	 *         currently active
70
	 */
30
	public MPart getActivePart();
71
	public MPart getActivePart();
31
72
32
	public boolean isPartVisible(MPart part);
73
	public boolean isPartVisible(MPart part);
33
74
75
	/**
76
	 * Shows the part that is identified by the given id and grant it focus.
77
	 * 
78
	 * @param id
79
	 *            the identifier of the part, must not be <code>null</code>
80
	 * @return the shown part, or <code>null</code> if no parts or part descriptors can be found
81
	 *         that match the specified id
82
	 */
34
	public MPart showPart(String id);
83
	public MPart showPart(String id);
35
84
85
	public MPart showPart(String id, PartState partState);
86
36
	public Collection<MSaveablePart> getSaveableParts();
87
	public Collection<MSaveablePart> getSaveableParts();
37
88
38
	public Collection<MSaveablePart> getDirtyParts();
89
	public Collection<MSaveablePart> getDirtyParts();
(-)src/org/eclipse/e4/workbench/ui/internal/PartServiceImpl.java (-2 / +27 lines)
Lines 33-38 Link Here
33
import org.eclipse.e4.ui.services.IServiceConstants;
33
import org.eclipse.e4.ui.services.IServiceConstants;
34
import org.eclipse.e4.ui.services.events.IEventBroker;
34
import org.eclipse.e4.ui.services.events.IEventBroker;
35
import org.eclipse.e4.workbench.modeling.EPartService;
35
import org.eclipse.e4.workbench.modeling.EPartService;
36
import org.eclipse.e4.workbench.ui.IPresentationEngine;
36
import org.eclipse.e4.workbench.ui.UIEvents;
37
import org.eclipse.e4.workbench.ui.UIEvents;
37
import org.eclipse.emf.ecore.EObject;
38
import org.eclipse.emf.ecore.EObject;
38
import org.eclipse.emf.ecore.util.EcoreUtil;
39
import org.eclipse.emf.ecore.util.EcoreUtil;
Lines 68-73 Link Here
68
	private MElementContainer<MUIElement> rootContainer;
69
	private MElementContainer<MUIElement> rootContainer;
69
70
70
	@Inject
71
	@Inject
72
	private IPresentationEngine engine;
73
74
	@Inject
71
	void setPart(@Optional @Named(IServiceConstants.ACTIVE_PART) MPart p) {
75
	void setPart(@Optional @Named(IServiceConstants.ACTIVE_PART) MPart p) {
72
		activePart = p;
76
		activePart = p;
73
	}
77
	}
Lines 253-263 Link Here
253
	}
257
	}
254
258
255
	public MPart showPart(String id) {
259
	public MPart showPart(String id) {
260
		return showPart(id, PartState.ACTIVATE);
261
	}
262
263
	public MPart showPart(String id, PartState partState) {
256
		Assert.isNotNull(id);
264
		Assert.isNotNull(id);
257
265
258
		MPart part = findPart(id);
266
		MPart part = findPart(id);
259
		if (part != null) {
267
		if (part != null) {
260
			activate(part);
268
			switch (partState) {
269
			case ACTIVATE:
270
				activate(part);
271
				return part;
272
			case VISIBLE:
273
				bringToTop(part);
274
				return part;
275
			case CREATE:
276
				engine.createGui(part);
277
				return part;
278
			}
261
			return part;
279
			return part;
262
		}
280
		}
263
281
Lines 294-300 Link Here
294
		}
312
		}
295
313
296
		// 3) make it visible / active / re-layout
314
		// 3) make it visible / active / re-layout
297
		activate(part);
315
		switch (partState) {
316
		case ACTIVATE:
317
			activate(part);
318
			return part;
319
		case VISIBLE:
320
			bringToTop(part);
321
			return part;
322
		}
298
		return part;
323
		return part;
299
	}
324
	}
300
325

Return to bug 295003