diff --git a/src/MooseIDE-Tagging-Tests/MiTagCreationFormTest.class.st b/src/MooseIDE-Tagging-Tests/MiTagCreationFormTest.class.st index 27333fc25..f20090ae0 100644 --- a/src/MooseIDE-Tagging-Tests/MiTagCreationFormTest.class.st +++ b/src/MooseIDE-Tagging-Tests/MiTagCreationFormTest.class.st @@ -11,7 +11,7 @@ Class { { #category : 'helpers' } MiTagCreationFormTest >> presenterClass [ - ^ MiTagCreationForm + ^ MiTagCreationForm ] { #category : 'helpers' } @@ -93,14 +93,25 @@ MiTagCreationFormTest >> testQueryDropListFetchQueriesFromQueriesProducer [ ] { #category : 'tests' } -MiTagCreationFormTest >> testSetIntentTag [ +MiTagCreationFormTest >> testSetExtentTag [ self deny: creationForm intentButton state. - self flag: 'fix weird behavior'. + creationForm extentButton click. + creationForm extentButton action value. "this should be triggered by clicking on the button but it does seem to work :-(" + + self deny: creationForm intentButton state. + self assert: creationForm extentButton state. + self deny: creationForm queryListLabeled isVisible +] + +{ #category : 'tests' } +MiTagCreationFormTest >> testSetIntentTag [ + + self deny: creationForm intentButton state. creationForm intentButton click. - creationForm intentButton action value. + creationForm intentButton action value. "this should be triggered by clicking on the button but it does seem to work :-(" self assert: creationForm intentButton state. self deny: creationForm extentButton state. diff --git a/src/MooseIDE-Tagging/MiTagAbstractForm.class.st b/src/MooseIDE-Tagging/MiTagAbstractForm.class.st new file mode 100644 index 000000000..b0c90d96e --- /dev/null +++ b/src/MooseIDE-Tagging/MiTagAbstractForm.class.st @@ -0,0 +1,312 @@ +" +the page that allows to enter information about the tag (like its name and category) +This is the right part of the tag browser +" +Class { + #name : 'MiTagAbstractForm', + #superclass : 'SpPresenter', + #instVars : [ + 'colorPicker', + 'cancelButton', + 'submitButton', + 'nameField', + 'descriptionField', + 'categorySelection', + 'isIntent', + 'queryList', + 'tagBrowser' + ], + #category : 'MooseIDE-Tagging-Browser', + #package : 'MooseIDE-Tagging', + #tag : 'Browser' +} + +{ #category : 'accessing' } +MiTagAbstractForm >> cancelButton [ + + ^ cancelButton +] + +{ #category : 'accessing' } +MiTagAbstractForm >> categorySelection [ + + ^ categorySelection +] + +{ #category : 'initialization' } +MiTagAbstractForm >> checkFormInputs [ + + nameField text ifEmpty: [ ^ false ]. + ^ true +] + +{ #category : 'initialization' } +MiTagAbstractForm >> close [ + + owner close +] + +{ #category : 'brokerage' } +MiTagAbstractForm >> consume: aQuery [ + + self updateQueryList +] + +{ #category : 'initialization' } +MiTagAbstractForm >> fetchQueries [ + + ^ (tagBrowser application itemsFor: FQAbstractQuery) asOrderedCollection +] + +{ #category : 'initialization' } +MiTagAbstractForm >> formLayout [ + + ^ SpBoxLayout newTopToBottom + spacing: 10; + add: (SpBoxLayout newLeftToRight + spacing: 5; + add: (SpBoxLayout newTopToBottom + add: 'Name' asPresenter expand: false; + add: nameField expand: false; + yourself); + add: (SpBoxLayout newTopToBottom + add: 'Category (optional)'; + add: categorySelection; + yourself) + width: 200; + yourself) + expand: false; + add: (SpBoxLayout newTopToBottom + add: 'Description (optional)' asPresenter expand: false; + add: descriptionField expand: true; + yourself) + expand: true ; + yourself +] + +{ #category : 'initialization' } +MiTagAbstractForm >> initialize [ + + super initialize. + isIntent := false. + +] + +{ #category : 'initialization' } +MiTagAbstractForm >> initializeDialogButtonsLayout [ + + ^SpBoxLayout newLeftToRight + hAlignEnd ; + add: cancelButton expand: false ; + add: submitButton expand: false ; + yourself +] + +{ #category : 'initialization' } +MiTagAbstractForm >> initializeFormLayout [ + + self subclassResponsibility +] + +{ #category : 'initialization' } +MiTagAbstractForm >> initializeLayout [ + + | sep colorPickerWidth colorPickerLayout | + self layout: (SpBoxLayout newTopToBottom spacing: 5). + + colorPickerWidth := 240. + + (sep := SpRoassalPresenter new) canvas color: (Color + r: 40 + g: 40 + b: 40 + range: 255) translucent. + + colorPickerLayout := SpBoxLayout newTopToBottom + add: (SpBoxLayout newLeftToRight + add: 'Tag Color' asPresenter; + hAlignCenter; + yourself) + width: colorPickerWidth; + add: colorPicker ; + yourself. + + self initializeFormLayout. + + self layout + add: (SpBoxLayout newLeftToRight + spacing: 10; + add: colorPickerLayout width: colorPickerWidth ; + add: sep width: 2; + add: (SpBoxLayout newTopToBottom + spacing: 5; + add: (self initializeFormLayout) expand: true fill: true; + add: self initializeDialogButtonsLayout expand: false ; + yourself); + yourself) + +] + +{ #category : 'initialization' } +MiTagAbstractForm >> initializePresenters [ + + submitButton := self newButton + label: 'Add' ; + action: [ self submit ]. + cancelButton := self newButton + label: 'Cancel' ; + action: [ self close ]. + + colorPicker := self newColorPicker + setColor: Color random. + + self initializeTagDescriptionPresenters. + + self initializeLayout +] + +{ #category : 'initialization' } +MiTagAbstractForm >> initializeTagDescriptionPresenters [ + + nameField := self newTextInput. + descriptionField := self newText. + categorySelection := self newDropList + sortingBlock: [ :item | + item model + ifNil: [ '' ] + ifNotNil: [ :category | category name ] ] + ascending; + display: [ :cat | cat ifNil: [ '' ] ifNotNil: [ cat name ] ]. + queryList := self newDropList + startWithoutSelection; + display: [ :query | self stringForQuery: query ]. + +] + +{ #category : 'testing' } +MiTagAbstractForm >> isIntentSubmit [ + + self subclassResponsibility +] + +{ #category : 'accessing' } +MiTagAbstractForm >> nameField [ + + ^ nameField +] + +{ #category : 'testing' } +MiTagAbstractForm >> notIntentSubmit [ + + self subclassResponsibility +] + +{ #category : 'accessing' } +MiTagAbstractForm >> queryList [ + + ^ queryList +] + +{ #category : 'brokerage' } +MiTagAbstractForm >> remove: aQuery [ + + self updateQueryList +] + +{ #category : 'initialization' } +MiTagAbstractForm >> reset [ + + colorPicker setColor: Color random. + nameField text: ''. + descriptionField text: ''. + categorySelection resetSelection. + queryList resetSelection. + self updateQueryList +] + +{ #category : 'private' } +MiTagAbstractForm >> setExtentForm [ + + isIntent := false. + self update +] + +{ #category : 'private' } +MiTagAbstractForm >> setIntentForm [ + + isIntent := true. + + self update +] + +{ #category : 'accessing' } +MiTagAbstractForm >> specModel [ + + ^tagBrowser specModel +] + +{ #category : 'initialization' } +MiTagAbstractForm >> stringForQuery: aQuery [ + + | queryText contractor | + queryText := aQuery ifNil: [ '' ] ifNotNil: [ + String streamContents: [ :aStream | + aQuery storeWithParentsOn: aStream ] ]. + contractor := LbCContractor new addStrategy: + (LbCEllipsisStrategy new + separator: '...'; + upTo: 50; + yourself). + ^ contractor reduce: queryText +] + +{ #category : 'initialization' } +MiTagAbstractForm >> submit [ + + | tag | + self checkFormInputs ifFalse: [ ^ self ]. + + tag := isIntent + ifTrue: [ self isIntentSubmit ] + ifFalse: [ self notIntentSubmit ]. + + tag ifNil: [ + self alert: + 'This tag name is already in use. Please choose a different one.' ]. + + tagBrowser refreshTagList. + self close +] + +{ #category : 'accessing' } +MiTagAbstractForm >> submitButton [ + + ^ submitButton +] + +{ #category : 'accessing' } +MiTagAbstractForm >> tagBrowser: aTagBrowser [ + + tagBrowser := aTagBrowser. + self updateQueryList. + self updateCategories +] + +{ #category : 'private' } +MiTagAbstractForm >> updateCategories [ + "allow to have no category, hence the first nil element" + + categorySelection items: { nil }, (self specModel allCategories) +] + +{ #category : 'accessing' } +MiTagAbstractForm >> updateQueryList [ + + queryList items: self fetchQueries +] + +{ #category : 'accessing - deprecated' } +MiTagAbstractForm >> windowTitle [ + + ^'Create tag' +] diff --git a/src/MooseIDE-Tagging/MiTagCreationForm.class.st b/src/MooseIDE-Tagging/MiTagCreationForm.class.st index 01e593f5f..a448cd009 100644 --- a/src/MooseIDE-Tagging/MiTagCreationForm.class.st +++ b/src/MooseIDE-Tagging/MiTagCreationForm.class.st @@ -1,214 +1,60 @@ -" -the page that allows to enter information about the tag (like its name and category) -This is the right part of the tag browser -" Class { #name : 'MiTagCreationForm', - #superclass : 'SpPresenter', + #superclass : 'MiTagAbstractForm', #instVars : [ - 'colorPicker', - 'cancelButton', - 'submitButton', - 'nameField', - 'descriptionField', - 'categorySelection', 'intentButton', 'extentButton', - 'isIntent', - 'queryList', - 'queryListLabeled', - 'tagBrowser' + 'queryListLabeled' ], #category : 'MooseIDE-Tagging-Browser', #package : 'MooseIDE-Tagging', #tag : 'Browser' } -{ #category : 'accessing' } -MiTagCreationForm >> cancelButton [ - - ^ cancelButton -] - -{ #category : 'accessing' } -MiTagCreationForm >> categorySelection [ - - ^ categorySelection -] - -{ #category : 'initialization' } -MiTagCreationForm >> checkFormInputs [ - - nameField text ifEmpty: [ ^ false ]. - ^ true -] - -{ #category : 'initialization' } -MiTagCreationForm >> close [ - - owner close -] - { #category : 'private' } MiTagCreationForm >> connectPresenters [ - + extentButton action: [ self setExtentForm ]. intentButton action: [ self setIntentForm ]. ] -{ #category : 'brokerage' } -MiTagCreationForm >> consume: aQuery [ - - self updateQueryList -] - { #category : 'accessing' } MiTagCreationForm >> extentButton [ ^ extentButton ] -{ #category : 'initialization' } -MiTagCreationForm >> fetchQueries [ - - ^ (tagBrowser application itemsFor: FQAbstractQuery) asOrderedCollection -] - -{ #category : 'initialization' } -MiTagCreationForm >> initialize [ - - super initialize. - isIntent := false. - -] - -{ #category : 'initialization' } -MiTagCreationForm >> initializeDialogButtonsLayout [ - - ^SpBoxLayout newLeftToRight - hAlignEnd ; - add: cancelButton expand: false ; - add: submitButton expand: false ; - yourself -] - { #category : 'initialization' } MiTagCreationForm >> initializeFormLayout [ - ^SpBoxLayout newTopToBottom - spacing: 5; - - add: (SpBoxLayout newLeftToRight - add: extentButton; - add: intentButton; - yourself) - expand: false; - - add: (SpBoxLayout newLeftToRight - spacing: 5; - - add: (SpBoxLayout newTopToBottom - add: 'Name' asPresenter expand: false; - add: nameField expand: false; - yourself); - - add: (SpBoxLayout newTopToBottom - add: 'Category (optional)'; - add: categorySelection; - yourself) - width: 200; - - yourself) - expand: false; - - add: (SpBoxLayout newTopToBottom - add: 'Description (optional)' asPresenter - expand: false; - add: descriptionField; - yourself) - expand: true; - add: queryListLabeled expand: false; - yourself. -] - -{ #category : 'initialization' } -MiTagCreationForm >> initializeLayout [ - - | sep colorPickerWidth colorPickerLayout | - self layout: (SpBoxLayout newTopToBottom spacing: 5). - - colorPickerWidth := 240. - - (sep := SpRoassalPresenter new) canvas color: (Color - r: 40 - g: 40 - b: 40 - range: 255) translucent. - - colorPickerLayout := SpBoxLayout newTopToBottom - add: (SpBoxLayout newLeftToRight - add: 'Tag Color' asPresenter; - hAlignCenter; - yourself) - width: colorPickerWidth; - add: colorPicker ; - yourself. - - self initializeFormLayout. - - self layout - add: (SpBoxLayout newLeftToRight - spacing: 10; - add: colorPickerLayout width: colorPickerWidth ; - add: sep width: 2; - add: (SpBoxLayout newTopToBottom - spacing: 5; - add: (self initializeFormLayout) expand: true fill: true; - add: self initializeDialogButtonsLayout expand: false ; - yourself); - yourself) - + ^ SpBoxLayout newTopToBottom + spacing: 5; + add: (SpBoxLayout newLeftToRight + add: extentButton; + add: intentButton; + yourself) + expand: false; + add: self formLayout expand: true; + add: queryListLabeled expand: false; + yourself ] { #category : 'initialization' } MiTagCreationForm >> initializePresenters [ - - submitButton := self newButton - label: 'Add' ; - action: [ self submit ]. - cancelButton := self newButton - label: 'Cancel' ; - action: [ self close ]. - - colorPicker := self newColorPicker - setColor: Color random. + extentButton := self newToggleButton state: true; label: 'Static'. intentButton := self newToggleButton state: false; label: 'Dynamic'. - - self initializeTagDescriptionPresenters. - - self initializeLayout + super initializePresenters ] { #category : 'initialization' } MiTagCreationForm >> initializeTagDescriptionPresenters [ - nameField := self newTextInput. - descriptionField := self newText. - categorySelection := self newDropList - sortingBlock: [ :item | - item model - ifNil: [ '' ] - ifNotNil: [ :category | category name ] ] - ascending; - display: [ :cat | cat ifNil: [ '' ] ifNotNil: [ cat name ] ]. - queryList := self newDropList - startWithoutSelection; - display: [ :query | self stringForQuery: query ]. + super initializeTagDescriptionPresenters. queryListLabeled := MiPresenter new layout: (SpBoxLayout newTopToBottom add: 'Query' asPresenter expand: false; @@ -224,16 +70,25 @@ MiTagCreationForm >> intentButton [ ^ intentButton ] -{ #category : 'accessing' } -MiTagCreationForm >> nameField [ +{ #category : 'testing' } +MiTagCreationForm >> isIntentSubmit [ - ^ nameField + self specModel + createDynamicTag: nameField text + description: descriptionField text + color: colorPicker color + category: categorySelection selectedItem + query: queryList selectedItem ] -{ #category : 'accessing' } -MiTagCreationForm >> queryList [ +{ #category : 'testing' } +MiTagCreationForm >> notIntentSubmit [ - ^ queryList + self specModel + createTag: nameField text + description: descriptionField text + color: colorPicker color + category: categorySelection selectedItem ] { #category : 'accessing' } @@ -242,33 +97,16 @@ MiTagCreationForm >> queryListLabeled [ ^ queryListLabeled ] -{ #category : 'brokerage' } -MiTagCreationForm >> remove: aQuery [ - - self updateQueryList -] - -{ #category : 'initialization' } -MiTagCreationForm >> reset [ - - colorPicker setColor: Color random. - nameField text: ''. - descriptionField text: ''. - categorySelection resetSelection. - queryList resetSelection. - self updateQueryList -] - { #category : 'private' } MiTagCreationForm >> setExtentForm [ isIntent ifFalse: [ extentButton state: true. ^ self ]. - isIntent := false. + intentButton state: false. queryListLabeled hide. - self update + super setExtentForm ] { #category : 'private' } @@ -277,90 +115,8 @@ MiTagCreationForm >> setIntentForm [ isIntent ifTrue: [ intentButton state: true. ^ self ]. - isIntent := true. + extentButton state: false. queryListLabeled show. - self update -] - -{ #category : 'accessing' } -MiTagCreationForm >> specModel [ - - ^tagBrowser specModel -] - -{ #category : 'initialization' } -MiTagCreationForm >> stringForQuery: aQuery [ - - | queryText contractor | - queryText := aQuery ifNil: [ '' ] ifNotNil: [ - String streamContents: [ :aStream | - aQuery storeWithParentsOn: aStream ] ]. - contractor := LbCContractor new addStrategy: - (LbCEllipsisStrategy new - separator: '...'; - upTo: 50; - yourself). - ^ contractor reduce: queryText -] - -{ #category : 'initialization' } -MiTagCreationForm >> submit [ - - | tag | - self checkFormInputs ifFalse: [ ^ self ]. - - tag := isIntent - ifTrue: [ - self specModel - createDynamicTag: nameField text - description: descriptionField text - color: colorPicker color - category: categorySelection selectedItem - query: queryList selectedItem ] - ifFalse: [ - self specModel - createTag: nameField text - description: descriptionField text - color: colorPicker color - category: categorySelection selectedItem ]. - - tag - ifNil: [ self alert: 'This tag name is already in use. Please choose a different one.' ]. - - tagBrowser refreshTagList. - self close -] - -{ #category : 'accessing' } -MiTagCreationForm >> submitButton [ - - ^ submitButton -] - -{ #category : 'accessing' } -MiTagCreationForm >> tagBrowser: aTagBrowser [ - - tagBrowser := aTagBrowser. - self updateQueryList. - self updateCategories -] - -{ #category : 'private' } -MiTagCreationForm >> updateCategories [ - "allow to have no category, hence the first nil element" - - categorySelection items: { nil }, (self specModel allCategories) -] - -{ #category : 'accessing' } -MiTagCreationForm >> updateQueryList [ - - queryList items: self fetchQueries -] - -{ #category : 'accessing - deprecated' } -MiTagCreationForm >> windowTitle [ - - ^'Create tag' + super setIntentForm ] diff --git a/src/MooseIDE-Tagging/MiTagEditionForm.class.st b/src/MooseIDE-Tagging/MiTagEditionForm.class.st index 417dab4df..88d88df83 100644 --- a/src/MooseIDE-Tagging/MiTagEditionForm.class.st +++ b/src/MooseIDE-Tagging/MiTagEditionForm.class.st @@ -1,6 +1,6 @@ Class { #name : 'MiTagEditionForm', - #superclass : 'MiTagCreationForm', + #superclass : 'MiTagAbstractForm', #category : 'MooseIDE-Tagging-Browser', #package : 'MooseIDE-Tagging', #tag : 'Browser' @@ -9,7 +9,7 @@ Class { { #category : 'initialization' } MiTagEditionForm >> checkFormInputs [ - nameField text ifEmpty: [ ^ false ]. + self specModel currentTag isIntent ifFalse: [ (self specModel getTagNamed: nameField text) ifNotNil: [ :tag | self specModel currentTag = tag ifFalse: [ @@ -27,18 +27,9 @@ MiTagEditionForm >> checkFormInputs [ yourself); popup. ^ false ] ] ]. + - - ^ true -] - -{ #category : 'initialization' } -MiTagEditionForm >> connectPresenters [ - - "cancelButton action: [ - self reset. - self owner closeTagEditionForm ]. - submitButton action: [ self submit ]" + ^ super checkFormInputs ] { #category : 'accessing' } @@ -58,41 +49,15 @@ MiTagEditionForm >> fillWithCurrentTag [ ] { #category : 'initialization' } -MiTagEditionForm >> formLayout [ - - ^ SpBoxLayout newTopToBottom - spacing: 10; - add: (SpBoxLayout newLeftToRight - spacing: 5; - add: (SpBoxLayout newTopToBottom - add: 'Name' asPresenter expand: false; - add: nameField expand: false; - yourself); - add: (SpBoxLayout newTopToBottom - add: 'Category (optional)'; - add: categorySelection; - yourself) - width: 200; - yourself) - expand: false; - add: (SpBoxLayout newTopToBottom - add: 'Description (optional)' asPresenter expand: false; - add: descriptionField height: 150; - yourself) - expand: false; - add: (SpBoxLayout newLeftToRight - vAlignEnd; - spacing: 10; - add: cancelButton; - add: submitButton; - yourself); - yourself +MiTagEditionForm >> formTitle [ + + ^ 'Edit tag' ] { #category : 'initialization' } -MiTagEditionForm >> formTitle [ +MiTagEditionForm >> initializeFormLayout [ - ^ 'Edit tag' + ^ self formLayout ] { #category : 'initialization' } @@ -105,6 +70,27 @@ MiTagEditionForm >> initializePresenters [ intentButton hide. ] +{ #category : 'initialization' } +MiTagEditionForm >> isIntentSubmit [ + + self specModel + editCurrentDynamicTag: nameField text + description: descriptionField text + color: colorPicker color + category: categorySelection selectedItem + query: queryList selectedItem +] + +{ #category : 'initialization' } +MiTagEditionForm >> notIntentSubmit [ + + self specModel + editCurrentTag: nameField text + description: descriptionField text + color: colorPicker color + category: categorySelection selectedItem +] + { #category : 'accessing' } MiTagEditionForm >> setDynamicTag: aTag [ @@ -137,19 +123,8 @@ MiTagEditionForm >> submit [ self checkFormInputs ifFalse: [ ^ self ]. self specModel currentTag isIntent - ifTrue: [ - self specModel - editCurrentDynamicTag: nameField text - description: descriptionField text - color: colorPicker color - category: categorySelection selectedItem - query: queryList selectedItem ] - ifFalse: [ - self specModel - editCurrentTag: nameField text - description: descriptionField text - color: colorPicker color - category: categorySelection selectedItem ]. + ifTrue: [ self isIntentSubmit ] + ifFalse: [ self notIntentSubmit ]. tagBrowser refreshTagList. self close