KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > feature > NewFeatureRequireWizardPage


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

11 package org.eclipse.pde.internal.ui.editor.feature;
12
13 import java.util.ArrayList JavaDoc;
14 import org.eclipse.core.runtime.*;
15 import org.eclipse.pde.core.plugin.*;
16 import org.eclipse.pde.internal.core.feature.*;
17 import org.eclipse.pde.internal.core.ifeature.*;
18 import org.eclipse.pde.internal.ui.*;
19 import org.eclipse.swt.widgets.*;
20 import org.eclipse.ui.help.*;
21
22 public class NewFeatureRequireWizardPage extends ReferenceWizardPage {
23     public static final String JavaDoc KEY_TITLE = "FeatureEditor.RequiresSection.newPlugin.title"; //$NON-NLS-1$
24
public static final String JavaDoc KEY_DESC = "FeatureEditor.RequiresSection.newPlugin.desc"; //$NON-NLS-1$
25
public static final String JavaDoc KEY_ADDING = "FeatureEditor.RequiresSection.newPlugin.adding"; //$NON-NLS-1$
26
public static final String JavaDoc KEY_UPDATING =
27         "FeatureEditor.RequiresSection.newPlugin.updating"; //$NON-NLS-1$
28

29     public NewFeatureRequireWizardPage(IFeatureModel model) {
30         super(model, true);
31         setTitle(PDEPlugin.getResourceString(KEY_TITLE));
32         setDescription(PDEPlugin.getResourceString(KEY_DESC));
33     }
34     
35     protected boolean isOnTheList(IPluginModelBase candidate) {
36         IPluginBase plugin = candidate.getPluginBase();
37         if (candidate.isFragmentModel()) return true;
38         IFeatureImport[] imports = model.getFeature().getImports();
39
40         for (int i = 0; i < imports.length; i++) {
41             IFeatureImport fimport = imports[i];
42             if (plugin.getId().equals(fimport.getId()))
43                 return true;
44         }
45         // don't show plug-ins that are listed in this feature
46
IFeaturePlugin [] fplugins = model.getFeature().getPlugins();
47         for (int i=0; i<fplugins.length; i++) {
48             IFeaturePlugin fplugin = fplugins[i];
49             if (plugin.getId().equals(fplugin.getId()))
50                 return true;
51         }
52         return false;
53     }
54
55     protected void doAdd(Object JavaDoc [] candidates, IProgressMonitor monitor) throws CoreException {
56         monitor.beginTask(
57             PDEPlugin.getResourceString(KEY_ADDING),
58             candidates.length + 1);
59         IFeature feature = model.getFeature();
60         ArrayList JavaDoc added = new ArrayList JavaDoc();
61         for (int i = 0; i < candidates.length; i++) {
62             IPluginModelBase candidate = (IPluginModelBase) candidates[i];
63             IPluginBase pluginBase = candidate.getPluginBase();
64             if (candidate.isFragmentModel()) continue;
65             monitor.subTask(pluginBase.getTranslatedName());
66             FeatureImport fimport = (FeatureImport) model.getFactory().createImport();
67             fimport.setPlugin((IPlugin)candidate.getPluginBase());
68             fimport.setId(pluginBase.getId());
69             added.add(fimport);
70             monitor.worked(1);
71         }
72         monitor.subTask(""); //$NON-NLS-1$
73
monitor.setTaskName(PDEPlugin.getResourceString(KEY_UPDATING));
74         feature.addImports((IFeatureImport[])added.toArray(new IFeatureImport[added.size()]));
75         monitor.worked(1);
76     }
77     
78     public void createControl(Composite parent) {
79         super.createControl(parent);
80         WorkbenchHelp.setHelp(getControl(), IHelpContextIds.FEATURE_ADD_REQUIRED_WIZARD);
81     }
82
83 }
84
Popular Tags