|
Lines 4-109
Link Here
|
| 4 |
*/ |
4 |
*/ |
| 5 |
package org.eclipse.jdt.internal.junit.ui; |
5 |
package org.eclipse.jdt.internal.junit.ui; |
| 6 |
|
6 |
|
|
|
7 |
import java.util.ArrayList; |
| 8 |
import java.util.Arrays; |
| 9 |
import java.util.Iterator; |
| 10 |
import java.util.List; |
| 11 |
import java.util.StringTokenizer; |
| 12 |
|
| 13 |
import org.eclipse.jdt.core.IJavaElement; |
| 14 |
import org.eclipse.jdt.core.IType; |
| 15 |
import org.eclipse.jdt.core.JavaModelException; |
| 16 |
import org.eclipse.jdt.core.search.SearchEngine; |
| 17 |
import org.eclipse.jdt.internal.junit.util.ExceptionHandler; |
| 18 |
import org.eclipse.jdt.internal.junit.util.SWTUtil; |
| 19 |
import org.eclipse.jdt.ui.IJavaElementSearchConstants; |
| 20 |
import org.eclipse.jdt.ui.ISharedImages; |
| 21 |
import org.eclipse.jdt.ui.JavaUI; |
| 7 |
import org.eclipse.jface.dialogs.IDialogConstants; |
22 |
import org.eclipse.jface.dialogs.IDialogConstants; |
| 8 |
import org.eclipse.jface.preference.*; |
23 |
import org.eclipse.jface.dialogs.ProgressMonitorDialog; |
|
|
24 |
import org.eclipse.jface.preference.IPreferenceStore; |
| 25 |
import org.eclipse.jface.preference.PreferencePage; |
| 26 |
import org.eclipse.jface.viewers.CheckStateChangedEvent; |
| 27 |
import org.eclipse.jface.viewers.CheckboxTableViewer; |
| 28 |
import org.eclipse.jface.viewers.ColumnLayoutData; |
| 29 |
import org.eclipse.jface.viewers.ColumnWeightData; |
| 30 |
import org.eclipse.jface.viewers.ContentViewer; |
| 31 |
import org.eclipse.jface.viewers.ICheckStateListener; |
| 32 |
import org.eclipse.jface.viewers.ILabelProvider; |
| 33 |
import org.eclipse.jface.viewers.ISelection; |
| 34 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
| 35 |
import org.eclipse.jface.viewers.IStructuredContentProvider; |
| 36 |
import org.eclipse.jface.viewers.IStructuredSelection; |
| 37 |
import org.eclipse.jface.viewers.ITableLabelProvider; |
| 38 |
import org.eclipse.jface.viewers.LabelProvider; |
| 39 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
| 40 |
import org.eclipse.jface.viewers.TableLayout; |
| 41 |
import org.eclipse.jface.viewers.Viewer; |
| 9 |
import org.eclipse.swt.SWT; |
42 |
import org.eclipse.swt.SWT; |
| 10 |
import org.eclipse.swt.events.*; |
43 |
import org.eclipse.swt.custom.TableEditor; |
| 11 |
import org.eclipse.swt.layout.*; |
44 |
import org.eclipse.swt.events.FocusAdapter; |
| 12 |
import org.eclipse.swt.widgets.*; |
45 |
import org.eclipse.swt.events.FocusEvent; |
| 13 |
import org.eclipse.ui.*; |
46 |
import org.eclipse.swt.events.KeyAdapter; |
|
|
47 |
import org.eclipse.swt.events.KeyEvent; |
| 48 |
import org.eclipse.swt.graphics.Image; |
| 49 |
import org.eclipse.swt.layout.GridData; |
| 50 |
import org.eclipse.swt.layout.GridLayout; |
| 51 |
import org.eclipse.swt.widgets.Button; |
| 52 |
import org.eclipse.swt.widgets.Composite; |
| 53 |
import org.eclipse.swt.widgets.Control; |
| 54 |
import org.eclipse.swt.widgets.Event; |
| 55 |
import org.eclipse.swt.widgets.Label; |
| 56 |
import org.eclipse.swt.widgets.Listener; |
| 57 |
import org.eclipse.swt.widgets.Shell; |
| 58 |
import org.eclipse.swt.widgets.Table; |
| 59 |
import org.eclipse.swt.widgets.TableColumn; |
| 60 |
import org.eclipse.swt.widgets.TableItem; |
| 61 |
import org.eclipse.swt.widgets.Text; |
| 62 |
import org.eclipse.ui.IWorkbench; |
| 63 |
import org.eclipse.ui.IWorkbenchPreferencePage; |
| 64 |
import org.eclipse.ui.dialogs.ElementListSelectionDialog; |
| 65 |
import org.eclipse.ui.dialogs.SelectionDialog; |
| 14 |
import org.eclipse.ui.help.WorkbenchHelp; |
66 |
import org.eclipse.ui.help.WorkbenchHelp; |
|
|
67 |
import org.eclipse.ui.model.WorkbenchViewerSorter; |
| 15 |
|
68 |
|
| 16 |
/** |
69 |
/** |
| 17 |
* Preference page for JUnit settings. Supports to define the failure |
70 |
* Preference page for JUnit settings. Supports to define the failure |
| 18 |
* stack filter patterns. |
71 |
* stack filter patterns. |
| 19 |
*/ |
72 |
*/ |
| 20 |
public class JUnitPreferencePage extends PreferencePage |
73 |
public class JUnitPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { |
| 21 |
implements IWorkbenchPreferencePage, SelectionListener { |
74 |
|
| 22 |
|
75 |
private static final String DEFAULT_NEW_FILTER_TEXT= ""; //$NON-NLS-1$ |
| 23 |
private String fFilterString; |
76 |
private static final Image IMG_CUNIT= JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_CLASS); |
| 24 |
private Table fTable; |
77 |
private static final Image IMG_PKG= JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_PACKAGE); |
| 25 |
private Button fAddButton; |
|
|
| 26 |
private Button fRemoveButton; |
| 27 |
private Button fShowOnErrorCheck; |
| 28 |
|
| 29 |
public static String STACK_FILTER_ENTRIES_COUNT= "NOF_STACK_FILTER_ENTRIES"; //$NON-NLS-1$ |
| 30 |
public static String STACK_FILTER_ENTRY_= "STACK_FILTER_ENTRY_"; //$NON-NLS-1$ |
| 31 |
public static String DO_FILTER_STACK= "DO_FILTER_STACK"; //$NON-NLS-1$ |
| 32 |
public static String SHOW_ON_ERROR_ONLY= "SHOW_ON_ERROR"; //$NON-NLS-1$ |
| 33 |
|
78 |
|
| 34 |
private static String[] fgDefaultFilterPatterns= new String[] { |
79 |
private static String[] fgDefaultFilterPatterns= new String[] { "org.eclipse.jdt.internal.junit.runner.*", //$NON-NLS-1$ |
| 35 |
"org.eclipse.jdt.internal.junit.runner", //$NON-NLS-1$ |
80 |
"org.eclipse.jdt.internal.junit.ui.*", //$NON-NLS-1$ |
| 36 |
"org.eclipse.jdt.internal.junit.ui", //$NON-NLS-1$ |
|
|
| 37 |
"junit.framework.TestCase", //$NON-NLS-1$ |
81 |
"junit.framework.TestCase", //$NON-NLS-1$ |
| 38 |
"junit.framework.TestResult", //$NON-NLS-1$ |
82 |
"junit.framework.TestResult", //$NON-NLS-1$ |
| 39 |
"junit.framework.TestSuite", //$NON-NLS-1$ |
83 |
"junit.framework.TestSuite", //$NON-NLS-1$ |
| 40 |
"junit.framework.Assert.", // don't filter AssertionFailure //$NON-NLS-1$ |
84 |
"junit.framework.Assert", //$NON-NLS-1$ |
| 41 |
"java.lang.reflect.Method.invoke" //$NON-NLS-1$ |
85 |
"java.lang.reflect.Method.invoke" //$NON-NLS-1$ |
| 42 |
}; |
86 |
}; |
| 43 |
|
87 |
|
| 44 |
public JUnitPreferencePage() { |
88 |
// Step filter widgets |
| 45 |
super(); |
89 |
private CheckboxTableViewer fFilterViewer; |
| 46 |
setPreferenceStore(JUnitPlugin.getDefault().getPreferenceStore()); |
90 |
private Table fFilterTable; |
| 47 |
} |
|
|
| 48 |
|
91 |
|
| 49 |
public static String[] getFilterPatterns() { |
92 |
private Button fShowOnErrorCheck; |
| 50 |
IPreferenceStore store= JUnitPlugin.getDefault().getPreferenceStore(); |
93 |
private Button fAddPackageButton; |
| 51 |
int count= store.getInt(STACK_FILTER_ENTRIES_COUNT); |
94 |
private Button fAddTypeButton; |
| 52 |
String[] result= new String[count]; |
95 |
private Button fRemoveFilterButton; |
| 53 |
for (int i= 0; i < count; i++) { |
96 |
private Button fAddFilterButton; |
| 54 |
result[i]= store.getString(STACK_FILTER_ENTRY_ + i); |
97 |
|
|
|
98 |
private Button fEnableAllButton; |
| 99 |
private Button fDisableAllButton; |
| 100 |
|
| 101 |
private Text fEditorText; |
| 102 |
private String fInvalidEditorText= null; |
| 103 |
private TableEditor fTableEditor; |
| 104 |
private TableItem fNewTableItem; |
| 105 |
private Filter fNewStackFilter; |
| 106 |
private Label fTableLabel; |
| 107 |
|
| 108 |
private StackFilterContentProvider fStackFilterContentProvider; |
| 109 |
|
| 110 |
/** |
| 111 |
* Model object that represents a single entry in the filter table. |
| 112 |
*/ |
| 113 |
private class Filter { |
| 114 |
|
| 115 |
private String fName; |
| 116 |
private boolean fChecked; |
| 117 |
|
| 118 |
public Filter(String name, boolean checked) { |
| 119 |
setName(name); |
| 120 |
setChecked(checked); |
| 121 |
} |
| 122 |
|
| 123 |
public String getName() { |
| 124 |
return fName; |
| 125 |
} |
| 126 |
|
| 127 |
public void setName(String name) { |
| 128 |
fName= name; |
| 129 |
} |
| 130 |
|
| 131 |
public boolean isChecked() { |
| 132 |
return fChecked; |
| 133 |
} |
| 134 |
|
| 135 |
public void setChecked(boolean checked) { |
| 136 |
fChecked= checked; |
| 137 |
} |
| 138 |
|
| 139 |
public boolean equals(Object o) { |
| 140 |
if (!(o instanceof Filter)) |
| 141 |
return false; |
| 142 |
|
| 143 |
Filter other= (Filter) o; |
| 144 |
return (getName().equals(other.getName())); |
| 145 |
} |
| 146 |
|
| 147 |
public int hashCode() { |
| 148 |
return fName.hashCode(); |
| 55 |
} |
149 |
} |
| 56 |
return result; |
|
|
| 57 |
} |
| 58 |
|
| 59 |
public static boolean getFilterStack() { |
| 60 |
IPreferenceStore store= JUnitPlugin.getDefault().getPreferenceStore(); |
| 61 |
return store.getBoolean(DO_FILTER_STACK); |
| 62 |
} |
150 |
} |
| 63 |
|
151 |
|
| 64 |
public static void setFilterStack(boolean filter) { |
152 |
/** |
| 65 |
IPreferenceStore store= JUnitPlugin.getDefault().getPreferenceStore(); |
153 |
* Sorter for the filter table; sorts alphabetically ascending. |
| 66 |
store.setValue(DO_FILTER_STACK, filter); |
154 |
*/ |
|
|
155 |
private class FilterViewerSorter extends WorkbenchViewerSorter { |
| 156 |
public int compare(Viewer viewer, Object e1, Object e2) { |
| 157 |
ILabelProvider lprov= (ILabelProvider) ((ContentViewer) viewer).getLabelProvider(); |
| 158 |
String name1= lprov.getText(e1); |
| 159 |
String name2= lprov.getText(e2); |
| 160 |
if (name1 == null) |
| 161 |
name1= ""; //$NON-NLS-1$ |
| 162 |
|
| 163 |
if (name2 == null) |
| 164 |
name2= ""; //$NON-NLS-1$ |
| 165 |
|
| 166 |
if (name1.length() > 0 && name2.length() > 0) { |
| 167 |
char char1= name1.charAt(name1.length() - 1); |
| 168 |
char char2= name2.charAt(name2.length() - 1); |
| 169 |
if (char1 == '*' && char1 != char2) |
| 170 |
return -1; |
| 171 |
|
| 172 |
if (char2 == '*' && char2 != char1) |
| 173 |
return 1; |
| 174 |
} |
| 175 |
return name1.compareTo(name2); |
| 176 |
} |
| 67 |
} |
177 |
} |
| 68 |
|
178 |
|
| 69 |
public static void initializeDefaults(IPreferenceStore store) { |
179 |
/** |
| 70 |
store.setDefault(JUnitPreferencePage.DO_FILTER_STACK, true); |
180 |
* Label provider for Filter model objects |
| 71 |
store.setDefault(JUnitPreferencePage.SHOW_ON_ERROR_ONLY, false); |
181 |
*/ |
| 72 |
int count= store.getInt(STACK_FILTER_ENTRIES_COUNT); |
182 |
private class FilterLabelProvider extends LabelProvider implements ITableLabelProvider { |
| 73 |
if (count == 0) { |
183 |
|
| 74 |
store.setValue(STACK_FILTER_ENTRIES_COUNT, fgDefaultFilterPatterns.length); |
184 |
public String getColumnText(Object object, int column) { |
| 75 |
for (int i= 0; i < fgDefaultFilterPatterns.length; i++) { |
185 |
return (column == 0) ? ((Filter) object).getName() : ""; //$NON-NLS-1$ |
| 76 |
store.setValue(STACK_FILTER_ENTRY_ + i, fgDefaultFilterPatterns[i]); |
186 |
} |
|
|
187 |
|
| 188 |
public String getText(Object element) { |
| 189 |
return ((Filter) element).getName(); |
| 190 |
} |
| 191 |
|
| 192 |
public Image getColumnImage(Object object, int column) { |
| 193 |
String name= ((Filter) object).getName(); |
| 194 |
if (name.endsWith(".*") || name.equals(JUnitMessages.getString("JUnitMainTab.label.defaultpackage"))) { //$NON-NLS-1$ //$NON-NLS-2$ |
| 195 |
//package |
| 196 |
return IMG_PKG; |
| 197 |
} else if ("".equals(name)) { //$NON-NLS-1$ |
| 198 |
//needed for the in-place editor |
| 199 |
return null; |
| 200 |
} else if ((Character.isUpperCase(name.charAt(0))) && (name.indexOf('.') < 0)) { |
| 201 |
//class in default package |
| 202 |
return IMG_CUNIT; |
| 203 |
} else { |
| 204 |
//fully-qualified class or other filter |
| 205 |
final int lastDotIndex= name.lastIndexOf('.'); |
| 206 |
if ((-1 != lastDotIndex) && ((name.length() - 1) != lastDotIndex) && Character.isUpperCase(name.charAt(lastDotIndex + 1))) |
| 207 |
return IMG_CUNIT; |
| 77 |
} |
208 |
} |
|
|
209 |
//other filter |
| 210 |
return null; |
| 78 |
} |
211 |
} |
| 79 |
} |
212 |
} |
| 80 |
|
213 |
|
| 81 |
/* |
214 |
/** |
| 82 |
* @see PreferencePage#createContents(Composite) |
215 |
* Content provider for the filter table. Content consists of instances of |
|
|
216 |
* Filter. |
| 83 |
*/ |
217 |
*/ |
| 84 |
protected Control createContents(Composite parent) { |
218 |
private class StackFilterContentProvider implements IStructuredContentProvider { |
| 85 |
noDefaultAndApplyButton(); |
219 |
|
|
|
220 |
private List fFilters; |
| 221 |
|
| 222 |
public StackFilterContentProvider() { |
| 223 |
List active= createActiveStackFiltersList(); |
| 224 |
List inactive= createInactiveStackFiltersList(); |
| 225 |
populateFilters(active, inactive); |
| 226 |
} |
| 227 |
|
| 228 |
public void setDefaults() { |
| 229 |
fFilterViewer.remove(fFilters.toArray()); |
| 230 |
List active= createDefaultStackFiltersList(); |
| 231 |
List inactive= new ArrayList(); |
| 232 |
populateFilters(active, inactive); |
| 233 |
} |
| 234 |
|
| 235 |
protected void populateFilters(List activeList, List inactiveList) { |
| 236 |
fFilters= new ArrayList(activeList.size() + inactiveList.size()); |
| 237 |
populateList(activeList, true); |
| 238 |
if (inactiveList.size() != 0) |
| 239 |
populateList(inactiveList, false); |
| 240 |
} |
| 241 |
|
| 242 |
protected void populateList(List list, boolean checked) { |
| 243 |
Iterator iterator= list.iterator(); |
| 244 |
|
| 245 |
while (iterator.hasNext()) { |
| 246 |
String name= (String) iterator.next(); |
| 247 |
addFilter(name, checked); |
| 248 |
} |
| 249 |
} |
| 250 |
|
| 251 |
public Filter addFilter(String name, boolean checked) { |
| 252 |
Filter filter= new Filter(name, checked); |
| 253 |
if (!fFilters.contains(filter)) { |
| 254 |
fFilters.add(filter); |
| 255 |
fFilterViewer.add(filter); |
| 256 |
fFilterViewer.setChecked(filter, checked); |
| 257 |
} |
| 258 |
updateActions(); |
| 259 |
return filter; |
| 260 |
} |
| 261 |
|
| 262 |
public void saveFilters() { |
| 263 |
List active= new ArrayList(fFilters.size()); |
| 264 |
List inactive= new ArrayList(fFilters.size()); |
| 265 |
Iterator iterator= fFilters.iterator(); |
| 266 |
while (iterator.hasNext()) { |
| 267 |
Filter filter= (Filter) iterator.next(); |
| 268 |
String name= filter.getName(); |
| 269 |
if (filter.isChecked()) |
| 270 |
active.add(name); |
| 271 |
else |
| 272 |
inactive.add(name); |
| 273 |
} |
| 274 |
String pref= JUnitPreferencePage.serializeList((String[]) active.toArray(new String[active.size()])); |
| 275 |
getPreferenceStore().setValue(IJUnitPreferencesConstants.PREF_ACTIVE_FILTERS_LIST, pref); |
| 276 |
pref= JUnitPreferencePage.serializeList((String[]) inactive.toArray(new String[inactive.size()])); |
| 277 |
getPreferenceStore().setValue(IJUnitPreferencesConstants.PREF_INACTIVE_FILTERS_LIST, pref); |
| 278 |
} |
| 279 |
|
| 280 |
public void removeFilters(Object[] filters) { |
| 281 |
for (int i= (filters.length - 1); i >= 0; --i) { |
| 282 |
Filter filter= (Filter) filters[i]; |
| 283 |
fFilters.remove(filter); |
| 284 |
} |
| 285 |
fFilterViewer.remove(filters); |
| 286 |
updateActions(); |
| 287 |
} |
| 288 |
|
| 289 |
public void toggleFilter(Filter filter) { |
| 290 |
boolean newState= !filter.isChecked(); |
| 291 |
filter.setChecked(newState); |
| 292 |
fFilterViewer.setChecked(filter, newState); |
| 293 |
} |
| 294 |
|
| 295 |
public Object[] getElements(Object inputElement) { |
| 296 |
return fFilters.toArray(); |
| 297 |
} |
| 86 |
|
298 |
|
|
|
299 |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} |
| 300 |
public void dispose() {} |
| 301 |
|
| 302 |
} |
| 303 |
|
| 304 |
public JUnitPreferencePage() { |
| 305 |
super(); |
| 306 |
setPreferenceStore(JUnitPlugin.getDefault().getPreferenceStore()); |
| 307 |
} |
| 308 |
|
| 309 |
protected Control createContents(Composite parent) { |
| 310 |
WorkbenchHelp.setHelp(parent, IJUnitHelpContextIds.JUNIT_PREFERENCE_PAGE); |
| 311 |
|
| 87 |
Composite composite= new Composite(parent, SWT.NULL); |
312 |
Composite composite= new Composite(parent, SWT.NULL); |
| 88 |
GridLayout layout= new GridLayout(); |
313 |
GridLayout layout= new GridLayout(); |
| 89 |
layout.numColumns= 2; |
314 |
layout.numColumns= 1; |
| 90 |
layout.marginWidth= 0; |
|
|
| 91 |
layout.marginHeight= 0; |
315 |
layout.marginHeight= 0; |
|
|
316 |
layout.marginWidth= 0; |
| 92 |
composite.setLayout(layout); |
317 |
composite.setLayout(layout); |
| 93 |
GridData data= new GridData(); |
318 |
GridData data= new GridData(); |
| 94 |
data.verticalAlignment= GridData.FILL; |
319 |
data.verticalAlignment= GridData.FILL; |
| 95 |
data.horizontalAlignment= GridData.FILL; |
320 |
data.horizontalAlignment= GridData.FILL; |
| 96 |
|
|
|
| 97 |
composite.setLayoutData(data); |
321 |
composite.setLayoutData(data); |
| 98 |
|
322 |
|
| 99 |
createShowCheck(composite); |
323 |
createStackFilterPreferences(composite); |
| 100 |
createFilterTable(composite); |
|
|
| 101 |
createListButtons(composite); |
| 102 |
WorkbenchHelp.setHelp(composite, IJUnitHelpContextIds.JUNIT_PREFERENCE_PAGE); |
| 103 |
|
324 |
|
| 104 |
return composite; |
325 |
return composite; |
| 105 |
} |
326 |
} |
| 106 |
|
327 |
|
|
|
328 |
/** |
| 329 |
* Create a group to contain the step filter related widgetry |
| 330 |
*/ |
| 331 |
private void createStackFilterPreferences(Composite composite) { |
| 332 |
Composite container= new Composite(composite, SWT.NONE); |
| 333 |
GridLayout layout= new GridLayout(); |
| 334 |
layout.numColumns= 2; |
| 335 |
layout.marginHeight= 0; |
| 336 |
layout.marginWidth= 0; |
| 337 |
container.setLayout(layout); |
| 338 |
GridData gd= new GridData(GridData.FILL_BOTH); |
| 339 |
container.setLayoutData(gd); |
| 340 |
|
| 341 |
createShowCheck(container); |
| 342 |
createFilterTable(container); |
| 343 |
createStepFilterButtons(container); |
| 344 |
} |
| 345 |
|
| 107 |
private void createShowCheck(Composite composite) { |
346 |
private void createShowCheck(Composite composite) { |
| 108 |
GridData data; |
347 |
GridData data; |
| 109 |
fShowOnErrorCheck= new Button(composite, SWT.CHECK); |
348 |
fShowOnErrorCheck= new Button(composite, SWT.CHECK); |
|
Lines 111-241
Link Here
|
| 111 |
data= new GridData(); |
350 |
data= new GridData(); |
| 112 |
data.horizontalAlignment= GridData.FILL; |
351 |
data.horizontalAlignment= GridData.FILL; |
| 113 |
data.horizontalSpan= 2; |
352 |
data.horizontalSpan= 2; |
| 114 |
fShowOnErrorCheck.setLayoutData(data); |
353 |
fShowOnErrorCheck.setLayoutData(data); |
| 115 |
fShowOnErrorCheck.setSelection(getShowOnErrorOnly()); |
354 |
fShowOnErrorCheck.setSelection(getShowOnErrorOnly()); |
| 116 |
} |
355 |
} |
| 117 |
|
356 |
|
| 118 |
/** |
357 |
private void createFilterTable(Composite container) { |
| 119 |
* @return boolean |
358 |
fTableLabel= new Label(container, SWT.NONE); |
| 120 |
*/ |
359 |
fTableLabel.setText(JUnitMessages.getString("JUnitPreferencePage.filter.label")); //$NON-NLS-1$ |
| 121 |
public static boolean getShowOnErrorOnly() { |
360 |
GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); |
| 122 |
IPreferenceStore store= JUnitPlugin.getDefault().getPreferenceStore(); |
361 |
gd.horizontalSpan= 2; |
| 123 |
return store.getBoolean(SHOW_ON_ERROR_ONLY); |
362 |
fTableLabel.setLayoutData(gd); |
|
|
363 |
|
| 364 |
fFilterTable= new Table(container, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); |
| 365 |
|
| 366 |
gd= new GridData(GridData.FILL_HORIZONTAL); |
| 367 |
fFilterTable.setLayoutData(gd); |
| 368 |
|
| 369 |
TableLayout tableLayout= new TableLayout(); |
| 370 |
ColumnLayoutData[] columnLayoutData= new ColumnLayoutData[1]; |
| 371 |
columnLayoutData[0]= new ColumnWeightData(100); |
| 372 |
tableLayout.addColumnData(columnLayoutData[0]); |
| 373 |
fFilterTable.setLayout(tableLayout); |
| 374 |
new TableColumn(fFilterTable, SWT.NONE); |
| 375 |
fFilterViewer= new CheckboxTableViewer(fFilterTable); |
| 376 |
fTableEditor= new TableEditor(fFilterTable); |
| 377 |
fFilterViewer.setLabelProvider(new FilterLabelProvider()); |
| 378 |
fFilterViewer.setSorter(new FilterViewerSorter()); |
| 379 |
fStackFilterContentProvider= new StackFilterContentProvider(); |
| 380 |
fFilterViewer.setContentProvider(fStackFilterContentProvider); |
| 381 |
// input just needs to be non-null |
| 382 |
fFilterViewer.setInput(this); |
| 383 |
gd= new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL); |
| 384 |
fFilterViewer.getTable().setLayoutData(gd); |
| 385 |
fFilterViewer.addCheckStateListener(new ICheckStateListener() { |
| 386 |
public void checkStateChanged(CheckStateChangedEvent event) { |
| 387 |
Filter filter= (Filter) event.getElement(); |
| 388 |
fStackFilterContentProvider.toggleFilter(filter); |
| 389 |
} |
| 390 |
}); |
| 391 |
fFilterViewer.addSelectionChangedListener(new ISelectionChangedListener() { |
| 392 |
public void selectionChanged(SelectionChangedEvent event) { |
| 393 |
ISelection selection= event.getSelection(); |
| 394 |
fRemoveFilterButton.setEnabled(!selection.isEmpty()); |
| 395 |
} |
| 396 |
}); |
| 124 |
} |
397 |
} |
| 125 |
|
398 |
|
| 126 |
protected void createListButtons(Composite composite) { |
399 |
private void createStepFilterButtons(Composite container) { |
| 127 |
Composite buttonComposite= new Composite(composite, SWT.NONE); |
400 |
Composite buttonContainer= new Composite(container, SWT.NONE); |
| 128 |
GridLayout layout= new GridLayout(); |
401 |
GridData gd= new GridData(GridData.FILL_VERTICAL); |
| 129 |
layout.marginHeight= 0; |
402 |
buttonContainer.setLayoutData(gd); |
| 130 |
buttonComposite.setLayout(layout); |
403 |
GridLayout buttonLayout= new GridLayout(); |
| 131 |
GridData gridData= new GridData(); |
404 |
buttonLayout.numColumns= 1; |
| 132 |
gridData.verticalAlignment= GridData.FILL; |
405 |
buttonLayout.marginHeight= 0; |
| 133 |
gridData.horizontalAlignment= GridData.FILL; |
406 |
buttonLayout.marginWidth= 0; |
| 134 |
buttonComposite.setLayoutData(gridData); |
407 |
buttonContainer.setLayout(buttonLayout); |
| 135 |
|
408 |
|
| 136 |
fAddButton= new Button(buttonComposite, SWT.CENTER | SWT.PUSH); |
409 |
fAddFilterButton= new Button(buttonContainer, SWT.PUSH); |
| 137 |
fAddButton.setText(JUnitMessages.getString("JUnitPreferencePage.addbutton.label")); //$NON-NLS-1$ |
410 |
fAddFilterButton.setText(JUnitMessages.getString("JUnitPreferencePage.addfilterbutton.label")); //$NON-NLS-1$ |
| 138 |
setButtonGridData(fAddButton); |
411 |
fAddFilterButton.setToolTipText(JUnitMessages.getString("JUnitPreferencePage.addfilterbutton.tooltip")); //$NON-NLS-1$ |
| 139 |
fAddButton.addSelectionListener(this); |
412 |
gd= new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); |
| 140 |
|
413 |
fAddFilterButton.setLayoutData(gd); |
| 141 |
fRemoveButton= new Button(buttonComposite, SWT.CENTER | SWT.PUSH); |
414 |
SWTUtil.setButtonDimensionHint(fAddFilterButton); |
| 142 |
fRemoveButton.setText(JUnitMessages.getString("JUnitPreferencePage.removebutton.label")); //$NON-NLS-1$ |
415 |
fAddFilterButton.addListener(SWT.Selection, new Listener() { |
| 143 |
setButtonGridData(fRemoveButton); |
416 |
public void handleEvent(Event e) { |
| 144 |
fRemoveButton.addSelectionListener(this); |
417 |
editFilter(); |
|
|
418 |
} |
| 419 |
}); |
| 420 |
|
| 421 |
fAddTypeButton= new Button(buttonContainer, SWT.PUSH); |
| 422 |
fAddTypeButton.setText(JUnitMessages.getString("JUnitPreferencePage.addtypebutton.label")); //$NON-NLS-1$ |
| 423 |
fAddTypeButton.setToolTipText(JUnitMessages.getString("JUnitPreferencePage.addtypebutton.tooltip")); //$NON-NLS-1$ |
| 424 |
gd= getButtonGridData(fAddTypeButton); |
| 425 |
fAddTypeButton.setLayoutData(gd); |
| 426 |
SWTUtil.setButtonDimensionHint(fAddTypeButton); |
| 427 |
fAddTypeButton.addListener(SWT.Selection, new Listener() { |
| 428 |
public void handleEvent(Event e) { |
| 429 |
addType(); |
| 430 |
} |
| 431 |
}); |
| 432 |
|
| 433 |
fAddPackageButton= new Button(buttonContainer, SWT.PUSH); |
| 434 |
fAddPackageButton.setText(JUnitMessages.getString("JUnitPreferencePage.addpackagebutton.label")); //$NON-NLS-1$ |
| 435 |
fAddPackageButton.setToolTipText(JUnitMessages.getString("JUnitPreferencePage.addpackagebutton.tooltip")); //$NON-NLS-1$ |
| 436 |
gd= getButtonGridData(fAddPackageButton); |
| 437 |
fAddPackageButton.setLayoutData(gd); |
| 438 |
SWTUtil.setButtonDimensionHint(fAddPackageButton); |
| 439 |
fAddPackageButton.addListener(SWT.Selection, new Listener() { |
| 440 |
public void handleEvent(Event e) { |
| 441 |
addPackage(); |
| 442 |
} |
| 443 |
}); |
| 444 |
|
| 445 |
fRemoveFilterButton= new Button(buttonContainer, SWT.PUSH); |
| 446 |
fRemoveFilterButton.setText(JUnitMessages.getString("JUnitPreferencePage.removefilterbutton.label")); //$NON-NLS-1$ |
| 447 |
fRemoveFilterButton.setToolTipText(JUnitMessages.getString("JUnitPreferencePage.removefilterbutton.tooltip")); //$NON-NLS-1$ |
| 448 |
gd= getButtonGridData(fRemoveFilterButton); |
| 449 |
fRemoveFilterButton.setLayoutData(gd); |
| 450 |
SWTUtil.setButtonDimensionHint(fRemoveFilterButton); |
| 451 |
fRemoveFilterButton.addListener(SWT.Selection, new Listener() { |
| 452 |
public void handleEvent(Event e) { |
| 453 |
removeFilters(); |
| 454 |
} |
| 455 |
}); |
| 456 |
fRemoveFilterButton.setEnabled(false); |
| 457 |
|
| 458 |
fEnableAllButton= new Button(buttonContainer, SWT.PUSH); |
| 459 |
fEnableAllButton.setText(JUnitMessages.getString("JUnitPreferencePage.enableallbutton.label")); //$NON-NLS-1$ |
| 460 |
fEnableAllButton.setToolTipText(JUnitMessages.getString("JUnitPreferencePage.enableallbutton.tooltip")); //$NON-NLS-1$ |
| 461 |
gd= getButtonGridData(fEnableAllButton); |
| 462 |
fEnableAllButton.setLayoutData(gd); |
| 463 |
SWTUtil.setButtonDimensionHint(fEnableAllButton); |
| 464 |
fEnableAllButton.addListener(SWT.Selection, new Listener() { |
| 465 |
public void handleEvent(Event e) { |
| 466 |
checkAllFilters(true); |
| 467 |
} |
| 468 |
}); |
| 469 |
|
| 470 |
fDisableAllButton= new Button(buttonContainer, SWT.PUSH); |
| 471 |
fDisableAllButton.setText(JUnitMessages.getString("JUnitPreferencePage.disableallbutton.label")); //$NON-NLS-1$ |
| 472 |
fDisableAllButton.setToolTipText(JUnitMessages.getString("JUnitPreferencePage.disableallbutton.tooltip")); //$NON-NLS-1$ |
| 473 |
gd= getButtonGridData(fDisableAllButton); |
| 474 |
fDisableAllButton.setLayoutData(gd); |
| 475 |
SWTUtil.setButtonDimensionHint(fDisableAllButton); |
| 476 |
fDisableAllButton.addListener(SWT.Selection, new Listener() { |
| 477 |
public void handleEvent(Event e) { |
| 478 |
checkAllFilters(false); |
| 479 |
} |
| 480 |
}); |
| 481 |
|
| 145 |
} |
482 |
} |
| 146 |
|
483 |
|
| 147 |
private void setButtonGridData(Button button) { |
484 |
private GridData getButtonGridData(Button button) { |
| 148 |
GridData data = new GridData(); |
485 |
GridData gd= new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); |
| 149 |
data.horizontalAlignment = GridData.FILL; |
|
|
| 150 |
data.grabExcessHorizontalSpace = true; |
| 151 |
data.heightHint= convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT); |
| 152 |
int widthHint= convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); |
486 |
int widthHint= convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); |
| 153 |
data.widthHint= Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); |
487 |
gd.widthHint= Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); |
| 154 |
button.setLayoutData(data); |
488 |
gd.heightHint= convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT); |
|
|
489 |
return gd; |
| 155 |
} |
490 |
} |
| 156 |
|
491 |
|
| 157 |
protected void createFilterTable(Composite composite) { |
492 |
public void init(IWorkbench workbench) {} |
| 158 |
Label label= new Label(composite, SWT.NONE); |
493 |
|
| 159 |
label.setText(JUnitMessages.getString("JUnitPreferencePage.filter.label")); //$NON-NLS-1$ |
494 |
/** |
| 160 |
GridData gridData= new GridData(); |
495 |
* Create a new filter in the table (with the default 'new filter' value), |
| 161 |
gridData.horizontalAlignment= GridData.FILL; |
496 |
* then open up an in-place editor on it. |
| 162 |
gridData.horizontalSpan= 2; |
497 |
*/ |
| 163 |
label.setLayoutData(gridData); |
498 |
private void editFilter() { |
| 164 |
|
499 |
// if a previous edit is still in progress, finish it |
| 165 |
fTable= new Table(composite, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); |
500 |
if (fEditorText != null) |
| 166 |
GridData data= new GridData(); |
501 |
validateChangeAndCleanup(); |
| 167 |
//Set heightHint with a small value so the list size will be defined by |
502 |
|
| 168 |
//the space available in the dialog instead of resizing the dialog to |
503 |
fNewStackFilter= fStackFilterContentProvider.addFilter(DEFAULT_NEW_FILTER_TEXT, true); |
| 169 |
//fit all the items in the list. |
504 |
fNewTableItem= fFilterTable.getItem(0); |
| 170 |
data.heightHint= fTable.getItemHeight(); |
505 |
|
| 171 |
data.verticalAlignment= GridData.FILL; |
506 |
// create & configure Text widget for editor |
| 172 |
data.horizontalAlignment= GridData.FILL; |
507 |
// Fix for bug 1766. Border behavior on for text fields varies per platform. |
| 173 |
data.grabExcessHorizontalSpace= true; |
508 |
// On Motif, you always get a border, on other platforms, |
| 174 |
data.grabExcessVerticalSpace= true; |
509 |
// you don't. Specifying a border on Motif results in the characters |
|
|
510 |
// getting pushed down so that only there very tops are visible. Thus, |
| 511 |
// we have to specify different style constants for the different platforms. |
| 512 |
int textStyles= SWT.SINGLE | SWT.LEFT; |
| 513 |
if (!SWT.getPlatform().equals("motif")) //$NON-NLS-1$ |
| 514 |
textStyles |= SWT.BORDER; |
| 515 |
|
| 516 |
fEditorText= new Text(fFilterTable, textStyles); |
| 517 |
GridData gd= new GridData(GridData.FILL_BOTH); |
| 518 |
fEditorText.setLayoutData(gd); |
| 519 |
|
| 520 |
// set the editor |
| 521 |
fTableEditor.horizontalAlignment= SWT.LEFT; |
| 522 |
fTableEditor.grabHorizontal= true; |
| 523 |
fTableEditor.setEditor(fEditorText, fNewTableItem, 0); |
| 524 |
|
| 525 |
// get the editor ready to use |
| 526 |
fEditorText.setText(fNewStackFilter.getName()); |
| 527 |
fEditorText.selectAll(); |
| 528 |
setEditorListeners(fEditorText); |
| 529 |
fEditorText.setFocus(); |
| 530 |
} |
| 531 |
|
| 532 |
private void setEditorListeners(Text text) { |
| 533 |
// CR means commit the changes, ESC means abort and don't commit |
| 534 |
text.addKeyListener(new KeyAdapter() { |
| 535 |
public void keyReleased(KeyEvent event) { |
| 536 |
if (event.character == SWT.CR) { |
| 537 |
if (fInvalidEditorText != null) { |
| 538 |
fEditorText.setText(fInvalidEditorText); |
| 539 |
fInvalidEditorText= null; |
| 540 |
} else |
| 541 |
validateChangeAndCleanup(); |
| 542 |
} else if (event.character == SWT.ESC) { |
| 543 |
removeNewFilter(); |
| 544 |
cleanupEditor(); |
| 545 |
} |
| 546 |
} |
| 547 |
}); |
| 548 |
// Consider loss of focus on the editor to mean the same as CR |
| 549 |
text.addFocusListener(new FocusAdapter() { |
| 550 |
public void focusLost(FocusEvent event) { |
| 551 |
if (fInvalidEditorText != null) { |
| 552 |
fEditorText.setText(fInvalidEditorText); |
| 553 |
fInvalidEditorText= null; |
| 554 |
} else |
| 555 |
validateChangeAndCleanup(); |
| 556 |
} |
| 557 |
}); |
| 558 |
// Consume traversal events from the text widget so that CR doesn't |
| 559 |
// traverse away to dialog's default button. Without this, hitting |
| 560 |
// CR in the text field closes the entire dialog. |
| 561 |
text.addListener(SWT.Traverse, new Listener() { |
| 562 |
public void handleEvent(Event event) { |
| 563 |
event.doit= false; |
| 564 |
} |
| 565 |
}); |
| 566 |
} |
| 175 |
|
567 |
|
| 176 |
fTable.setLayoutData(data); |
568 |
private void validateChangeAndCleanup() { |
| 177 |
fTable.addSelectionListener(this); |
569 |
String trimmedValue= fEditorText.getText().trim(); |
| 178 |
fillList(); |
570 |
// if the new value is blank, remove the filter |
| 179 |
if (fTable.getItemCount() > 0) |
571 |
if (trimmedValue.length() < 1) |
| 180 |
fTable.setSelection(0); |
572 |
removeNewFilter(); |
|
|
573 |
|
| 574 |
// if it's invalid, beep and leave sitting in the editor |
| 575 |
else if (!validateEditorInput(trimmedValue)) { |
| 576 |
fInvalidEditorText= trimmedValue; |
| 577 |
fEditorText.setText(JUnitMessages.getString("JUnitPreferencePage.invalidstepfilterreturnescape")); //$NON-NLS-1$ |
| 578 |
getShell().getDisplay().beep(); |
| 579 |
return; |
| 580 |
// otherwise, commit the new value if not a duplicate |
| 581 |
} else { |
| 582 |
Object[] filters= fStackFilterContentProvider.getElements(null); |
| 583 |
for (int i= 0; i < filters.length; i++) { |
| 584 |
Filter filter= (Filter) filters[i]; |
| 585 |
if (filter.getName().equals(trimmedValue)) { |
| 586 |
removeNewFilter(); |
| 587 |
cleanupEditor(); |
| 588 |
return; |
| 589 |
} |
| 590 |
} |
| 591 |
fNewTableItem.setText(trimmedValue); |
| 592 |
fNewStackFilter.setName(trimmedValue); |
| 593 |
fFilterViewer.refresh(); |
| 594 |
} |
| 595 |
cleanupEditor(); |
| 181 |
} |
596 |
} |
| 182 |
|
597 |
|
| 183 |
/* |
598 |
/** |
| 184 |
* @see IWorkbenchPreferencePage#init(IWorkbench) |
599 |
* Cleanup all widgetry & resources used by the in-place editing |
| 185 |
*/ |
600 |
*/ |
| 186 |
public void init(IWorkbench workbench) { |
601 |
private void cleanupEditor() { |
|
|
602 |
if (fEditorText == null) |
| 603 |
return; |
| 604 |
|
| 605 |
fNewStackFilter= null; |
| 606 |
fNewTableItem= null; |
| 607 |
fTableEditor.setEditor(null, null, 0); |
| 608 |
fEditorText.dispose(); |
| 609 |
fEditorText= null; |
| 187 |
} |
610 |
} |
| 188 |
|
611 |
|
| 189 |
/* |
612 |
private void removeNewFilter() { |
| 190 |
* @see SelectionListener#widgetDefaultSelected(SelectionEvent) |
613 |
fStackFilterContentProvider.removeFilters(new Object[] { fNewStackFilter }); |
|
|
614 |
} |
| 615 |
|
| 616 |
/** |
| 617 |
* A valid step filter is simply one that is a valid Java identifier. |
| 618 |
* and, as defined in the JDI spec, the regular expressions used for |
| 619 |
* step filtering must be limited to exact matches or patterns that |
| 620 |
* begin with '*' or end with '*'. Beyond this, a string cannot be validated |
| 621 |
* as corresponding to an existing type or package (and this is probably not |
| 622 |
* even desirable). |
| 191 |
*/ |
623 |
*/ |
| 192 |
public void widgetDefaultSelected(SelectionEvent selectionEvent) { |
624 |
private boolean validateEditorInput(String trimmedValue) { |
| 193 |
widgetSelected(selectionEvent); |
625 |
char firstChar= trimmedValue.charAt(0); |
|
|
626 |
if ((!(Character.isJavaIdentifierStart(firstChar)) || (firstChar == '*'))) |
| 627 |
return false; |
| 628 |
|
| 629 |
int length= trimmedValue.length(); |
| 630 |
for (int i= 1; i < length; i++) { |
| 631 |
char c= trimmedValue.charAt(i); |
| 632 |
if (!Character.isJavaIdentifierPart(c)) { |
| 633 |
if (c == '.' && i != (length - 1)) |
| 634 |
continue; |
| 635 |
if (c == '*' && i == (length - 1)) |
| 636 |
continue; |
| 637 |
|
| 638 |
return false; |
| 639 |
} |
| 640 |
} |
| 641 |
return true; |
| 194 |
} |
642 |
} |
| 195 |
|
643 |
|
|
|
644 |
private void addType() { |
| 645 |
Shell shell= getShell(); |
| 646 |
SelectionDialog dialog= null; |
| 647 |
try { |
| 648 |
dialog= |
| 649 |
JavaUI.createTypeDialog( |
| 650 |
shell, |
| 651 |
new ProgressMonitorDialog(shell), |
| 652 |
SearchEngine.createWorkspaceScope(), |
| 653 |
IJavaElementSearchConstants.CONSIDER_CLASSES, |
| 654 |
false); |
| 655 |
} catch (JavaModelException jme) { |
| 656 |
String title= JUnitMessages.getString("JUnitPreferencePage.addtypedialog.title"); //$NON-NLS-1$ |
| 657 |
String message= JUnitMessages.getString("JUnitPreferencePage.addtypedialog.error.message"); //$NON-NLS-1$ |
| 658 |
ExceptionHandler.handle(jme, shell, title, message); |
| 659 |
return; |
| 660 |
} |
| 196 |
|
661 |
|
| 197 |
protected void addFilterString(String filterEntry) { |
662 |
dialog.setTitle(JUnitMessages.getString("JUnitPreferencePage.addtypedialog.title")); //$NON-NLS-1$ |
| 198 |
if (filterEntry != null) { |
663 |
dialog.setMessage(JUnitMessages.getString("JUnitPreferencePage.addtypedialog.message")); //$NON-NLS-1$ |
| 199 |
TableItem tableItem= new TableItem(fTable, SWT.NONE); |
664 |
if (dialog.open() == IDialogConstants.CANCEL_ID) |
| 200 |
tableItem.setText(filterEntry); |
665 |
return; |
|
|
666 |
|
| 667 |
Object[] types= dialog.getResult(); |
| 668 |
if (types != null && types.length > 0) { |
| 669 |
IType type= (IType) types[0]; |
| 670 |
fStackFilterContentProvider.addFilter(type.getFullyQualifiedName(), true); |
| 201 |
} |
671 |
} |
| 202 |
} |
672 |
} |
| 203 |
|
673 |
|
| 204 |
/* |
674 |
private void addPackage() { |
| 205 |
* @see SelectionListener#widgetSelected(SelectionEvent) |
675 |
Shell shell= getShell(); |
| 206 |
*/ |
676 |
ElementListSelectionDialog dialog= null; |
| 207 |
public void widgetSelected(SelectionEvent selectionEvent) { |
677 |
try { |
| 208 |
if (selectionEvent.getSource().equals(fAddButton)) { |
678 |
dialog= JUnitPlugin.createAllPackagesDialog(shell, null, true); |
| 209 |
FilterPatternsDialog dialog= new FilterPatternsDialog(getControl().getShell(), JUnitMessages.getString("JUnitPreferencePage.adddialog.title"), JUnitMessages.getString("JUnitPreferencePage.addialog.prompt")); //$NON-NLS-1$ //$NON-NLS-2$ |
679 |
} catch (JavaModelException jme) { |
| 210 |
dialog.open(); |
680 |
String title= JUnitMessages.getString("JUnitPreferencePage.addpackagedialog.title"); //$NON-NLS-1$ |
| 211 |
String pattern= dialog.getValue(); |
681 |
String message= JUnitMessages.getString("JUnitPreferencePage.addpackagedialog.error.message"); //$NON-NLS-1$ |
| 212 |
addFilterString(pattern); |
682 |
ExceptionHandler.handle(jme, shell, title, message); |
| 213 |
fTable.deselectAll(); |
683 |
return; |
| 214 |
fTable.select(fTable.getItemCount()-1); |
684 |
} |
|
|
685 |
|
| 686 |
dialog.setTitle(JUnitMessages.getString("JUnitPreferencePage.addpackagedialog.title")); //$NON-NLS-1$ |
| 687 |
dialog.setMessage(JUnitMessages.getString("JUnitPreferencePage.addpackagedialog.message")); //$NON-NLS-1$ |
| 688 |
dialog.setMultipleSelection(true); |
| 689 |
if (dialog.open() == IDialogConstants.CANCEL_ID) |
| 690 |
return; |
| 691 |
|
| 692 |
Object[] packages= dialog.getResult(); |
| 693 |
if (packages == null) |
| 694 |
return; |
| 695 |
|
| 696 |
for (int i= 0; i < packages.length; i++) { |
| 697 |
IJavaElement pkg= (IJavaElement) packages[i]; |
| 698 |
|
| 699 |
String filter= pkg.getElementName(); |
| 700 |
if (filter.length() < 1) |
| 701 |
filter= JUnitMessages.getString("JUnitMainTab.label.defaultpackage"); //$NON-NLS-1$ |
| 702 |
else |
| 703 |
filter += ".*"; //$NON-NLS-1$ |
| 704 |
|
| 705 |
fStackFilterContentProvider.addFilter(filter, true); |
| 215 |
} |
706 |
} |
| 216 |
else if (selectionEvent.getSource().equals(fRemoveButton)) { |
707 |
} |
| 217 |
fTable.remove(fTable.getSelectionIndices()); |
708 |
private void removeFilters() { |
| 218 |
} |
709 |
IStructuredSelection selection= (IStructuredSelection) fFilterViewer.getSelection(); |
| 219 |
fRemoveButton.setEnabled(fTable.getSelectionIndex() != -1); |
710 |
fStackFilterContentProvider.removeFilters(selection.toArray()); |
|
|
711 |
} |
| 712 |
|
| 713 |
private void checkAllFilters(boolean check) { |
| 714 |
Object[] filters= fStackFilterContentProvider.getElements(null); |
| 715 |
for (int i= (filters.length - 1); i >= 0; --i) |
| 716 |
((Filter) filters[i]).setChecked(check); |
| 717 |
|
| 718 |
fFilterViewer.setAllChecked(check); |
| 220 |
} |
719 |
} |
| 221 |
|
720 |
|
| 222 |
public boolean performOk() { |
721 |
public boolean performOk() { |
| 223 |
IPreferenceStore store= getPreferenceStore(); |
722 |
IPreferenceStore store= getPreferenceStore(); |
| 224 |
int filterEntriesCount= fTable.getItemCount(); |
723 |
store.setValue(IJUnitPreferencesConstants.SHOW_ON_ERROR_ONLY, fShowOnErrorCheck.getSelection()); |
| 225 |
|
724 |
fStackFilterContentProvider.saveFilters(); |
| 226 |
store.setValue(STACK_FILTER_ENTRIES_COUNT, filterEntriesCount); |
725 |
return true; |
| 227 |
for (int i= 0; i < filterEntriesCount; i++) { |
726 |
} |
| 228 |
store.setValue(STACK_FILTER_ENTRY_ + i, fTable.getItem(i).getText()); |
727 |
|
|
|
728 |
protected void performDefaults() { |
| 729 |
setDefaultValues(); |
| 730 |
super.performDefaults(); |
| 731 |
} |
| 732 |
|
| 733 |
private void setDefaultValues() { |
| 734 |
fStackFilterContentProvider.setDefaults(); |
| 735 |
} |
| 736 |
|
| 737 |
/** |
| 738 |
* Returns the default list of active stack filters. |
| 739 |
* |
| 740 |
* @return list |
| 741 |
*/ |
| 742 |
protected List createDefaultStackFiltersList() { |
| 743 |
return Arrays.asList(fgDefaultFilterPatterns); |
| 744 |
} |
| 745 |
|
| 746 |
/** |
| 747 |
* Returns a list of active stack filters. |
| 748 |
* |
| 749 |
* @return list |
| 750 |
*/ |
| 751 |
protected List createActiveStackFiltersList() { |
| 752 |
return Arrays.asList(getFilterPatterns()); |
| 753 |
} |
| 754 |
|
| 755 |
/** |
| 756 |
* Returns a list of active stack filters. |
| 757 |
* |
| 758 |
* @return list |
| 759 |
*/ |
| 760 |
protected List createInactiveStackFiltersList() { |
| 761 |
String[] strings= |
| 762 |
JUnitPreferencePage.parseList(getPreferenceStore().getString(IJUnitPreferencesConstants.PREF_INACTIVE_FILTERS_LIST)); |
| 763 |
return Arrays.asList(strings); |
| 764 |
} |
| 765 |
|
| 766 |
protected void updateActions() { |
| 767 |
if (fEnableAllButton == null) |
| 768 |
return; |
| 769 |
|
| 770 |
boolean enabled= fFilterViewer.getTable().getItemCount() > 0; |
| 771 |
fEnableAllButton.setEnabled(enabled); |
| 772 |
fDisableAllButton.setEnabled(enabled); |
| 773 |
} |
| 774 |
|
| 775 |
public static String[] getFilterPatterns() { |
| 776 |
IPreferenceStore store= JUnitPlugin.getDefault().getPreferenceStore(); |
| 777 |
return JUnitPreferencePage.parseList(store.getString(IJUnitPreferencesConstants.PREF_ACTIVE_FILTERS_LIST)); |
| 778 |
} |
| 779 |
|
| 780 |
public static boolean getFilterStack() { |
| 781 |
IPreferenceStore store= JUnitPlugin.getDefault().getPreferenceStore(); |
| 782 |
return store.getBoolean(IJUnitPreferencesConstants.DO_FILTER_STACK); |
| 783 |
} |
| 784 |
|
| 785 |
public static void setFilterStack(boolean filter) { |
| 786 |
IPreferenceStore store= JUnitPlugin.getDefault().getPreferenceStore(); |
| 787 |
store.setValue(IJUnitPreferencesConstants.DO_FILTER_STACK, filter); |
| 788 |
} |
| 789 |
|
| 790 |
public static void initializeDefaults(IPreferenceStore store) { |
| 791 |
store.setDefault(IJUnitPreferencesConstants.DO_FILTER_STACK, true); |
| 792 |
store.setDefault(IJUnitPreferencesConstants.SHOW_ON_ERROR_ONLY, false); |
| 793 |
|
| 794 |
String list= store.getString(IJUnitPreferencesConstants.PREF_ACTIVE_FILTERS_LIST); |
| 795 |
|
| 796 |
if ("".equals(list)) { //$NON-NLS-1$ |
| 797 |
String pref= JUnitPreferencePage.serializeList(fgDefaultFilterPatterns); |
| 798 |
store.setValue(IJUnitPreferencesConstants.PREF_ACTIVE_FILTERS_LIST, pref); |
| 229 |
} |
799 |
} |
| 230 |
store.setValue(SHOW_ON_ERROR_ONLY, fShowOnErrorCheck.getSelection()); |
800 |
|
| 231 |
return true; |
801 |
store.setValue(IJUnitPreferencesConstants.PREF_INACTIVE_FILTERS_LIST, ""); //$NON-NLS-1$ |
|
|
802 |
} |
| 803 |
|
| 804 |
public static boolean getShowOnErrorOnly() { |
| 805 |
IPreferenceStore store= JUnitPlugin.getDefault().getPreferenceStore(); |
| 806 |
return store.getBoolean(IJUnitPreferencesConstants.SHOW_ON_ERROR_ONLY); |
| 232 |
} |
807 |
} |
| 233 |
|
808 |
|
| 234 |
private void fillList() { |
809 |
/** |
| 235 |
String[] patterns= getFilterPatterns(); |
810 |
* Parses the comma separated string into an array of strings |
| 236 |
for (int i= 0; i < patterns.length; i++) { |
811 |
* |
| 237 |
TableItem tableItem= new TableItem(fTable, SWT.NONE); |
812 |
* @return list |
| 238 |
tableItem.setText(patterns[i]); |
813 |
*/ |
|
|
814 |
private static String[] parseList(String listString) { |
| 815 |
List list= new ArrayList(10); |
| 816 |
StringTokenizer tokenizer= new StringTokenizer(listString, ","); //$NON-NLS-1$ |
| 817 |
while (tokenizer.hasMoreTokens()) |
| 818 |
list.add(tokenizer.nextToken()); |
| 819 |
return (String[]) list.toArray(new String[list.size()]); |
| 820 |
} |
| 821 |
|
| 822 |
/** |
| 823 |
* Serializes the array of strings into one comma |
| 824 |
* separated string. |
| 825 |
* |
| 826 |
* @param list array of strings |
| 827 |
* @return a single string composed of the given list |
| 828 |
*/ |
| 829 |
private static String serializeList(String[] list) { |
| 830 |
if (list == null) |
| 831 |
return ""; //$NON-NLS-1$ |
| 832 |
|
| 833 |
StringBuffer buffer= new StringBuffer(); |
| 834 |
for (int i= 0; i < list.length; i++) { |
| 835 |
if (i > 0) |
| 836 |
buffer.append(','); |
| 837 |
|
| 838 |
buffer.append(list[i]); |
| 239 |
} |
839 |
} |
|
|
840 |
return buffer.toString(); |
| 240 |
} |
841 |
} |
| 241 |
} |
842 |
} |