1 /*******************************************************************************
2  * Copyright (c) 2000, 2015 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *     Simon Scholz <simon.scholz@vogella.com> - Bug 448060
14  *     Lars Vogel <Lars.Vogel@vogella.com> - Bug 430988
15  *     Simon Scholz <simon.scholz@vogella.com> - Bug 455527
16  *******************************************************************************/
17 package org.eclipse.ui.tests.dialogs;
18 
19 import org.eclipse.core.resources.IProject;
20 import org.eclipse.core.resources.ResourcesPlugin;
21 import org.eclipse.e4.core.contexts.IEclipseContext;
22 import org.eclipse.e4.ui.model.application.MApplication;
23 import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
24 import org.eclipse.e4.ui.workbench.modeling.EModelService;
25 import org.eclipse.e4.ui.workbench.modeling.EPartService;
26 import org.eclipse.jface.dialogs.Dialog;
27 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
28 import org.eclipse.jface.viewers.ArrayContentProvider;
29 import org.eclipse.jface.viewers.LabelProvider;
30 import org.eclipse.swt.widgets.Shell;
31 import org.eclipse.ui.IPerspectiveDescriptor;
32 import org.eclipse.ui.IWorkbench;
33 import org.eclipse.ui.PlatformUI;
34 import org.eclipse.ui.dialogs.ContainerSelectionDialog;
35 import org.eclipse.ui.dialogs.EditorSelectionDialog;
36 import org.eclipse.ui.dialogs.ListSelectionDialog;
37 import org.eclipse.ui.dialogs.ProjectLocationSelectionDialog;
38 import org.eclipse.ui.dialogs.SaveAsDialog;
39 import org.eclipse.ui.dialogs.TypeFilteringDialog;
40 import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
41 import org.eclipse.ui.internal.WorkbenchMessages;
42 import org.eclipse.ui.internal.WorkbenchPlugin;
43 import org.eclipse.ui.internal.dialogs.AboutDialog;
44 import org.eclipse.ui.internal.dialogs.AboutPluginsDialog;
45 import org.eclipse.ui.internal.dialogs.FileExtensionDialog;
46 import org.eclipse.ui.internal.dialogs.SavePerspectiveDialog;
47 import org.eclipse.ui.internal.dialogs.SelectPerspectiveDialog;
48 import org.eclipse.ui.internal.dialogs.ShowViewDialog;
49 import org.eclipse.ui.internal.registry.PerspectiveRegistry;
50 import org.eclipse.ui.internal.views.navigator.ResourceNavigatorMessages;
51 import org.eclipse.ui.tests.harness.util.DialogCheck;
52 import org.junit.Ignore;
53 import org.junit.Test;
54 import org.osgi.framework.Bundle;
55 
56 public class UIDialogsAuto {
57 	private static final String PROJECT_SELECTION_MESSAGE ="Select Other Projects";
58 
59 	private static final String FILTER_SELECTION_MESSAGE = ResourceNavigatorMessages.FilterSelection_message;
60 
getShell()61 	private Shell getShell() {
62 		return DialogCheck.getShell();
63 	}
64 
getWorkbench()65 	private IWorkbench getWorkbench() {
66 		return PlatformUI.getWorkbench();
67 	}
68 
69 	@Test
testAbout()70 	public void testAbout() {
71 		Dialog dialog = null;
72 		dialog = new AboutDialog(getShell());
73 		DialogCheck.assertDialogTexts(dialog);
74 	}
75 
76 	@Test
testAboutPlugins()77 	public void testAboutPlugins() {
78 		Dialog dialog = null;
79 		dialog = new AboutPluginsDialog(
80 				getShell(),
81 				"",
82 				new Bundle [] {WorkbenchPlugin.getDefault().getBundle() },
83 				WorkbenchMessages.AboutFeaturesDialog_pluginInfoTitle,
84 				"Title",
85 				IWorkbenchHelpContextIds.ABOUT_FEATURES_PLUGINS_DIALOG);
86 		DialogCheck.assertDialogTexts(dialog);
87 	}
88 
89 	@Test
testAddProjects()90 	public void testAddProjects() {
91 		Dialog dialog = new ListSelectionDialog(getShell(), null, ArrayContentProvider.getInstance(),
92 				new LabelProvider(), PROJECT_SELECTION_MESSAGE);
93 		DialogCheck.assertDialogTexts(dialog);
94 	}
95 
96 	@Test
testCopyMoveProject()97 	public void testCopyMoveProject() {
98 		IProject dummyProject = ResourcesPlugin.getWorkspace().getRoot()
99 				.getProject("DummyProject");
100 		Dialog dialog = new ProjectLocationSelectionDialog(getShell(),
101 				dummyProject);
102 		DialogCheck.assertDialogTexts(dialog);
103 	}
104 
105 	@Test
testCopyMoveResource()106 	public void testCopyMoveResource() {
107 		Dialog dialog = new ContainerSelectionDialog(getShell(), null, true,
108 				"Copy Resources");
109 		DialogCheck.assertDialogTexts(dialog);
110 	}
111 
112 	@Test
testEditActionSetsDialog()113 	public void testEditActionSetsDialog() {
114 		// @issue need to uncomment this once customize persp dialog fixed up
115 		/*
116 		 * Dialog dialog; Perspective persp = null; //Test perspective: use
117 		 * current perspective of test case try {//fixme: should try to get
118 		 * current perspective, or default; currently only //gets first
119 		 * perspective in the registry. persp = new
120 		 * Perspective((PerspectiveDescriptor)getWorkbench().getPerspectiveRegistry().getPerspectives()[0],
121 		 * (WorkbenchPage)getWorkbench().getActiveWorkbenchWindow().getActivePage() );
122 		 * dialog = new CustomizePerspectiveDialog(getShell(), persp); } catch
123 		 * (WorkbenchException e) { dialog = null; }
124 		 * DialogCheck.assertDialogTexts(dialog); if (persp != null) {
125 		 * persp.dispose(); }
126 		 */
127 	}
128 
129 	@Test
testEditorSelection()130 	public void testEditorSelection() {
131 		Dialog dialog = new EditorSelectionDialog(getShell());
132 		DialogCheck.assertDialogTexts(dialog);
133 	}
134 
135 	/**
136 	 * 1GJWD2E: ITPUI:ALL - Test classes should not be released in public packages.
137 	 */
138 	@Test
139 	@Ignore("1GJWD2E: ITPUI:ALL")
testFindReplace()140 	public void testFindReplace() {
141 //		Dialog dialog = TextEditorTestStub.newFindReplaceDialog(getShell());
142 //		DialogCheck.assertDialogTexts(dialog);
143 	}
144 
145 	@Test
146 	@Ignore("1GJWD2E: ITPUI:ALL")
testGotoResource()147 	public void testGotoResource() {
148 //		Dialog dialog = NavigatorTestStub.newGotoResourceDialog(getShell(), new IResource[0]);
149 //		DialogCheck.assertDialogTexts(dialog);
150 	}
151 
152 	@Test
testNavigatorFilter()153 	public void testNavigatorFilter() {
154 		Dialog dialog = new ListSelectionDialog(getShell(), null, ArrayContentProvider.getInstance(),
155 				new LabelProvider(), FILTER_SELECTION_MESSAGE);
156 		DialogCheck.assertDialogTexts(dialog);
157 	}
158 
159 	@Test
testNewFileType()160 	public void testNewFileType() {
161 		Dialog dialog = new FileExtensionDialog(getShell());
162 		DialogCheck.assertDialogTexts(dialog);
163 	}
164 
165 	@Test
testProgressInformation()166 	public void testProgressInformation() {
167 		ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
168 		dialog.setBlockOnOpen(true);
169 		DialogCheck.assertDialogTexts(dialog);
170 	}
171 
172 	@Test
testSaveAs()173 	public void testSaveAs() {
174 		Dialog dialog = new SaveAsDialog(getShell());
175 		DialogCheck.assertDialogTexts(dialog);
176 	}
177 
178 	@Test
testSavePerspective()179 	public void testSavePerspective() {
180 		PerspectiveRegistry reg = (PerspectiveRegistry) WorkbenchPlugin
181 				.getDefault().getPerspectiveRegistry();
182 		// Get persp name.
183 		SavePerspectiveDialog dialog = new SavePerspectiveDialog(getShell(),
184 				reg);
185 		IPerspectiveDescriptor description = reg
186 				.findPerspectiveWithId(getWorkbench()
187 						.getActiveWorkbenchWindow().getActivePage()
188 						.getPerspective().getId());
189 		dialog.setInitialSelection(description);
190 		DialogCheck.assertDialogTexts(dialog);
191 	}
192 
193 	@Test
testSelectPerspective()194 	public void testSelectPerspective() {
195 		Dialog dialog = new SelectPerspectiveDialog(getShell(), PlatformUI
196 				.getWorkbench().getPerspectiveRegistry());
197 		DialogCheck.assertDialogTexts(dialog);
198 	}
199 
200 	@Test
testSelectTypes()201 	public void testSelectTypes() {
202 		Dialog dialog = new TypeFilteringDialog(getShell(), null);
203 		DialogCheck.assertDialogTexts(dialog);
204 	}
205 
206 	@Test
testShowView()207 	public void testShowView() {
208 		IWorkbench workbench = getWorkbench();
209 
210 		Shell shell = workbench.getActiveWorkbenchWindow().getShell();
211 		// Get the view identifier, if any.
212 		IEclipseContext ctx = workbench.getService(IEclipseContext.class);
213 		EModelService modelService = workbench.getService(EModelService.class);
214 		EPartService partService = workbench.getService(EPartService.class);
215 		MApplication app = workbench.getService(MApplication.class);
216 		MWindow window = workbench.getService(MWindow.class);
217 		Dialog dialog = new ShowViewDialog(shell, app, window, modelService, partService, ctx);
218 		DialogCheck.assertDialogTexts(dialog);
219 	}
220 
221 	/**
222 	 * 1GJWD2E: ITPUI:ALL - Test classes should not be released in public packages.
223 	 */
224 	@Test
225 	@Ignore("1GJWD2E: ITPUI:ALL")
testTaskFilters()226 	public void testTaskFilters() {
227 //		Dialog dialog = TaskListTestStub.newFiltersDialog(getShell());
228 //		DialogCheck.assertDialogTexts(dialog);
229 	}
230 
231 }
232