1 11 package org.eclipse.pde.internal.ui.wizards.product; 12 13 import java.util.ArrayList ; 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 F_FILE_EXTENSION = "product"; 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 pageName, IStructuredSelection selection) { 62 super(pageName, selection); 63 setDescription(PDEUIMessages.ProductFileWizadPage_title); 64 setTitle(PDEUIMessages.NewProductFileWizard_title); 65 setFileExtension(F_FILE_EXTENSION); 67 68 initializeModel(selection); 69 } 70 71 private void initializeModel(IStructuredSelection selection) { 72 Object 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 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 point = extensions[i].getPoint(); 133 if ("org.eclipse.core.runtime.products".equals(point)) { String id = extensions[i].getId(); 135 if (id != null) { 136 String full = fModel.getPluginBase().getId() + "." + id; 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 [] getLaunchConfigurations() { 156 ArrayList list = new ArrayList (); 157 try { 158 ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager(); 159 ILaunchConfigurationType type = manager.getLaunchConfigurationType("org.eclipse.pde.ui.RuntimeWorkbench"); 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 [])list.toArray(new String [list.size()]); 168 } 169 170 public ILaunchConfiguration getSelectedLaunchConfiguration() { 171 if (!fLaunchConfigButton.getSelection()) 172 return null; 173 174 String configName = fLaunchConfigCombo.getText(); 175 try { 176 ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager(); 177 ILaunchConfigurationType type = manager.getLaunchConfigurationType("org.eclipse.pde.ui.RuntimeWorkbench"); 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 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 |