1 11 package org.eclipse.pde.internal.ui.editor.product; 12 13 import java.util.TreeSet ; 14 15 import org.eclipse.core.runtime.Platform; 16 import org.eclipse.jdt.launching.JavaRuntime; 17 import org.eclipse.jdt.launching.environments.IExecutionEnvironment; 18 import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager; 19 import org.eclipse.jface.layout.GridDataFactory; 20 import org.eclipse.pde.core.IModelChangedEvent; 21 import org.eclipse.pde.core.plugin.TargetPlatform; 22 import org.eclipse.pde.internal.core.iproduct.IJREInfo; 23 import org.eclipse.pde.internal.core.iproduct.IProduct; 24 import org.eclipse.pde.internal.core.iproduct.IProductModel; 25 import org.eclipse.pde.internal.ui.PDEPlugin; 26 import org.eclipse.pde.internal.ui.PDEPluginImages; 27 import org.eclipse.pde.internal.ui.PDEUIMessages; 28 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory; 29 import org.eclipse.pde.internal.ui.editor.PDEFormPage; 30 import org.eclipse.pde.internal.ui.editor.PDESection; 31 import org.eclipse.pde.internal.ui.launcher.VMHelper; 32 import org.eclipse.pde.internal.ui.parts.ComboPart; 33 import org.eclipse.swt.SWT; 34 import org.eclipse.swt.custom.CTabFolder; 35 import org.eclipse.swt.custom.CTabItem; 36 import org.eclipse.swt.dnd.Clipboard; 37 import org.eclipse.swt.events.ModifyEvent; 38 import org.eclipse.swt.events.ModifyListener; 39 import org.eclipse.swt.events.SelectionAdapter; 40 import org.eclipse.swt.events.SelectionEvent; 41 import org.eclipse.swt.graphics.Color; 42 import org.eclipse.swt.layout.GridData; 43 import org.eclipse.swt.widgets.Button; 44 import org.eclipse.swt.widgets.Composite; 45 import org.eclipse.swt.widgets.Display; 46 import org.eclipse.swt.widgets.Event; 47 import org.eclipse.swt.widgets.Listener; 48 import org.eclipse.swt.widgets.Text; 49 import org.eclipse.ui.dialogs.PreferencesUtil; 50 import org.eclipse.ui.forms.IFormColors; 51 import org.eclipse.ui.forms.widgets.FormToolkit; 52 import org.eclipse.ui.forms.widgets.Section; 53 54 public class JRESection extends PDESection { 55 56 private Button fJRERadioButton; 57 private Button fEERadioButton; 58 private Button fInstalledJREsButton; 59 private Button fExecutionEnvironmentsButton; 60 private ComboPart fJREsCombo; 61 private ComboPart fEEsCombo; 62 private TreeSet fEEChoices; 63 private boolean fBlockChanges; 64 65 private static final String [] TAB_LABELS = new String [4]; 66 static { 67 TAB_LABELS[IJREInfo.LINUX] = "linux"; TAB_LABELS[IJREInfo.MACOS] = "macosx"; TAB_LABELS[IJREInfo.SOLAR] = "solaris"; TAB_LABELS[IJREInfo.WIN32] = "win32"; } 72 73 private CTabFolder fTabFolder; 74 private int fLastTab; 75 76 public JRESection(PDEFormPage page, Composite parent) { 77 super(page, parent, Section.DESCRIPTION); 78 createClient(getSection(), page.getEditor().getToolkit()); 79 } 80 81 protected void createClient(Section section, FormToolkit toolkit) { 82 83 section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1)); 84 GridData data = new GridData(GridData.FILL_HORIZONTAL); 85 data.horizontalSpan = 2; 86 section.setLayoutData(data); 87 88 section.setText(PDEUIMessages.ProductJRESection_title); 89 section.setDescription(PDEUIMessages.ProductJRESection_desc); 90 91 Composite client = toolkit.createComposite(section); 92 client.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 3)); 93 client.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 94 95 initializeValues(); 96 97 fTabFolder = new CTabFolder(client, SWT.FLAT | SWT.TOP); 98 toolkit.adapt(fTabFolder, true, true); 99 GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL); 100 fTabFolder.setLayoutData(gd); 101 gd.heightHint = 2; 102 gd.horizontalSpan = 3; 103 gd.grabExcessHorizontalSpace = true; 104 toolkit.getColors().initializeSectionToolBarColors(); 105 Color selectedColor = toolkit.getColors().getColor(IFormColors.TB_BG); 106 fTabFolder.setSelectionBackground(new Color[] { selectedColor, 107 toolkit.getColors().getBackground() }, 108 new int[] { 100 }, true); 109 110 fTabFolder.addSelectionListener(new SelectionAdapter() { 111 public void widgetSelected(SelectionEvent e) { 112 refresh(); 113 } 114 }); 115 fTabFolder.setUnselectedImageVisible(false); 116 117 fJRERadioButton = toolkit.createButton(client, PDEUIMessages.ProductJRESection_jreName, SWT.RADIO); 118 fJRERadioButton.addSelectionListener(new SelectionAdapter() { 119 public void widgetSelected(SelectionEvent e) { 120 updateWidgets(); 121 getJVMLocations().setJVM(fJREsCombo.getSelection(), fLastTab, IJREInfo.TYPE_JRE); 122 } 123 }); 124 125 fJREsCombo = new ComboPart(); 126 fJREsCombo.createControl(client, toolkit, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY); 127 fJREsCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 128 String [] installs = VMHelper.getVMInstallNames(); 129 fJREsCombo.setItems(installs); 130 fJREsCombo.add("", 0); fJREsCombo.addModifyListener(new ModifyListener() { 132 public void modifyText(ModifyEvent e) { 133 if(!fBlockChanges) 134 getJVMLocations().setJVM(fJREsCombo.getSelection(), fLastTab, IJREInfo.TYPE_JRE); 135 } 136 }); 137 138 fInstalledJREsButton = toolkit.createButton(client, PDEUIMessages.ProductJRESection_browseJREs, SWT.PUSH); 139 GridDataFactory.fillDefaults().applyTo(fInstalledJREsButton); 140 fInstalledJREsButton.addListener(SWT.Selection, new Listener() { 141 public void handleEvent(Event event) { 142 PreferencesUtil.createPreferenceDialogOn( 143 getSection().getShell(), 144 "org.eclipse.jdt.debug.ui.preferences.VMPreferencePage", new String [] { "org.eclipse.jdt.debug.ui.preferences.VMPreferencePage" }, null).open(); } 147 }); 148 149 fEERadioButton = toolkit.createButton(client, PDEUIMessages.ProductJRESection_eeName, SWT.RADIO); 150 fEERadioButton.addSelectionListener(new SelectionAdapter() { 151 public void widgetSelected(SelectionEvent e) { 152 updateWidgets(); 153 getJVMLocations().setJVM(fEEsCombo.getSelection(), fLastTab, IJREInfo.TYPE_EE); 154 } 155 }); 156 157 fEEsCombo = new ComboPart(); 158 fEEsCombo.createControl(client, toolkit, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY); 159 fEEsCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 160 fEEsCombo.setItems((String [])fEEChoices.toArray(new String [fEEChoices.size()])); 161 162 fEEsCombo.addModifyListener(new ModifyListener() { 163 public void modifyText(ModifyEvent e) { 164 if(!fBlockChanges) 165 getJVMLocations().setJVM(fEEsCombo.getSelection(), fLastTab, IJREInfo.TYPE_EE); 166 } 167 }); 168 169 fExecutionEnvironmentsButton = toolkit.createButton(client, PDEUIMessages.ProductJRESection_browseEEs, SWT.PUSH); 170 GridDataFactory.fillDefaults().applyTo(fExecutionEnvironmentsButton); 171 fExecutionEnvironmentsButton.addListener(SWT.Selection, new Listener() { 172 public void handleEvent(Event event) { 173 PreferencesUtil.createPreferenceDialogOn( 174 getSection().getShell(), 175 "org.eclipse.jdt.debug.ui.jreProfiles", new String [] { "org.eclipse.jdt.debug.ui.jreProfiles" }, null).open(); } 178 }); 179 180 createTabs(); 181 toolkit.paintBordersFor(client); 182 section.setClient(client); 183 getProductModel().addModelChangedListener(this); 185 } 186 187 190 private IProductModel getProductModel() { 191 return (IProductModel) getPage().getPDEEditor().getAggregateModel(); 192 } 193 194 197 public void dispose() { 198 IProductModel model = getProductModel(); 199 if (model != null) { 200 model.removeModelChangedListener(this); 201 } 202 super.dispose(); 203 } 204 205 private void createTabs() { 206 for (int i = 0; i < TAB_LABELS.length; i++) { 207 CTabItem item = new CTabItem(fTabFolder, SWT.NULL); 208 item.setText(TAB_LABELS[i]); 209 item.setImage(PDEPlugin.getDefault().getLabelProvider().get( 210 PDEPluginImages.DESC_OPERATING_SYSTEM_OBJ)); 211 } 212 fLastTab = 0; 213 fTabFolder.setSelection(fLastTab); 214 215 String currentTarget = TargetPlatform.getOS(); 216 217 if (Platform.OS_WIN32.equals(currentTarget)) { 218 fTabFolder.setSelection(3); 219 } else if (Platform.OS_MACOSX.equals(currentTarget)) { 220 fTabFolder.setSelection(1); 221 } else if (Platform.OS_SOLARIS.equals(currentTarget)) { 222 fTabFolder.setSelection(2); 223 } 224 } 225 226 public void refresh() { 227 fBlockChanges = true; 228 fLastTab = fTabFolder.getSelectionIndex(); 229 int type = getJVMLocations().getJVMType(fLastTab); 230 String name = getJVMLocations().getJVM(fLastTab); 231 switch(type) { 232 case IJREInfo.TYPE_JRE: 233 if (fJREsCombo.indexOf(name) < 0) 234 fJREsCombo.add(name); 235 fJREsCombo.setText(name); 236 fJRERadioButton.setSelection(true); 237 fEERadioButton.setSelection(false); 238 break; 239 case IJREInfo.TYPE_EE: 240 if (fEEsCombo.indexOf(name) < 0) 241 fEEsCombo.add(name); 242 fEEsCombo.setText(name); 243 fEERadioButton.setSelection(true); 244 fJRERadioButton.setSelection(false); 245 break; 246 } 247 updateWidgets(); 248 super.refresh(); 249 fBlockChanges = false; 250 } 251 252 private IJREInfo getJVMLocations() { 253 IJREInfo info = getProduct().getJREInfo(); 254 if (info == null) { 255 info = getModel().getFactory().createJVMInfo(); 256 getProduct().setJREInfo(info); 257 } 258 return info; 259 } 260 261 private IProduct getProduct() { 262 return getModel().getProduct(); 263 } 264 265 private IProductModel getModel() { 266 return (IProductModel)getPage().getPDEEditor().getAggregateModel(); 267 } 268 269 public boolean canPaste(Clipboard clipboard) { 270 Display d = getSection().getDisplay(); 271 return d.getFocusControl() instanceof Text; 272 } 273 274 protected void updateWidgets() { 275 fJREsCombo.setEnabled(fJRERadioButton.getSelection()); 276 fEEsCombo.setEnabled(fEERadioButton.getSelection()); 277 } 278 279 protected void initializeValues() { 280 fEEChoices = new TreeSet (); 281 IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); 282 IExecutionEnvironment[] envs = manager.getExecutionEnvironments(); 283 for (int i = 0; i < envs.length; i++) 284 fEEChoices.add(envs[i].getId()); 285 } 286 287 290 public void modelChanged(IModelChangedEvent e) { 291 if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) { 293 handleModelEventWorldChanged(e); 294 } 295 } 296 297 300 private void handleModelEventWorldChanged(IModelChangedEvent event) { 301 refresh(); 302 getPage().setLastFocusControl(fJREsCombo.getControl()); 311 } 312 } 313 | Popular Tags |