|
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 |