Search in sources :

Example 1 with IPackageFilter

use of bndtools.internal.pkgselection.IPackageFilter in project bndtools by bndtools.

the class ExportPatternsListPart method selectPackagesToAdd.

protected List<ExportedPackage> selectPackagesToAdd() {
    List<ExportedPackage> added = null;
    final IPackageFilter filter = new IPackageFilter() {

        @Override
        public boolean select(String packageName) {
            if (packageName.equals("java") || packageName.startsWith("java."))
                return false;
            return true;
        }
    };
    IFormPage page = (IFormPage) getManagedForm().getContainer();
    IWorkbenchWindow window = page.getEditorSite().getWorkbenchWindow();
    // Prepare the package lister from the Java project
    IProject project = ResourceUtil.getResource(page.getEditorInput()).getProject();
    IJavaProject javaProject = JavaCore.create(project);
    IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject });
    JavaSearchScopePackageLister packageLister = new JavaSearchScopePackageLister(searchScope, window);
    // Create and open the dialog
    PackageSelectionDialog dialog = new PackageSelectionDialog(window.getShell(), packageLister, filter, "Select new packages to export from the bundle.");
    dialog.setSourceOnly(true);
    dialog.setMultipleSelection(true);
    if (dialog.open() == Window.OK) {
        Object[] results = dialog.getResult();
        added = new LinkedList<ExportedPackage>();
        // Select the results
        for (Object result : results) {
            String newPackageName = (String) result;
            ExportedPackage newPackage = new ExportedPackage(newPackageName, new Attrs());
            added.add(newPackage);
        }
    }
    return added;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Attrs(aQute.bnd.header.Attrs) IFormPage(org.eclipse.ui.forms.editor.IFormPage) IProject(org.eclipse.core.resources.IProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) ExportedPackage(aQute.bnd.build.model.clauses.ExportedPackage) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) JavaSearchScopePackageLister(bndtools.internal.pkgselection.JavaSearchScopePackageLister) IPackageFilter(bndtools.internal.pkgselection.IPackageFilter) PackageSelectionDialog(bndtools.internal.pkgselection.PackageSelectionDialog)

Example 2 with IPackageFilter

use of bndtools.internal.pkgselection.IPackageFilter in project bndtools by bndtools.

the class PrivatePackagesPart method doAddPackages.

private void doAddPackages() {
    // Prepare the exclusion list based on existing private packages
    final Set<String> packageNameSet = new HashSet<String>(packages);
    // Create a filter from the exclusion list and packages matching
    // "java.*", which must not be included in a bundle
    IPackageFilter filter = new IPackageFilter() {

        @Override
        public boolean select(String packageName) {
            return !packageName.equals("java") && !packageName.startsWith("java.") && !packageNameSet.contains(packageName);
        }
    };
    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 packages: unable to find a Java project associated with the editor input.");
        return;
    }
    IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject });
    JavaSearchScopePackageLister packageLister = new JavaSearchScopePackageLister(searchScope, window);
    // Create and open the dialog
    PackageSelectionDialog dialog = new PackageSelectionDialog(getSection().getShell(), packageLister, filter, "Select new packages to include in the bundle.");
    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 newPackageName = (String) result;
            if (packages.add(newPackageName)) {
                added.add(newPackageName);
            }
        }
        // Update the model and view
        if (!added.isEmpty()) {
            viewer.add(added.toArray());
            markDirty();
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFormPage(org.eclipse.ui.forms.editor.IFormPage) LinkedList(java.util.LinkedList) IJavaProject(org.eclipse.jdt.core.IJavaProject) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) JavaSearchScopePackageLister(bndtools.internal.pkgselection.JavaSearchScopePackageLister) IPackageFilter(bndtools.internal.pkgselection.IPackageFilter) HashSet(java.util.HashSet) PackageSelectionDialog(bndtools.internal.pkgselection.PackageSelectionDialog)

Aggregations

IPackageFilter (bndtools.internal.pkgselection.IPackageFilter)2 JavaSearchScopePackageLister (bndtools.internal.pkgselection.JavaSearchScopePackageLister)2 PackageSelectionDialog (bndtools.internal.pkgselection.PackageSelectionDialog)2 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 IJavaSearchScope (org.eclipse.jdt.core.search.IJavaSearchScope)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 IFormPage (org.eclipse.ui.forms.editor.IFormPage)2 ExportedPackage (aQute.bnd.build.model.clauses.ExportedPackage)1 Attrs (aQute.bnd.header.Attrs)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 IProject (org.eclipse.core.resources.IProject)1