From 381e5da76b42651c6676f08cdbcb7b1f2e7693bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Blizni=C4=8Denko?= Date: Thu, 17 Oct 2024 17:48:13 +0200 Subject: [PATCH] Improved sorting, validation and display of class attributes --- .../OPUmlAttributeController.class.st | 35 ++++++++++++++++++- .../OPUmlClassItemListCompartment.class.st | 10 +++--- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/repository/OpenPonk-ClassEditor/OPUmlAttributeController.class.st b/repository/OpenPonk-ClassEditor/OPUmlAttributeController.class.st index 05e6f287..bc5e474d 100644 --- a/repository/OpenPonk-ClassEditor/OPUmlAttributeController.class.st +++ b/repository/OpenPonk-ClassEditor/OPUmlAttributeController.class.st @@ -39,6 +39,7 @@ OPUmlAttributeController >> dependingOnElements [ nullableElement ifNil: [ Set empty ] ifNotNil: [ :element | Set with: element ] ]. + ^ super dependingOnElements , (asSetOrEmpty value: model owningAssociation) ] @@ -169,7 +170,18 @@ OPUmlAttributeController >> modelClass [ { #category : 'hooks' } OPUmlAttributeController >> placeholderName [ - ^ 'attribute' + (self model isNil or: [ + self model type isNil or: [ + self model type name isNil or: [ self model type name isEmpty ] ] ]) + ifTrue: [ ^ 'attribute' ]. + ^ String streamContents: [ :s | + | words | + words := (self model type name select: [ :each | + each isAlphaNumeric or: [ each isSeparator ] ]) + splitOn: [ :each | each isSeparator ]. + s << words first first asLowercase asString. + s << words first allButFirst asString. + words allButFirstDo: [ :eachWord | s << eachWord capitalized ] ] ] { #category : 'construction' } @@ -204,6 +216,27 @@ OPUmlAttributeController >> typeNamed: aName [ ^ OPUMLClass new name: aName ] +{ #category : 'validation' } +OPUmlAttributeController >> validate [ + + super validate. + model ifNil: [ ^ self ]. + (model owningClass isNotNil and: [ model owningAssociation isNotNil ]) + ifTrue: [ + OPModelInvalid signal: (String streamContents: [ :s | + s << 'Property "' << model name asString << '" owned by class "' + << model owningClass name asString + << '" is also owned by assoc. '. + model owningAssociation name + ifNil: [ + model owningAssociation memberEnds + do: [ :each | + each type ifNotNil: [ :type | s << '"' << type name << '"' ] ] + separatedBy: [ s << ' <-> ' ] ] + ifNotNil: [ :assName | s << '"' << assName << '"' ] ]) ]. + model owningAssociation: nil +] + { #category : 'forms' } OPUmlAttributeController >> writeMultiplicityFrom: aString to: aProperty [ | values | diff --git a/repository/OpenPonk-ClassEditor/OPUmlClassItemListCompartment.class.st b/repository/OpenPonk-ClassEditor/OPUmlClassItemListCompartment.class.st index f7c27509..02671f33 100644 --- a/repository/OpenPonk-ClassEditor/OPUmlClassItemListCompartment.class.st +++ b/repository/OpenPonk-ClassEditor/OPUmlClassItemListCompartment.class.st @@ -9,8 +9,10 @@ Class { { #category : 'sorting' } OPUmlClassItemListCompartment >> sortOwnedElements [ - ownedElements sort: [ :a :b | - (a modelElement isStatic and: [ b modelElement isStatic not ]) or: [ - (a modelElement isStatic or: [ b modelElement isStatic not ]) and: [ - a modelElement name < b modelElement name ] ] ] + ownedElements sort: [ :a :b | + (a modelElement isStatic and: [ b modelElement isStatic not ]) or: [ + (a modelElement isStatic or: [ b modelElement isStatic not ]) and: [ + a modelElement name < b modelElement name or: [ + a modelElement name = b modelElement name and: [ + a modelElement uuid < b modelElement uuid ] ] ] ] ] ]