From e1c4602529b85a10142be210630a373a52f81e7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Blizni=C4=8Denko?= Date: Sat, 23 Nov 2024 16:35:32 +0100 Subject: [PATCH] Find existing diagramElement before creating one --- .../OPAbstractDiagramControllerTest.class.st | 1 + .../OPAbstractElementControllerTest.class.st | 1 + .../OpenPonk-Core/OPController.class.st | 6 ++++++ .../OPDiagramController.class.st | 4 +--- .../OpenPonk-Core/OPDiagramElement.class.st | 20 +++++++++++++++++++ .../OPElementController.class.st | 7 ++++++- .../OpenPonk-Spec/OPDiagramExplorer.class.st | 1 + 7 files changed, 36 insertions(+), 4 deletions(-) diff --git a/repository/OpenPonk-Core/OPAbstractDiagramControllerTest.class.st b/repository/OpenPonk-Core/OPAbstractDiagramControllerTest.class.st index f5151ed6..224a0a97 100644 --- a/repository/OpenPonk-Core/OPAbstractDiagramControllerTest.class.st +++ b/repository/OpenPonk-Core/OPAbstractDiagramControllerTest.class.st @@ -17,6 +17,7 @@ OPAbstractDiagramControllerTest >> setUp [ super setUp. controller model: model. + controller diagramElement: OPDiagram new. controller canvasPresenter: (OPCanvasPresenter new canvas: RSCanvas new; yourself) diff --git a/repository/OpenPonk-Core/OPAbstractElementControllerTest.class.st b/repository/OpenPonk-Core/OPAbstractElementControllerTest.class.st index fb3009a3..0de19d0f 100644 --- a/repository/OpenPonk-Core/OPAbstractElementControllerTest.class.st +++ b/repository/OpenPonk-Core/OPAbstractElementControllerTest.class.st @@ -75,6 +75,7 @@ OPAbstractElementControllerTest >> setUp [ diagramController canvasPresenter: (OPCanvasPresenter new canvas: RSCanvas new; yourself). + diagramController diagramElement: OPDiagram new. self setUpCreationTarget ] diff --git a/repository/OpenPonk-Core/OPController.class.st b/repository/OpenPonk-Core/OPController.class.st index 315d0df6..8da8c8f9 100644 --- a/repository/OpenPonk-Core/OPController.class.st +++ b/repository/OpenPonk-Core/OPController.class.st @@ -93,6 +93,12 @@ OPController >> descriptionName [ yourself ] +{ #category : 'accessing' } +OPController >> diagram [ + + ^ self diagramController diagram +] + { #category : 'accessing' } OPController >> diagramController [ ^ diagramController diff --git a/repository/OpenPonk-Core/OPDiagramController.class.st b/repository/OpenPonk-Core/OPDiagramController.class.st index f6541813..a87682f2 100644 --- a/repository/OpenPonk-Core/OPDiagramController.class.st +++ b/repository/OpenPonk-Core/OPDiagramController.class.st @@ -276,9 +276,6 @@ OPDiagramController >> deselectAll [ { #category : 'accessing' } OPDiagramController >> diagram [ - self - deprecated: 'Use diagramElement instead' - transformWith: '`@receiver diagram ' -> '`@receiver diagramElement '. ^ self diagramElement ] @@ -534,6 +531,7 @@ OPDiagramController >> nameOfTypeForModel: aModel [ { #category : 'controllers management' } OPDiagramController >> newControllerFor: aModel [ + ^ controllerFactory newControllerFor: aModel ] diff --git a/repository/OpenPonk-Core/OPDiagramElement.class.st b/repository/OpenPonk-Core/OPDiagramElement.class.st index aefaedad..ccf21de1 100644 --- a/repository/OpenPonk-Core/OPDiagramElement.class.st +++ b/repository/OpenPonk-Core/OPDiagramElement.class.st @@ -147,6 +147,14 @@ OPDiagramElement >> addedByMouseClickTo: aPoint [ ] +{ #category : 'enumerating' } +OPDiagramElement >> allOwnedElements [ + + ^ self ownedElements + , + (self ownedElements flatCollect: [ :each | each allOwnedElements ]) +] + { #category : 'enumerating' } OPDiagramElement >> allOwnedShapesPositionableByUser [ @@ -194,6 +202,18 @@ OPDiagramElement >> createOwnedElementsWithoutController [ ] +{ #category : 'accessing' } +OPDiagramElement >> diagramElementOfType: aType withModelElement: anElement ifFound: aFoundBlock [ + + ((self isKindOf: aType) and: [ modelElements includes: anElement ]) + ifTrue: [ ^ aFoundBlock cull: self ]. + ownedElements do: [ :each | + each + diagramElementOfType: aType + withModelElement: anElement + ifFound: [ :found | ^ aFoundBlock cull: found ] ] +] + { #category : 'testing' } OPDiagramElement >> exists [ diff --git a/repository/OpenPonk-Core/OPElementController.class.st b/repository/OpenPonk-Core/OPElementController.class.st index 058f1540..1f7dea2a 100644 --- a/repository/OpenPonk-Core/OPElementController.class.st +++ b/repository/OpenPonk-Core/OPElementController.class.st @@ -94,7 +94,12 @@ OPElementController >> ensureDiagramElement [ self diagramElement ifExists: [ self linkDiagramElementToModel ] - else: [ self createDiagramElement ]. + else: [ + self diagram + diagramElementOfType: self diagramElementClass + withModelElement: self model + ifFound: [ :found | ^ self diagramElement: found ]. + self createDiagramElement ]. ^ self diagramElement ] diff --git a/repository/OpenPonk-Spec/OPDiagramExplorer.class.st b/repository/OpenPonk-Spec/OPDiagramExplorer.class.st index b0419698..5def8ff2 100644 --- a/repository/OpenPonk-Spec/OPDiagramExplorer.class.st +++ b/repository/OpenPonk-Spec/OPDiagramExplorer.class.st @@ -80,6 +80,7 @@ OPDiagramExplorer >> showAllElements [ { #category : 'actions' } OPDiagramExplorer >> showDependentFor: aModelObject [ + self showElements: (self dependentFor: aModelObject) ]