public void addConnection(int key1, int key2) {
		Element element1 = elements.get(key1);
		Element element2 = elements.get(key2);

		if (element1 == null) {
			throw new IllegalArgumentException(
					"Unable to find element with key " + key1 + " in the model");
		}

		if (element2 == null) {
			throw new IllegalArgumentException(
					"Unable to find element with key " + key2 + " in the model");
		}

		if (element1.isInSet1() == element2.isInSet1()) {
			throw new IllegalArgumentException(
					"Cannot connect elements from the same set");
		}

		boolean result1 = elements.get(key1).addConnection(key2);
		boolean result2 = elements.get(key2).addConnection(key1);

		if (result1 != result2) {
			throw new IllegalStateException(
					"Inconsistency in DataModel: connection was not added to both elements");
		}

		if (result1) {
			UndoableEdit edit = new AddConnectionEdit(key1, key2);

			firePropertyChange(CONNECTION_ADDED, key1, key2);
			postEdit(edit);
		} 
	}