public class DeleteSelectionAction extends AbstractGraphAction {
protected void actionPerformed(final AnActionEvent e, final Graph2D graph) {
final DeleteProvider deleteProvider = getDeleteProvider(e);
final GraphBuilder graphBuilder = getGraphBuilder(e);
if (deleteProvider == null || graphBuilder == null) return;
final List<Node> nodesToBeDeleted = getNodesToBeDeleted(graph, graphBuilder, deleteProvider);
final List<Edge> edgesToBeDeleted = getEdgesToBeDeleted(graph, graphBuilder, deleteProvider);
if (nodesToBeDeleted.size() > 0 || edgesToBeDeleted.size() > 0) {
final String messageText = GraphBundle.message("graph.delete.message") + "?";
final String messageCaption = GraphBundle.message("graph.delete.message.caption");
if (DialogWrapper.OK_EXIT_CODE ==
Messages.showOkCancelDialog(messageText, messageCaption, Messages.getQuestionIcon())) {
for (Node node : nodesToBeDeleted) {
final Object nodeObject = graphBuilder.getNodeObject(node);
if (nodeObject != null) deleteProvider.deleteNode(nodeObject);
}
for (Edge edge : edgesToBeDeleted) {
final Object edgeObject = graphBuilder.getEdgeObject(edge);
if (edgeObject != null) deleteProvider.deleteEdge(edgeObject);
}
}
graphBuilder.updateGraph();
}
}