Merge remote-tracking branch 'origin/GP-2228-dragonmacher-structured-editor-error-message'

This commit is contained in:
Ryan Kurtz 2024-10-11 12:49:08 -04:00
commit d069fbad2b

View File

@ -568,11 +568,12 @@ public abstract class CompEditorModel extends CompositeEditorModel {
@Override
public DataTypeComponent add(DataType dataType) throws UsrException {
if (isContiguousSelection()) {
return add(getMinIndexSelected(), dataType);
}
if (!isContiguousSelection()) {
setStatus("Replace data type only works on a contiguous selection", true);
return null;
}
return add(getMinIndexSelected(), dataType);
}
/**
* Adds the specified data type at the specified component index. Whether
@ -822,7 +823,8 @@ public abstract class CompEditorModel extends CompositeEditorModel {
* @param length component length
* @throws InvalidDataTypeException if check fails
*/
private void checkForReplace(int rowIndex, DataType datatype, int length) throws InvalidDataTypeException {
private void checkForReplace(int rowIndex, DataType datatype, int length)
throws InvalidDataTypeException {
DataTypeComponent dtc = getComponent(rowIndex);
if (dtc == null) {
throw new InvalidDataTypeException("Invalid component selection");
@ -851,14 +853,17 @@ public abstract class CompEditorModel extends CompositeEditorModel {
int undefinedSpaceAvail = getNumUndefinedBytesAfter(dtc);
if (sizeDiff > undefinedSpaceAvail) {
int spaceNeeded = sizeDiff - undefinedSpaceAvail;
String msg = newCompSize + " byte replacement at 0x" + Integer.toHexString(dtc.getOffset());
String msg =
newCompSize + " byte replacement at 0x" + Integer.toHexString(dtc.getOffset());
if (struct.getDefinedComponentAtOrAfterOffset(dtc.getOffset() + 1) == null) {
// suggest growing structure
int suggestedSize = getLength() + spaceNeeded;
throw new InvalidDataTypeException(msg + " requires structure length of " + suggestedSize + "-bytes.");
throw new InvalidDataTypeException(
msg + " requires structure length of " + suggestedSize + "-bytes.");
}
// suggest insert bytes (NOTE: in the future a conflict removal/grow could be offered)
throw new InvalidDataTypeException(msg + " requires " + spaceNeeded + " additional undefined bytes.");
throw new InvalidDataTypeException(
msg + " requires " + spaceNeeded + " additional undefined bytes.");
}
}
@ -886,7 +891,8 @@ public abstract class CompEditorModel extends CompositeEditorModel {
if (nextCompOffset >= length) {
return 0;
}
DataTypeComponent nextDefinedDtc = struct.getDefinedComponentAtOrAfterOffset(nextCompOffset);
DataTypeComponent nextDefinedDtc =
struct.getDefinedComponentAtOrAfterOffset(nextCompOffset);
int nextDefinedOffset = (nextDefinedDtc == null) ? length : nextDefinedDtc.getOffset();
return Math.max(0, nextDefinedOffset - nextCompOffset); // prevent negative return value
}