KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Set JavaDoc;
14
15 import org.eclipse.core.resources.IFile;
16 import org.eclipse.pde.core.plugin.IPluginAttribute;
17 import org.eclipse.pde.core.plugin.IPluginElement;
18 import org.eclipse.pde.core.plugin.IPluginModelBase;
19 import org.eclipse.pde.core.plugin.PluginRegistry;
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.search.dependencies.DependencyCalculator;
23
24
25 public class ProductFromExtensionOperation extends BaseProductCreationOperation {
26     
27     private String JavaDoc fId;
28
29     public ProductFromExtensionOperation(IFile file, String JavaDoc productId) {
30         super(file);
31         fId = productId;
32     }
33     
34     /* (non-Javadoc)
35      * @see org.eclipse.pde.internal.ui.wizards.product.BaseProductCreationOperation#initializeProduct(org.eclipse.pde.internal.core.iproduct.IProduct)
36      */

37     protected void initializeProduct(IProduct product) {
38         if (fId == null)
39             return;
40         IProductModelFactory factory = product.getModel().getFactory();
41         initializeProductInfo(factory, product, fId);
42         addPlugins(factory, product, getPlugins());
43         super.initializeProduct(product);
44     }
45     
46     private String JavaDoc[] getPlugins() {
47         int lastDot = fId.lastIndexOf('.');
48         if (lastDot == -1)
49             return new String JavaDoc[0];
50         
51         DependencyCalculator calculator = new DependencyCalculator(false);
52         // add plugin declaring product and its pre-reqs
53
IPluginModelBase model = PluginRegistry.findModel(fId.substring(0, lastDot));
54         if (model != null)
55             calculator.findDependency(model);
56         
57         // add plugin declaring product application and its pre-reqs
58
IPluginElement element = getProductExtension(fId);
59         if (element != null) {
60             IPluginAttribute attr = element.getAttribute("application"); //$NON-NLS-1$
61
if (attr != null) {
62                 String JavaDoc appId = attr.getValue();
63                 lastDot = appId.lastIndexOf('.');
64                 if (lastDot != -1) {
65                     model = PluginRegistry.findModel(appId.substring(0, lastDot));
66                     if (model != null) {
67                         calculator.findDependency(model);
68                     }
69                 }
70             }
71         }
72         Set JavaDoc ids = calculator.getBundleIDs();
73         return (String JavaDoc[])ids.toArray(new String JavaDoc[ids.size()]);
74     }
75
76 }
77
Popular Tags