KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > product > ProductFromConfigOperation


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.wizards.product;
12
13 import org.eclipse.core.resources.IContainer;
14 import org.eclipse.core.resources.IFile;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.Path;
17 import org.eclipse.debug.core.ILaunchConfiguration;
18 import org.eclipse.pde.core.plugin.TargetPlatform;
19 import org.eclipse.pde.internal.core.iproduct.IConfigurationFileInfo;
20 import org.eclipse.pde.internal.core.iproduct.IProduct;
21 import org.eclipse.pde.internal.core.iproduct.IProductModelFactory;
22 import org.eclipse.pde.internal.ui.PDEPlugin;
23 import org.eclipse.pde.internal.ui.launcher.LaunchPluginValidator;
24 import org.eclipse.pde.ui.launcher.IPDELauncherConstants;
25
26
27 public class ProductFromConfigOperation extends BaseProductCreationOperation {
28
29     private ILaunchConfiguration fLaunchConfiguration;
30
31     public ProductFromConfigOperation(IFile file, ILaunchConfiguration config) {
32         super(file);
33         fLaunchConfiguration = config;
34     }
35     
36     /* (non-Javadoc)
37      * @see org.eclipse.pde.internal.ui.wizards.product.BaseProductCreationOperation#initializeProduct(org.eclipse.pde.internal.core.iproduct.IProduct)
38      */

39     protected void initializeProduct(IProduct product) {
40         if (fLaunchConfiguration == null)
41             return;
42         try {
43             IProductModelFactory factory = product.getModel().getFactory();
44             boolean useProduct = fLaunchConfiguration.getAttribute(IPDELauncherConstants.USE_PRODUCT, false);
45             if (useProduct) {
46                 String JavaDoc id = fLaunchConfiguration.getAttribute(IPDELauncherConstants.PRODUCT, (String JavaDoc)null);
47                 if (id != null) {
48                     initializeProductInfo(factory, product, id);
49                 }
50             } else {
51                 String JavaDoc appName = fLaunchConfiguration.getAttribute(IPDELauncherConstants.APPLICATION, TargetPlatform.getDefaultApplication());
52                 product.setApplication(appName);
53             }
54             addPlugins(factory, product, LaunchPluginValidator.getPluginList(fLaunchConfiguration));
55             if (fLaunchConfiguration.getAttribute(IPDELauncherConstants.CONFIG_GENERATE_DEFAULT, true)) {
56                 super.initializeProduct(product);
57             } else {
58                 String JavaDoc path = fLaunchConfiguration.getAttribute(IPDELauncherConstants.CONFIG_TEMPLATE_LOCATION, "/"); //$NON-NLS-1$
59
IContainer container = PDEPlugin.getWorkspace().getRoot().getContainerForLocation(new Path(path));
60                 if (container != null) {
61                     IConfigurationFileInfo info = factory.createConfigFileInfo();
62                     info.setUse("custom"); //$NON-NLS-1$
63
info.setPath(container.getFullPath().toString());
64                     product.setConfigurationFileInfo(info);
65                 } else {
66                     super.initializeProduct(product);
67                 }
68             }
69         } catch (CoreException e) {
70         }
71     }
72     
73 }
74
Popular Tags