use of org.eclipse.core.commands.ExecutionException in project sling by apache.
the class ConvertToContentProjectHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
final IProject project = (IProject) ((IStructuredSelection) selection).getFirstElement();
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getDisplay().getActiveShell(), new WorkbenchLabelProvider(), new BaseWorkbenchContentProvider());
dialog.setMessage("Select content sync root location (containing the jcr root)");
dialog.setTitle("Content Sync Root");
IContainer initialContainer = ProjectHelper.getInferredContentProjectContentRoot(project);
if (initialContainer != null) {
dialog.setInitialElementSelections(Arrays.asList(initialContainer));
}
dialog.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof IProject) {
return ((IProject) element).equals(project);
}
// display folders only
return element instanceof IContainer;
}
});
dialog.setInput(new IWorkbenchAdapter() {
@Override
public Object getParent(Object o) {
return null;
}
@Override
public String getLabel(Object o) {
return null;
}
@Override
public ImageDescriptor getImageDescriptor(Object object) {
return null;
}
@Override
public Object[] getChildren(Object o) {
return new Object[] { project };
}
});
// this is the root element
dialog.setAllowMultiple(false);
dialog.setValidator(new ISelectionStatusValidator() {
@Override
public IStatus validate(Object[] selection) {
if (selection.length > 0) {
final Object item = selection[0];
if (item instanceof IContainer) {
IContainer selectedContainer = (IContainer) item;
String errorMsg = ProjectHelper.validateContentPackageStructure(selectedContainer);
if (errorMsg != null) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, errorMsg);
} else {
return new Status(IStatus.OK, Activator.PLUGIN_ID, "");
}
}
}
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "");
}
});
if (dialog.open() == ContainerSelectionDialog.OK) {
Object[] result = dialog.getResult();
if (result != null && result.length > 0) {
final IContainer container = (IContainer) result[0];
IRunnableWithProgress r = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
IResource jcrRoot = container.findMember("jcr_root");
if (jcrRoot == null || !(jcrRoot instanceof IFolder)) {
MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project", "jcr_root not found under " + container + " (or not a Folder)");
return;
}
ConfigurationHelper.convertToContentPackageProject(project, monitor, jcrRoot.getProjectRelativePath());
} catch (CoreException e) {
Activator.getDefault().getPluginLogger().warn("Could not convert project", e);
MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project", e.getMessage());
}
}
};
try {
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(r);
} catch (Exception e) {
Activator.getDefault().getPluginLogger().warn("Could not convert project", e);
MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project", e.getMessage());
}
}
}
}
return null;
}
use of org.eclipse.core.commands.ExecutionException in project sling by apache.
the class ConvertToBundleProjectHandler method execute.
@Override
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;
}
Aggregations