It's going to vary from gym to gym and from person to person, but I'd say the other person was in the wrong. Sharing equipment is great, and I alternate sets with people I don't know at all or very well all the time if we both need to use a certain piece of equipment, but I wouldn't be happy if they just walked up and did it without asking me first.
If you're not confident about your form, and you're concerned about having somebody else in that close proximity and you think there's a chance of one or both of you getting injured as a result, you have every right to ask them to wait for you to finish. You have enough to worry about just getting your form right for your lifts, you don't need the added distraction of worrying about another person's safety while doing it.
Nobody should ever be walking up to a piece of equipment somebody else is using and starting to train on it, taking weights from it - I once had somebody walk up and take a plate from the bar in between my sets, while I was sat on the bench - or anything else without asking that person first.
For me, general etiquette is this:
- If I'm unsure if somebody is using the equipment, ask somebody working nearby if anybody is using it. This shouldn't be an issue if you train in a gym where everybody racks their weights and tidies up behind themselves when they're done, but that's not always the case.
- If somebody is using the equipment that I need to use, I ask them how many sets they have left.
- If they only have a few sets to go then I'll just wait.
- If they have a lot more sets to do then I'll ask if they mind alternating sets. Most of the time people will say yes, but they don't have to. They might have specific rest times they need to keep to for their training, for example, and therefore can't have me taking an unknown amount of time for my set in between.
- If you are alternating sets, and you're using different weights, help out with unloading and loading the bar. I usually do a side of the bar each if I'm alternating with somebody because it just gets things done faster, but you could also take it in turns to do the full unloading and loading between each of your sets. Either way, make sure you're at least doing your fair share.
- Put your weights back in the right place afterwards. Note that in the right place doesn't necessarily mean where you found them. Again, this varies from gym to gym; mine has numbers painted on the racks so you know which size/weight plates go where. If I pick up a 10kg plate from the 5kg section, it goes back in the 10kg section, not where I got it from.