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;
}
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();
}
}
}
Aggregations