1 11 12 package org.eclipse.debug.internal.ui.views.memory; 13 14 15 import org.eclipse.debug.core.model.IMemoryBlockRetrieval; 16 import org.eclipse.debug.core.model.IMemoryBlockRetrievalExtension; 17 import org.eclipse.debug.internal.ui.DebugUIMessages; 18 import org.eclipse.debug.internal.ui.SWTFactory; 19 import org.eclipse.debug.ui.IDebugUIConstants; 20 import org.eclipse.jface.dialogs.IDialogConstants; 21 import org.eclipse.jface.dialogs.TrayDialog; 22 import org.eclipse.swt.SWT; 23 import org.eclipse.swt.events.ModifyEvent; 24 import org.eclipse.swt.events.ModifyListener; 25 import org.eclipse.swt.widgets.Combo; 26 import org.eclipse.swt.widgets.Composite; 27 import org.eclipse.swt.widgets.Control; 28 import org.eclipse.swt.widgets.Shell; 29 import org.eclipse.swt.widgets.Text; 30 import org.eclipse.ui.PlatformUI; 31 32 35 public class MonitorMemoryBlockDialog extends TrayDialog implements ModifyListener{ 36 37 private Combo expressionInput; 38 private Text lengthInput; 39 private String expression; 40 private String length; 41 private boolean needLength = true; 42 private String fPrefillExp = null; 43 private String fPrefillLength = null; 44 45 49 private static final int LABEL_WIDTH = 210; 50 51 54 public MonitorMemoryBlockDialog(Shell parentShell, IMemoryBlockRetrieval memRetrieval, String prefillExp, String prefillLength) { 55 super(parentShell); 56 57 if (memRetrieval instanceof IMemoryBlockRetrievalExtension) 58 needLength = false; 59 60 fPrefillExp = prefillExp; 61 fPrefillLength = prefillLength; 62 setShellStyle(getShellStyle() | SWT.RESIZE); 63 } 64 65 68 protected Control createDialogArea(Composite parent) { 69 Composite comp = (Composite) super.createDialogArea(parent); 70 SWTFactory.createWrapLabel(comp, DebugUIMessages.MonitorMemoryBlockDialog_EnterExpressionToMonitor, 1, LABEL_WIDTH); 71 expressionInput = SWTFactory.createCombo(comp, SWT.BORDER, 1, MemoryViewUtil.getHistory()); 72 if (fPrefillExp != null) { 73 expressionInput.setText(fPrefillExp); 74 } 75 expressionInput.addModifyListener(this); 76 77 if (needLength) { 78 SWTFactory.createLabel(comp, DebugUIMessages.MonitorMemoryBlockDialog_NumberOfBytes, 1); 79 lengthInput = SWTFactory.createSingleText(comp, 1); 80 if (fPrefillLength != null) { 81 lengthInput.setText(fPrefillLength); 82 } 83 lengthInput.addModifyListener(this); 84 } 85 PlatformUI.getWorkbench().getHelpSystem().setHelp(comp, IDebugUIConstants.PLUGIN_ID + ".MonitorMemoryBlockDialog_context"); return comp; 87 } 88 91 protected void configureShell(Shell newShell) { 92 super.configureShell(newShell); 93 94 newShell.setText(DebugUIMessages.MonitorMemoryBlockDialog_MonitorMemory); 95 } 96 97 100 public String getExpression() { 101 return expression; 102 } 103 104 107 public String getLength() { 108 return length; 109 } 110 111 114 protected void okPressed() { 115 116 expression = expressionInput.getText(); 117 118 MemoryViewUtil.addHistory(expression); 120 121 if (needLength) 122 length = lengthInput.getText(); 123 124 super.okPressed(); 125 } 126 127 130 public void modifyText(ModifyEvent e) { 131 updateOKButtonState(); 132 } 133 134 private void updateOKButtonState() { 135 if (needLength) 136 { 137 String lengthText = lengthInput.getText(); 138 String input = expressionInput.getText(); 139 140 if (input == null || input.equals("") || lengthText == null || lengthText.equals("")) { 142 getButton(IDialogConstants.OK_ID).setEnabled(false); 143 } 144 else 145 { 146 getButton(IDialogConstants.OK_ID).setEnabled(true); 147 } 148 } 149 } 150 151 154 protected Control createButtonBar(Composite parent) { 155 156 Control ret = super.createButtonBar(parent); 157 158 if (needLength) 159 updateOKButtonState(); 160 else 161 getButton(IDialogConstants.OK_ID).setEnabled(true); 163 164 return ret; 165 } 166 } 167 | Popular Tags |