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  *     EclipseSource Corporation - ongoing enhancements
14  *******************************************************************************/
15 package org.eclipse.pde.internal.ui.wizards.product;
16 
17 import java.lang.reflect.InvocationTargetException;
18 import org.eclipse.jface.dialogs.MessageDialog;
19 import org.eclipse.jface.wizard.Wizard;
20 import org.eclipse.pde.internal.core.iproduct.IProduct;
21 import org.eclipse.pde.internal.ui.PDEPluginImages;
22 import org.eclipse.pde.internal.ui.PDEUIMessages;
23 
24 public class ProductIntroWizard extends Wizard {
25 
26 	private ProductDefinitonWizardPage fProductDefinitionPage;
27 	private ProductIntroWizardPage fNewIntroPage;
28 	private boolean fNeedNewProduct;
29 	private String fIntroId;
30 	private String fProductId;
31 	private String fPluginId;
32 	private String fApplication;
33 	private IProduct fProduct;
34 
ProductIntroWizard(IProduct product, boolean needNewProduct)35 	public ProductIntroWizard(IProduct product, boolean needNewProduct) {
36 		setDefaultPageImageDescriptor(PDEPluginImages.DESC_DEFCON_WIZ);
37 		setNeedsProgressMonitor(true);
38 		fProduct = product;
39 		fNeedNewProduct = needNewProduct;
40 		setWindowTitle(PDEUIMessages.ProductIntroWizard_title);
41 	}
42 
43 	@Override
addPages()44 	public void addPages() {
45 		if (fNeedNewProduct) {
46 			fProductDefinitionPage = new ProductDefinitonWizardPage("product", fProduct); //$NON-NLS-1$
47 			addPage(fProductDefinitionPage);
48 		}
49 		fNewIntroPage = new ProductIntroWizardPage("intro", fProduct); //$NON-NLS-1$
50 		addPage(fNewIntroPage);
51 	}
52 
53 	@Override
performFinish()54 	public boolean performFinish() {
55 		try {
56 			if (fNeedNewProduct) {
57 				fProductId = fProductDefinitionPage.getProductId();
58 				fPluginId = fProductDefinitionPage.getDefiningPlugin();
59 				fApplication = fProductDefinitionPage.getApplication();
60 				String newProductName = fProductDefinitionPage.getProductName();
61 				if (newProductName != null)
62 					fProduct.setName(newProductName);
63 				fProduct.setProductId(getProductId());
64 				fProduct.setApplication(fApplication);
65 				getContainer().run(false, true, new ProductDefinitionOperation(fProduct, fPluginId, fProductId, fApplication, getContainer().getShell()));
66 			}
67 
68 			fIntroId = fNewIntroPage.getIntroId();
69 			if (fPluginId == null)
70 				fPluginId = fNewIntroPage.getDefiningPlugin();
71 			getContainer().run(false, true, new ProductIntroOperation(fProduct, fPluginId, fIntroId, getContainer().getShell()));
72 		} catch (InvocationTargetException e) {
73 			MessageDialog.openError(getContainer().getShell(), PDEUIMessages.ProductDefinitionWizard_error, e.getTargetException().getMessage());
74 			return false;
75 		} catch (InterruptedException e) {
76 			return false;
77 		}
78 		return true;
79 	}
80 
getIntroId()81 	public String getIntroId() {
82 		return fIntroId;
83 	}
84 
getProductId()85 	public String getProductId() {
86 		return fPluginId + "." + fProductId; //$NON-NLS-1$
87 	}
88 
getApplication()89 	public String getApplication() {
90 		return fApplication;
91 	}
92 
93 }
94