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 (-1 / +227 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 23-28 Link Here
23
import org.eclipse.e4.ui.model.application.MPart;
23
import org.eclipse.e4.ui.model.application.MPart;
24
import org.eclipse.e4.ui.model.application.MPartDescriptor;
24
import org.eclipse.e4.ui.model.application.MPartDescriptor;
25
import org.eclipse.e4.ui.model.application.MPartStack;
25
import org.eclipse.e4.ui.model.application.MPartStack;
26
import org.eclipse.e4.ui.model.application.MSaveablePart;
26
import org.eclipse.e4.ui.model.application.MWindow;
27
import org.eclipse.e4.ui.model.application.MWindow;
27
import org.eclipse.e4.ui.services.IServiceConstants;
28
import org.eclipse.e4.ui.services.IServiceConstants;
28
import org.eclipse.e4.ui.workbench.swt.internal.E4Application;
29
import org.eclipse.e4.ui.workbench.swt.internal.E4Application;
Lines 682-687 Link Here
682
		assertEquals(part, partService.getActivePart());
683
		assertEquals(part, partService.getActivePart());
683
	}
684
	}
684
685
686
	public void testShowPart_DefinedCategoryStackNotExists() {
687
		MApplication application = MApplicationFactory.eINSTANCE
688
				.createApplication();
689
		MWindow window = MApplicationFactory.eINSTANCE.createWindow();
690
		application.getChildren().add(window);
691
692
		MPartDescriptor partDescriptor = MApplicationFactory.eINSTANCE
693
				.createPartDescriptor();
694
		partDescriptor.setCategory("categoryId");
695
		partDescriptor.setId("partId");
696
		application.getDescriptors().add(partDescriptor);
697
698
		partDescriptor = MApplicationFactory.eINSTANCE.createPartDescriptor();
699
		partDescriptor.setCategory("categoryId");
700
		partDescriptor.setId("partId2");
701
		application.getDescriptors().add(partDescriptor);
702
703
		applicationContext.set(MApplication.class.getName(), application);
704
		application.setContext(applicationContext);
705
		Workbench.processHierarchy(application);
706
		((Notifier) application).eAdapters().add(
707
				new UIEventPublisher(applicationContext));
708
709
		engine.createGui(window);
710
711
		EPartService partService = (EPartService) window.getContext().get(
712
				EPartService.class.getName());
713
		MPart part = partService.showPart("partId");
714
715
		assertEquals(1, window.getChildren().size());
716
		assertTrue(window.getChildren().get(0) instanceof MPartStack);
717
718
		MPartStack stack = (MPartStack) window.getChildren().get(0);
719
		assertEquals("categoryId", stack.getId());
720
721
		assertEquals(1, stack.getChildren().size());
722
		assertEquals(part, stack.getChildren().get(0));
723
724
		MPart part2 = partService.showPart("partId2");
725
		assertEquals(2, stack.getChildren().size());
726
		assertEquals(part, stack.getChildren().get(0));
727
		assertEquals(part2, stack.getChildren().get(1));
728
	}
729
730
	public void testShowPart_DefinedCategoryStackExists() {
731
		MApplication application = MApplicationFactory.eINSTANCE
732
				.createApplication();
733
		MWindow window = MApplicationFactory.eINSTANCE.createWindow();
734
		application.getChildren().add(window);
735
736
		MPartDescriptor partDescriptor = MApplicationFactory.eINSTANCE
737
				.createPartDescriptor();
738
		partDescriptor.setCategory("categoryId");
739
		partDescriptor.setId("partId");
740
		application.getDescriptors().add(partDescriptor);
741
742
		partDescriptor = MApplicationFactory.eINSTANCE.createPartDescriptor();
743
		partDescriptor.setCategory("categoryId");
744
		partDescriptor.setId("partId2");
745
		application.getDescriptors().add(partDescriptor);
746
747
		MPartStack stack = MApplicationFactory.eINSTANCE.createPartStack();
748
		stack.setId("categoryId");
749
		window.getChildren().add(stack);
750
751
		applicationContext.set(MApplication.class.getName(), application);
752
		application.setContext(applicationContext);
753
		Workbench.processHierarchy(application);
754
		((Notifier) application).eAdapters().add(
755
				new UIEventPublisher(applicationContext));
756
757
		engine.createGui(window);
758
759
		EPartService partService = (EPartService) window.getContext().get(
760
				EPartService.class.getName());
761
		MPart part = partService.showPart("partId");
762
		assertEquals(1, stack.getChildren().size());
763
		assertEquals(part, stack.getChildren().get(0));
764
765
		MPart part2 = partService.showPart("partId2");
766
		assertEquals(2, stack.getChildren().size());
767
		assertEquals(part, stack.getChildren().get(0));
768
		assertEquals(part2, stack.getChildren().get(1));
769
	}
