blob: 4fea3ff5b9fc107a9a6a378764fda2ece6f2c3aa [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2000, 2015 IBM Corporation 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:
* IBM Corporation - initial API and implementation
* Remy Chi Jian Suen <remy.suen@gmail.com>
* - Bug 44162 [Wizards] Define constants for wizard ids of new.file, new.folder, and new.project
* Christian Pontesegger
* - copied from org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard, modified addPages()
*******************************************************************************/
package org.eclipse.ease.lang.unittest.ui.wizards;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.internal.ide.DialogUtil;
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
import org.eclipse.ui.internal.wizards.newresource.ResourceMessages;
import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
/**
* Wizard that creates a new testsuite file resource in the workspace.
* <p>
* During the call to <code>open</code>, the wizard dialog is presented to the user. When the user hits Finish, a file resource at the user-specified workspace
* path is created, the dialog closes, and the call to <code>open</code> returns.
* </p>
*
*/
public class TestSuiteWizard extends BasicNewResourceWizard {
/**
* The wizard id for creating new testsuites in the workspace.
*/
public static final String WIZARD_ID = "org.eclipse.ease.lang.unittest.ui.wizard.newTestSuiteWizard"; //$NON-NLS-1$
private WizardNewFileCreationPage mainPage;
/**
* Creates a wizard for creating a new file resource in the workspace.
*/
public TestSuiteWizard() {
super();
}
/*
* (non-Javadoc) Method declared on IWizard.
*/
@Override
public void addPages() {
super.addPages();
mainPage = new TestSuiteCreationPage("newFilePage1", getSelection());//$NON-NLS-1$
mainPage.setTitle("Script Testsuite");
mainPage.setDescription("This wizard creates a new script testsuite.");
mainPage.setFileName("Testsuite.suite");
mainPage.setAllowExistingResources(false);
mainPage.setFileExtension("suite");
addPage(mainPage);
}
/*
* (non-Javadoc) Method declared on IWorkbenchWizard.
*/
@Override
public void init(final IWorkbench workbench, final IStructuredSelection currentSelection) {
super.init(workbench, currentSelection);
setWindowTitle(ResourceMessages.FileResource_shellTitle);
setNeedsProgressMonitor(true);
}
@Override
protected void initializeDefaultPageImageDescriptor() {
final ImageDescriptor desc = IDEWorkbenchPlugin.getIDEImageDescriptor("wizban/newfile_wiz.png");//$NON-NLS-1$
setDefaultPageImageDescriptor(desc);
}
/*
* (non-Javadoc) Method declared on IWizard.
*/
@Override
public boolean performFinish() {
final IFile file = mainPage.createNewFile();
if (file == null) {
return false;
}
selectAndReveal(file);
// Open editor on new file.
final IWorkbenchWindow dw = getWorkbench().getActiveWorkbenchWindow();
try {
if (dw != null) {
final IWorkbenchPage page = dw.getActivePage();
if (page != null) {
IDE.openEditor(page, file, true);
}
}
} catch (final PartInitException e) {
DialogUtil.openError(dw.getShell(), ResourceMessages.FileResource_errorMessage, e.getMessage(), e);
}
return true;
}
}