1 11 package org.eclipse.debug.internal.ui.actions.variables; 12 13 import org.eclipse.debug.internal.ui.DebugUIPlugin; 14 import org.eclipse.debug.ui.IDebugUIConstants; 15 import org.eclipse.jface.dialogs.IDialogConstants; 16 import org.eclipse.jface.dialogs.IDialogSettings; 17 import org.eclipse.jface.dialogs.IInputValidator; 18 import org.eclipse.jface.dialogs.TrayDialog; 19 import org.eclipse.swt.SWT; 20 import org.eclipse.swt.events.ModifyEvent; 21 import org.eclipse.swt.events.ModifyListener; 22 import org.eclipse.swt.graphics.Font; 23 import org.eclipse.swt.layout.GridData; 24 import org.eclipse.swt.widgets.Button; 25 import org.eclipse.swt.widgets.Composite; 26 import org.eclipse.swt.widgets.Control; 27 import org.eclipse.swt.widgets.Label; 28 import org.eclipse.swt.widgets.Shell; 29 import org.eclipse.swt.widgets.Text; 30 31 39 public class ChangeVariableValueInputDialog extends TrayDialog { 40 41 42 45 private String title; 46 47 50 private String message; 51 52 55 private String value= ""; 57 60 private IInputValidator validator; 61 62 65 private Button okButton; 66 67 70 private Text text; 71 72 75 private Label errorMessageLabel; 76 91 public ChangeVariableValueInputDialog(Shell parentShell, String dialogTitle, String dialogMessage, String initialValue, IInputValidator validator) { 92 super(parentShell); 93 this.title = dialogTitle; 94 message = dialogMessage; 95 if (initialValue == null) 96 value = ""; else 98 value = initialValue; 99 this.validator = validator; 100 101 setShellStyle(getShellStyle() | SWT.RESIZE); 102 } 103 106 protected void buttonPressed(int buttonId) { 107 if (buttonId == IDialogConstants.OK_ID) { 108 value= text.getText(); 109 } else { 110 value= null; 111 } 112 super.buttonPressed(buttonId); 113 } 114 117 protected void configureShell(Shell shell) { 118 super.configureShell(shell); 119 if (title != null) 120 shell.setText(title); 121 } 122 125 protected void createButtonsForButtonBar(Composite parent) { 126 okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); 128 createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); 129 130 text.setFocus(); 132 if (value != null) { 133 text.setText(value); 134 text.selectAll(); 135 } 136 } 137 140 protected Control createDialogArea(Composite parent) { 141 Font font = parent.getFont(); 142 Composite composite = (Composite)super.createDialogArea(parent); 144 145 if (message != null) { 147 Label label = new Label(composite, SWT.WRAP); 148 label.setText(message); 149 GridData data = new GridData( 150 GridData.GRAB_HORIZONTAL | 151 GridData.HORIZONTAL_ALIGN_FILL | 152 GridData.VERTICAL_ALIGN_CENTER); 153 data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); 154 label.setLayoutData(data); 155 label.setFont(font); 156 } 157 158 text= new Text(composite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL| SWT.H_SCROLL); 159 160 GridData gridData= new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL); 161 gridData.heightHint = 50; 162 gridData.widthHint = 100; 163 text.setLayoutData(gridData); 164 text.setFont(font); 165 text.addModifyListener( 166 new ModifyListener() { 167 public void modifyText(ModifyEvent e) { 168 if (okButton.isEnabled()) { 169 return; 170 } 171 errorMessageLabel.setText(""); errorMessageLabel.getParent().update(); 173 okButton.setEnabled(true); 174 } 175 } 176 ); 177 178 errorMessageLabel = new Label(composite, SWT.NONE); 179 errorMessageLabel.setLayoutData(new GridData( 180 GridData.GRAB_HORIZONTAL | 181 GridData.HORIZONTAL_ALIGN_FILL)); 182 errorMessageLabel.setFont(font); 183 return composite; 184 } 185 190 protected Label getErrorMessageLabel() { 191 return errorMessageLabel; 192 } 193 198 protected Button getOkButton() { 199 return okButton; 200 } 201 206 protected Text getText() { 207 return text; 208 } 209 214 protected IInputValidator getValidator() { 215 return validator; 216 } 217 222 public String getValue() { 223 return value; 224 } 225 236 protected void validateInput() { 237 238 String errorMessage = null; 239 240 if (validator != null) { 241 errorMessage = validator.isValid(text.getText()); 242 } 243 244 errorMessageLabel.setText(errorMessage == null ? "" : errorMessage); okButton.setEnabled(errorMessage == null); 247 248 errorMessageLabel.getParent().update(); 249 } 250 protected void okPressed() { 251 validateInput(); 252 if (okButton.isEnabled()) { 253 super.okPressed(); 254 } 255 } 256 257 262 protected String getDialogSettingsSectionName() { 263 return IDebugUIConstants.PLUGIN_ID + ".CHANGE_VARIABLE_VALUE_DIALOG_SECTION"; } 265 266 269 protected IDialogSettings getDialogBoundsSettings() { 270 IDialogSettings settings = DebugUIPlugin.getDefault().getDialogSettings(); 271 IDialogSettings section = settings.getSection(getDialogSettingsSectionName()); 272 if (section == null) { 273 section = settings.addNewSection(getDialogSettingsSectionName()); 274 } 275 return section; 276 } 277 278 281 protected void handleShellCloseEvent() { 282 value= null; 283 super.handleShellCloseEvent(); 284 } 285 } 286 | Popular Tags |