1 11 package org.eclipse.jdt.debug.ui.launchConfigurations; 12 13 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.debug.core.ILaunchConfiguration; 16 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 17 import org.eclipse.debug.ui.ILaunchConfigurationDialog; 18 import org.eclipse.debug.ui.StringVariableSelectionDialog; 19 import org.eclipse.jdt.internal.debug.ui.IJavaDebugHelpContextIds; 20 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 21 import org.eclipse.jdt.internal.debug.ui.JavaDebugImages; 22 import org.eclipse.jdt.internal.debug.ui.actions.ControlAccessibleListener; 23 import org.eclipse.jdt.internal.debug.ui.launcher.LauncherMessages; 24 import org.eclipse.jdt.internal.debug.ui.launcher.VMArgumentsBlock; 25 import org.eclipse.jdt.internal.debug.ui.launcher.WorkingDirectoryBlock; 26 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; 27 import org.eclipse.swt.SWT; 28 import org.eclipse.swt.events.ModifyEvent; 29 import org.eclipse.swt.events.ModifyListener; 30 import org.eclipse.swt.events.SelectionEvent; 31 import org.eclipse.swt.events.SelectionListener; 32 import org.eclipse.swt.graphics.Font; 33 import org.eclipse.swt.graphics.Image; 34 import org.eclipse.swt.layout.GridData; 35 import org.eclipse.swt.layout.GridLayout; 36 import org.eclipse.swt.widgets.Button; 37 import org.eclipse.swt.widgets.Composite; 38 import org.eclipse.swt.widgets.Group; 39 import org.eclipse.swt.widgets.Label; 40 import org.eclipse.swt.widgets.Text; 41 import org.eclipse.ui.PlatformUI; 42 43 51 public class JavaArgumentsTab extends JavaLaunchTab { 52 53 protected Label fPrgmArgumentsLabel; 55 protected Text fPrgmArgumentsText; 56 57 protected VMArgumentsBlock fVMArgumentsBlock; 59 60 protected WorkingDirectoryBlock fWorkingDirectoryBlock; 62 63 protected static final String EMPTY_STRING = ""; 65 public JavaArgumentsTab() { 66 fVMArgumentsBlock = createVMArgsBlock(); 67 fWorkingDirectoryBlock = createWorkingDirBlock(); 68 } 69 70 protected VMArgumentsBlock createVMArgsBlock() { 71 return new VMArgumentsBlock(); 72 } 73 74 protected WorkingDirectoryBlock createWorkingDirBlock() { 75 return new WorkingDirectoryBlock(); 76 } 77 78 81 public void createControl(Composite parent) { 82 Font font = parent.getFont(); 83 Composite comp = new Composite(parent, SWT.NONE); 84 GridLayout layout = new GridLayout(1, true); 85 comp.setLayout(layout); 86 comp.setFont(font); 87 88 GridData gd = new GridData(GridData.FILL_BOTH); 89 comp.setLayoutData(gd); 90 setControl(comp); 91 setHelpContextId(); 92 93 Group group = new Group(comp, SWT.NONE); 94 group.setFont(font); 95 layout = new GridLayout(); 96 group.setLayout(layout); 97 group.setLayoutData(new GridData(GridData.FILL_BOTH)); 98 99 String controlName = (LauncherMessages.JavaArgumentsTab__Program_arguments__5); 100 group.setText(controlName); 101 102 fPrgmArgumentsText = new Text(group, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL); 103 gd = new GridData(GridData.FILL_BOTH); 104 gd.heightHint = 40; 105 gd.widthHint = 100; 106 fPrgmArgumentsText.setLayoutData(gd); 107 fPrgmArgumentsText.setFont(font); 108 fPrgmArgumentsText.addModifyListener(new ModifyListener() { 109 public void modifyText(ModifyEvent evt) { 110 updateLaunchConfigurationDialog(); 111 } 112 }); 113 ControlAccessibleListener.addListener(fPrgmArgumentsText, group.getText()); 114 115 String buttonLabel = LauncherMessages.JavaArgumentsTab_5; 116 Button pgrmArgVariableButton = createPushButton(group, buttonLabel, null); 117 pgrmArgVariableButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); 118 pgrmArgVariableButton.addSelectionListener(new SelectionListener() { 119 public void widgetSelected(SelectionEvent e) { 120 StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell()); 121 dialog.open(); 122 String variable = dialog.getVariableExpression(); 123 if (variable != null) { 124 fPrgmArgumentsText.insert(variable); 125 } 126 } 127 public void widgetDefaultSelected(SelectionEvent e) { 128 } 129 130 }); 131 132 fVMArgumentsBlock.createControl(comp); 133 134 fWorkingDirectoryBlock.createControl(comp); 135 } 136 137 141 protected void setHelpContextId() { 142 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_ARGUMENTS_TAB); 143 } 144 145 148 public void dispose() { 149 } 150 151 154 public boolean isValid(ILaunchConfiguration config) { 155 return fWorkingDirectoryBlock.isValid(config); 156 } 157 158 163 public void setDefaults(ILaunchConfigurationWorkingCopy config) { 164 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String )null); 165 fVMArgumentsBlock.setDefaults(config); 166 fWorkingDirectoryBlock.setDefaults(config); 167 } 168 169 172 public void initializeFrom(ILaunchConfiguration configuration) { 173 try { 174 fPrgmArgumentsText.setText(configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, "")); fVMArgumentsBlock.initializeFrom(configuration); 176 fWorkingDirectoryBlock.initializeFrom(configuration); 177 } catch (CoreException e) { 178 setErrorMessage(LauncherMessages.JavaArgumentsTab_Exception_occurred_reading_configuration___15 + e.getStatus().getMessage()); 179 JDIDebugUIPlugin.log(e); 180 } 181 } 182 183 186 public void performApply(ILaunchConfigurationWorkingCopy configuration) { 187 configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, getAttributeValueFrom(fPrgmArgumentsText)); 188 fVMArgumentsBlock.performApply(configuration); 189 fWorkingDirectoryBlock.performApply(configuration); 190 } 191 192 197 protected String getAttributeValueFrom(Text text) { 198 String content = text.getText().trim(); 199 if (content.length() > 0) { 200 return content; 201 } 202 return null; 203 } 204 205 208 public String getName() { 209 return LauncherMessages.JavaArgumentsTab__Arguments_16; 210 } 211 212 215 public void setLaunchConfigurationDialog(ILaunchConfigurationDialog dialog) { 216 super.setLaunchConfigurationDialog(dialog); 217 fWorkingDirectoryBlock.setLaunchConfigurationDialog(dialog); 218 fVMArgumentsBlock.setLaunchConfigurationDialog(dialog); 219 } 220 223 public String getErrorMessage() { 224 String m = super.getErrorMessage(); 225 if (m == null) { 226 return fWorkingDirectoryBlock.getErrorMessage(); 227 } 228 return m; 229 } 230 231 234 public String getMessage() { 235 String m = super.getMessage(); 236 if (m == null) { 237 return fWorkingDirectoryBlock.getMessage(); 238 } 239 return m; 240 } 241 242 245 public Image getImage() { 246 return JavaDebugImages.get(JavaDebugImages.IMG_VIEW_ARGUMENTS_TAB); 247 } 248 249 254 public String getId() { 255 return "org.eclipse.jdt.debug.ui.javaArgumentsTab"; } 257 258 261 public void activated(ILaunchConfigurationWorkingCopy workingCopy) { 262 fWorkingDirectoryBlock.initializeFrom(workingCopy); 263 } 264 265 268 public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) { 269 } 271 } 272 273 | Popular Tags |