-
-
Notifications
You must be signed in to change notification settings - Fork 26
Fix display for nested/vlen cmpds #474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mattjala
wants to merge
8
commits into
HDFGroup:master
Choose a base branch
from
mattjala:nested_seq_cmpd
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
575268f
Fix display for nested/vlen cmpds
mattjala e64602f
Committing clang-format changes
github-actions[bot] cd9c0ff
Guard against unsafe writes
mattjala 5fbc86b
Committing clang-format changes
github-actions[bot] 8471a41
Fix array of varstr read
mattjala f757785
Remove support for vlen pre-allocation
mattjala 6cd3296
Display nested types in single cell
mattjala 20b1c71
Committing clang-format changes
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,40 @@ public class DataFactoryUtils { | |
| /** the CMPD_START_IDX_MAP_INDEX value. */ | ||
| public static final int CMPD_START_IDX_MAP_INDEX = 1; | ||
|
|
||
| /** | ||
| * Number of flat leaf names a Datatype contributes to the flat-name list | ||
| * produced by H5Datatype.extractCompoundInfo. The rules: | ||
| * compound - sum of children's counts (no header entry) | ||
| * array(compound) - 1 header + sum of inner compound's children's counts | ||
| * array(atomic) - 1 | ||
| * vlen(any) - 1 (header only; vlen recursion is disabled) | ||
| * atomic, varstr - 1 | ||
| */ | ||
| public static int countLeafNames(Datatype t) | ||
| { | ||
| if (t == null) | ||
| return 1; | ||
| if (t.isCompound()) { | ||
| int sum = 0; | ||
| List<Datatype> children = t.getCompoundMemberTypes(); | ||
| if (children != null) | ||
| for (Datatype child : children) | ||
| sum += countLeafNames(child); | ||
| return sum; | ||
| } | ||
| if (t.isArray()) { | ||
| Datatype base = t.getDatatypeBase(); | ||
| if (base != null && base.isCompound()) { | ||
| int sum = 1; | ||
| for (Datatype child : base.getCompoundMemberTypes()) | ||
| sum += countLeafNames(child); | ||
| return sum; | ||
| } | ||
| return 1; | ||
| } | ||
| return 1; | ||
| } | ||
|
|
||
| /** | ||
| * Given a CompoundDataFormat, as well as a compound datatype, removes the | ||
| * non-selected datatypes from the List of datatypes inside the compound | ||
|
|
@@ -62,34 +96,35 @@ public class DataFactoryUtils { | |
| public static List<Datatype> filterNonSelectedMembers(CompoundDataFormat dataFormat, | ||
| final Datatype compoundType) | ||
| { | ||
| return filterNonSelectedMembers(dataFormat, compoundType, true); | ||
| } | ||
|
|
||
| /** | ||
| * Variant of {@link #filterNonSelectedMembers(CompoundDataFormat, Datatype)} that | ||
| * skips the selected-member filter for inner (non-top-level) compounds. | ||
| * | ||
| * The dataset's flat selected-member list only enumerates top-level leaves; inner | ||
| * compound members can't be individually deselected. Filtering an inner compound | ||
| * against that list would spuriously remove every non-compound member. | ||
| */ | ||
| public static List<Datatype> filterNonSelectedMembers(CompoundDataFormat dataFormat, | ||
| final Datatype compoundType, boolean isTopLevel) | ||
| { | ||
| List<Datatype> selectedTypes = new ArrayList<>(compoundType.getCompoundMemberTypes()); | ||
| if (!isTopLevel) | ||
| return selectedTypes; | ||
|
|
||
| List<Datatype> allSelectedTypes = Arrays.asList(dataFormat.getSelectedMemberTypes()); | ||
| if (allSelectedTypes == null) { | ||
| log.debug("filterNonSelectedMembers(): selected compound member datatype list is null"); | ||
| return null; | ||
| } | ||
|
|
||
| /* | ||
| * Make sure to make a copy of the compound datatype's member list, as we will | ||
| * make modifications to the list when members aren't selected. | ||
| */ | ||
| List<Datatype> selectedTypes = new ArrayList<>(compoundType.getCompoundMemberTypes()); | ||
|
|
||
| /* | ||
| * Among the datatypes within this compound type, only keep the ones that are | ||
| * actually selected in the dataset. | ||
| */ | ||
| Iterator<Datatype> localIt = selectedTypes.iterator(); | ||
| while (localIt.hasNext()) { | ||
| Datatype curType = localIt.next(); | ||
|
|
||
| /* | ||
| * Since the passed in allSelectedMembers list is a flattened out datatype | ||
| * structure, we want to leave the nested compound Datatypes inside our local | ||
| * list of datatypes. | ||
| */ | ||
| if (curType.isCompound()) | ||
| continue; | ||
|
|
||
| if (!allSelectedTypes.contains(curType)) | ||
| localIt.remove(); | ||
| } | ||
|
|
@@ -189,26 +224,35 @@ else if (base.isArray()) { | |
| } | ||
| log.trace("buildColIdxToStartIdxMap(): arrSize after base={}", arrSize); | ||
| } | ||
| // A vlen member is always a single column rendered by VlenDataProvider as the | ||
| // whole sequence (a brace-string, recursing for nested compounds). A top-level | ||
| // vlen-of-compound is already peeled to its inner compound at the dataset level, | ||
| // so any vlen reaching here is a member - never expanded into per-element columns. | ||
|
|
||
| if (nestedCompoundType != null) { | ||
| List<Datatype> cmpdSelectedTypes = filterNonSelectedMembers(dataFormat, nestedCompoundType); | ||
| List<Datatype> cmpdSelectedTypes = | ||
| filterNonSelectedMembers(dataFormat, nestedCompoundType, false); | ||
|
|
||
| /* | ||
| * For Array/Vlen of Compound types, we repeat the compound members n times, | ||
| * where n is the number of array elements of variable-length elements. | ||
| * Therefore, we repeat our mapping for these types n times. | ||
| * For Array of Compound types, we repeat the compound members n times, | ||
| * where n is the number of array elements. For a top-level | ||
| * vlen-of-compound, arrSize is 1 (one column per inner member). | ||
| */ | ||
| for (int j = 0; j < arrSize; j++) { | ||
| buildColIdxToProviderMap(outMap, dataFormat, cmpdSelectedTypes, curMapIndex, | ||
| curProviderIndex, depth + 1); | ||
| } | ||
| } | ||
| else if (curType.isCompound()) { | ||
| List<Datatype> cmpdSelectedTypes = filterNonSelectedMembers(dataFormat, curType); | ||
| List<Datatype> cmpdSelectedTypes = filterNonSelectedMembers(dataFormat, curType, false); | ||
|
|
||
| buildColIdxToProviderMap(outMap, dataFormat, cmpdSelectedTypes, curMapIndex, curProviderIndex, | ||
| depth + 1); | ||
| } | ||
| else if (curType.isVLEN() && !curType.isVarStr()) { | ||
| for (int j = 0; j < arrSize; j++) | ||
| outMap.put(curMapIndex[0]++, curProviderIndex[0]); | ||
| } | ||
| else | ||
| outMap.put(curMapIndex[0]++, curProviderIndex[0]); | ||
|
|
||
|
|
@@ -297,9 +341,12 @@ else if (base.isArray()) { | |
| } | ||
| log.trace("buildRelColIdxToStartIdxMap(): arrSize after base={}", arrSize); | ||
| } | ||
| // Single column per vlen member (see buildColIdxToProviderMap). No per-element | ||
| // expansion; top-level vlen-of-compound is already peeled at the dataset level. | ||
|
|
||
| if (nestedCompoundType != null) { | ||
| List<Datatype> cmpdSelectedTypes = filterNonSelectedMembers(dataFormat, nestedCompoundType); | ||
| List<Datatype> cmpdSelectedTypes = | ||
| filterNonSelectedMembers(dataFormat, nestedCompoundType, false); | ||
|
|
||
| /* | ||
| * For Array/Vlen of Compound types, we repeat the compound members n times, | ||
|
|
@@ -318,11 +365,21 @@ else if (curType.isCompound()) { | |
| if (depth == 0) | ||
| curStartIdx[0] = curMapIndex[0]; | ||
|
|
||
| List<Datatype> cmpdSelectedTypes = filterNonSelectedMembers(dataFormat, curType); | ||
| List<Datatype> cmpdSelectedTypes = filterNonSelectedMembers(dataFormat, curType, false); | ||
|
|
||
| buildRelColIdxToStartIdxMap(outMap, dataFormat, cmpdSelectedTypes, curMapIndex, curStartIdx, | ||
| depth + 1); | ||
| } | ||
| else if (curType.isVLEN() && !curType.isVarStr()) { | ||
| for (int j = 0; j < arrSize; j++) { | ||
| if (depth == 0) { | ||
| outMap.put(curMapIndex[0], curMapIndex[0]); | ||
| curMapIndex[0]++; | ||
| } | ||
| else | ||
| outMap.put(curMapIndex[0]++, curStartIdx[0]); | ||
| } | ||
| } | ||
| else { | ||
| if (depth == 0) { | ||
| outMap.put(curMapIndex[0], curMapIndex[0]); | ||
|
|
@@ -333,4 +390,42 @@ else if (curType.isCompound()) { | |
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Return true when the datatype tree contains a construct whose table-view | ||
| * write path is not symmetric with the (recently expanded) display path, | ||
| * so a single-cell edit cannot be reliably mapped back to storage. | ||
| */ | ||
| public static boolean isUnsafeForWrite(Datatype dtype) { return isUnsafe(dtype, false); } | ||
|
|
||
| private static boolean isUnsafe(Datatype dtype, boolean insideCompound) | ||
| { | ||
| if (dtype == null) | ||
| return false; | ||
|
|
||
| if (dtype.isVLEN() && !dtype.isVarStr()) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I'm reading this correctly it doesn't seem quite right, as HDFView has had limited support for writing variable-length types for a bit now. |
||
| return true; | ||
|
|
||
| if (dtype.isArray()) { | ||
| Datatype base = dtype.getDatatypeBase(); | ||
| if (base != null && (base.isCompound() || base.isArray() || (base.isVLEN() && !base.isVarStr()))) | ||
| return true; | ||
| return insideCompound; | ||
| } | ||
|
|
||
| if (dtype.isCompound()) { | ||
| if (insideCompound) | ||
| return true; | ||
| List<Datatype> members = dtype.getCompoundMemberTypes(); | ||
| if (members != null) { | ||
| for (Datatype m : members) { | ||
| if (isUnsafe(m, true)) | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For maintainability this really seems like something that should be handled by the individual DataProviderFactory classes instead of here, since that's where the editing logic will be at. And instead of displaying an information dialog each class should throw an UnsupportedOperationException instead. See https://archive.eclipse.org/nattable/releases/1.1.0/apidocs/org/eclipse/nebula/widgets/nattable/data/IDataProvider.html#setDataValue(int,%20int,%20java.lang.Object)