45
45
import org .eclipse .ui .IFileEditorInput ;
46
46
import org .eclipse .ui .IPageLayout ;
47
47
import org .eclipse .ui .IPersistableElement ;
48
- import org .eclipse .ui .ISources ;
49
48
import org .eclipse .ui .IWorkbenchWindow ;
50
49
import org .eclipse .ui .PartInitException ;
50
+ import org .eclipse .ui .PlatformUI ;
51
51
import org .eclipse .ui .internal .CloseAllHandler ;
52
52
import org .eclipse .ui .internal .Workbench ;
53
53
import org .junit .Before ;
@@ -89,13 +89,13 @@ private MApplication getApplicationModel() {
89
89
* Tests the enabled when and execution logic within the
90
90
* {@link CloseAllHandler}.
91
91
*
92
- * Scenario 1: E4 style part contribution which is tagged as representing an
92
+ * Scenario 1: compatibility layer type editor is closed via the handler (and
93
+ * the enablement of handler is checked).
94
+ *
95
+ * Scenario 2: E4 style part contribution which is tagged as representing an
93
96
* 'editor' is closed via the handler (and the enablement of handler is
94
97
* checked).
95
98
*
96
- * Scenario 2: compatibility layer type editor is closed via the handler (and
97
- * the enablement of handler is checked).
98
- *
99
99
* Scenario 3: a mix of an open compatibility layer type editor *and* an E4
100
100
* style part contribution which is tagged as representing an 'editor' are both
101
101
* closed via the handler (and the enablement of handler is checked).
@@ -114,35 +114,11 @@ public void testCloseMixedEditorTypes() {
114
114
boolean canExecute = handlerService .canExecute (parameterizedCommand );
115
115
assertFalse (canExecute );
116
116
117
- // scenario 1: e4 part descriptor contribution
118
- MPartDescriptor partDescriptor = createDummyPartDescriptor ();
119
- application .getDescriptors ().add (partDescriptor );
120
-
121
- // open our e4 part which represents an editor
122
- MPart dummyPart = createAndOpenE4Part (partDescriptor );
123
-
124
- // verify the close all handler is enabled now (since dummy editor has been
125
- // opened)
126
- canExecute = handlerService .canExecute (parameterizedCommand );
127
- assertTrue (canExecute );
128
-
129
- // close all editors (dummy editor should close!)
130
- dummyPart = partService .findPart (DUMMY_E4_PART_ID );
131
- assertNotNull (dummyPart );
132
- handlerService .executeHandler (parameterizedCommand );
133
- dummyPart = partService .findPart (DUMMY_E4_PART_ID );
134
- assertNull (dummyPart );
135
-
136
- // verify the close all handler is *not* enabled now (since dummy editor has
137
- // been closed)
138
- canExecute = handlerService .canExecute (parameterizedCommand );
139
- assertFalse (canExecute );
140
-
141
117
// scenario 2: open a compatibility layer editor
118
+ IWorkbenchWindow window = PlatformUI .getWorkbench ().getActiveWorkbenchWindow ();
119
+ assertNotNull ("Active workbench window not found." , window );
120
+
142
121
IFileEditorInput input = new DummyFileEditorInput ();
143
- Object activeWindow = applicationContext .getActive (ISources .ACTIVE_WORKBENCH_WINDOW_NAME );
144
- assertTrue ("Active workbench window not found." , activeWindow instanceof IWorkbenchWindow );
145
- IWorkbenchWindow window = (IWorkbenchWindow ) activeWindow ;
146
122
try {
147
123
window .getActivePage ().openEditor (input , TEST_COMPATIBILITY_LAYER_EDITOR_ID );
148
124
} catch (PartInitException e ) {
@@ -165,6 +141,30 @@ public void testCloseMixedEditorTypes() {
165
141
canExecute = handlerService .canExecute (parameterizedCommand );
166
142
assertFalse (canExecute );
167
143
144
+ // scenario 1: e4 part descriptor contribution
145
+ MPartDescriptor partDescriptor = createDummyPartDescriptor ();
146
+ application .getDescriptors ().add (partDescriptor );
147
+
148
+ // open our e4 part which represents an editor
149
+ MPart dummyPart = createAndOpenE4Part (partDescriptor );
150
+
151
+ // verify the close all handler is enabled now (since dummy editor has been
152
+ // opened)
153
+ canExecute = handlerService .canExecute (parameterizedCommand );
154
+ assertTrue (canExecute );
155
+
156
+ // close all editors (dummy editor should close!)
157
+ dummyPart = partService .findPart (DUMMY_E4_PART_ID );
158
+ assertNotNull (dummyPart );
159
+ handlerService .executeHandler (parameterizedCommand );
160
+ dummyPart = partService .findPart (DUMMY_E4_PART_ID );
161
+ assertNull (dummyPart );
162
+
163
+ // verify the close all handler is *not* enabled now (since dummy editor has
164
+ // been closed)
165
+ canExecute = handlerService .canExecute (parameterizedCommand );
166
+ assertFalse (canExecute );
167
+
168
168
// scenario 3:
169
169
// finally: re-open both the compatibility layer editor *and* the dummy e4 part
170
170
// which represents an editor, and verify they are *both* closed when we invoked
0 commit comments