Skip to content

v2: ArrayView automatic view selection for primitive array types#4751

Open
abdelaziz-mahdy wants to merge 7 commits intodevelopmentfrom
improve-array-view-v2
Open

v2: ArrayView automatic view selection for primitive array types#4751
abdelaziz-mahdy wants to merge 7 commits intodevelopmentfrom
improve-array-view-v2

Conversation

@abdelaziz-mahdy
Copy link
Copy Markdown
Collaborator

Another approach for #4750

Problem

ArrayView always used AnyView as the default valueView, showing a type picker dropdown even for simple primitive arrays like Array with javaType: 'Long[]'. This required creating separate view classes (StringArrayView, IntegerArrayView, etc.) for each primitive type, which is not scalable.

Solution

Enhanced the ArrayViewRefinement to automatically detect primitive element types and configure the appropriate view:

  • Added expression-based view property that checks both of and javaType
  • Extracts element type from javaType (e.g., 'Long[]''Long')
  • Maps Java primitives to FOAM types (intInt, longLong, etc.)
  • Looks up the FOAM type's VIEW and passes it as valueView to ArrayView

Changes

  • Modified ArrayViewRefinement in Element2.js to use expression-based view with type detection

ArrayView now detects primitive 'of' types (Int, Long, String, etc.)
and uses their default views instead of AnyView. This eliminates the
need for separate StringArrayView, IntegerArrayView, LongArrayView
classes - one generic ArrayView handles all primitive array types by
looking up foam.lang.<type>.VIEW at runtime.
@abdelaziz-mahdy abdelaziz-mahdy changed the title ArrayView automatic view selection for primitive array types v2: ArrayView automatic view selection for primitive array types Jan 21, 2026
Comment thread src/foam/u2/Element2.js Outdated
Comment thread src/foam/u2/Element2.js
name: 'view',
factory: function() {
// Extract element type from javaType (e.g., 'Long[]' -> 'Long')
if ( this.javaType ) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem right. What if we don't load java support, which we shouldn't be doing for the web.

Copy link
Copy Markdown
Collaborator Author

@abdelaziz-mahdy abdelaziz-mahdy Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would #4750 make more sense then? its missing storing the of though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants