1 11 package org.eclipse.debug.internal.ui.actions.variables.details; 12 13 import org.eclipse.debug.internal.ui.DebugUIPlugin; 14 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 15 import org.eclipse.debug.internal.ui.views.variables.VariablesViewMessages; 16 import org.eclipse.debug.ui.IDebugUIConstants; 17 import org.eclipse.jface.dialogs.IDialogConstants; 18 import org.eclipse.jface.dialogs.IDialogSettings; 19 import org.eclipse.jface.dialogs.IInputValidator; 20 import org.eclipse.jface.dialogs.TrayDialog; 21 import org.eclipse.swt.SWT; 22 import org.eclipse.swt.events.ModifyEvent; 23 import org.eclipse.swt.events.ModifyListener; 24 import org.eclipse.swt.layout.GridData; 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 import org.eclipse.ui.PlatformUI; 31 32 37 public class DetailPaneMaxLengthDialog extends TrayDialog { 38 39 private static final String SETTINGS_ID = DebugUIPlugin.getUniqueIdentifier() + ".MAX_DETAILS_LENGTH_DIALOG"; 41 private Text fTextWidget; 42 private Text fErrorTextWidget; 43 private String fErrorMessage; 44 private String fValue; 45 private IInputValidator fValidator; 46 47 52 public DetailPaneMaxLengthDialog(Shell parent) { 53 super(parent); 54 setShellStyle(getShellStyle() | SWT.RESIZE); 55 fValue = Integer.toString(DebugUIPlugin.getDefault().getPreferenceStore().getInt(IDebugUIConstants.PREF_MAX_DETAIL_LENGTH)); 56 fValidator = new IInputValidator() { 57 public String isValid(String newText) { 58 try { 59 int num = Integer.parseInt(newText); 60 if (num < 0) { 61 return VariablesViewMessages.DetailPaneMaxLengthDialog_2; 62 } 63 } catch (NumberFormatException e) { 64 return VariablesViewMessages.DetailPaneMaxLengthDialog_3; 65 } 66 return null; 67 } 68 69 }; 70 } 71 72 75 protected IDialogSettings getDialogBoundsSettings() { 76 IDialogSettings settings = DebugUIPlugin.getDefault().getDialogSettings(); 77 IDialogSettings section = settings.getSection(SETTINGS_ID); 78 if (section == null) { 79 section = settings.addNewSection(SETTINGS_ID); 80 } 81 return section; 82 } 83 84 87 protected Control createContents(Composite parent) { 88 getShell().setText(VariablesViewMessages.DetailPaneMaxLengthDialog_0); 89 Control contents = super.createContents(parent); 90 PlatformUI.getWorkbench().getHelpSystem().setHelp(getDialogArea(), IDebugHelpContextIds.DETAIL_PANE_MAX_LENGTH_ACTION); 91 return contents; 92 } 93 94 97 protected Control createDialogArea(Composite parent) { 98 Composite composite = (Composite) super.createDialogArea(parent); 99 Label label = new Label(composite, SWT.WRAP); 100 label.setText(VariablesViewMessages.DetailPaneMaxLengthDialog_1); 101 GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER); 102 data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); 103 label.setLayoutData(data); 104 label.setFont(parent.getFont()); 105 fTextWidget = new Text(composite, SWT.SINGLE | SWT.BORDER); 106 fTextWidget.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); 107 fTextWidget.setText(fValue); 108 fTextWidget.addModifyListener(new ModifyListener() { 109 public void modifyText(ModifyEvent e) { 110 validateInput(); 111 fValue = fTextWidget.getText(); 112 } 113 }); 114 fErrorTextWidget = new Text(composite, SWT.READ_ONLY); 115 fErrorTextWidget.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL 116 | GridData.HORIZONTAL_ALIGN_FILL)); 117 fErrorTextWidget.setBackground(fErrorTextWidget.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); 118 setErrorMessage(fErrorMessage); 119 applyDialogFont(composite); 120 return composite; 121 } 122 123 126 protected void okPressed() { 127 String text = getValue(); 128 try { 129 DebugUIPlugin.getDefault().getPreferenceStore().setValue(IDebugUIConstants.PREF_MAX_DETAIL_LENGTH, Integer.parseInt(text)); 130 } 131 catch (NumberFormatException e) { 132 DebugUIPlugin.log(e); 133 } 134 super.okPressed(); 135 } 136 137 143 public String getValue() { 144 return fValue; 145 } 146 147 151 private void validateInput() { 152 String errorMessage = null; 153 if (fValidator != null) { 154 errorMessage = fValidator.isValid(fTextWidget.getText()); 155 } 156 setErrorMessage(errorMessage); 157 } 158 159 164 public void setErrorMessage(String errorMessage) { 165 fErrorMessage = errorMessage; 166 if (fErrorTextWidget != null && !fErrorTextWidget.isDisposed()) { 167 fErrorTextWidget.setText(errorMessage == null ? "" : errorMessage); fErrorTextWidget.getParent().update(); 169 Control button = getButton(IDialogConstants.OK_ID); 172 if (button != null) { 173 button.setEnabled(errorMessage == null); 174 } 175 } 176 } 177 } 178 | Popular Tags |