1 11 package org.eclipse.jdt.internal.debug.ui.actions; 12 13 import org.eclipse.debug.core.DebugException; 14 import org.eclipse.jdt.debug.core.IJavaVariable; 15 import org.eclipse.jdt.internal.debug.ui.IJavaDebugHelpContextIds; 16 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 17 import org.eclipse.jface.dialogs.Dialog; 18 import org.eclipse.jface.dialogs.IDialogSettings; 19 import org.eclipse.jface.text.Document; 20 import org.eclipse.jface.text.TextViewer; 21 import org.eclipse.swt.SWT; 22 import org.eclipse.swt.custom.StyledText; 23 import org.eclipse.swt.events.SelectionAdapter; 24 import org.eclipse.swt.events.SelectionEvent; 25 import org.eclipse.swt.layout.GridData; 26 import org.eclipse.swt.layout.GridLayout; 27 import org.eclipse.swt.widgets.Button; 28 import org.eclipse.swt.widgets.Composite; 29 import org.eclipse.swt.widgets.Control; 30 import org.eclipse.swt.widgets.Group; 31 import org.eclipse.swt.widgets.Shell; 32 import org.eclipse.ui.IWorkbench; 33 import org.eclipse.ui.PlatformUI; 34 35 41 public class StringValueInputDialog extends ExpressionInputDialog { 42 43 private TextViewer fTextViewer; 44 private Button fTextButton; 45 private Button fEvaluationButton; 46 private Button fWrapText; 47 private Group fTextGroup; 48 49 private boolean fUseLiteralValue= true; 50 private static final String USE_EVALUATION = "USE_EVALUATION"; private static final String WRAP_TEXT = "WRAP_TEXT"; 53 57 protected StringValueInputDialog(Shell parentShell, IJavaVariable variable) { 58 super(parentShell, variable); 59 } 60 61 64 protected Control createDialogArea(Composite parent) { 65 IWorkbench workbench = PlatformUI.getWorkbench(); 66 workbench.getHelpSystem().setHelp( 67 parent, 68 IJavaDebugHelpContextIds.STRING_VALUE_INPUT_DIALOG); 69 return super.createDialogArea(parent); 70 } 71 72 76 protected void createInputArea(Composite parent) { 77 super.createInputArea(parent); 78 createRadioButtons(parent); 79 Dialog.applyDialogFont(parent); 80 } 81 82 86 protected void populateInputArea() { 87 boolean useEvaluation= false; 88 IDialogSettings settings = getDialogSettings(); 89 if (settings != null) { 90 useEvaluation= settings.getBoolean(USE_EVALUATION); 91 } 92 if (useEvaluation) { 93 createSourceViewer(); 94 fUseLiteralValue= false; 95 fEvaluationButton.setSelection(true); 96 } else { 97 createTextViewer(); 98 fTextButton.setSelection(true); 99 } 100 } 101 102 106 private void createTextViewer() { 107 fTextGroup= new Group(fInputArea, SWT.NONE); 108 fTextGroup.setLayout(new GridLayout()); 109 fTextGroup.setLayoutData(new GridData(GridData.FILL_BOTH)); 110 fTextGroup.setText(ActionMessages.StringValueInputDialog_0); 111 112 Composite parent= fTextGroup; 113 114 fTextViewer= new TextViewer(parent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); 115 fTextViewer.setDocument(new Document()); 116 GridData gridData = new GridData(GridData.FILL_BOTH); 117 gridData.widthHint= 300; 118 gridData.heightHint= 150; 119 fTextViewer.getTextWidget().setLayoutData(gridData); 120 try { 121 String valueString = fVariable.getValue().getValueString(); 122 fTextViewer.getDocument().set(valueString); 123 fTextViewer.setSelectedRange(0, valueString.length()); 124 } catch (DebugException e) { 125 JDIDebugUIPlugin.log(e); 126 } 127 fTextViewer.getControl().setFocus(); 128 fWrapText= new Button(parent, SWT.CHECK); 129 fWrapText.setText(ActionMessages.StringValueInputDialog_4); 130 boolean wrap= true; 131 IDialogSettings settings = getDialogSettings(); 132 if (settings != null) { 133 wrap= settings.getBoolean(WRAP_TEXT); 134 } 135 fWrapText.setSelection(wrap); 136 updateWordWrap(); 137 fWrapText.addSelectionListener(new SelectionAdapter() { 138 public void widgetSelected(SelectionEvent e) { 139 updateWordWrap(); 140 } 141 }); 142 143 Dialog.applyDialogFont(fInputArea); 144 } 145 146 private void updateWordWrap() { 147 fTextViewer.getTextWidget().setWordWrap(fWrapText.getSelection()); 148 } 149 150 154 protected void createRadioButtons(Composite parent) { 155 fTextButton= new Button(parent, SWT.RADIO); 156 fTextButton.setText(ActionMessages.StringValueInputDialog_1); 157 fTextButton.addSelectionListener(new SelectionAdapter() { 158 public void widgetSelected(SelectionEvent e) { 159 handleRadioSelectionChanged(); 160 } 161 }); 162 fEvaluationButton= new Button(parent, SWT.RADIO); 163 fEvaluationButton.setText(ActionMessages.StringValueInputDialog_2); 164 } 165 166 170 private void handleRadioSelectionChanged() { 171 boolean literal = fTextButton.getSelection(); 172 if (literal != fUseLiteralValue) { 173 fUseLiteralValue= literal; 174 if (fUseLiteralValue) { 175 disposeSourceViewer(); 176 createTextViewer(); 177 } else { 178 disposeTextViewer(); 180 createSourceViewer(); 181 } 182 fInputArea.layout(true, true); 183 } 184 } 185 186 189 protected void disposeTextViewer() { 190 if (fTextGroup != null) { 191 fTextGroup.dispose(); 192 fTextGroup= null; 193 } 194 195 if (fTextViewer != null) { 196 StyledText textWidget = fTextViewer.getTextWidget(); 197 if (textWidget != null) { 198 textWidget.dispose(); 199 } 200 fTextViewer= null; 201 } 202 if (fWrapText != null) { 203 fWrapText.dispose(); 204 fWrapText= null; 205 } 206 } 207 208 211 protected void refreshValidState() { 212 if (fSourceViewer != null) { 213 super.refreshValidState(); 214 return; 215 } 216 setErrorMessage(null); 218 } 219 220 224 protected void okPressed() { 225 IDialogSettings settings= getDialogSettings(); 226 if (settings == null) { 227 settings= JDIDebugUIPlugin.getDefault().getDialogSettings().addNewSection(getDialogSettingsSectionName()); 228 } 229 settings.put(USE_EVALUATION, fEvaluationButton.getSelection()); 230 if (fWrapText != null) { 231 settings.put(WRAP_TEXT, fWrapText.getSelection()); 232 } 233 super.okPressed(); 234 } 235 236 243 public boolean isUseLiteralValue() { 244 return fUseLiteralValue; 245 } 246 247 252 protected String getText() { 253 if (fTextButton.getSelection()) { 254 return fTextViewer.getDocument().get(); 255 } 256 return super.getText(); 257 } 258 259 264 protected void dispose() { 265 if (fTextButton.getSelection()) { 266 disposeTextViewer(); 267 } else { 268 super.dispose(); 269 } 270 } 271 272 276 protected IDialogSettings getDialogSettings() { 277 return JDIDebugUIPlugin.getDefault().getDialogSettings().getSection(getDialogSettingsSectionName()); 278 } 279 280 283 protected String getDialogSettingsSectionName() { 284 return "STRING_VALUE_INPUT_DIALOG"; } 286 } 287 | Popular Tags |