| /******************************************************************************* |
| * Copyright (c) 2012, 2017 NumberFour AG and others. |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * NumberFour AG - initial API and Implementation (Alex Panchenko) |
| *******************************************************************************/ |
| package org.eclipse.dltk.ui.tests; |
| |
| import org.eclipse.swt.widgets.Display; |
| import org.eclipse.ui.IEditorPart; |
| import org.eclipse.ui.IEditorReference; |
| import org.eclipse.ui.IWorkbenchPage; |
| import org.eclipse.ui.IWorkbenchPartSite; |
| import org.eclipse.ui.IWorkbenchWindow; |
| import org.eclipse.ui.PlatformUI; |
| import org.eclipse.ui.intro.IIntroManager; |
| import org.eclipse.ui.intro.IIntroPart; |
| |
| public class UITestUtils { |
| |
| private static void closeEditor(IEditorPart editor) { |
| IWorkbenchPartSite site; |
| IWorkbenchPage page; |
| if (editor != null && (site = editor.getSite()) != null |
| && (page = site.getPage()) != null) |
| page.closeEditor(editor, false); |
| } |
| |
| public static void closeAllEditors() { |
| IWorkbenchWindow[] windows = PlatformUI.getWorkbench() |
| .getWorkbenchWindows(); |
| for (int i = 0; i < windows.length; i++) { |
| IWorkbenchPage[] pages = windows[i].getPages(); |
| for (int j = 0; j < pages.length; j++) { |
| IEditorReference[] editorReferences = pages[j] |
| .getEditorReferences(); |
| for (int k = 0; k < editorReferences.length; k++) |
| closeEditor(editorReferences[k].getEditor(false)); |
| } |
| } |
| } |
| |
| public static void closeIntro() { |
| final IIntroManager introManager = PlatformUI.getWorkbench() |
| .getIntroManager(); |
| final IIntroPart part = introManager.getIntro(); |
| if (part != null) { |
| introManager.closeIntro(part); |
| } |
| } |
| |
| public static void processEvents() { |
| final Display display = Display.getCurrent(); |
| while (!display.isDisposed() && display.readAndDispatch()) { |
| } |
| } |
| |
| } |