KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > callhierarchy > FiltersDialog


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  * Jesper Kamstrup Linnet (eclipse@kamstrup-linnet.dk) - initial API and implementation
10  * (report 36180: Callers/Callees view)
11  *******************************************************************************/

12 package org.eclipse.jdt.internal.ui.callhierarchy;
13
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.events.ModifyEvent;
16 import org.eclipse.swt.events.ModifyListener;
17 import org.eclipse.swt.events.SelectionAdapter;
18 import org.eclipse.swt.events.SelectionEvent;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.layout.GridLayout;
21 import org.eclipse.swt.widgets.Button;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Control;
24 import org.eclipse.swt.widgets.Label;
25 import org.eclipse.swt.widgets.Shell;
26 import org.eclipse.swt.widgets.Text;
27
28 import org.eclipse.jface.dialogs.IDialogConstants;
29 import org.eclipse.jface.dialogs.StatusDialog;
30
31 import org.eclipse.ui.PlatformUI;
32
33 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
34 import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
35
36 import org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchy;
37
38 class FiltersDialog extends StatusDialog {
39     private Label fNamesHelpText;
40     private Button fFilterOnNames;
41     private Text fNames;
42     private Text fMaxCallDepth;
43
44     /**
45      * @param parentShell
46      */

47     protected FiltersDialog(Shell parentShell) {
48         super(parentShell);
49     }
50
51     /* (non-Javadoc)
52      * Method declared on Window.
53      */

54     protected void configureShell(Shell newShell) {
55         super.configureShell(newShell);
56         newShell.setText(CallHierarchyMessages.FiltersDialog_filter);
57         PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaHelpContextIds.CALL_HIERARCHY_FILTERS_DIALOG);
58     }
59
60     /* (non-Javadoc)
61      * Method declared on Dialog.
62      */

63     protected Control createDialogArea(Composite parent) {
64         Composite superComposite = (Composite) super.createDialogArea(parent);
65
66         Composite composite = new Composite(superComposite, SWT.NONE);
67         composite.setFont(superComposite.getFont());
68         composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
69
70         GridLayout layout = new GridLayout();
71         layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
72         layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
73         layout.verticalSpacing= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
74         layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
75         composite.setLayout(layout);
76
77         createNamesArea(composite);
78         new Label(composite, SWT.NONE); // Filler
79
createMaxCallDepthArea(composite);
80             
81         updateUIFromFilter();
82         
83         return composite;
84     }
85     
86     private void createMaxCallDepthArea(Composite parent) {
87         Composite composite= new Composite(parent, SWT.NONE);
88         composite.setFont(parent.getFont());
89         GridLayout layout = new GridLayout();
90         layout.numColumns = 2;
91         composite.setLayout(layout);
92
93         Label label= new Label(composite, SWT.NONE);
94         label.setFont(composite.getFont());
95         label.setText(CallHierarchyMessages.FiltersDialog_maxCallDepth);
96         
97         fMaxCallDepth = new Text(composite, SWT.SINGLE | SWT.BORDER);
98         fMaxCallDepth.setFont(composite.getFont());
99         fMaxCallDepth.setTextLimit(6);
100         fMaxCallDepth.addModifyListener(new ModifyListener() {
101                 public void modifyText(ModifyEvent e) {
102                     validateInput();
103                 }
104             });
105
106         GridData gridData = new GridData();
107         gridData.widthHint = convertWidthInCharsToPixels(10);
108         fMaxCallDepth.setLayoutData(gridData);
109     }
110
111     private void createNamesArea(Composite parent) {
112         fFilterOnNames = createCheckbox(parent,
113                 CallHierarchyMessages.FiltersDialog_filterOnNames, true);
114         
115         fNames= new Text(parent, SWT.SINGLE | SWT.BORDER);
116         fNames.setFont(parent.getFont());
117         fNames.addModifyListener(new ModifyListener() {
118                 public void modifyText(ModifyEvent e) {
119                     validateInput();
120                 }
121             });
122
123         GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
124         gridData.widthHint = convertWidthInCharsToPixels(60);
125         fNames.setLayoutData(gridData);
126         
127         fNamesHelpText= new Label(parent, SWT.LEFT);
128         fNamesHelpText.setFont(parent.getFont());
129         fNamesHelpText.setText(CallHierarchyMessages.FiltersDialog_filterOnNamesSubCaption);
130     }
131
132     /**
133      * Creates a check box button with the given parent and text.
134      *
135      * @param parent the parent composite
136      * @param text the text for the check box
137      * @param grabRow <code>true</code>to grab the remaining horizontal space,
138      * <code>false</code> otherwise
139      *
140      * @return the check box button
141      */

