@Override
	protected boolean replaceRange(int startRowIndex, int endRowIndex, DataType datatype,
			int length, TaskMonitor monitor)
			throws InvalidDataTypeException, InsufficientBytesException, CancelledException {

		if (length <= 0) {
			throw new InvalidDataTypeException(
				"Can not replace a range with a " + length + " length data type.");
		}

		// Verify that we aren't adding this structure or anything that it is
		// part of to this editable structure.
		if (datatype.equals(viewComposite)) {
			String msg = datatype.getDisplayName() + " can't contain itself.";
			throw new InvalidDataTypeException(msg);
		}
		else if ((datatype instanceof Composite) &&
			(((Composite) datatype).isPartOf(viewComposite))) {
			String msg = "Can't replace with " + datatype.getDisplayName() + " since it has " +
				viewComposite.getDisplayName() + " within it.";
			throw new InvalidDataTypeException(msg);
		}

		if (startRowIndex > endRowIndex) {
			throw new IllegalArgumentException("startIndex of " + startRowIndex +
				" is greater than endIndex of " + endRowIndex + ".");
		}

		FieldSelection overlap = new FieldSelection();
		overlap.addRange(startRowIndex, endRowIndex + 1);
		overlap.intersect(selection);
		boolean replacedSelected = (overlap.getNumRanges() > 0);

		int txId = viewDTM.startTransaction("Insert Multiple");
		try {

			// Union just replaces entire selection range with single instance of new component.
			deleteComponentRange(startRowIndex, endRowIndex, monitor);

			insert(startRowIndex, datatype, length, null, null);
		}
		finally {
			viewDTM.endTransaction(txId, true);
		}

		if (replacedSelected) {
			selection.addRange(startRowIndex, startRowIndex + 1);
			fixSelection();
		}
		return true;
	}
Insert the named data type before the specified index.

@param rowIndex index of the row (component).

@throws InvalidDataTypeException if the union being edited is part
        of the data type being inserted or if inserting isn't allowed.
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/UnionEditorModel.java