Israel's wall, settlements and colonies: legal?

The following graphic illustrates a key issue in the ongoing conflict between Israel and the Palestinian people. Israel [light grey      ] has built a wall [outlined in black ] along its border with the Palestinian territories:



The International Court of Justice found the wall's construction to be an act of "self defense" protected under Article 51 of the United Nations Charter. However, as the graphic makes clear, the wall cuts deep into the Palestinian territory at certain points, and by no small margin.

It's unclear how "self defense" justifies the wall being built in such a manner; even more so, it's unclear how Israel can justify the creation of settlements (the blue triangles on the map) beyond the wall and deep within the area designated as Palestinian territory. Can you?