1 11 package org.eclipse.jdt.internal.debug.ui.jres; 12 13 14 import com.ibm.icu.text.MessageFormat; 15 import java.util.HashMap ; 16 import java.util.Map ; 17 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.debug.core.ILaunchConfiguration; 20 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 21 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; 22 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 23 import org.eclipse.jdt.internal.debug.ui.actions.ControlAccessibleListener; 24 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; 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.graphics.Font; 31 import org.eclipse.swt.layout.GridData; 32 import org.eclipse.swt.layout.GridLayout; 33 import org.eclipse.swt.widgets.Button; 34 import org.eclipse.swt.widgets.Composite; 35 import org.eclipse.swt.widgets.Group; 36 import org.eclipse.swt.widgets.Text; 37 38 public class StandardVMCommandTab extends AbstractLaunchConfigurationTab { 39 40 protected Text fJavaCommandText; 41 protected Button fDefaultButton; 42 protected Button fSpecificButton; 43 44 protected static final Map EMPTY_MAP = new HashMap (1); 45 46 49 public void createControl(Composite parent) { 50 Font font = parent.getFont(); 51 Composite comp = new Composite(parent, parent.getStyle()); 52 GridLayout layout = new GridLayout(); 53 comp.setLayout(layout); 54 comp.setLayoutData(new GridData(GridData.FILL_BOTH)); 55 comp.setFont(font); 56 57 Group group = new Group(comp, SWT.NONE); 58 setControl(group); 59 GridLayout topLayout = new GridLayout(); 60 group.setLayout(topLayout); 61 topLayout.numColumns = 2; 62 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 63 group.setLayoutData(gd); 64 group.setFont(font); 65 66 group.setText(JREMessages.AbstractJavaCommandTab_1); 67 68 fDefaultButton = new Button(group, SWT.RADIO); 69 fDefaultButton.setFont(font); 70 gd = new GridData(GridData.BEGINNING); 71 gd.horizontalSpan = 2; 72 fDefaultButton.setLayoutData(gd); 73 fDefaultButton.setText(MessageFormat.format(JREMessages.AbstractJavaCommandTab_2, new String []{getDefaultCommand()})); 74 75 fDefaultButton.addSelectionListener(new SelectionAdapter() { 76 public void widgetSelected(SelectionEvent evt) { 77 handleSelection(); 78 } 79 }); 80 81 fSpecificButton = new Button(group, SWT.RADIO); 82 fSpecificButton.setFont(font); 83 gd = new GridData(GridData.BEGINNING); 84 fSpecificButton.setLayoutData(gd); 85 fSpecificButton.setText(JREMessages.AbstractJavaCommandTab_4); 86 87 fSpecificButton.addSelectionListener(new SelectionAdapter() { 88 public void widgetSelected(SelectionEvent evt) { 89 handleSelection(); 90 } 91 }); 92 93 fJavaCommandText= new Text(group, SWT.SINGLE | SWT.BORDER); 94 gd = new GridData(GridData.FILL_HORIZONTAL); 95 fJavaCommandText.setLayoutData(gd); 96 fJavaCommandText.setFont(font); 97 fJavaCommandText.addModifyListener(new ModifyListener() { 98 public void modifyText(ModifyEvent evt) { 99 updateLaunchConfigurationDialog(); 100 } 101 }); 102 ControlAccessibleListener.addListener(fJavaCommandText, fSpecificButton.getText()); 103 setControl(group); 104 } 105 106 protected void handleSelection() { 107 boolean useDefault = fDefaultButton.getSelection(); 108 fDefaultButton.setSelection(useDefault); 109 fSpecificButton.setSelection(!useDefault); 110 fJavaCommandText.setEnabled(!useDefault); 111 updateLaunchConfigurationDialog(); 112 } 113 114 protected String getDefaultCommand() { 115 return "javaw"; } 117 118 121 public String getName() { 122 return JREMessages.AbstractJavaCommandTab_3; 123 } 124 125 128 public void initializeFrom(ILaunchConfiguration configuration) { 129 String javaCommand= null; 130 try { 131 Map attributeMap = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE_SPECIFIC_ATTRS_MAP, (Map )null); 132 if (attributeMap != null) { 133 javaCommand = (String ) attributeMap.get(IJavaLaunchConfigurationConstants.ATTR_JAVA_COMMAND); 134 } 135 } catch(CoreException ce) { 136 JDIDebugUIPlugin.log(ce); 137 } 138 if (javaCommand == null) { 139 javaCommand = getDefaultCommand(); 140 } 141 fJavaCommandText.setText(javaCommand); 142 if (javaCommand.equals(getDefaultCommand())) { 143 fDefaultButton.setSelection(true); 145 } else { 146 fDefaultButton.setSelection(false); 147 } 148 handleSelection(); 149 } 150 151 154 public void performApply(ILaunchConfigurationWorkingCopy configuration) { 155 if (fDefaultButton.getSelection()) { 156 configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE_SPECIFIC_ATTRS_MAP, (Map )null); 157 } else { 158 String javaCommand = fJavaCommandText.getText(); 159 Map attributeMap = new HashMap (1); 160 attributeMap.put(IJavaLaunchConfigurationConstants.ATTR_JAVA_COMMAND, javaCommand); 161 configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE_SPECIFIC_ATTRS_MAP, attributeMap); 162 } 163 } 164 165 168 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { 169 configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE_SPECIFIC_ATTRS_MAP, (Map )null); 170 } 171 172 175 public String getId() { 176 return "org.eclipse.jdt.debug.ui.standardVMCommandTab"; } 178 179 182 public boolean isValid(ILaunchConfiguration launchConfig) { 183 boolean valid= fDefaultButton.getSelection() || fJavaCommandText.getText().length() != 0; 184 if (valid) { 185 setErrorMessage(null); 186 setMessage(null); 187 } else { 188 setErrorMessage(JREMessages.AbstractJavaCommandTab_Java_executable_must_be_specified_5); 189 setMessage(null); 190 } 191 return valid; 192 } 193 } 194 | Popular Tags |