Skip to content

Commit

Permalink
Merge 496ea4a
Browse files Browse the repository at this point in the history
  • Loading branch information
JanBliznicenko committed Nov 23, 2024
2 parents 317e542 + 496ea4a commit 6460c73
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 27 deletions.
26 changes: 23 additions & 3 deletions repository/OpenPonk-ClassEditor/OPTUmlBaseController.trait.st
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,35 @@ OPTUmlBaseController >> descriptionVisibility [
OPTUmlBaseController >> validateProperty: aProperty [

aProperty ifNil: [ ^ self ].
aProperty owningClass
(aProperty association isNotNil and: [
(aProperty type respondsTo: #oclIsKindOf:) not or: [
(aProperty type oclIsKindOf: #Classifier) not ] ]) ifTrue: [
self validationFailedAssociationPropertyWithoutClassifierType:
aProperty ].
aProperty owningAssociation
ifNil: [
aProperty owningAssociation ifNil: [
aProperty owningClass ifNil: [
self validationFailedPropertyWithoutOwner: aProperty ] ]
ifNotNil: [
aProperty owningAssociation ifNotNil: [
aProperty owningClass ifNotNil: [
self validationFailedPropertyWithTwoOwners: aProperty ] ]
]

{ #category : 'validation' }
OPTUmlBaseController >> validationFailedAssociationPropertyWithoutClassifierType: aProperty [

OPModelInvalid signal: (String streamContents: [ :s |
s << 'Property "' << aProperty name asString << '" has type '
<< aProperty type asString << ' although it is part of '
<< aProperty association asString ]).

"Try to use opposite owningClass as type"
aProperty opposite owningClass ifNotNil: [ :oppositeOwner |
aProperty type: oppositeOwner ]

"No way to fix this - the association end information is lost"
]

{ #category : 'validation' }
OPTUmlBaseController >> validationFailedPropertyWithTwoOwners: aProperty [

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,16 @@ OPUmlAssociationController >> writeMultiplicityFrom: aString to: aProperty [

{ #category : 'writing' }
OPUmlAssociationController >> writeNavigability: isNavigable to: aProperty [

isNavigable
ifTrue: [ aProperty owningClass: aProperty opposite type.
aProperty owningAssociation: nil ]
ifFalse: [ aProperty owningClass: nil.
aProperty owningAssociation: aProperty association ]
ifTrue: [
aProperty owningClass: aProperty opposite type.
aProperty owningAssociation: nil.
self diagramController showInDiagramModel: aProperty ]
ifFalse: [
aProperty owningClass: nil.
aProperty owningAssociation: aProperty association.
self diagramController
controllerForModel: aProperty
ifFound: [ :found | found removeControllerAndDiagramElement ] ]
]
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,37 @@ OPUmlAssociationControllerTest >> modelClass [
^ OPUMLAssociation
]

{ #category : 'tests - diagram' }
OPUmlAssociationControllerTest >> testNavigableRemovalOfAssociationRemovesMemberEnds [

| first second attributeController attributeDiagramElement |
self showInDiagram.
first := model memberEnds first.
second := model memberEnds second.
self deny: (diagramController isVisibleInDiagram: second).
controller writeNavigability: true to: second.
diagramController showInDiagramModel: second.
self assert: (diagramController isVisibleInDiagram: second).
attributeController := diagramController controllerForModel: second.
self
assert: attributeController class
equals: OPUmlAttributeController.
attributeDiagramElement := attributeController diagramElement.
self
assert: attributeDiagramElement class
equals: OPUmlAttributeLabel.
self assert: attributeDiagramElement isRendered.
self
assertCollection: diagramController diagram allOwnedElements
includesAny: { attributeDiagramElement }.
controller removeControllerAndModel.
self deny: (diagramController isVisibleInDiagram: controller).
self deny: (diagramController isVisibleInDiagram: second).
self
denyCollection: diagramController diagram allOwnedElements
includesAny: { attributeDiagramElement }
]

{ #category : 'tests - diagram' }
OPUmlAssociationControllerTest >> testRemovalOfAssociationRemovesMemberEnds [

Expand All @@ -32,13 +63,17 @@ OPUmlAssociationControllerTest >> testRemovalOfAssociationRemovesMemberEnds [
removeControllerAndModel.
(diagramController controllerForModel: targetModel)
removeControllerAndModel.
self assert: diagramController controllers asArray equals: #( )
self
assertCollection: diagramController controllers
hasSameElements: #( )
]

{ #category : 'tests' }
OPUmlAssociationControllerTest >> testWriteNavigabilityAssocOwnedToClassOwned [

| first second |
self prepareToShow.
controller diagramController: diagramController.
first := model memberEnds first.
second := model memberEnds second.
controller writeNavigability: true to: second.
Expand All @@ -50,6 +85,7 @@ OPUmlAssociationControllerTest >> testWriteNavigabilityAssocOwnedToClassOwned [
OPUmlAssociationControllerTest >> testWriteNavigabilityClassOwnedToAssocOwned [
| first |
self prepareToShow.
controller diagramController: diagramController.
first := model memberEnds first.
controller writeNavigability: false to: first.
self deny: first isNavigable.
Expand Down
32 changes: 21 additions & 11 deletions repository/OpenPonk-ClassEditor/OPUmlAttributeController.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,27 @@ OPUmlAttributeController >> descriptionMultiplicity [
OPUmlAttributeController >> descriptionType [

<magritteDescription>
^ MAStringDescription new
accessor: (MAPluggableAccessor
read: [ :me | me model type ifNil: [ '' ] ifNotNil: #name ]
write: [ :me :newValue |
newValue
ifEmpty: [ me model type: nil ]
ifNotEmpty: [ me model type: (self typeNamed: newValue) ].
self modelChanged ]);
label: 'Type';
priority: 5;
yourself
| description writeBlock |
description := MAStringDescription new.
writeBlock := self model association
ifNotNil: [
description beReadOnly.
[ :me :newValue | ] ]
ifNil: [
[ :me :newValue |
newValue
ifEmpty: [ me model type: nil ]
ifNotEmpty: [
me model type: (self typeNamed: newValue) ].
self modelChanged ] ].
description
accessor: (MAPluggableAccessor
read: [ :me |
me model type ifNil: [ '' ] ifNotNil: [ :type | type name ] ]
write: writeBlock);
label: 'Type';
priority: 5.
^ description
]

{ #category : 'figures' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,19 @@ OPUmlPropertyMagritteDescriptions >> descriptionName [

{ #category : 'descriptions' }
OPUmlPropertyMagritteDescriptions >> descriptionType [

<magritteDescription>
^ MAStringDescription new
beReadOnly;
accessor:
(MAPluggableAccessor
read: [ :me | (reader value: me) type name ]
write: [ :me :newValue | ]);
label: labelPrefix;
priority: 1;
yourself
beReadOnly;
accessor: (MAPluggableAccessor
read: [ :me |
(reader value: me) type
ifNil: [ '' ]
ifNotNil: [ :type | type name ] ]
write: [ :me :newValue | ]);
label: labelPrefix;
priority: 1;
yourself
]

{ #category : 'descriptions' }
Expand Down

0 comments on commit 6460c73

Please sign in to comment.