Here is the solution that I have followed to solve the problem.
In the custom generated DeleteAction class, Override the following methods
// confirm dialog for rightclicking and selecting "Delete from Model"
@Override
public void runWithEvent(Event event) {
if(deleteDialog("the selected element(s)"))
super.runWithEvent(event);
}
// Confirm dialog for pressing delete key.
@Override
public void run() {
if(deleteDialog("the selected element(s)")) {
super.run();
}
}
to add the delete key action, In generated XXXDiagramEditor class,
// In the generated configureGraphicalViewer() - Change to @Generated NOT
KeyHandler keyHandler = getDiagramGraphicalViewer().getKeyHandler();
keyHandler.put(KeyStroke.getPressed(SWT.DEL, 127, 0), new DeleteElementAction(this)/*Custom generated delete action*/);
getDiagramGraphicalViewer().setKeyHandler(keyHandler);
After adding these codes, everything worked like a charm. It will ask for a confirmation dialog when we press delete (Even after selecting any number of elements) and does the required operations. Also when we right click and select delete from model it works. Also, we don't need the component role edit policy. I have removed it from installEditPolicy()
[also the editPolicy file].