KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > feature > PluginListPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.feature;
12
13 import java.util.TreeSet JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.debug.core.DebugPlugin;
17 import org.eclipse.debug.core.ILaunchConfiguration;
18 import org.eclipse.debug.core.ILaunchConfigurationType;
19 import org.eclipse.debug.core.ILaunchManager;
20 import org.eclipse.debug.ui.DebugUITools;
21 import org.eclipse.jface.dialogs.Dialog;
22 import org.eclipse.jface.dialogs.IDialogSettings;
23 import org.eclipse.jface.viewers.CheckboxTableViewer;
24 import org.eclipse.jface.viewers.IStructuredContentProvider;
25 import org.eclipse.pde.core.plugin.IPluginBase;
26 import org.eclipse.pde.core.plugin.IPluginModelBase;
27 import org.eclipse.pde.core.plugin.PluginRegistry;
28 import org.eclipse.pde.internal.core.PDECore;
29 import org.eclipse.pde.internal.ui.IHelpContextIds;
30 import org.eclipse.pde.internal.ui.PDEPlugin;
31 import org.eclipse.pde.internal.ui.PDEUIMessages;
32 import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
33 import org.eclipse.pde.internal.ui.wizards.ListUtil;
34 import org.eclipse.swt.SWT;
35 import org.eclipse.swt.events.SelectionAdapter;
36 import org.eclipse.swt.events.SelectionEvent;
37 import org.eclipse.swt.layout.GridData;
38 import org.eclipse.swt.layout.GridLayout;
39 import org.eclipse.swt.widgets.Button;
40 import org.eclipse.swt.widgets.Combo;
41 import org.eclipse.swt.widgets.Composite;
42 import org.eclipse.ui.PlatformUI;
43
44 import com.ibm.icu.text.Collator;
45
46 public class PluginListPage extends BasePluginListPage {
47     class PluginContentProvider
48         extends DefaultContentProvider
49         implements IStructuredContentProvider {
50         public Object JavaDoc[] getElements(Object JavaDoc parent) {
51             return PluginRegistry.getActiveModels();
52         }
53     }
54     
55     private Combo fLaunchConfigsCombo;
56     private Button fInitLaunchConfigButton;
57     
58     private static final String JavaDoc S_INIT_LAUNCH = "initLaunch"; //$NON-NLS-1$
59

60     public PluginListPage() {
61         super("pluginListPage"); //$NON-NLS-1$
62
setTitle(PDEUIMessages.NewFeatureWizard_PlugPage_title);
63         setDescription(PDEUIMessages.NewFeatureWizard_PlugPage_desc);
64     }
65
66     public void createControl(Composite parent) {
67         Composite container = new Composite(parent, SWT.NULL);
68         GridLayout layout = new GridLayout();
69         layout.numColumns = 3;
70         layout.verticalSpacing = 9;
71         container.setLayout(layout);
72         GridData gd;
73         
74         String JavaDoc[] launchConfigs = getLaunchConfigurations();
75         
76         IDialogSettings settings = getDialogSettings();
77         boolean initLaunch = (settings != null) ? settings.getBoolean(S_INIT_LAUNCH) && launchConfigs.length > 0 : false;
78         
79         if (launchConfigs.length > 0) {
80             fInitLaunchConfigButton = new Button(container, SWT.RADIO);
81             fInitLaunchConfigButton.setText(PDEUIMessages.PluginListPage_initializeFromLaunch);
82             fInitLaunchConfigButton.setSelection(initLaunch);
83             fInitLaunchConfigButton.addSelectionListener(new SelectionAdapter() {
84
85                 public void widgetSelected(SelectionEvent e) {
86                     boolean initLaunchConfigs = fInitLaunchConfigButton.getSelection();
87                     fLaunchConfigsCombo.setEnabled(initLaunchConfigs);
88                     tablePart.setEnabled(!initLaunchConfigs);
89                 }
90                 
91             });
92         
93             fLaunchConfigsCombo = new Combo(container, SWT.READ_ONLY);
94             fLaunchConfigsCombo.setItems(launchConfigs);
95             gd = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
96             gd.horizontalSpan = 2;
97             fLaunchConfigsCombo.setLayoutData(gd);
98             fLaunchConfigsCombo.select(0);
99             fLaunchConfigsCombo.setEnabled(initLaunch);
100             
101             Button initPluginsButton = new Button(container, SWT.RADIO);
102             initPluginsButton.setText(PDEUIMessages.PluginListPage_initializeFromPlugins);
103             gd = new GridData();
104             gd.horizontalSpan = 3;
105             initPluginsButton.setLayoutData(gd);
106             initPluginsButton.setSelection(!initLaunch);
107         }
108
109         tablePart.createControl(container, 3);
110         CheckboxTableViewer pluginViewer = tablePart.getTableViewer();
111         pluginViewer.setContentProvider(new PluginContentProvider());
112         pluginViewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider());
113         pluginViewer.setComparator(ListUtil.PLUGIN_COMPARATOR);
114         gd = (GridData) tablePart.getControl().getLayoutData();
115         if (launchConfigs.length > 0) {
116             gd.horizontalIndent = 30;
117             ((GridData)tablePart.getCounterLabel().getLayoutData()).horizontalIndent = 30;
118         }
119         gd.heightHint = 250;
120         gd.widthHint = 300;
121         pluginViewer.setInput(PDECore.getDefault().getModelManager());
122         tablePart.setSelection(new Object JavaDoc[0]);
123         tablePart.setEnabled(!initLaunch);
124         setControl(container);
125         Dialog.applyDialogFont(container);
126         PlatformUI.getWorkbench().getHelpSystem().setHelp(container, IHelpContextIds.NEW_FEATURE_REFERENCED_PLUGINS);
127     }
128
129     public IPluginBase[] getSelectedPlugins() {
130         if (fInitLaunchConfigButton == null || !fInitLaunchConfigButton.getSelection()) {
131             Object JavaDoc[] result = tablePart.getSelection();
132             IPluginBase[] plugins = new IPluginBase[result.length];
133             for (int i=0; i<result.length; i++) {
134                 IPluginModelBase model = (IPluginModelBase)result[i];
135                 plugins[i] = model.getPluginBase();
136             }
137             return plugins;
138         }
139         return new IPluginBase[0];
140     }
141     
142     protected void saveSettings(IDialogSettings settings) {
143         settings.put(S_INIT_LAUNCH, fInitLaunchConfigButton != null && fInitLaunchConfigButton.getSelection());
144     }
145     
146     private String JavaDoc[] getLaunchConfigurations() {
147         TreeSet JavaDoc launcherNames = new TreeSet JavaDoc(Collator.getInstance());
148         try {
149             ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
150             String JavaDoc [] types = new String JavaDoc[] {"org.eclipse.pde.ui.RuntimeWorkbench", "org.eclipse.pde.ui.EquinoxLauncher"}; //$NON-NLS-1$ //$NON-NLS-2$
151
for (int j = 0; j < 2; j++) {
152                 ILaunchConfigurationType type = manager.getLaunchConfigurationType(types[j]);
153                 ILaunchConfiguration[] configs = manager.getLaunchConfigurations(type);
154                 for (int i = 0; i < configs.length; i++) {
155                     if (!DebugUITools.isPrivate(configs[i]))
156                         launcherNames.add(configs[i].getName());
157                 }
158             }
159         } catch (CoreException e) {
160         }
161         return (String JavaDoc[])launcherNames.toArray(new String JavaDoc[launcherNames.size()]);
162     }
163     
164     public ILaunchConfiguration getSelectedLaunchConfiguration() {
165         if (fInitLaunchConfigButton == null || !fInitLaunchConfigButton.getSelection())
166             return null;
167         
168         String JavaDoc configName = fLaunchConfigsCombo.getText();
169         try {
170             ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
171             String JavaDoc [] types = new String JavaDoc[] {"org.eclipse.pde.ui.RuntimeWorkbench", "org.eclipse.pde.ui.EquinoxLauncher"}; //$NON-NLS-1$ //$NON-NLS-2$
172
for (int j = 0; j < 2; j++) {
173                 ILaunchConfigurationType type = manager.getLaunchConfigurationType(types[j]);
174                 ILaunchConfiguration[] configs = manager.getLaunchConfigurations(type);
175                 for (int i = 0; i < configs.length; i++) {
176                     if (configs[i].getName().equals(configName) && !DebugUITools.isPrivate(configs[i]))
177                         return configs[i];
178                 }
179             }
180         } catch (CoreException e) {
181         }
182         return null;
183     }
184     
185
186 }
187
Popular Tags