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