770
771
	public void testGetSaveableParts() {
772
		MApplication application = createApplication(1, new String[1][0]);
773
		MWindow window = application.getChildren().get(0);
774
775
		engine.createGui(window);
776
777
		EPartService partService = (EPartService) window.getContext().get(
778
				EPartService.class.getName());
779
		Collection<MSaveablePart> saveableParts = partService
780
				.getSaveableParts();
781
		assertNotNull(saveableParts);
782
		assertEquals(0, saveableParts.size());
783
	}
784
785
	public void testGetSaveableParts2() {
786
		MApplication application = createApplication("partId");
787
		MWindow window = application.getChildren().get(0);
788
789
		engine.createGui(window);
790
791
		EPartService partService = (EPartService) window.getContext().get(
792
				EPartService.class.getName());
793
		Collection<MSaveablePart> saveableParts = partService
794
				.getSaveableParts();
795
		assertNotNull(saveableParts);
796
		assertEquals(0, saveableParts.size());
797
	}
798
799
	public void testGetSaveableParts3() {
800
		MApplication application = MApplicationFactory.eINSTANCE
801
				.createApplication();
802
803
		MWindow window = MApplicationFactory.eINSTANCE.createWindow();
804
		application.getChildren().add(window);
805
		MSaveablePart saveablePart = MApplicationFactory.eINSTANCE
806
				.createSaveablePart();
807
		window.getChildren().add(saveablePart);
808
809
		// setup the context
810
		applicationContext.set(MApplication.class.getName(), application);
811
		application.setContext(applicationContext);
812
		Workbench.processHierarchy(application);
813
		((Notifier) application).eAdapters().add(
814
				new UIEventPublisher(applicationContext));
815
816
		engine.createGui(window);
817
818
		EPartService partService = (EPartService) window.getContext().get(
819
				EPartService.class.getName());
820
		Collection<MSaveablePart> saveableParts = partService
821
				.getSaveableParts();
822
		assertNotNull(saveableParts);
823
		assertEquals(1, saveableParts.size());
824
	}
825
826
	public void testGetDirtyParts() {
827
		MApplication application = createApplication(1, new String[1][0]);
828
		MWindow window = application.getChildren().get(0);
829
830
		engine.createGui(window);
831
832
		EPartService partService = (EPartService) window.getContext().get(
833
				EPartService.class.getName());
834
		Collection<MSaveablePart> dirtyParts = partService.getDirtyParts();
835
		assertNotNull(dirtyParts);
836
		assertEquals(0, dirtyParts.size());
837
	}
838
839
	public void testGetDirtyParts2() {
840
		MApplication application = createApplication("partId");
841
		MWindow window = application.getChildren().get(0);
842
843
		engine.createGui(window);
844
845
		EPartService partService = (EPartService) window.getContext().get(
846
				EPartService.class.getName());
847
		Collection<MSaveablePart> dirtyParts = partService.getDirtyParts();
848
		assertNotNull(dirtyParts);
849
		assertEquals(0, dirtyParts.size());
850
	}
851
852
	private void testGetDirtyParts3(boolean before, boolean after) {
853
		MApplication application = MApplicationFactory.eINSTANCE
854
				.createApplication();
855
856
		MWindow window = MApplicationFactory.eINSTANCE.createWindow();
857
		application.getChildren().add(window);
858
		MSaveablePart saveablePart = MApplicationFactory.eINSTANCE
859
				.createSaveablePart();
860
		saveablePart.setDirty(before);
861
		window.getChildren().add(saveablePart);
862
863
		// setup the context
864
		applicationContext.set(MApplication.class.getName(), application);
865
		application.setContext(applicationContext);
866
		Workbench.processHierarchy(application);
867
		((Notifier) application).eAdapters().add(
868
				new UIEventPublisher(applicationContext));
869
870
		engine.createGui(window);
871
872
		EPartService partService = (EPartService) window.getContext().get(
873
				EPartService.class.getName());
874
		Collection<MSaveablePart> dirtyParts = partService.getDirtyParts();
875
		assertNotNull(dirtyParts);
876
877
		if (before) {
878
			assertEquals(1, dirtyParts.size());
879
			assertEquals(saveablePart, dirtyParts.iterator().next());
880
		} else {
881
			assertEquals(0, dirtyParts.size());
882
		}
883
884
		saveablePart.setDirty(after);
885
		dirtyParts = partService.getDirtyParts();
886
887
		if (after) {
888
			assertEquals(1, dirtyParts.size());
889
			assertEquals(saveablePart, dirtyParts.iterator().next());
890
		} else {
891
			assertEquals(0, dirtyParts.size());
892
		}
893
	}
894
895
	public void testGetDirtyParts3_TrueTrue() {
896
		testGetDirtyParts3(true, true);
897
	}
