1 /*******************************************************************************
2  *  Copyright (c) 2005, 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  *******************************************************************************/
14 package org.eclipse.pde.internal.ui.wizards.product;
15 
16 import java.lang.reflect.InvocationTargetException;
17 import org.eclipse.core.resources.IFile;
18 import org.eclipse.jface.operation.IRunnableWithProgress;
19 import org.eclipse.jface.viewers.IStructuredSelection;
20 import org.eclipse.pde.internal.ui.*;
21 import org.eclipse.ui.IWorkbench;
22 import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
23 
24 public class NewProductFileWizard extends BasicNewResourceWizard {
25 
26 	private ProductFileWizardPage fMainPage;
27 
28 	@Override
addPages()29 	public void addPages() {
30 		fMainPage = new ProductFileWizardPage("product", getSelection()); //$NON-NLS-1$
31 		addPage(fMainPage);
32 	}
33 
34 	@Override
performFinish()35 	public boolean performFinish() {
36 		try {
37 			getContainer().run(false, true, getOperation());
38 		} catch (InvocationTargetException e) {
39 			PDEPlugin.logException(e);
40 			return false;
41 		} catch (InterruptedException e) {
42 			return false;
43 		}
44 		return true;
45 	}
46 
getOperation()47 	private IRunnableWithProgress getOperation() {
48 		IFile file = fMainPage.createNewFile();
49 		int option = fMainPage.getInitializationOption();
50 		if (option == ProductFileWizardPage.USE_LAUNCH_CONFIG)
51 			return new ProductFromConfigOperation(file, fMainPage.getSelectedLaunchConfiguration());
52 		if (option == ProductFileWizardPage.USE_PRODUCT)
53 			return new ProductFromExtensionOperation(file, fMainPage.getSelectedProduct());
54 		return new BaseProductCreationOperation(file);
55 	}
56 
57 	@Override
init(IWorkbench workbench, IStructuredSelection currentSelection)58 	public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
59 		super.init(workbench, currentSelection);
60 		setWindowTitle(PDEUIMessages.NewProductFileWizard_windowTitle);
61 		setNeedsProgressMonitor(true);
62 	}
63 
64 	@Override
initializeDefaultPageImageDescriptor()65 	protected void initializeDefaultPageImageDescriptor() {
66 		setDefaultPageImageDescriptor(PDEPluginImages.DESC_PRODUCT_WIZ);
67 	}
68 
69 }
70