1 /******************************************************************************* 2 * Copyright (c) 2000, 2006 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 *******************************************************************************/ 14 package org.eclipse.ui.tests.dialogs; 15 16 import org.eclipse.jface.dialogs.Dialog; 17 import org.eclipse.jface.dialogs.IDialogSettings; 18 import org.eclipse.jface.viewers.ISelection; 19 import org.eclipse.jface.viewers.IStructuredSelection; 20 import org.eclipse.jface.viewers.StructuredSelection; 21 import org.eclipse.jface.wizard.IWizardPage; 22 import org.eclipse.jface.wizard.WizardDialog; 23 import org.eclipse.swt.widgets.Shell; 24 import org.eclipse.ui.IWorkbench; 25 import org.eclipse.ui.PlatformUI; 26 import org.eclipse.ui.dialogs.WizardNewProjectReferencePage; 27 import org.eclipse.ui.internal.IWorkbenchHelpContextIds; 28 import org.eclipse.ui.internal.WorkbenchPlugin; 29 import org.eclipse.ui.internal.dialogs.ExportWizard; 30 import org.eclipse.ui.internal.dialogs.ImportWizard; 31 import org.eclipse.ui.internal.dialogs.NewWizard; 32 import org.eclipse.ui.internal.ide.IIDEHelpContextIds; 33 import org.eclipse.ui.internal.wizards.newresource.ResourceMessages; 34 import org.eclipse.ui.tests.harness.util.DialogCheck; 35 import org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard; 36 import org.eclipse.ui.wizards.newresource.BasicNewFolderResourceWizard; 37 import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard; 38 import org.junit.Ignore; 39 import org.junit.Test; 40 41 public class UIWizards { 42 private static final int SIZING_WIZARD_WIDTH = 470; 43 44 private static final int SIZING_WIZARD_HEIGHT = 550; 45 46 private static final int SIZING_WIZARD_WIDTH_2 = 500; 47 48 private static final int SIZING_WIZARD_HEIGHT_2 = 500; 49 getShell()50 private Shell getShell() { 51 return DialogCheck.getShell(); 52 } 53 getWorkbench()54 private IWorkbench getWorkbench() { 55 return PlatformUI.getWorkbench(); 56 } 57 exportWizard(IWizardPage page)58 private WizardDialog exportWizard(IWizardPage page) { 59 ExportWizard wizard = new ExportWizard(); 60 wizard.init(getWorkbench(), null); 61 IDialogSettings workbenchSettings = WorkbenchPlugin.getDefault() 62 .getDialogSettings(); 63 IDialogSettings wizardSettings = workbenchSettings 64 .getSection("ExportResourcesAction"); 65 if (wizardSettings == null) { 66 wizardSettings = workbenchSettings 67 .addNewSection("ExportResourcesAction"); 68 } 69 wizard.setDialogSettings(wizardSettings); 70 wizard.setForcePreviousAndNextButtons(true); 71 WizardDialog dialog = new WizardDialog(getShell(), wizard); 72 dialog.create(); 73 dialog.getShell().setSize( 74 Math.max(SIZING_WIZARD_WIDTH, dialog.getShell().getSize().x), 75 SIZING_WIZARD_HEIGHT); 76 PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), IWorkbenchHelpContextIds.EXPORT_WIZARD); 77 78 if (page != null) { 79 page.setWizard(wizard); 80 dialog.showPage(page); 81 } 82 return dialog; 83 } 84 importWizard(IWizardPage page)85 private WizardDialog importWizard(IWizardPage page) { 86 ImportWizard wizard = new ImportWizard(); 87 wizard.init(getWorkbench(), null); 88 IDialogSettings workbenchSettings = WorkbenchPlugin.getDefault() 89 .getDialogSettings(); 90 IDialogSettings wizardSettings = workbenchSettings 91 .getSection("ImportResourcesAction"); 92 if (wizardSettings == null) { 93 wizardSettings = workbenchSettings 94 .addNewSection("ImportResourcesAction"); 95 } 96 wizard.setDialogSettings(wizardSettings); 97 wizard.setForcePreviousAndNextButtons(true); 98 99 WizardDialog dialog = new WizardDialog(getShell(), wizard); 100 dialog.create(); 101 dialog.getShell().setSize( 102 Math.max(SIZING_WIZARD_WIDTH, dialog.getShell().getSize().x), 103 SIZING_WIZARD_HEIGHT); 104 PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), IWorkbenchHelpContextIds.IMPORT_WIZARD); 105 106 if (page != null) { 107 page.setWizard(wizard); 108 dialog.showPage(page); 109 } 110 return dialog; 111 } 112 113 @Test testExportResources()114 public void testExportResources() {//reference: ExportResourcesAction 115 Dialog dialog = exportWizard(null); 116 DialogCheck.assertDialog(dialog); 117 } 118 119 /** 120 * 1GJWD2E: ITPUI:ALL - Test classes should not be released in public packages. 121 */ 122 @Test 123 @Ignore("1GJWD2E: ITPUI:ALL") testFileSystemExport()124 public void testFileSystemExport() { 125 // Dialog dialog = exportWizard(DataTransferTestStub.newFileSystemResourceExportPage1(null)); 126 // DialogCheck.assertDialog(dialog); 127 } 128 129 @Test 130 @Ignore("1GJWD2E: ITPUI:ALL") testZipFileExport()131 public void testZipFileExport() { 132 // Dialog dialog = exportWizard(DataTransferTestStub.newZipFileResourceExportPage1(null)); 133 // DialogCheck.assertDialog(dialog); 134 } 135 136 @Test testImportResources()137 public void testImportResources() {//reference: ImportResourcesAction 138 Dialog dialog = importWizard(null); 139 DialogCheck.assertDialog(dialog); 140 } 141 142 /** 143 * 1GJWD2E: ITPUI:ALL - Test classes should not be released in public packages. 144 */ 145 @Test 146 @Ignore("1GJWD2E: ITPUI:ALL") testFileSystemImport()147 public void testFileSystemImport() { 148 // Dialog dialog = importWizard(DataTransferTestStub.newFileSystemResourceImportPage1( 149 // WorkbenchPlugin.getDefault().getWorkbench(), StructuredSelection.EMPTY)); 150 // DialogCheck.assertDialog(dialog); 151 } 152 153 @Test 154 @Ignore("1GJWD2E: ITPUI:ALL") testZipFileImport()155 public void testZipFileImport() { 156 // Dialog dialog = importWizard(DataTransferTestStub.newZipFileResourceImportPage1(null)); 157 // DialogCheck.assertDialog(dialog); 158 } 159 160 @Test testNewFile()161 public void testNewFile() { 162 BasicNewFileResourceWizard wizard = new BasicNewFileResourceWizard(); 163 wizard.init(PlatformUI.getWorkbench(), new StructuredSelection()); 164 wizard.setNeedsProgressMonitor(true); 165 WizardDialog dialog = new WizardDialog(getShell(), wizard); 166 dialog.create(); 167 dialog.getShell().setText("CreateFileAction_title"); 168 PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), 169 IIDEHelpContextIds.NEW_FILE_WIZARD); 170 DialogCheck.assertDialog(dialog); 171 } 172 173 @Test testNewFolder()174 public void testNewFolder() { 175 BasicNewFolderResourceWizard wizard = new BasicNewFolderResourceWizard(); 176 wizard.init(PlatformUI.getWorkbench(), new StructuredSelection()); 177 wizard.setNeedsProgressMonitor(true); 178 WizardDialog dialog = new WizardDialog(getShell(), wizard); 179 dialog.create(); 180 dialog.getShell().setText("CreateFolderAction_title"); 181 PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), 182 IIDEHelpContextIds.NEW_FOLDER_WIZARD); 183 DialogCheck.assertDialog(dialog); 184 } 185 186 @Test testNewProjectPage1()187 public void testNewProjectPage1() { 188 BasicNewProjectResourceWizard wizard = new BasicNewProjectResourceWizard(); 189 wizard.init(PlatformUI.getWorkbench(), null); 190 wizard.setNeedsProgressMonitor(true); 191 192 WizardDialog dialog = new WizardDialog(getShell(), wizard); 193 dialog.create(); 194 dialog.getShell().setSize( 195 Math.max(SIZING_WIZARD_WIDTH_2, dialog.getShell().getSize().x), 196 SIZING_WIZARD_HEIGHT_2); 197 dialog.getShell().setText("CreateFileAction_title"); 198 PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), 199 IIDEHelpContextIds.NEW_PROJECT_WIZARD); 200 DialogCheck.assertDialog(dialog); 201 } 202 203 @Test testNewProjectPage2()204 public void testNewProjectPage2() { 205 BasicNewProjectResourceWizard wizard = new BasicNewProjectResourceWizard(); 206 wizard.init(PlatformUI.getWorkbench(), null); 207 wizard.setNeedsProgressMonitor(true); 208 209 WizardNewProjectReferencePage page = new WizardNewProjectReferencePage( 210 "basicReferenceProjectPage");//$NON-NLS-1$ 211 page.setTitle(ResourceMessages.NewProject_referenceTitle); 212 page.setDescription(ResourceMessages.NewProject_referenceDescription); 213 page.setWizard(wizard); 214 215 WizardDialog dialog = new WizardDialog(getShell(), wizard); 216 dialog.create(); 217 dialog.getShell().setSize( 218 Math.max(SIZING_WIZARD_WIDTH_2, dialog.getShell().getSize().x), 219 SIZING_WIZARD_HEIGHT_2); 220 dialog.getShell().setText("CreateFileAction_title"); 221 dialog.showPage(page); 222 PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), 223 IIDEHelpContextIds.NEW_PROJECT_WIZARD); 224 DialogCheck.assertDialog(dialog); 225 } 226 227 @Test testNewProject()228 public void testNewProject() { 229 // Create wizard selection wizard. 230 NewWizard wizard = new NewWizard(); 231 wizard.setProjectsOnly(true); 232 ISelection selection = getWorkbench().getActiveWorkbenchWindow() 233 .getSelectionService().getSelection(); 234 IStructuredSelection selectionToPass = null; 235 if (selection instanceof IStructuredSelection) { 236 selectionToPass = (IStructuredSelection) selection; 237 } else { 238 selectionToPass = StructuredSelection.EMPTY; 239 } 240 wizard.init(getWorkbench(), selectionToPass); 241 IDialogSettings workbenchSettings = WorkbenchPlugin.getDefault() 242 .getDialogSettings(); 243 IDialogSettings wizardSettings = workbenchSettings 244 .getSection("NewWizardAction");//$NON-NLS-1$ 245 if (wizardSettings == null) 246 { 247 wizardSettings = workbenchSettings.addNewSection("NewWizardAction");//$NON-NLS-1$ 248 } 249 wizard.setDialogSettings(wizardSettings); 250 wizard.setForcePreviousAndNextButtons(true); 251 252 // Create wizard dialog. 253 WizardDialog dialog = new WizardDialog(getShell(), wizard); 254 dialog.create(); 255 dialog.getShell().setSize( 256 Math.max(SIZING_WIZARD_WIDTH_2, dialog.getShell().getSize().x), 257 SIZING_WIZARD_HEIGHT_2); 258 PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), 259 IIDEHelpContextIds.NEW_PROJECT_WIZARD); 260 DialogCheck.assertDialog(dialog); 261 } 262 263 @Test testNewResource()264 public void testNewResource() { 265 NewWizard wizard = new NewWizard(); 266 ISelection selection = getWorkbench().getActiveWorkbenchWindow() 267 .getSelectionService().getSelection(); 268 IStructuredSelection selectionToPass = null; 269 if (selection instanceof IStructuredSelection) { 270 selectionToPass = (IStructuredSelection) selection; 271 } else { 272 selectionToPass = StructuredSelection.EMPTY; 273 } 274 wizard.init(getWorkbench(), selectionToPass); 275 IDialogSettings workbenchSettings = WorkbenchPlugin.getDefault() 276 .getDialogSettings(); 277 IDialogSettings wizardSettings = workbenchSettings 278 .getSection("NewWizardAction");//$NON-NLS-1$ 279 if (wizardSettings == null) 280 { 281 wizardSettings = workbenchSettings.addNewSection("NewWizardAction");//$NON-NLS-1$ 282 } 283 wizard.setDialogSettings(wizardSettings); 284 wizard.setForcePreviousAndNextButtons(true); 285 286 WizardDialog dialog = new WizardDialog(getShell(), wizard); 287 dialog.create(); 288 dialog.getShell().setSize( 289 Math.max(SIZING_WIZARD_WIDTH_2, dialog.getShell().getSize().x), 290 SIZING_WIZARD_HEIGHT_2); 291 PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), IWorkbenchHelpContextIds.NEW_WIZARD); 292 DialogCheck.assertDialog(dialog); 293 } 294 } 295 296