Search in sources :

Example 1 with TestCaseSelectionDialog

use of bndtools.internal.testcaseselection.TestCaseSelectionDialog in project bndtools by bndtools.

the class TestSuiteLabelProvider method doAdd.

void doAdd() {
    // Prepare the exclusion list based on existing test cases
    final Set<String> testSuitesSet = new HashSet<String>(testSuites);
    // Create a filter from the exclusion list
    ITestCaseFilter filter = new ITestCaseFilter() {

        @Override
        public boolean select(String testCaseName) {
            return !testSuitesSet.contains(testCaseName);
        }
    };
    IFormPage page = (IFormPage) getManagedForm().getContainer();
    IWorkbenchWindow window = page.getEditorSite().getWorkbenchWindow();
    // Prepare the package lister from the Java project
    IJavaProject javaProject = getJavaProject();
    if (javaProject == null) {
        MessageDialog.openError(getSection().getShell(), "Error", "Cannot add test cases: unable to find a Java project associated with the editor input.");
        return;
    }
    IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject });
    JavaSearchScopeTestCaseLister testCaseLister = new JavaSearchScopeTestCaseLister(searchScope, window);
    // Create and open the dialog
    TestCaseSelectionDialog dialog = new TestCaseSelectionDialog(getSection().getShell(), testCaseLister, filter, Messages.TestSuitesPart_title);
    dialog.setSourceOnly(true);
    dialog.setMultipleSelection(true);
    if (dialog.open() == Window.OK) {
        Object[] results = dialog.getResult();
        List<String> added = new LinkedList<String>();
        // Select the results
        for (Object result : results) {
            String newTestSuites = (String) result;
            if (testSuites.add(newTestSuites)) {
                added.add(newTestSuites);
            }
        }
        // Update the model and view
        if (!added.isEmpty()) {
            viewer.add(added.toArray());
            markDirty();
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ITestCaseFilter(bndtools.internal.testcaseselection.ITestCaseFilter) IFormPage(org.eclipse.ui.forms.editor.IFormPage) LinkedList(java.util.LinkedList) IJavaProject(org.eclipse.jdt.core.IJavaProject) TestCaseSelectionDialog(bndtools.internal.testcaseselection.TestCaseSelectionDialog) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) JavaSearchScopeTestCaseLister(bndtools.internal.testcaseselection.JavaSearchScopeTestCaseLister) HashSet(java.util.HashSet)

Aggregations

ITestCaseFilter (bndtools.internal.testcaseselection.ITestCaseFilter)1 JavaSearchScopeTestCaseLister (bndtools.internal.testcaseselection.JavaSearchScopeTestCaseLister)1 TestCaseSelectionDialog (bndtools.internal.testcaseselection.TestCaseSelectionDialog)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IJavaSearchScope (org.eclipse.jdt.core.search.IJavaSearchScope)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 IFormPage (org.eclipse.ui.forms.editor.IFormPage)1