in eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleProjectHandler.java [48:124]
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
List<IProject> applicableProjects = new LinkedList<>();
IProject[] allProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
for (IProject p : allProjects) {
if (p.isOpen() && ProjectHelper.isPotentialBundleProject(p)) {
applicableProjects.add(p);
}
}
Object[] elems = ((IStructuredSelection) selection).toArray();
List<IProject> initialSelection = new ArrayList<>(elems.length);
for (Object elem : elems) {
IProject project = null;
if (elem instanceof IFile) {
IFile file = (IFile) elem;
project = file.getProject();
} else if (elem instanceof IProject) {
project = (IProject) elem;
} else if (elem instanceof IJavaProject) {
project = ((IJavaProject) elem).getProject();
}
if (project != null)
initialSelection.add(project);
}
ConvertProjectsWizard wizard = new ConvertProjectsWizard(applicableProjects, initialSelection,
"Convert to Bundle Project(s)", "Select project(s) to convert to Bundle project(s)\n"
+ "List contains open Java projects that are not yet bundle or content projects.");
final Display display = getDisplay();
final WizardDialog dialog = new WizardDialog(display.getActiveShell(), wizard);
BusyIndicator.showWhile(display, new Runnable() {
public void run() {
dialog.open();
}
});
if (dialog.getReturnCode()!=WizardDialog.OK) {
// user did not click OK
return null;
}
final List<IProject> selectedProjects = wizard.getSelectedProjects();
if (selectedProjects == null || selectedProjects.size()==0) {
// no project was selected
return null;
}
IRunnableWithProgress r = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
try {
for (IProject project : selectedProjects) {
ConfigurationHelper.convertToBundleProject(project);
}
} catch (CoreException e) {
e.printStackTrace();
MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project",
e.getMessage());
}
}
};
try {
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(r);
} catch (Exception e) {
e.printStackTrace();
MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project",
e.getMessage());
}
}
return null;
}