1 11 package org.eclipse.debug.internal.ui.actions; 12 13 14 import org.eclipse.debug.core.model.IWatchExpression; 15 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 16 import org.eclipse.jface.dialogs.StatusDialog; 17 import org.eclipse.jface.resource.JFaceResources; 18 import org.eclipse.jface.text.Document; 19 import org.eclipse.jface.text.DocumentEvent; 20 import org.eclipse.jface.text.IDocument; 21 import org.eclipse.jface.text.IDocumentListener; 22 import org.eclipse.jface.text.source.SourceViewer; 23 import org.eclipse.jface.text.source.SourceViewerConfiguration; 24 import org.eclipse.swt.SWT; 25 import org.eclipse.swt.graphics.Font; 26 import org.eclipse.swt.layout.GridData; 27 import org.eclipse.swt.layout.GridLayout; 28 import org.eclipse.swt.widgets.Button; 29 import org.eclipse.swt.widgets.Composite; 30 import org.eclipse.swt.widgets.Control; 31 import org.eclipse.swt.widgets.Label; 32 import org.eclipse.swt.widgets.Shell; 33 import org.eclipse.ui.PlatformUI; 34 35 38 public class WatchExpressionDialog extends StatusDialog { 39 40 43 private IWatchExpression fWatchExpression; 44 45 private SourceViewer fSnippetViewer; 47 private Button fCheckBox; 48 49 public WatchExpressionDialog(Shell parent, IWatchExpression watchExpression, boolean editDialog) { 50 super(parent); 51 fWatchExpression= watchExpression; 52 setShellStyle(getShellStyle() | SWT.MAX | SWT.RESIZE); 53 String helpContextId = null; 54 if (editDialog) { 55 setTitle(ActionMessages.WatchExpressionDialog_0); helpContextId = IDebugHelpContextIds.EDIT_WATCH_EXPRESSION_DIALOG; 57 } else { 58 setTitle(ActionMessages.WatchExpressionDialog_1); helpContextId = IDebugHelpContextIds.ADD_WATCH_EXPRESSION_DIALOG; 60 } 61 PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, helpContextId); 62 } 63 64 69 protected Control createDialogArea(Composite parent) { 70 Font font = parent.getFont(); 71 72 Composite container = new Composite(parent, SWT.NONE); 73 GridLayout layout = new GridLayout(); 74 container.setLayout(layout); 75 GridData gd= new GridData(GridData.FILL_BOTH); 76 container.setLayoutData(gd); 77 78 Label label= new Label(container, SWT.NONE); 80 label.setText(ActionMessages.WatchExpressionDialog_2); gd= new GridData(GridData.BEGINNING); 82 label.setLayoutData(gd); 83 label.setFont(font); 84 85 fSnippetViewer= new SourceViewer(container, null, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); 86 fSnippetViewer.setInput(this); 87 88 89 IDocument document= new Document(); 90 fSnippetViewer.configure(new SourceViewerConfiguration()); 94 fSnippetViewer.setEditable(true); 95 fSnippetViewer.setDocument(document); 96 document.addDocumentListener(new IDocumentListener() { 97 public void documentAboutToBeChanged(DocumentEvent event) { 98 } 99 public void documentChanged(DocumentEvent event) { 100 checkValues(); 101 } 102 }); 103 104 fSnippetViewer.getTextWidget().setFont(JFaceResources.getTextFont()); 105 106 Control control= fSnippetViewer.getControl(); 107 gd= new GridData(GridData.FILL_BOTH); 108 gd.heightHint= convertHeightInCharsToPixels(10); 109 gd.widthHint= convertWidthInCharsToPixels(80); 110 control.setLayoutData(gd); 111 fSnippetViewer.getDocument().set(fWatchExpression.getExpressionText()); 112 113 fCheckBox= new Button(container, SWT.CHECK | SWT.LEFT); 115 fCheckBox.setText(ActionMessages.WatchExpressionDialog_3); fCheckBox.setSelection(fWatchExpression.isEnabled()); 117 fCheckBox.setFont(font); 118 119 applyDialogFont(container); 120 fSnippetViewer.getControl().setFocus(); 121 return container; 122 } 123 124 127 protected void okPressed() { 128 fWatchExpression.setEnabled(fCheckBox.getSelection()); 129 fWatchExpression.setExpressionText(fSnippetViewer.getDocument().get()); 130 super.okPressed(); 131 } 132 133 136 private void checkValues() { 137 StatusInfo status= new StatusInfo(); 138 if (fSnippetViewer.getDocument().get().trim().length() == 0) { 139 status.setError(ActionMessages.WatchExpressionDialog_4); } 141 updateStatus(status); 142 } 143 144 } 145 | Popular Tags |