Skip to content

Commit

Permalink
Merge pull request magritte-metamodel#343 from seandenigris/issue_3478
Browse files Browse the repository at this point in the history
[Bug]: GT Issue 3478 - ElementBuilder does not honor beHidden
  • Loading branch information
seandenigris authored Dec 29, 2023
2 parents 5518255 + 145fc29 commit 5bd2981
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 117 deletions.
26 changes: 15 additions & 11 deletions source/Magritte-GToolkit/MACompositeElementBuilder.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ See {{gtClass:MACompositeAccessor}} for more info.
Class {
#name : #MACompositeElementBuilder,
#superclass : #MAElementBuilder,
#category : 'Magritte-GToolkit'
#category : #'Magritte-GToolkit'
}

{ #category : #accessing }
Expand All @@ -23,15 +23,19 @@ MACompositeElementBuilder class >> example [

{ #category : #accessing }
MACompositeElementBuilder >> visitSingleOptionDescription: aDescription [
| inputElement items |

self flag: 'lots of duplication with super implementation'.
items := aDescription allOptions copyWith: MACompositeConflict new; yourself.
inputElement := MADropdownElement new
items: items;
itemDescription: aDescription reference;
selection: (aDescription read: self memento);
when: MADropdownWish do: [ :aWish |
aWish selection = MACompositeConflict new ifFalse: [ aDescription write: aWish selection to: self memento ] ];
yourself.
self addInputField: inputElement using: aDescription

self
using: aDescription
addInputField: [
| items |
items := aDescription allOptions copyWith: MACompositeConflict new; yourself.
MADropdownElement new
items: items;
itemDescription: aDescription reference;
selection: (aDescription read: self memento);
when: MADropdownWish do: [ :aWish |
aWish selection = MACompositeConflict new ifFalse: [ aDescription write: aWish selection to: self memento ] ];
yourself ]
]
235 changes: 129 additions & 106 deletions source/Magritte-GToolkit/MAElementBuilder.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,12 @@ MAElementBuilder >> addButtons: aCollection [
self buttonSelectors: aCollection
]

{ #category : #accessing }
MAElementBuilder >> addInputField: inputElement using: aDescription [
| labelElement diffElement |
labelElement := BrLabel new
text: aDescription label , ':';
addEventHandlerOn: BlClickEvent
do: [ :evt | evt target phlow spawnObject: (aDescription read: self object) ];
aptitude: BrGlamorousLabelAptitude.
labelElement constraintsDo: [ :c |
c vertical fitContent.
c horizontal fitContent.
c grid vertical alignCenter ].
aDescription isRequired ifTrue: [ self flag: 'unsupported' ].
aDescription hasComment ifTrue: [
self addTooltip: aDescription comment to: labelElement.
self addTooltip: aDescription comment to: inputElement ].
"diffElement := BrEditor new
text: inputElement text copy; ""if we don't copy, diff magically changes as input updates"
"aptitude: BrGlamorousEditorAptitude".
self form addChild: labelElement.
self form addChild: inputElement.
"self form addChild: diffElement."
]

{ #category : #accessing }
{ #category : #private }
MAElementBuilder >> addInputFieldUsing: aDescription [

| inputElement |
inputElement := self newInputElementUsing: aDescription.
self addInputField: inputElement using: aDescription
self
using: aDescription
addInputField: [ self newInputElementUsing: aDescription ]
]

{ #category : #accessing }
Expand Down Expand Up @@ -106,6 +82,37 @@ MAElementBuilder >> buttonSelectors: aCollection [
buttonSelectors := aCollection
]

{ #category : #private }
MAElementBuilder >> calendarButtonFor: editor [
"Adapted from GtSpotterDropdownButtonStencil>>#create"

| dropdownAptitude |
dropdownAptitude := BrGlamorousWithDropdownAptitude
handle: [
BrButton new
icon: BrGlamorousVectorIcons note;
aptitude: BrGlamorousButtonWithIconAptitude - BrGlamorousButtonWithLabelTooltipAptitude
- BrGlamorousButtonExteriorAptitude ]
content: [ | calendar date |
date := [ editor text asString asDate ] on: Error do: [ Date today ].
calendar := GtCalendarElement forDate: date.
calendar
when: GtCalendarDateClickedEvent
do: [ "calendar date: event date. Redundant because a new calendar will be created on next button click":event |
editor
beEditable;
text: event date mmddyyyy;
acceptEdition.
calendar fireEvent: BrDropdownHideWish new ] ].

^ BrButton new
icon: BrGlamorousVectorIcons note;
label: 'Pick from calendar';
aptitude: BrGlamorousButtonWithIconAptitude;
addAptitude: dropdownAptitude;
yourself
]

{ #category : #accessing }
MAElementBuilder >> completionControllerClass [

Expand Down Expand Up @@ -269,6 +276,38 @@ MAElementBuilder >> toolbar [
^ toolbar
]

{ #category : #private }
MAElementBuilder >> using: aDescription addInputField: aValuable [

| labelElement "diffElement" inputElement |
aDescription isVisible ifFalse: [ ^ self ].

inputElement := aValuable value.
labelElement := BrLabel new
text: aDescription label , ':';
addEventHandlerOn: BlClickEvent
do: [ :evt | evt target phlow spawnObject: (aDescription read: self object) ];
aptitude: BrGlamorousLabelAptitude.
labelElement constraintsDo: [ :c |
c vertical fitContent.
c horizontal fitContent.
c grid vertical alignCenter ].

aDescription isRequired ifTrue: [ self flag: 'unsupported' ].

aDescription hasComment ifTrue: [
self addTooltip: aDescription comment to: labelElement.
self addTooltip: aDescription comment to: inputElement ].

"diffElement := BrEditor new
text: inputElement text copy; ""if we don't copy, diff magically changes as input updates"
"aptitude: BrGlamorousEditorAptitude".

self form addChild: labelElement.
self form addChild: inputElement.
"self form addChild: diffElement."
]

{ #category : #accessing }
MAElementBuilder >> visit: anObject [
self flag: 'if we keep the decorator stuff here, remove this method'.
Expand All @@ -283,13 +322,15 @@ MAElementBuilder >> visitBlockDescription: anObject [

{ #category : #'visiting-description' }
MAElementBuilder >> visitBooleanDescription: aDescription [
| inputElement |
inputElement := BrCheckbox new
aptitude: BrGlamorousCheckboxAptitude;
checked: (aDescription read: self memento);
whenCheckedDo: [ aDescription write: true to: self memento ];
whenUncheckedDo: [ aDescription write: false to: self memento ].
self addInputField: inputElement using: aDescription

self
using: aDescription
addInputField: [
BrCheckbox new
aptitude: BrGlamorousCheckboxAptitude;
checked: (aDescription read: self memento);
whenCheckedDo: [ aDescription write: true to: self memento ];
whenUncheckedDo: [ aDescription write: false to: self memento ] ]
]

{ #category : #'visiting-description' }
Expand All @@ -314,45 +355,19 @@ MAElementBuilder >> visitDateAndTimeDescription: anObject [

{ #category : #'visiting-description' }
MAElementBuilder >> visitDateDescription: aDescription [
| inputElement editor calendarButton |
editor := self newInputElementUsing: aDescription.

"Adapted from GtSpotterDropdownButtonStencil>>#create"
calendarButton := BrButton new
icon: BrGlamorousVectorIcons note;
label: 'Pick from calendar';
aptitude: BrGlamorousButtonWithIconAptitude;
addAptitude: (BrGlamorousWithDropdownAptitude
handle: [ BrButton new
icon: BrGlamorousVectorIcons note;
aptitude:
BrGlamorousButtonWithIconAptitude
- BrGlamorousButtonWithLabelTooltipAptitude
- BrGlamorousButtonExteriorAptitude ]
content: [
| calendar date |
date := [ editor text asString asDate ]
on: Error
do: [ Date today ].
calendar := GtCalendarElement forDate: date.
calendar
when: GtCalendarDateClickedEvent
do: [ :event |
"calendar date: event date. Redundant because a new calendar will be created on next button click"
editor
beEditable;
text: event date mmddyyyy;
acceptEdition.
calendar fireEvent: BrDropdownHideWish new ] ]);
yourself.
inputElement := BrHorizontalPane new
fitContent;
cellSpacing: 5;
addChild: editor;
addChild: calendarButton;
yourself.

self addInputField: inputElement using: aDescription

self
using: aDescription
addInputField: [
| editor calendarButton |
editor := self newInputElementUsing: aDescription.
calendarButton := self calendarButtonFor: editor. "calendar date: event date. Redundant because a new calendar will be created on next button click"
BrHorizontalPane new
fitContent;
cellSpacing: 5;
addChild: editor;
addChild: calendarButton;
yourself ]
]

{ #category : #'visiting-description' }
Expand Down Expand Up @@ -387,27 +402,31 @@ MAElementBuilder >> visitMagnitudeDescription: anObject [

{ #category : #'visiting-description' }
MAElementBuilder >> visitMemoDescription: aDescription [
| inputElement lineHeight resizableElement |
| lineHeight |
self flag: 'Lots of duplication from standard inputElement creation; line height very rough based on 14 pt size - waiting on answer on Discord'.
lineHeight := 14 * 1.5.
inputElement := BrEditor new
beEditable;
text: (self textUsing: aDescription);
aptitude: BrGlamorousEditorAptitude new glamorousRegularFontAndSize;
vMatchParent;
hMatchParent.
inputElement editor when: BrTextEditorModifiedEvent
do: [ :event | aDescription writeFromString: event text greaseString to: self memento ].

resizableElement := BlElement new
aptitude: BrGlamorousWithVerticalResizerAptitude;
constraintsDo: [ :c |
c horizontal matchParent.
c vertical exact: lineHeight * aDescription lineCount ];
addChild: inputElement;
yourself.

self addInputField: resizableElement using: aDescription
self
using: aDescription
addInputField: [
| inputElement |
inputElement := BrEditor new
beEditable;
text: (self textUsing: aDescription);
aptitude: BrGlamorousEditorAptitude new glamorousRegularFontAndSize;
vMatchParent;
hMatchParent.

inputElement editor when: BrTextEditorModifiedEvent
do: [ :event | aDescription writeFromString: event text greaseString to: self memento ].

BlElement new
aptitude: BrGlamorousWithVerticalResizerAptitude;
constraintsDo: [ :c |
c horizontal matchParent.
c vertical exact: lineHeight * aDescription lineCount ];
addChild: inputElement;
yourself ]
]

{ #category : #'visiting-description' }
Expand Down Expand Up @@ -447,26 +466,30 @@ MAElementBuilder >> visitRelationDescription: anObject [

{ #category : #private }
MAElementBuilder >> visitRelationDescription: aDescription withTokenElementClass: aClass [
| inputElement |


aDescription gtSearchSource ifNil: [ ^ self visitRelationDescription: aDescription ].

inputElement := aClass forObject: self memento withRelationDescription: aDescription.

self addInputField: inputElement using: aDescription
self
using: aDescription
addInputField: [
aClass
forObject: self memento
withRelationDescription: aDescription ]
]

{ #category : #'visiting-description' }
MAElementBuilder >> visitSingleOptionDescription: aDescription [
| inputElement |
inputElement := MADropdownElement new
items: aDescription allOptions;
itemDescription: aDescription reference;
selection: (self memento readUsing: aDescription);
when: MADropdownWish do: [ :aWish |
aDescription write: aWish selection to: self memento ];
yourself.
self addInputField: inputElement using: aDescription

self
using: aDescription
addInputField: [
MADropdownElement new
items: aDescription allOptions;
itemDescription: aDescription reference;
selection: (self memento readUsing: aDescription);
when: MADropdownWish do: [ :aWish |
aDescription write: aWish selection to: self memento ];
yourself ]
]

{ #category : #'visiting-description' }
Expand Down

0 comments on commit 5bd2981

Please sign in to comment.