KickJava   Java API By Example, From Geeks To Geeks.

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


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.ArrayList JavaDoc;
14
15 import org.eclipse.core.resources.IProject;
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IAdaptable;
19 import org.eclipse.debug.core.DebugPlugin;
20 import org.eclipse.debug.core.ILaunchConfiguration;
21 import org.eclipse.debug.core.ILaunchConfigurationType;
22 import org.eclipse.debug.core.ILaunchManager;
23 import org.eclipse.debug.ui.DebugUITools;
24 import org.eclipse.jface.dialogs.Dialog;
25 import org.eclipse.jface.viewers.IStructuredSelection;
26 import org.eclipse.pde.core.plugin.IPluginExtension;
27 import org.eclipse.pde.core.plugin.IPluginModelBase;
28 import org.eclipse.pde.core.plugin.PluginRegistry;
29 import org.eclipse.pde.core.plugin.TargetPlatform;
30 import org.eclipse.pde.internal.ui.IHelpContextIds;
31 import org.eclipse.pde.internal.ui.PDEUIMessages;
32 import org.eclipse.pde.internal.ui.wizards.PDEWizardNewFileCreationPage;
33 import org.eclipse.swt.SWT;
34 import org.eclipse.swt.events.SelectionAdapter;
35 import org.eclipse.swt.events.SelectionEvent;
36 import org.eclipse.swt.layout.GridData;
37 import org.eclipse.swt.layout.GridLayout;
38 import org.eclipse.swt.widgets.Button;
39 import org.eclipse.swt.widgets.Combo;
40 import org.eclipse.swt.widgets.Composite;
41 import org.eclipse.swt.widgets.Group;
42 import org.eclipse.ui.PlatformUI;
43
44 public class ProductFileWizardPage extends PDEWizardNewFileCreationPage {
45     
46     public final static int USE_DEFAULT = 0;
47     public final static int USE_PRODUCT = 1;
48     public final static int USE_LAUNCH_CONFIG = 2;
49     
50     private static final String JavaDoc F_FILE_EXTENSION = "product"; //$NON-NLS-1$
51

52     private Button fBasicButton;
53     private Button fProductButton;
54     private Combo fProductCombo;
55     private Button fLaunchConfigButton;
56     private Combo fLaunchConfigCombo;
57     private Group fGroup;
58     
59     private IPluginModelBase fModel;
60     
61     public ProductFileWizardPage(String JavaDoc pageName, IStructuredSelection selection) {
62         super(pageName, selection);
63         setDescription(PDEUIMessages.ProductFileWizadPage_title);
64         setTitle(PDEUIMessages.NewProductFileWizard_title);
65         // Force the file extension to be 'product'
66
setFileExtension(F_FILE_EXTENSION);
67         
68         initializeModel(selection);
69     }
70     
71     private void initializeModel(IStructuredSelection selection) {
72         Object JavaDoc selected = selection.getFirstElement();
73         if (selected instanceof IAdaptable) {
74             IResource resource = (IResource)((IAdaptable)selected).getAdapter(IResource.class);
75             if (resource != null) {
76                 IProject project = resource.getProject();
77                 fModel = PluginRegistry.findModel(project);
78             }
79         }
80     }
81
82     /* (non-Javadoc)
83      * @see org.eclipse.ui.dialogs.WizardNewFileCreationPage#createAdvancedControls(org.eclipse.swt.widgets.Composite)
84      */

85     protected void createAdvancedControls(Composite parent) {
86         fGroup = new Group(parent, SWT.NONE);
87         fGroup.setText(PDEUIMessages.ProductFileWizadPage_groupTitle);
88         fGroup.setLayout(new GridLayout(2, false));
89         fGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
90         
91         fBasicButton = new Button(fGroup, SWT.RADIO);
92         GridData gd = new GridData();
93         gd.horizontalSpan = 2;
94         fBasicButton.setLayoutData(gd);
95         fBasicButton.setText(PDEUIMessages.ProductFileWizadPage_basic);
96         
97         fProductButton = new Button(fGroup, SWT.RADIO);
98         fProductButton.setText(PDEUIMessages.ProductFileWizadPage_existingProduct);
99         fProductButton.addSelectionListener(new SelectionAdapter() {
100             public void widgetSelected(SelectionEvent e) {
101                 fProductCombo.setEnabled(fProductButton.getSelection());
102             }
103         });
104         
105         fProductCombo = new Combo(fGroup, SWT.SINGLE|SWT.READ_ONLY);
106         fProductCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
107         fProductCombo.setItems(TargetPlatform.getProducts());
108         
109         fLaunchConfigButton = new Button(fGroup, SWT.RADIO);
110         fLaunchConfigButton.setText(PDEUIMessages.ProductFileWizadPage_existingLaunchConfig);
111         fLaunchConfigButton.addSelectionListener(new SelectionAdapter() {
112             public void widgetSelected(SelectionEvent e) {
113                 fLaunchConfigCombo.setEnabled(fLaunchConfigButton.getSelection());
114             }
115         });
116         
117         fLaunchConfigCombo = new Combo(fGroup, SWT.SINGLE|SWT.READ_ONLY);
118         fLaunchConfigCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
119         fLaunchConfigCombo.setItems(getLaunchConfigurations());
120         
121         initializeState();
122     }
123     
124     private void initializeState() {
125         fLaunchConfigCombo.setEnabled(false);
126         if (fLaunchConfigCombo.getItemCount() > 0)
127             fLaunchConfigCombo.setText(fLaunchConfigCombo.getItem(0));
128         
129         if (fModel != null && fModel.getPluginBase().getId() != null) {
130             IPluginExtension[] extensions = fModel.getPluginBase().getExtensions();
131             for (int i = 0; i < extensions.length; i++) {
132                 String JavaDoc point = extensions[i].getPoint();
133                 if ("org.eclipse.core.runtime.products".equals(point)) { //$NON-NLS-1$
134
String JavaDoc id = extensions[i].getId();
135                     if (id != null) {
136                         String JavaDoc full = fModel.getPluginBase().getId() + "." + id; //$NON-NLS-1$
137
if (fProductCombo.indexOf(full) != -1) {
138                             fProductCombo.setText(full);
139                             fProductButton.setSelection(true);
140                             return;
141                         }
142                     }
143                 }
144             }
145         }
146         
147         fBasicButton.setSelection(true);
148
149         fProductCombo.setEnabled(false);
150         if (fProductCombo.getItemCount() > 0)
151             fProductCombo.setText(fProductCombo.getItem(0));
152
153     }
154     
155     private String JavaDoc[] getLaunchConfigurations() {
156         ArrayList JavaDoc list = new ArrayList JavaDoc();
157         try {
158             ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
159             ILaunchConfigurationType type = manager.getLaunchConfigurationType("org.eclipse.pde.ui.RuntimeWorkbench"); //$NON-NLS-1$
160
ILaunchConfiguration[] configs = manager.getLaunchConfigurations(type);
161             for (int i = 0; i < configs.length; i++) {
162                 if (!DebugUITools.isPrivate(configs[i]))
163                     list.add(configs[i].getName());
164             }
165         } catch (CoreException e) {
166         }
167         return (String JavaDoc[])list.toArray(new String JavaDoc[list.size()]);
168     }
169     
170     public ILaunchConfiguration getSelectedLaunchConfiguration() {
171         if (!fLaunchConfigButton.getSelection())
172             return null;
173         
174         String JavaDoc configName = fLaunchConfigCombo.getText();
175         try {
176             ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
177             ILaunchConfigurationType type = manager.getLaunchConfigurationType("org.eclipse.pde.ui.RuntimeWorkbench"); //$NON-NLS-1$
178
ILaunchConfiguration[] configs = manager.getLaunchConfigurations(type);
179             for (int i = 0; i < configs.length; i++) {
180                 if (configs[i].getName().equals(configName) && !DebugUITools.isPrivate(configs[i]))
181                     return configs[i];
182             }
183         } catch (CoreException e) {
184         }
185         return null;
186     }
187     
188     public String JavaDoc getSelectedProduct() {
189         return fProductButton.getSelection() ? fProductCombo.getText() : null;
190     }
191     
192     public int getInitializationOption() {
193         if (fBasicButton.getSelection())
194             return USE_DEFAULT;
195         if (fProductButton.getSelection())
196             return USE_PRODUCT;
197         return USE_LAUNCH_CONFIG;
198     }
199     
200     public void createControl(Composite parent) {
201         super.createControl(parent);
202         Dialog.applyDialogFont(fGroup);
203         
204         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IHelpContextIds.PRODUCT_FILE_PAGE );
205     }
206     
207 }
208
Popular Tags