GP-2228 - Added a status message when applying a favorite data type to a

non-contiguous selection is not allowed
This commit is contained in:
dragonmacher 2024-10-10 18:38:29 -04:00
parent 065a845d4a
commit 83d2cbcf31

View File

@ -568,10 +568,11 @@ public abstract class CompEditorModel extends CompositeEditorModel {
@Override @Override
public DataTypeComponent add(DataType dataType) throws UsrException { public DataTypeComponent add(DataType dataType) throws UsrException {
if (isContiguousSelection()) { if (!isContiguousSelection()) {
return add(getMinIndexSelected(), dataType); setStatus("Replace data type only works on a contiguous selection", true);
return null;
} }
return null; return add(getMinIndexSelected(), dataType);
} }
/** /**
@ -598,7 +599,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {
return null; return null;
} }
}); });
fixSelection(); fixSelection();
componentEdited(); componentEdited();
selectionChanged(); selectionChanged();
@ -822,7 +823,8 @@ public abstract class CompEditorModel extends CompositeEditorModel {
* @param length component length * @param length component length
* @throws InvalidDataTypeException if check fails * @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); DataTypeComponent dtc = getComponent(rowIndex);
if (dtc == null) { if (dtc == null) {
throw new InvalidDataTypeException("Invalid component selection"); throw new InvalidDataTypeException("Invalid component selection");
@ -843,25 +845,28 @@ public abstract class CompEditorModel extends CompositeEditorModel {
int currentCompSize = dtc.getLength(); int currentCompSize = dtc.getLength();
int newCompSize = length; int newCompSize = length;
int sizeDiff = newCompSize - currentCompSize; int sizeDiff = newCompSize - currentCompSize;
if (sizeDiff <= 0) { if (sizeDiff <= 0) {
return; return;
} }
int undefinedSpaceAvail = getNumUndefinedBytesAfter(dtc); int undefinedSpaceAvail = getNumUndefinedBytesAfter(dtc);
if (sizeDiff > undefinedSpaceAvail) { if (sizeDiff > undefinedSpaceAvail) {
int spaceNeeded = 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) { if (struct.getDefinedComponentAtOrAfterOffset(dtc.getOffset() + 1) == null) {
// suggest growing structure // suggest growing structure
int suggestedSize = getLength() + spaceNeeded; 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) // 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.");
} }
} }
/** /**
* Get the number of undefined bytes after the specified component. * Get the number of undefined bytes after the specified component.
* The viewComposite must be a non-packed structure. * The viewComposite must be a non-packed structure.
@ -879,16 +884,17 @@ public abstract class CompEditorModel extends CompositeEditorModel {
if (struct.isPackingEnabled()) { if (struct.isPackingEnabled()) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
// TODO: May need special logic if dtc is zero-length component // TODO: May need special logic if dtc is zero-length component
int length = getLength(); int length = getLength();
int nextCompOffset = dtc.getEndOffset() + 1; int nextCompOffset = dtc.getEndOffset() + 1;
if (nextCompOffset >= length) { if (nextCompOffset >= length) {
return 0; return 0;
} }
DataTypeComponent nextDefinedDtc = struct.getDefinedComponentAtOrAfterOffset(nextCompOffset); DataTypeComponent nextDefinedDtc =
struct.getDefinedComponentAtOrAfterOffset(nextCompOffset);
int nextDefinedOffset = (nextDefinedDtc == null) ? length : nextDefinedDtc.getOffset(); int nextDefinedOffset = (nextDefinedDtc == null) ? length : nextDefinedDtc.getOffset();
return Math.max(0, nextDefinedOffset - nextCompOffset); // prevent negative return value return Math.max(0, nextDefinedOffset - nextCompOffset); // prevent negative return value
} }
/** /**