142     private Button createCheckbox(Composite parent, String JavaDoc text, boolean grabRow) {
143         Button button = new Button(parent, SWT.CHECK);
144         button.setFont(parent.getFont());
145         
146         if (grabRow) {
147             GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
148             button.setLayoutData(gridData);
149         }
150
151         button.setText(text);
152         button.addSelectionListener(new SelectionAdapter() {
153             public void widgetSelected(SelectionEvent e) {
154                 validateInput();
155                 updateEnabledState();
156             }
157         });
158
159         return button;
160     }
161
162     /**
163      * Updates the enabled state of the widgetry.
164      */

165     private void updateEnabledState() {
166         fNames.setEnabled(fFilterOnNames.getSelection());
167         fNamesHelpText.setEnabled(fFilterOnNames.getSelection());
168     }
169     
170     /**
171      * Updates the given filter from the UI state.
172      */

173     private void updateFilterFromUI() {
174         int maxCallDepth = Integer.parseInt(this.fMaxCallDepth.getText());
175
176         CallHierarchyUI.getDefault().setMaxCallDepth(maxCallDepth);
177         CallHierarchy.getDefault().setFilters(fNames.getText());
178         CallHierarchy.getDefault().setFilterEnabled(fFilterOnNames.getSelection());
179     }
180     
181     /**
182      * Updates the UI state from the given filter.
183      */

184     private void updateUIFromFilter() {
185       fMaxCallDepth.setText(String.valueOf(CallHierarchyUI.getDefault().getMaxCallDepth()));
186       fNames.setText(CallHierarchy.getDefault().getFilters());
187       fFilterOnNames.setSelection(CallHierarchy.getDefault().isFilterEnabled());
188       updateEnabledState();
189     }
190     
191     /**
192      * Updates the filter from the UI state.
193      * Must be done here rather than by extending open()
194      * because after super.open() is called, the widgetry is disposed.
195      * @see org.eclipse.jface.dialogs.Dialog#okPressed()
196      */

197     protected void okPressed() {
198         if (!isMaxCallDepthValid()) {
199             if (fMaxCallDepth.forceFocus()) {
200                 fMaxCallDepth.setSelection(0, fMaxCallDepth.getCharCount());
201                 fMaxCallDepth.showSelection();
202             }
203         }
204         
205         updateFilterFromUI();
206         super.okPressed();
207     }
208
209     private boolean isMaxCallDepthValid() {
210         String JavaDoc text= fMaxCallDepth.getText();
211         if (text.length() == 0)
212             return false;
213             
214         try {
215             int maxCallDepth= Integer.parseInt(text);
216
217             return (maxCallDepth >= 1 && maxCallDepth <= 99);
218         } catch (NumberFormatException JavaDoc e) {
219             return false;
220         }
221     }
222     
223     private void validateInput() {
224         StatusInfo status= new StatusInfo();
225         if (!isMaxCallDepthValid()) {
226             status.setError(CallHierarchyMessages.FiltersDialog_messageMaxCallDepthInvalid);
227         }
228         updateStatus(status);
229     }
230 }
231
Popular Tags