This comment isn't about this situation, but in general. Generally, they will always "come out of nowhere". Why? Because if you were more alert, they would choose a different victim. So, a lot of one's practice should be geared to this reality.
Now, in this case sounds like the gun was in his face right when the door opened so other than internal mental alertness, there was nothing for him to observe as an indicator.
This is also why having some sort of striking skill is important. Everybody says something like "I don't need to know H2H. Ill just shoot them." Um, OK, not when the gun is already in your face and yours is in the holster under a shirt! If his "smack" to the gun was instead a fully committed claw to the eye or heel palm to the chin, this may have ended even better for him. Not critiquing though, he did well, reacted fast, stayed in the "fight" after shot, moved to cover and returned fire. Glad he'll be OK.