]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2011 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.StatusDialog; | |
29 | ||
30 | import org.eclipse.ui.PlatformUI; | |
31 | ||
32 | import org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchy; | |
33 | ||
34 | import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; | |
35 | import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; | |
36 | ||
37 | class FiltersDialog extends StatusDialog { | |
38 | private Label fNamesHelpText; | |
39 | private Button fFilterOnNames; | |
40 | private Text fNames; | |
41 | private Text fMaxCallDepth; | |
42 | ||
43 | ||
44 | protected FiltersDialog(Shell parentShell) { | |
45 | super(parentShell); | |
46 | } | |
47 | ||
48 | /* (non-Javadoc) | |
49 | * Method declared on Window. | |
50 | */ | |
51 | @Override | |
52 | protected void configureShell(Shell newShell) { | |
53 | super.configureShell(newShell); | |
54 | newShell.setText(CallHierarchyMessages.FiltersDialog_filter); | |
55 | PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaHelpContextIds.CALL_HIERARCHY_FILTERS_DIALOG); | |
56 | } | |
57 | ||
58 | /** | |
59 | * {@inheritDoc} | |
60 | */ | |
61 | @Override | |
62 | protected boolean isResizable() { | |
63 | return true; | |
64 | } | |
65 | ||
66 | /* (non-Javadoc) | |
67 | * Method declared on Dialog. | |
68 | */ | |
69 | @Override | |
70 | protected Control createDialogArea(Composite parent) { | |
71 | Composite composite= (Composite) super.createDialogArea(parent); | |
72 | ||
73 | createNamesArea(composite); | |
74 | new Label(composite, SWT.NONE); // Filler | |
75 | createMaxCallDepthArea(composite); | |
76 | ||
77 | updateUIFromFilter(); | |
78 | ||
79 | return composite; | |
80 | } | |
81 | ||
82 | private void createMaxCallDepthArea(Composite parent) { | |
83 | Composite composite= new Composite(parent, SWT.NONE); | |
84 | composite.setFont(parent.getFont()); | |
85 | GridLayout layout = new GridLayout(); | |
86 | layout.numColumns = 2; | |
87 | composite.setLayout(layout); | |
88 | ||
89 | Label label= new Label(composite, SWT.NONE); | |
90 | label.setFont(composite.getFont()); | |
91 | label.setText(CallHierarchyMessages.FiltersDialog_maxCallDepth); | |
92 | ||
93 | fMaxCallDepth = new Text(composite, SWT.SINGLE | SWT.BORDER); | |
94 | fMaxCallDepth.setFont(composite.getFont()); | |
95 | fMaxCallDepth.setTextLimit(6); | |
96 | fMaxCallDepth.addModifyListener(new ModifyListener() { | |
97 | public void modifyText(ModifyEvent e) { | |
98 | validateInput(); | |
99 | } | |
100 | }); | |
101 | ||
102 | GridData gridData = new GridData(); | |
103 | gridData.widthHint = convertWidthInCharsToPixels(10); | |
104 | fMaxCallDepth.setLayoutData(gridData); | |
105 | } | |
106 | ||
107 | private void createNamesArea(Composite parent) { | |
108 | fFilterOnNames = createCheckbox(parent, | |
109 | CallHierarchyMessages.FiltersDialog_filterOnNames, true); | |
110 | ||
111 | fNames= new Text(parent, SWT.SINGLE | SWT.BORDER); | |
112 | fNames.setFont(parent.getFont()); | |
113 | fNames.addModifyListener(new ModifyListener() { | |
114 | public void modifyText(ModifyEvent e) { | |
115 | validateInput(); | |
116 | } | |
117 | }); | |
118 | ||
119 | GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL); | |
120 | gridData.widthHint = convertWidthInCharsToPixels(60); | |
121 | fNames.setLayoutData(gridData); | |
122 | ||
123 | fNamesHelpText= new Label(parent, SWT.LEFT); | |
124 | fNamesHelpText.setFont(parent.getFont()); | |
125 | fNamesHelpText.setText(CallHierarchyMessages.FiltersDialog_filterOnNamesSubCaption); | |
126 | } | |
127 | ||
128 | /** | |
129 | * Creates a check box button with the given parent and text. | |
130 | * | |
131 | * @param parent the parent composite | |
132 | * @param text the text for the check box | |
133 | * @param grabRow <code>true</code>to grab the remaining horizontal space, | |
134 | * <code>false</code> otherwise | |
135 | * | |
136 | * @return the check box button | |
137 | */ | |
138 | private Button createCheckbox(Composite parent, String text, boolean grabRow) { | |
139 | Button button = new Button(parent, SWT.CHECK); | |
140 | button.setFont(parent.getFont()); | |
141 | ||
142 | if (grabRow) { | |
143 | GridData gridData = new GridData(GridData.FILL_HORIZONTAL); | |
144 | button.setLayoutData(gridData); | |
145 | } | |
146 | ||
147 | button.setText(text); | |
148 | button.addSelectionListener(new SelectionAdapter() { | |
149 | @Override | |
150 | public void widgetSelected(SelectionEvent e) { | |
151 | validateInput(); | |
152 | updateEnabledState(); | |
153 | } | |
154 | }); | |
155 | ||
156 | return button; | |
157 | } | |
158 | ||
159 | /** | |
160 | * Updates the enabled state of the widgetry. | |
161 | */ | |
162 | private void updateEnabledState() { | |
163 | fNames.setEnabled(fFilterOnNames.getSelection()); | |
164 | fNamesHelpText.setEnabled(fFilterOnNames.getSelection()); | |
165 | } | |
166 | ||
167 | /** | |
168 | * Updates the given filter from the UI state. | |
169 | */ | |
170 | private void updateFilterFromUI() { | |
171 | int maxCallDepth = Integer.parseInt(this.fMaxCallDepth.getText()); | |
172 | ||
173 | CallHierarchyUI.getDefault().setMaxCallDepth(maxCallDepth); | |
174 | CallHierarchy.getDefault().setFilters(fNames.getText()); | |
175 | CallHierarchy.getDefault().setFilterEnabled(fFilterOnNames.getSelection()); | |
176 | } | |
177 | ||
178 | /** | |
179 | * Updates the UI state from the given filter. | |
180 | */ | |
181 | private void updateUIFromFilter() { | |
182 | fMaxCallDepth.setText(String.valueOf(CallHierarchyUI.getDefault().getMaxCallDepth())); | |
183 | fNames.setText(CallHierarchy.getDefault().getFilters()); | |
184 | fFilterOnNames.setSelection(CallHierarchy.getDefault().isFilterEnabled()); | |
185 | updateEnabledState(); | |
186 | } | |
187 | ||
188 | /** | |
189 | * Updates the filter from the UI state. | |
190 | * Must be done here rather than by extending open() | |
191 | * because after super.open() is called, the widgetry is disposed. | |
192 | * @see org.eclipse.jface.dialogs.Dialog#okPressed() | |
193 | */ | |
194 | @Override | |
195 | protected void okPressed() { | |
196 | if (!isMaxCallDepthValid()) { | |
197 | if (fMaxCallDepth.forceFocus()) { | |
198 | fMaxCallDepth.setSelection(0, fMaxCallDepth.getCharCount()); | |
199 | fMaxCallDepth.showSelection(); | |
200 | } | |
201 | } | |
202 | ||
203 | updateFilterFromUI(); | |
204 | super.okPressed(); | |
205 | } | |
206 | ||
207 | private boolean isMaxCallDepthValid() { | |
208 | String text= fMaxCallDepth.getText(); | |
209 | if (text.length() == 0) | |
210 | return false; | |
211 | ||
212 | try { | |
213 | int maxCallDepth= Integer.parseInt(text); | |
214 | ||
215 | return (maxCallDepth >= 1 && maxCallDepth <= 99); | |
216 | } catch (NumberFormatException e) { | |
217 | return false; | |
218 | } | |
219 | } | |
220 | ||
221 | private void validateInput() { | |
222 | StatusInfo status= new StatusInfo(); | |
223 | if (!isMaxCallDepthValid()) { | |
224 | status.setError(CallHierarchyMessages.FiltersDialog_messageMaxCallDepthInvalid); | |
225 | } | |
226 | updateStatus(status); | |
227 | } | |
228 | } |