@Override
	public boolean isReplaceAllowed(int rowIndex, DataType dataType) {

		DataTypeComponent dtc = getComponent(rowIndex);
		if (dtc == null) {
			return false;
		}

		try {
			checkIsAllowableDataType(dataType);
		}
		catch (InvalidDataTypeException e) {
			return false;
		}

		if (isPackingEnabled() || isAtEnd(rowIndex)) {
			return true;
		}

		int undefSize = getNumUndefinedBytesAfter(dtc);
		if (undefSize < 0) {
			return true;
		}

		int numAvailable = dtc.getLength() + undefSize;
		return dataType.getLength() <= numAvailable;
	}
Returns whether or not insertion of the specified component is allowed
at the specified index.

@param currentIndex index of the component in the structure.
@param datatype the data type to be inserted.
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/StructureEditorModel.java