1 11 package org.eclipse.pde.internal.ui.launcher; 12 13 import java.util.Arrays ; 14 import java.util.Comparator ; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.debug.core.ILaunchConfiguration; 18 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 19 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; 20 import org.eclipse.pde.internal.ui.PDEUIMessages; 21 import org.eclipse.pde.internal.ui.preferences.PDEPreferencesUtil; 22 import org.eclipse.pde.internal.ui.util.SWTUtil; 23 import org.eclipse.pde.ui.launcher.AbstractLauncherTab; 24 import org.eclipse.pde.ui.launcher.IPDELauncherConstants; 25 import org.eclipse.swt.SWT; 26 import org.eclipse.swt.events.ModifyEvent; 27 import org.eclipse.swt.events.ModifyListener; 28 import org.eclipse.swt.events.SelectionAdapter; 29 import org.eclipse.swt.events.SelectionEvent; 30 import org.eclipse.swt.layout.GridData; 31 import org.eclipse.swt.layout.GridLayout; 32 import org.eclipse.swt.widgets.Button; 33 import org.eclipse.swt.widgets.Combo; 34 import org.eclipse.swt.widgets.Composite; 35 import org.eclipse.swt.widgets.Group; 36 import org.eclipse.swt.widgets.Label; 37 import org.eclipse.swt.widgets.Text; 38 39 public class JREBlock { 40 41 private AbstractLauncherTab fTab; 42 private Listener fListener = new Listener(); 43 private Button fJavawButton; 44 private Button fJavaButton; 45 private Combo fJreCombo; 46 private Text fBootstrap; 47 48 class Listener extends SelectionAdapter implements ModifyListener { 49 public void widgetSelected(SelectionEvent e) { 50 fTab.updateLaunchConfigurationDialog(); 51 } 52 public void modifyText(ModifyEvent e) { 53 fTab.updateLaunchConfigurationDialog(); 54 } 55 } 56 57 public JREBlock(AbstractLauncherTab tab) { 58 fTab = tab; 59 } 60 61 public void createControl(Composite parent) { 62 Group group = new Group(parent, SWT.NONE); 63 group.setText(PDEUIMessages.MainTab_jreSection); 64 GridLayout layout = new GridLayout(); 65 layout.numColumns = 2; 66 group.setLayout(layout); 67 group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 68 69 createJavaExecutableSection(group); 70 createJRESection(group); 71 createBootstrapEntriesSection(group); 72 } 73 74 protected void createJRESection(Composite parent) { 75 Label label = new Label(parent, SWT.NONE); 76 label.setText(PDEUIMessages.BasicLauncherTab_jre); 77 78 Composite composite = new Composite(parent, SWT.NONE); 79 GridLayout layout = new GridLayout(); 80 layout.numColumns = 2; 81 layout.marginHeight = layout.marginWidth = 0; 82 composite.setLayout(layout); 83 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 84 85 fJreCombo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY); 86 fJreCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 87 fJreCombo.addSelectionListener(fListener); 88 89 Button button = new Button(composite, SWT.PUSH); 90 button.setText(PDEUIMessages.BasicLauncherTab_installedJREs); 91 button.addSelectionListener(new SelectionAdapter() { 92 public void widgetSelected(SelectionEvent e) { 93 String currentVM = fJreCombo.getText(); 94 boolean useDefault = VMHelper.getDefaultVMInstallName().equals(currentVM); 95 String [] pageIDs = new String [] {"org.eclipse.jdt.debug.ui.preferences.VMPreferencePage"}; if (PDEPreferencesUtil.showPreferencePage(pageIDs, fTab.getControl().getShell())) { 97 setJRECombo(); 98 if (useDefault || fJreCombo.indexOf(currentVM) == -1) 99 fJreCombo.setText(VMHelper.getDefaultVMInstallName()); 100 else 101 fJreCombo.setText(currentVM); 102 } 103 } 104 }); 105 button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); 106 SWTUtil.setButtonDimensionHint(button); 107 } 108 109 protected void createJavaExecutableSection(Composite parent) { 110 Label label = new Label(parent, SWT.NONE); 111 label.setText(PDEUIMessages.BasicLauncherTab_javaExec); 112 113 Composite composite = new Composite(parent, SWT.NONE); 114 GridLayout layout = new GridLayout(); 115 layout.numColumns = 2; 116 layout.marginHeight = layout.marginWidth = 0; 117 layout.horizontalSpacing = 20; 118 composite.setLayout(layout); 119 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 120 121 fJavawButton = new Button(composite, SWT.RADIO); 122 fJavawButton.setText(PDEUIMessages.BasicLauncherTab_javaExecDefault); fJavawButton.addSelectionListener(fListener); 124 125 fJavaButton = new Button(composite, SWT.RADIO); 126 fJavaButton.setText("&java"); fJavaButton.addSelectionListener(fListener); 128 } 129 130 private void createBootstrapEntriesSection(Composite parent) { 131 Label label = new Label(parent, SWT.NONE); 132 label.setText(PDEUIMessages.BasicLauncherTab_bootstrap); 133 134 fBootstrap = new Text(parent, SWT.BORDER); 135 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 136 gd.widthHint = 300; 137 fBootstrap.setLayoutData(gd); 138 fBootstrap.addModifyListener(fListener); 139 } 140 141 public void initializeFrom(ILaunchConfiguration config) throws CoreException { 142 initializeJRESection(config); 143 initializeBootstrapEntriesSection(config); 144 } 145 146 private void initializeJRESection(ILaunchConfiguration config) throws CoreException { 147 String javaCommand = config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_JAVA_COMMAND, "javaw"); fJavawButton.setSelection(javaCommand.equals("javaw")); fJavaButton.setSelection(!fJavawButton.getSelection()); 150 151 setJRECombo(); 152 String vmInstallName = 153 config.getAttribute(IPDELauncherConstants.VMINSTALL, VMHelper.getDefaultVMInstallName()); 154 fJreCombo.setText(vmInstallName); 155 if (fJreCombo.getSelectionIndex() == -1) 156 fJreCombo.setText(VMHelper.getDefaultVMInstallName()); 157 } 158 159 private void initializeBootstrapEntriesSection(ILaunchConfiguration config) throws CoreException { 160 fBootstrap.setText(config.getAttribute(IPDELauncherConstants.BOOTSTRAP_ENTRIES, "")); } 162 163 public void performApply(ILaunchConfigurationWorkingCopy config) { 164 saveJRESection(config); 165 saveBootstrapEntriesSection(config); 166 } 167 168 protected void saveJRESection(ILaunchConfigurationWorkingCopy config) { 169 try { 170 String javaCommand = fJavawButton.getSelection() ? null : "java"; config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JAVA_COMMAND, javaCommand); 172 173 if (fJreCombo.getSelectionIndex() == -1) 174 return; 175 176 String jre = fJreCombo.getText(); 177 if (config.getAttribute(IPDELauncherConstants.VMINSTALL, (String ) null) != null) { 178 config.setAttribute(IPDELauncherConstants.VMINSTALL, jre); 179 } else { 180 config.setAttribute( 181 IPDELauncherConstants.VMINSTALL, 182 jre.equals(VMHelper.getDefaultVMInstallName()) ? null : jre); 183 } 184 } catch (CoreException e) { 185 } 186 } 187 188 protected void saveBootstrapEntriesSection(ILaunchConfigurationWorkingCopy config) { 189 config.setAttribute(IPDELauncherConstants.BOOTSTRAP_ENTRIES, fBootstrap.getText().trim()); 190 } 191 192 public void setDefaults(ILaunchConfigurationWorkingCopy config) { 193 config.setAttribute(IPDELauncherConstants.BOOTSTRAP_ENTRIES, ""); } 195 196 private void setJRECombo() { 197 String [] jres = VMHelper.getVMInstallNames(); 198 Arrays.sort(jres, new Comparator () { 199 public int compare(Object arg0, Object arg1) { 200 return arg0.toString().compareTo(arg1.toString()); 201 } 202 }); 203 fJreCombo.setItems(jres); 204 } 205 } 206 | Popular Tags |