KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > actions > expressions > WatchExpressionDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
38  * Dialog for edit watch expression.
39  */

40 public class WatchExpressionDialog extends StatusDialog {
41
42     /**
43      * The detail formatter to edit.
44      */

45     private IWatchExpression fWatchExpression;
46     
47     // widgets
48
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 JavaDoc 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     /**
67      * Create the dialog area.
68      *
69      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(Composite)
70      */

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         // snippet label
81
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         // enable checkbox
112
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     /**
123      * @see org.eclipse.jface.dialogs.Dialog#okPressed()
124      */

125     protected void okPressed() {
126         fWatchExpression.setEnabled(fCheckBox.getSelection());
127         fWatchExpression.setExpressionText(fSnippetViewer.getDocument().get());
128         super.okPressed();
129     }
130     
131     /**
132      * Check the field values and display a message in the status if needed.
133      */

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