use of com.redhat.devtools.intellij.tektoncd.ui.DeleteDialog in project intellij-tekton by redhat-developer.
the class DeleteAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath[] path, Object[] selected, Tkn tkncli) {
ActionMessage telemetry = TelemetryService.instance().action(NAME_PREFIX_CRUD + "delete resource");
ParentableNode[] elements = Arrays.stream(selected).map(item -> getElement(item)).toArray(ParentableNode[]::new);
ExecHelper.submit(() -> {
String deleteText = getDeleteText(tkncli, elements);
int resultDialog = UIHelper.executeInUI(() -> {
DeleteDialog delDialog = new DeleteDialog(null, getTitle(elements), deleteText, getDeleteChkText(elements));
delDialog.show();
if (delDialog.isOK()) {
return delDialog.hasToDeleteRelatedResources() ? OK_DELETE_RESOURCES_CODE : OK_DELETE_CODE;
}
return CANCEL_CODE;
});
if (resultDialog != CANCEL_CODE) {
String namespace = elements[0].getNamespace();
boolean deleteRelatedResources = resultDialog == OK_DELETE_RESOURCES_CODE;
Map<Class, List<ParentableNode>> resourcesByClass = TreeHelper.getResourcesByClass(elements);
for (Class type : resourcesByClass.keySet()) {
try {
deleteResources(type, resourcesByClass, namespace, deleteRelatedResources, tkncli);
((TektonTreeStructure) getTree(anActionEvent).getClientProperty(Constants.STRUCTURE_PROPERTY)).fireModified(resourcesByClass.get(type).get(0).getParent());
telemetry.property(TelemetryService.PROP_RESOURCE_KIND, type.getSimpleName()).property(TelemetryService.PROP_RESOURCE_RELATED, String.valueOf(deleteRelatedResources)).success().send();
} catch (IOException e) {
telemetry.error(anonymizeResource(null, namespace, e.getMessage())).send();
UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "Error"));
}
}
}
});
}
Aggregations