4545import org .eclipse .ui .IFileEditorInput ;
4646import org .eclipse .ui .IPageLayout ;
4747import org .eclipse .ui .IPersistableElement ;
48- import org .eclipse .ui .ISources ;
4948import org .eclipse .ui .IWorkbenchWindow ;
5049import org .eclipse .ui .PartInitException ;
50+ import org .eclipse .ui .PlatformUI ;
5151import org .eclipse .ui .internal .CloseAllHandler ;
5252import org .eclipse .ui .internal .Workbench ;
5353import org .junit .Before ;
@@ -89,13 +89,13 @@ private MApplication getApplicationModel() {
8989 * Tests the enabled when and execution logic within the
9090 * {@link CloseAllHandler}.
9191 *
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
9396 * 'editor' is closed via the handler (and the enablement of handler is
9497 * checked).
9598 *
96- * Scenario 2: compatibility layer type editor is closed via the handler (and
97- * the enablement of handler is checked).
98- *
9999 * Scenario 3: a mix of an open compatibility layer type editor *and* an E4
100100 * style part contribution which is tagged as representing an 'editor' are both
101101 * closed via the handler (and the enablement of handler is checked).
@@ -114,35 +114,11 @@ public void testCloseMixedEditorTypes() {
114114 boolean canExecute = handlerService .canExecute (parameterizedCommand );
115115 assertFalse (canExecute );
116116
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-
141117 // scenario 2: open a compatibility layer editor
118+ IWorkbenchWindow window = PlatformUI .getWorkbench ().getActiveWorkbenchWindow ();
119+ assertNotNull ("Active workbench window not found." , window );
120+
142121 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 ;
146122 try {
147123 window .getActivePage ().openEditor (input , TEST_COMPATIBILITY_LAYER_EDITOR_ID );
148124 } catch (PartInitException e ) {
@@ -165,6 +141,30 @@ public void testCloseMixedEditorTypes() {
165141 canExecute = handlerService .canExecute (parameterizedCommand );
166142 assertFalse (canExecute );
167143
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+
168168 // scenario 3:
169169 // finally: re-open both the compatibility layer editor *and* the dummy e4 part
170170 // which represents an editor, and verify they are *both* closed when we invoked
0 commit comments