KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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;
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 /**
36  * Dialog for edit watch expression.
37  */

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

43     private IWatchExpression fWatchExpression;
44
45     // widgets
46
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 JavaDoc helpContextId = null;
54         if (editDialog) {
55             setTitle(ActionMessages.WatchExpressionDialog_0); //$NON-NLS-1$
56
helpContextId = IDebugHelpContextIds.EDIT_WATCH_EXPRESSION_DIALOG;
57         } else {
58             setTitle(ActionMessages.WatchExpressionDialog_1); //$NON-NLS-1$
59
helpContextId = IDebugHelpContextIds.ADD_WATCH_EXPRESSION_DIALOG;
60         }
61         PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, helpContextId);
62     }
63
64     /**
65      * Create the dialog area.
66      *
67      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(Composite)
68      */

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         // snippet label
79
Label label= new Label(container, SWT.NONE);
80         label.setText(ActionMessages.WatchExpressionDialog_2); //$NON-NLS-1$
81
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         //IDocumentPartitioner partitioner= new RuleBasedPartitioner(...);
91
//document.setDocumentPartitioner(partitioner);
92
//partitioner.connect(document);
93
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         // enable checkbox
114
fCheckBox= new Button(container, SWT.CHECK | SWT.LEFT);
115         fCheckBox.setText(ActionMessages.WatchExpressionDialog_3); //$NON-NLS-1$
116
fCheckBox.setSelection(fWatchExpression.isEnabled());
117         fCheckBox.setFont(font);
118
119         applyDialogFont(container);
120         fSnippetViewer.getControl().setFocus();
121         return container;
122     }
123
124     /**
125      * @see org.eclipse.jface.dialogs.Dialog#okPressed()
126      */

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

136     private void checkValues() {
137         StatusInfo status= new StatusInfo();
138         if (fSnippetViewer.getDocument().get().trim().length() == 0) {
139             status.setError(ActionMessages.WatchExpressionDialog_4); //$NON-NLS-1$
140
}
141         updateStatus(status);
142     }
143
144 }
145
Popular Tags