898
899
	public void testGetDirtyParts3_TrueFalse() {
900
		testGetDirtyParts3(true, false);
901
	}
902
903
	public void testGetDirtyParts3_FalseTrue() {
904
		testGetDirtyParts3(false, true);
905
	}
906
907
	public void testGetDirtyParts3_FalseFalse() {
908
		testGetDirtyParts3(false, false);
909
	}
910
685
	public void testSwitchWindows() {
911
	public void testSwitchWindows() {
686
		// create an application with two windows
912
		// create an application with two windows
687
		MApplication application = MApplicationFactory.eINSTANCE
913
		MApplication application = MApplicationFactory.eINSTANCE
(-)src/org/eclipse/e4/workbench/modeling/EPartService.java (-1 / +6 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 12-17 Link Here
12
12
13
import java.util.Collection;
13
import java.util.Collection;
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
16
16
public interface EPartService {
17
public interface EPartService {
17
	public static final String PART_SERVICE_ROOT = "partServiceRoot"; //$NON-NLS-1$
18
	public static final String PART_SERVICE_ROOT = "partServiceRoot"; //$NON-NLS-1$
Lines 32-35 Link Here
32
33
33
	public MPart showPart(String id);
34
	public MPart showPart(String id);
34
35
36
	public Collection<MSaveablePart> getSaveableParts();
37
38
	public Collection<MSaveablePart> getDirtyParts();
39
35
}
40
}
(-)src/org/eclipse/e4/workbench/ui/internal/PartServiceImpl.java (-1 / +34 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 12-17 Link Here
12
12
13
import java.util.ArrayList;
13
import java.util.ArrayList;
14
import java.util.Collection;
14
import java.util.Collection;
15
import java.util.List;
15
import javax.inject.Inject;
16
import javax.inject.Inject;
16
import javax.inject.Named;
17
import javax.inject.Named;
17
import org.eclipse.core.runtime.Assert;
18
import org.eclipse.core.runtime.Assert;
Lines 26-31 Link Here
26
import org.eclipse.e4.ui.model.application.MPart;
27
import org.eclipse.e4.ui.model.application.MPart;
27
import org.eclipse.e4.ui.model.application.MPartDescriptor;
28
import org.eclipse.e4.ui.model.application.MPartDescriptor;
28
import org.eclipse.e4.ui.model.application.MPartStack;
29
import org.eclipse.e4.ui.model.application.MPartStack;
30
import org.eclipse.e4.ui.model.application.MSaveablePart;
29
import org.eclipse.e4.ui.model.application.MUIElement;
31
import org.eclipse.e4.ui.model.application.MUIElement;
30
import org.eclipse.e4.ui.model.application.MWindow;
32
import org.eclipse.e4.ui.model.application.MWindow;
31
import org.eclipse.e4.ui.services.IServiceConstants;
33
import org.eclipse.e4.ui.services.IServiceConstants;
Lines 281-286 Link Here
281
			((MElementContainer<MPart>) container).getChildren().add(part);
283
			((MElementContainer<MPart>) container).getChildren().add(part);
282
		} else { // wrap it in a stack
284
		} else { // wrap it in a stack
283
			MPartStack stack = MApplicationFactory.eINSTANCE.createPartStack();
285
			MPartStack stack = MApplicationFactory.eINSTANCE.createPartStack();
286
			stack.setId(descriptorMatch.getCategory());
284
			stack.getChildren().add(part);
287
			stack.getChildren().add(part);
285
			rootContainer.getChildren().add(stack);
288
			rootContainer.getChildren().add(stack);
286
		}
289
		}
Lines 292-295 Link Here
292
		activate(part);
295
		activate(part);
293
		return part;
296
		return part;
294
	}
297
	}
298
299
	/*
300
	 * (non-Javadoc)
301
	 * 
302
	 * @see org.eclipse.e4.workbench.modeling.EPartService#getSaveableParts()
303
	 */
304
	public Collection<MSaveablePart> getSaveableParts() {
305
		List<MSaveablePart> saveableParts = new ArrayList<MSaveablePart>();
306
		for (MPart part : getParts()) {
307
			if (part instanceof MSaveablePart) {
308
				saveableParts.add((MSaveablePart) part);
309
			}
310
		}
311
		return saveableParts;
312
	}
313
314
	/*
315
	 * (non-Javadoc)
316
	 * 
317
	 * @see org.eclipse.e4.workbench.modeling.EPartService#getDirtyParts()
318
	 */
319
	public Collection<MSaveablePart> getDirtyParts() {
320
		List<MSaveablePart> dirtyParts = new ArrayList<MSaveablePart>();
321
		for (MSaveablePart part : getSaveableParts()) {
322
			if (part.isDirty()) {
323
				dirtyParts.add(part);
324
			}
325
		}
326
		return dirtyParts;
327
	}
295
}
328
}

Return to bug 295003