1 12 package org.eclipse.jdt.internal.junit.ui; 13 14 import java.util.ArrayList ; 15 import java.util.Arrays ; 16 import java.util.Iterator ; 17 import java.util.List ; 18 import java.util.StringTokenizer ; 19 20 import org.eclipse.swt.SWT; 21 import org.eclipse.swt.custom.TableEditor; 22 import org.eclipse.swt.events.FocusAdapter; 23 import org.eclipse.swt.events.FocusEvent; 24 import org.eclipse.swt.events.KeyAdapter; 25 import org.eclipse.swt.events.KeyEvent; 26 import org.eclipse.swt.graphics.Image; 27 import org.eclipse.swt.layout.GridData; 28 import org.eclipse.swt.layout.GridLayout; 29 import org.eclipse.swt.widgets.Button; 30 import org.eclipse.swt.widgets.Composite; 31 import org.eclipse.swt.widgets.Control; 32 import org.eclipse.swt.widgets.Event; 33 import org.eclipse.swt.widgets.Label; 34 import org.eclipse.swt.widgets.Listener; 35 import org.eclipse.swt.widgets.Shell; 36 import org.eclipse.swt.widgets.Table; 37 import org.eclipse.swt.widgets.TableColumn; 38 import org.eclipse.swt.widgets.TableItem; 39 import org.eclipse.swt.widgets.Text; 40 41 import org.eclipse.jface.dialogs.Dialog; 42 import org.eclipse.jface.dialogs.IDialogConstants; 43 import org.eclipse.jface.preference.IPreferenceStore; 44 import org.eclipse.jface.preference.PreferencePage; 45 import org.eclipse.jface.viewers.CheckStateChangedEvent; 46 import org.eclipse.jface.viewers.CheckboxTableViewer; 47 import org.eclipse.jface.viewers.ColumnWeightData; 48 import org.eclipse.jface.viewers.ContentViewer; 49 import org.eclipse.jface.viewers.ICheckStateListener; 50 import org.eclipse.jface.viewers.ILabelProvider; 51 import org.eclipse.jface.viewers.ISelection; 52 import org.eclipse.jface.viewers.ISelectionChangedListener; 53 import org.eclipse.jface.viewers.IStructuredContentProvider; 54 import org.eclipse.jface.viewers.IStructuredSelection; 55 import org.eclipse.jface.viewers.ITableLabelProvider; 56 import org.eclipse.jface.viewers.LabelProvider; 57 import org.eclipse.jface.viewers.SelectionChangedEvent; 58 import org.eclipse.jface.viewers.Viewer; 59 import org.eclipse.jface.viewers.ViewerComparator; 60 import org.eclipse.jface.window.Window; 61 62 import org.eclipse.ui.IWorkbench; 63 import org.eclipse.ui.IWorkbenchPreferencePage; 64 import org.eclipse.ui.PlatformUI; 65 import org.eclipse.ui.dialogs.SelectionDialog; 66 import org.eclipse.ui.progress.IProgressService; 67 68 import org.eclipse.jdt.core.IJavaElement; 69 import org.eclipse.jdt.core.IType; 70 import org.eclipse.jdt.core.JavaModelException; 71 import org.eclipse.jdt.core.search.IJavaSearchScope; 72 import org.eclipse.jdt.core.search.SearchEngine; 73 74 import org.eclipse.jdt.ui.IJavaElementSearchConstants; 75 import org.eclipse.jdt.ui.ISharedImages; 76 import org.eclipse.jdt.ui.JavaUI; 77 78 import org.eclipse.jdt.internal.ui.util.SWTUtil; 79 import org.eclipse.jdt.internal.ui.util.TableLayoutComposite; 80 81 import org.eclipse.jdt.internal.junit.launcher.AssertionVMArg; 82 import org.eclipse.jdt.internal.junit.util.ExceptionHandler; 83 import org.eclipse.jdt.internal.junit.util.LayoutUtil; 84 85 89 public class JUnitPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { 90 91 private static final String DEFAULT_NEW_FILTER_TEXT= ""; private static final Image IMG_CUNIT= JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_CLASS); 93 private static final Image IMG_PKG= JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_PACKAGE); 94 95 private Button fEnableAssertionsCheckBox; 97 98 private Label fFilterViewerLabel; 100 private CheckboxTableViewer fFilterViewer; 101 private Table fFilterTable; 102 103 private Button fAddPackageButton; 104 private Button fAddTypeButton; 105 private Button fRemoveFilterButton; 106 private Button fAddFilterButton; 107 108 private Button fEnableAllButton; 109 private Button fDisableAllButton; 110 111 private Text fEditorText; 112 private String fInvalidEditorText= null; 113 private TableEditor fTableEditor; 114 private TableItem fNewTableItem; 115 private Filter fNewStackFilter; 116 117 private StackFilterContentProvider fStackFilterContentProvider; 118 119 122 private static class Filter { 123 124 private String fName; 125 private boolean fChecked; 126 127 public Filter(String name, boolean checked) { 128 setName(name); 129 setChecked(checked); 130 } 131 132 public String getName() { 133 return fName; 134 } 135 136 public void setName(String name) { 137 fName= name; 138 } 139 140 public boolean isChecked() { 141 return fChecked; 142 } 143 144 public void setChecked(boolean checked) { 145 fChecked= checked; 146 } 147 148 public boolean equals(Object o) { 149 if (!(o instanceof Filter)) 150 return false; 151 152 Filter other= (Filter) o; 153 return (getName().equals(other.getName())); 154 } 155 156 public int hashCode() { 157 return fName.hashCode(); 158 } 159 } 160 161 164 private static class FilterViewerSorter extends ViewerComparator { 165 public int compare(Viewer viewer, Object e1, Object e2) { 166 ILabelProvider lprov= (ILabelProvider) ((ContentViewer) viewer).getLabelProvider(); 167 String name1= lprov.getText(e1); 168 String name2= lprov.getText(e2); 169 if (name1 == null) 170 name1= ""; 172 if (name2 == null) 173 name2= ""; 175 if (name1.length() > 0 && name2.length() > 0) { 176 char char1= name1.charAt(name1.length() - 1); 177 char char2= name2.charAt(name2.length() - 1); 178 if (char1 == '*' && char1 != char2) 179 return -1; 180 181 if (char2 == '*' && char2 != char1) 182 return 1; 183 } 184 return getComparator().compare(name1, name2); 185 } 186 } 187 188 191 private static class FilterLabelProvider extends LabelProvider implements ITableLabelProvider { 192 193 public String getColumnText(Object object, int column) { 194 return (column == 0) ? ((Filter) object).getName() : ""; } 196 197 public String getText(Object element) { 198 return ((Filter) element).getName(); 199 } 200 201 public Image getColumnImage(Object object, int column) { 202 String name= ((Filter) object).getName(); 203 if (name.endsWith(".*") || name.equals(JUnitMessages.JUnitMainTab_label_defaultpackage)) { return IMG_PKG; 206 } else if ("".equals(name)) { return null; 209 } else if ((Character.isUpperCase(name.charAt(0))) && (name.indexOf('.') < 0)) { 210 return IMG_CUNIT; 212 } else { 213 final int lastDotIndex= name.lastIndexOf('.'); 215 if ((-1 != lastDotIndex) && ((name.length() - 1) != lastDotIndex) && Character.isUpperCase(name.charAt(lastDotIndex + 1))) 216 return IMG_CUNIT; 217 } 218 return null; 220 } 221 } 222 223 227 private class StackFilterContentProvider implements IStructuredContentProvider { 228 229 private List fFilters; 230 231 public StackFilterContentProvider() { 232 List active= createActiveStackFiltersList(); 233 List inactive= createInactiveStackFiltersList(); 234 populateFilters(active, inactive); 235 } 236 237 public void setDefaults() { 238 fFilterViewer.remove(fFilters.toArray()); 239 List active= JUnitPreferencesConstants.createDefaultStackFiltersList(); 240 List inactive= new ArrayList (); 241 populateFilters(active, inactive); 242 } 243 244 protected void populateFilters(List activeList, List inactiveList) { 245 fFilters= new ArrayList (activeList.size() + inactiveList.size()); 246 populateList(activeList, true); 247 if (inactiveList.size() != 0) 248 populateList(inactiveList, false); 249 } 250 251 protected void populateList(List list, boolean checked) { 252 Iterator iterator= list.iterator(); 253 254 while (iterator.hasNext()) { 255 String name= (String ) iterator.next(); 256 addFilter(name, checked); 257 } 258 } 259 260 public Filter addFilter(String name, boolean checked) { 261 Filter filter= new Filter(name, checked); 262 if (!fFilters.contains(filter)) { 263 fFilters.add(filter); 264 fFilterViewer.add(filter); 265 fFilterViewer.setChecked(filter, checked); 266 } 267 updateActions(); 268 return filter; 269 } 270 271 public void saveFilters() { 272 List active= new ArrayList (fFilters.size()); 273 List inactive= new ArrayList (fFilters.size()); 274 Iterator iterator= fFilters.iterator(); 275 while (iterator.hasNext()) { 276 Filter filter= (Filter) iterator.next(); 277 String name= filter.getName(); 278 if (filter.isChecked()) 279 active.add(name); 280 else 281 inactive.add(name); 282 } 283 String pref= JUnitPreferencesConstants.serializeList((String []) active.toArray(new String [active.size()])); 284 getPreferenceStore().setValue(JUnitPreferencesConstants.PREF_ACTIVE_FILTERS_LIST, pref); 285 pref= JUnitPreferencesConstants.serializeList((String []) inactive.toArray(new String [inactive.size()])); 286 getPreferenceStore().setValue(JUnitPreferencesConstants.PREF_INACTIVE_FILTERS_LIST, pref); 287 } 288 289 public void removeFilters(Object [] filters) { 290 for (int i= (filters.length - 1); i >= 0; --i) { 291 Filter filter= (Filter) filters[i]; 292 fFilters.remove(filter); 293 } 294 fFilterViewer.remove(filters); 295 updateActions(); 296 } 297 298 public void toggleFilter(Filter filter) { 299 boolean newState= !filter.isChecked(); 300 filter.setChecked(newState); 301 fFilterViewer.setChecked(filter, newState); 302 } 303 304 public Object [] getElements(Object inputElement) { 305 return fFilters.toArray(); 306 } 307 308 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} 309 public void dispose() {} 310 311 } 312 313 public JUnitPreferencePage() { 314 super(); 315 setDescription(JUnitMessages.JUnitPreferencePage_description); 316 setPreferenceStore(JUnitPlugin.getDefault().getPreferenceStore()); 317 } 318 319 protected Control createContents(Composite parent) { 320 PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IJUnitHelpContextIds.JUNIT_PREFERENCE_PAGE); 321 322 Composite composite= new Composite(parent, SWT.NULL); 323 GridLayout layout= new GridLayout(); 324 layout.numColumns= 1; 325 layout.marginHeight= 0; 326 layout.marginWidth= 0; 327 composite.setLayout(layout); 328 GridData data= new GridData(); 329 data.verticalAlignment= GridData.FILL; 330 data.horizontalAlignment= GridData.FILL; 331 composite.setLayoutData(data); 332 333 createEnableAssertionsCheckbox(composite); 334 createStackFilterPreferences(composite); 335 Dialog.applyDialogFont(composite); 336 return composite; 337 } 338 339 private void createEnableAssertionsCheckbox(Composite container) { 340 fEnableAssertionsCheckBox= new Button(container, SWT.CHECK | SWT.WRAP); 341 fEnableAssertionsCheckBox.setText(JUnitMessages.JUnitPreferencePage_enableassertionscheckbox_label); 342 fEnableAssertionsCheckBox.setToolTipText(JUnitMessages.JUnitPreferencePage_enableassertionscheckbox_tooltip); 343 GridData gd= getButtonGridData(fEnableAssertionsCheckBox); 344 fEnableAssertionsCheckBox.setLayoutData(gd); 345 SWTUtil.setButtonDimensionHint(fEnableAssertionsCheckBox); 346 setAssertionCheckBoxSelection(AssertionVMArg.getEnableAssertionsPreference()); 347 } 348 349 353 public boolean getAssertionCheckBoxSelection() { 354 return fEnableAssertionsCheckBox.getSelection(); 355 } 356 357 public void setAssertionCheckBoxSelection(boolean selected) { 358 fEnableAssertionsCheckBox.setSelection(selected); 359 } 360 361 364 private void createStackFilterPreferences(Composite composite) { 365 fFilterViewerLabel= new Label(composite, SWT.SINGLE | SWT.LEFT); 366 fFilterViewerLabel.setText(JUnitMessages.JUnitPreferencePage_filter_label); 367 368 Composite container= new Composite(composite, SWT.NONE); 369 GridLayout layout= new GridLayout(); 370 layout.numColumns= 2; 371 layout.marginHeight= 0; 372 layout.marginWidth= 0; 373 container.setLayout(layout); 374 GridData gd= new GridData(GridData.FILL_BOTH); 375 container.setLayoutData(gd); 376 377 createFilterTable(container); 378 createStepFilterButtons(container); 379 } 380 381 private void createFilterTable(Composite container) { 382 TableLayoutComposite layouter= new TableLayoutComposite(container, SWT.NONE); 383 layouter.addColumnData(new ColumnWeightData(100)); 384 layouter.setLayoutData(new GridData(GridData.FILL_BOTH)); 385 386 fFilterTable= new Table(layouter, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); 387 388 new TableColumn(fFilterTable, SWT.NONE); 389 fFilterViewer= new CheckboxTableViewer(fFilterTable); 390 fTableEditor= new TableEditor(fFilterTable); 391 fFilterViewer.setLabelProvider(new FilterLabelProvider()); 392 fFilterViewer.setComparator(new FilterViewerSorter()); 393 fStackFilterContentProvider= new StackFilterContentProvider(); 394 fFilterViewer.setContentProvider(fStackFilterContentProvider); 395 fFilterViewer.setInput(this); 397 fFilterViewer.addCheckStateListener(new ICheckStateListener() { 398 public void checkStateChanged(CheckStateChangedEvent event) { 399 Filter filter= (Filter) event.getElement(); 400 fStackFilterContentProvider.toggleFilter(filter); 401 } 402 }); 403 fFilterViewer.addSelectionChangedListener(new ISelectionChangedListener() { 404 public void selectionChanged(SelectionChangedEvent event) { 405 ISelection selection= event.getSelection(); 406 fRemoveFilterButton.setEnabled(!selection.isEmpty()); 407 } 408 }); 409 } 410 411 private void createStepFilterButtons(Composite container) { 412 Composite buttonContainer= new Composite(container, SWT.NONE); 413 GridData gd= new GridData(GridData.FILL_VERTICAL); 414 buttonContainer.setLayoutData(gd); 415 GridLayout buttonLayout= new GridLayout(); 416 buttonLayout.numColumns= 1; 417 buttonLayout.marginHeight= 0; 418 buttonLayout.marginWidth= 0; 419 buttonContainer.setLayout(buttonLayout); 420 421 fAddFilterButton= new Button(buttonContainer, SWT.PUSH); 422 fAddFilterButton.setText(JUnitMessages.JUnitPreferencePage_addfilterbutton_label); 423 fAddFilterButton.setToolTipText(JUnitMessages.JUnitPreferencePage_addfilterbutton_tooltip); 424 gd= new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); 425 fAddFilterButton.setLayoutData(gd); 426 LayoutUtil.setButtonDimensionHint(fAddFilterButton); 427 fAddFilterButton.addListener(SWT.Selection, new Listener() { 428 public void handleEvent(Event e) { 429 editFilter(); 430 } 431 }); 432 433 fAddTypeButton= new Button(buttonContainer, SWT.PUSH); 434 fAddTypeButton.setText(JUnitMessages.JUnitPreferencePage_addtypebutton_label); 435 fAddTypeButton.setToolTipText(JUnitMessages.JUnitPreferencePage_addtypebutton_tooltip); 436 gd= getButtonGridData(fAddTypeButton); 437 fAddTypeButton.setLayoutData(gd); 438 LayoutUtil.setButtonDimensionHint(fAddTypeButton); 439 fAddTypeButton.addListener(SWT.Selection, new Listener() { 440 public void handleEvent(Event e) { 441 addType(); 442 } 443 }); 444 445 fAddPackageButton= new Button(buttonContainer, SWT.PUSH); 446 fAddPackageButton.setText(JUnitMessages.JUnitPreferencePage_addpackagebutton_label); 447 fAddPackageButton.setToolTipText(JUnitMessages.JUnitPreferencePage_addpackagebutton_tooltip); 448 gd= getButtonGridData(fAddPackageButton); 449 fAddPackageButton.setLayoutData(gd); 450 SWTUtil.setButtonDimensionHint(fAddPackageButton); 451 fAddPackageButton.addListener(SWT.Selection, new Listener() { 452 public void handleEvent(Event e) { 453 addPackage(); 454 } 455 }); 456 457 fRemoveFilterButton= new Button(buttonContainer, SWT.PUSH); 458 fRemoveFilterButton.setText(JUnitMessages.JUnitPreferencePage_removefilterbutton_label); 459 fRemoveFilterButton.setToolTipText(JUnitMessages.JUnitPreferencePage_removefilterbutton_tooltip); 460 gd= getButtonGridData(fRemoveFilterButton); 461 fRemoveFilterButton.setLayoutData(gd); 462 SWTUtil.setButtonDimensionHint(fRemoveFilterButton); 463 fRemoveFilterButton.addListener(SWT.Selection, new Listener() { 464 public void handleEvent(Event e) { 465 removeFilters(); 466 } 467 }); 468 fRemoveFilterButton.setEnabled(false); 469 470 fEnableAllButton= new Button(buttonContainer, SWT.PUSH); 471 fEnableAllButton.setText(JUnitMessages.JUnitPreferencePage_enableallbutton_label); 472 fEnableAllButton.setToolTipText(JUnitMessages.JUnitPreferencePage_enableallbutton_tooltip); 473 gd= getButtonGridData(fEnableAllButton); 474 fEnableAllButton.setLayoutData(gd); 475 SWTUtil.setButtonDimensionHint(fEnableAllButton); 476 fEnableAllButton.addListener(SWT.Selection, new Listener() { 477 public void handleEvent(Event e) { 478 checkAllFilters(true); 479 } 480 }); 481 482 fDisableAllButton= new Button(buttonContainer, SWT.PUSH); 483 fDisableAllButton.setText(JUnitMessages.JUnitPreferencePage_disableallbutton_label); 484 fDisableAllButton.setToolTipText(JUnitMessages.JUnitPreferencePage_disableallbutton_tooltip); 485 gd= getButtonGridData(fDisableAllButton); 486 fDisableAllButton.setLayoutData(gd); 487 SWTUtil.setButtonDimensionHint(fDisableAllButton); 488 fDisableAllButton.addListener(SWT.Selection, new Listener() { 489 public void handleEvent(Event e) { 490 checkAllFilters(false); 491 } 492 }); 493 494 } 495 496 private GridData getButtonGridData(Button button) { 497 GridData gd= new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); 498 int widthHint= convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); 499 gd.widthHint= Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); 500 return gd; 501 } 502 503 public void init(IWorkbench workbench) {} 504 505 509 private void editFilter() { 510 if (fEditorText != null) 512 validateChangeAndCleanup(); 513 514 fNewStackFilter= fStackFilterContentProvider.addFilter(DEFAULT_NEW_FILTER_TEXT, true); 515 fNewTableItem= fFilterTable.getItem(0); 516 517 int textStyles= SWT.SINGLE | SWT.LEFT; 524 if (!SWT.getPlatform().equals("motif")) textStyles |= SWT.BORDER; 526 527 fEditorText= new Text(fFilterTable, textStyles); 528 GridData gd= new GridData(GridData.FILL_BOTH); 529 fEditorText.setLayoutData(gd); 530 531 fTableEditor.horizontalAlignment= SWT.LEFT; 533 fTableEditor.grabHorizontal= true; 534 fTableEditor.setEditor(fEditorText, fNewTableItem, 0); 535 536 fEditorText.setText(fNewStackFilter.getName()); 538 fEditorText.selectAll(); 539 setEditorListeners(fEditorText); 540 fEditorText.setFocus(); 541 } 542 543 private void setEditorListeners(Text text) { 544 text.addKeyListener(new KeyAdapter() { 546 public void keyReleased(KeyEvent event) { 547 if (event.character == SWT.CR) { 548 if (fInvalidEditorText != null) { 549 fEditorText.setText(fInvalidEditorText); 550 fInvalidEditorText= null; 551 } else 552 validateChangeAndCleanup(); 553 } else if (event.character == SWT.ESC) { 554 removeNewFilter(); 555 cleanupEditor(); 556 } 557 } 558 }); 559 text.addFocusListener(new FocusAdapter() { 561 public void focusLost(FocusEvent event) { 562 if (fInvalidEditorText != null) { 563 fEditorText.setText(fInvalidEditorText); 564 fInvalidEditorText= null; 565 } else 566 validateChangeAndCleanup(); 567 } 568 }); 569 text.addListener(SWT.Traverse, new Listener() { 573 public void handleEvent(Event event) { 574 event.doit= false; 575 } 576 }); 577 } 578 579 private void validateChangeAndCleanup() { 580 String trimmedValue= fEditorText.getText().trim(); 581 if (trimmedValue.length() < 1) 583 removeNewFilter(); 584 585 else if (!validateEditorInput(trimmedValue)) { 587 fInvalidEditorText= trimmedValue; 588 fEditorText.setText(JUnitMessages.JUnitPreferencePage_invalidstepfilterreturnescape); 589 getShell().getDisplay().beep(); 590 return; 591 } else { 593 Object [] filters= fStackFilterContentProvider.getElements(null); 594 for (int i= 0; i < filters.length; i++) { 595 Filter filter= (Filter) filters[i]; 596 if (filter.getName().equals(trimmedValue)) { 597 removeNewFilter(); 598 cleanupEditor(); 599 return; 600 } 601 } 602 fNewTableItem.setText(trimmedValue); 603 fNewStackFilter.setName(trimmedValue); 604 fFilterViewer.refresh(); 605 } 606 cleanupEditor(); 607 } 608 609 612 private void cleanupEditor() { 613 if (fEditorText == null) 614 return; 615 616 fNewStackFilter= null; 617 fNewTableItem= null; 618 fTableEditor.setEditor(null, null, 0); 619 fEditorText.dispose(); 620 fEditorText= null; 621 } 622 623 private void removeNewFilter() { 624 fStackFilterContentProvider.removeFilters(new Object [] { fNewStackFilter }); 625 } 626 627 635 private boolean validateEditorInput(String trimmedValue) { 636 char firstChar= trimmedValue.charAt(0); 637 if ((!(Character.isJavaIdentifierStart(firstChar)) || (firstChar == '*'))) 638 return false; 639 640 int length= trimmedValue.length(); 641 for (int i= 1; i < length; i++) { 642 char c= trimmedValue.charAt(i); 643 if (!Character.isJavaIdentifierPart(c)) { 644 if (c == '.' && i != (length - 1)) 645 continue; 646 if (c == '*' && i == (length - 1)) 647 continue; 648 649 return false; 650 } 651 } 652 return true; 653 } 654 655 private void addType() { 656 Shell shell= getShell(); 657 SelectionDialog dialog= null; 658 try { 659 dialog= 660 JavaUI.createTypeDialog( 661 shell, 662 PlatformUI.getWorkbench().getProgressService(), 663 SearchEngine.createWorkspaceScope(), 664 IJavaElementSearchConstants.CONSIDER_CLASSES, 665 false); 666 } catch (JavaModelException jme) { 667 String title= JUnitMessages.JUnitPreferencePage_addtypedialog_title; 668 String message= JUnitMessages.JUnitPreferencePage_addtypedialog_error_message; 669 ExceptionHandler.handle(jme, shell, title, message); 670 return; 671 } 672 673 dialog.setTitle(JUnitMessages.JUnitPreferencePage_addtypedialog_title); 674 dialog.setMessage(JUnitMessages.JUnitPreferencePage_addtypedialog_message); 675 if (dialog.open() == IDialogConstants.CANCEL_ID) 676 return; 677 678 Object [] types= dialog.getResult(); 679 if (types != null && types.length > 0) { 680 IType type= (IType) types[0]; 681 fStackFilterContentProvider.addFilter(type.getFullyQualifiedName('.'), true); 682 } 683 } 684 685 private void addPackage() { 686 Shell shell= getShell(); 687 IProgressService context= PlatformUI.getWorkbench().getProgressService(); 688 IJavaSearchScope createWorkspaceScope= SearchEngine.createWorkspaceScope(); 689 SelectionDialog dialog= JavaUI.createPackageDialog(shell, context, createWorkspaceScope, true, true, ""); dialog.setTitle(JUnitMessages.JUnitPreferencePage_addpackagedialog_title); 691 dialog.setMessage(JUnitMessages.JUnitPreferencePage_addpackagedialog_message); 692 if (dialog.open() != Window.OK) 693 return; 694 695 Object [] packages= dialog.getResult(); 696 if (packages == null) 697 return; 698 699 for (int i= 0; i < packages.length; i++) { 700 IJavaElement pkg= (IJavaElement) packages[i]; 701 702 String filter= pkg.getElementName(); 703 if (filter.length() < 1) 704 filter= JUnitMessages.JUnitMainTab_label_defaultpackage; 705 else 706 filter += ".*"; 708 fStackFilterContentProvider.addFilter(filter, true); 709 } 710 } 711 private void removeFilters() { 712 IStructuredSelection selection= (IStructuredSelection) fFilterViewer.getSelection(); 713 fStackFilterContentProvider.removeFilters(selection.toArray()); 714 } 715 716 private void checkAllFilters(boolean check) { 717 Object [] filters= fStackFilterContentProvider.getElements(null); 718 for (int i= (filters.length - 1); i >= 0; --i) 719 ((Filter) filters[i]).setChecked(check); 720 721 fFilterViewer.setAllChecked(check); 722 } 723 724 public boolean performOk() { 725 AssertionVMArg.setEnableAssertionsPreference(getAssertionCheckBoxSelection()); 726 fStackFilterContentProvider.saveFilters(); 727 return true; 728 } 729 730 protected void performDefaults() { 731 setDefaultValues(); 732 super.performDefaults(); 733 } 734 735 private void setDefaultValues() { 736 fEnableAssertionsCheckBox.setSelection(false); 737 fStackFilterContentProvider.setDefaults(); 738 } 739 740 745 protected List createActiveStackFiltersList() { 746 return Arrays.asList(getFilterPatterns()); 747 } 748 749 754 protected List createInactiveStackFiltersList() { 755 String [] strings= 756 JUnitPreferencePage.parseList(getPreferenceStore().getString(JUnitPreferencesConstants.PREF_INACTIVE_FILTERS_LIST)); 757 return Arrays.asList(strings); 758 } 759 760 protected void updateActions() { 761 if (fEnableAllButton == null) 762 return; 763 764 boolean enabled= fFilterViewer.getTable().getItemCount() > 0; 765 fEnableAllButton.setEnabled(enabled); 766 fDisableAllButton.setEnabled(enabled); 767 } 768 769 public static String [] getFilterPatterns() { 770 IPreferenceStore store= JUnitPlugin.getDefault().getPreferenceStore(); 771 return JUnitPreferencePage.parseList(store.getString(JUnitPreferencesConstants.PREF_ACTIVE_FILTERS_LIST)); 772 } 773 774 public static boolean getFilterStack() { 775 IPreferenceStore store= JUnitPlugin.getDefault().getPreferenceStore(); 776 return store.getBoolean(JUnitPreferencesConstants.DO_FILTER_STACK); 777 } 778 779 public static void setFilterStack(boolean filter) { 780 IPreferenceStore store= JUnitPlugin.getDefault().getPreferenceStore(); 781 store.setValue(JUnitPreferencesConstants.DO_FILTER_STACK, filter); 782 } 783 784 787 private static String [] parseList(String listString) { 788 List list= new ArrayList (10); 789 StringTokenizer tokenizer= new StringTokenizer (listString, ","); while (tokenizer.hasMoreTokens()) 791 list.add(tokenizer.nextToken()); 792 return (String []) list.toArray(new String [list.size()]); 793 } 794 } 795 | Popular Tags |