Skip to content

Commit

Permalink
Improved association end label handling
Browse files Browse the repository at this point in the history
  • Loading branch information
JanBliznicenko committed Nov 13, 2024
1 parent f13e172 commit c2e2235
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 48 deletions.
28 changes: 23 additions & 5 deletions repository/OpenPonk-ClassEditor/OPDiagramElement.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,37 @@ Extension { #name : 'OPDiagramElement' }
{ #category : '*OpenPonk-ClassEditor' }
OPDiagramElement >> showAssociationEndLabels [

^ self
stylePropertyNamed: #showAssociationEndLabels
ifAbsent: [ true ]
^ self stylePropertyNamed: self showAssociationEndLabelsKey ifAbsent: [
OPUmlDiagramHideSameAsClassEndLabelsFigureCommand
resultingShowState ]
]

{ #category : '*OpenPonk-ClassEditor' }
OPDiagramElement >> showAssociationEndLabels: aBoolean [
OPDiagramElement >> showAssociationEndLabels: aSymbol [

self stylePropertyNamed: #showAssociationEndLabels put: aBoolean
self stylePropertyNamed: self showAssociationEndLabelsKey put: aSymbol
]

{ #category : '*OpenPonk-ClassEditor' }
OPDiagramElement class >> showAssociationEndLabelsKey [

^ #showAssociationEndLabels
]

{ #category : '*OpenPonk-ClassEditor' }
OPDiagramElement >> showAssociationEndLabelsKey [

^ self class showAssociationEndLabelsKey
]

{ #category : '*OpenPonk-ClassEditor' }
OPDiagramElement >> supportsHidingLabelEnds [

^ false
]

{ #category : '*OpenPonk-ClassEditor' }
OPDiagramElement >> unsetAssociationEndLabels [

self removeLocalStylePropertyNamed: self showAssociationEndLabelsKey
]
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,22 @@ OPUmlAssociationEndLabel >> defaultMinDistance [
OPUmlAssociationEndLabel >> defaultText [

| type typeName defaultText |
self showAssociationEndLabels
= OPUmlDiagramHideEndLabelsFigureCommand resultingShowState ifTrue: [
^ '' ].
defaultText := self modelElement notationStringAsRoleName.
self showAssociationEndLabels ifTrue: [ ^ defaultText ].
self showAssociationEndLabels
= OPUmlDiagramShowEndLabelsFigureCommand resultingShowState ifTrue: [
^ defaultText ].
type := self modelElement type.
type ifNil: [ ^ defaultText ].
typeName := type name.
typeName ifNil: [ ^ defaultText ].
typeName ifEmpty: [ ^ defaultText ].
(typeName reject: [ :each | each isSeparator ]) asLowercase
= (defaultText reject: [ :each | each isSeparator ]) asLowercase
ifTrue: [ ^ '' ].
^ defaultText
ifFalse: [ ^ defaultText ].
^ ''
]

{ #category : 'initialization' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ OPUmlDiagramEndLabelsFigureCommand class >> canBeExecutedInContext: aToolContext

^ (super canBeExecutedInContext: aToolContext) and: [
aToolContext diagramElements anySatisfy: [ :any |
any supportsHidingLabelEnds and: [
any showAssociationEndLabels ~= self resultingShowState ] ] ]
any supportsHidingLabelEnds ] ]
]

{ #category : 'activation' }
OPUmlDiagramEndLabelsFigureCommand class >> contextMenuActivation [

<classAnnotation>
^ CmdContextMenuActivation
byItemOf: OPUmlDiagramEndLabelsFigureMenuGroup
for: OPCanvasPresenter
]

{ #category : 'testing' }
Expand All @@ -21,29 +29,32 @@ OPUmlDiagramEndLabelsFigureCommand class >> isAbstract [
^ self = OPUmlDiagramEndLabelsFigureCommand
]

{ #category : 'hooks' }
OPUmlDiagramEndLabelsFigureCommand class >> resultingShowState [
{ #category : 'accessing' }
OPUmlDiagramEndLabelsFigureCommand >> basicMenuItemName [

^ self subclassResponsibility
^ ''
]

{ #category : 'accessing' }
OPUmlDiagramEndLabelsFigureCommand >> defaultMenuIconName [
OPUmlDiagramEndLabelsFigureCommand >> defaultMenuItemName [

^ #smallLeftFlush
| basicName |
basicName := self basicMenuItemName.

self isCurrent ifFalse: [ ^ basicName ].

^ basicName , ' [current]'
]

{ #category : 'execution' }
OPUmlDiagramEndLabelsFigureCommand >> execute [
{ #category : 'testing' }
OPUmlDiagramEndLabelsFigureCommand >> isCurrent [

diagramElements
select: [ :each | each supportsHidingLabelEnds ]
thenDo: [ :each |
each showAssociationEndLabels: self resultingShowState ]
^ diagramElements anySatisfy: [ :any |
self isCurrentStyle: any localStyle ]
]

{ #category : 'hooks' }
OPUmlDiagramEndLabelsFigureCommand >> resultingShowState [
{ #category : 'testing' }
OPUmlDiagramEndLabelsFigureCommand >> isCurrentStyle: aStyle [

^ self class resultingShowState
^ self subclassResponsibility
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Class {
#name : 'OPUmlDiagramEndLabelsFigureMenuGroup',
#superclass : 'CmdMenuGroup',
#category : 'OpenPonk-ClassEditor-Commands',
#package : 'OpenPonk-ClassEditor',
#tag : 'Commands'
}

{ #category : 'accessing' }
OPUmlDiagramEndLabelsFigureMenuGroup >> name [

^ 'Association end labels'
]
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
Class {
#name : 'OPUmlDiagramHideEndLabelsFigureCommand',
#superclass : 'OPUmlDiagramEndLabelsFigureCommand',
#superclass : 'OPUmlDiagramSetEndLabelsFigureCommand',
#category : 'OpenPonk-ClassEditor-Commands',
#package : 'OpenPonk-ClassEditor',
#tag : 'Commands'
}

{ #category : 'testing' }
OPUmlDiagramHideEndLabelsFigureCommand class >> canBeExecutedInContext: aToolContext [
{ #category : 'hooks' }
OPUmlDiagramHideEndLabelsFigureCommand class >> resultingShowState [

^ (super canBeExecutedInContext: aToolContext) and: [
aToolContext diagramElements anySatisfy: [ :any |
any showAssociationEndLabels ] ]
^ #show
]

{ #category : 'hooks' }
OPUmlDiagramHideEndLabelsFigureCommand class >> resultingShowState [
{ #category : 'accessing' }
OPUmlDiagramHideEndLabelsFigureCommand >> basicMenuItemName [

^ false
^ 'Hide all'
]

{ #category : 'accessing' }
OPUmlDiagramHideEndLabelsFigureCommand >> defaultMenuItemName [
OPUmlDiagramHideEndLabelsFigureCommand >> defaultMenuIconFormSet [

^ 'Hide association end labels'
^ FormSet form: OPCoreIcons opHideLabelsIcon
]

{ #category : 'accessing' }
OPUmlDiagramHideEndLabelsFigureCommand >> description [

^ 'Hide association end labels where the text is just name of the class'
^ 'Hide all association end labels'
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Class {
#name : 'OPUmlDiagramHideSameAsClassEndLabelsFigureCommand',
#superclass : 'OPUmlDiagramSetEndLabelsFigureCommand',
#category : 'OpenPonk-ClassEditor-Commands',
#package : 'OpenPonk-ClassEditor',
#tag : 'Commands'
}

{ #category : 'hooks' }
OPUmlDiagramHideSameAsClassEndLabelsFigureCommand class >> resultingShowState [

^ #hideSame
]

{ #category : 'accessing' }
OPUmlDiagramHideSameAsClassEndLabelsFigureCommand >> basicMenuItemName [

^ 'Hide same as class name'
]

{ #category : 'accessing' }
OPUmlDiagramHideSameAsClassEndLabelsFigureCommand >> defaultMenuIconFormSet [

^ FormSet form: OPCoreIcons opHideSameLabelsIcon
]

{ #category : 'accessing' }
OPUmlDiagramHideSameAsClassEndLabelsFigureCommand >> description [

^ 'Hide association end labels where the text is the same as name of the class'
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Class {
#name : 'OPUmlDiagramSetEndLabelsFigureCommand',
#superclass : 'OPUmlDiagramEndLabelsFigureCommand',
#category : 'OpenPonk-ClassEditor-Commands',
#package : 'OpenPonk-ClassEditor',
#tag : 'Commands'
}

{ #category : 'testing' }
OPUmlDiagramSetEndLabelsFigureCommand class >> isAbstract [

^ self = OPUmlDiagramSetEndLabelsFigureCommand
]

{ #category : 'hooks' }
OPUmlDiagramSetEndLabelsFigureCommand class >> resultingShowState [

^ #''
]

{ #category : 'execution' }
OPUmlDiagramSetEndLabelsFigureCommand >> execute [

diagramElements
select: [ :each | each supportsHidingLabelEnds ]
thenDo: [ :each |
each showAssociationEndLabels: self resultingShowState ]
]

{ #category : 'testing' }
OPUmlDiagramSetEndLabelsFigureCommand >> isCurrentStyle: aStyle [

aStyle ifNil: [ ^ false ].
^ aStyle
at: OPUmlAssociationEndLabel showAssociationEndLabelsKey
ifPresent: [ :styleValue | styleValue = self resultingShowState ]
ifAbsent: [ false ]
]

{ #category : 'hooks' }
OPUmlDiagramSetEndLabelsFigureCommand >> resultingShowState [

^ self class resultingShowState
]
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
Class {
#name : 'OPUmlDiagramShowEndLabelsFigureCommand',
#superclass : 'OPUmlDiagramEndLabelsFigureCommand',
#superclass : 'OPUmlDiagramSetEndLabelsFigureCommand',
#category : 'OpenPonk-ClassEditor-Commands',
#package : 'OpenPonk-ClassEditor',
#tag : 'Commands'
}

{ #category : 'testing' }
OPUmlDiagramShowEndLabelsFigureCommand class >> canBeExecutedInContext: aToolContext [
{ #category : 'hooks' }
OPUmlDiagramShowEndLabelsFigureCommand class >> resultingShowState [

^ (super canBeExecutedInContext: aToolContext) and: [
aToolContext diagramElements anySatisfy: [ :any |
any showAssociationEndLabels not ] ]
^ #hide
]

{ #category : 'hooks' }
OPUmlDiagramShowEndLabelsFigureCommand class >> resultingShowState [
{ #category : 'accessing' }
OPUmlDiagramShowEndLabelsFigureCommand >> basicMenuItemName [

^ true
^ 'Show all'
]

{ #category : 'accessing' }
OPUmlDiagramShowEndLabelsFigureCommand >> defaultMenuItemName [
OPUmlDiagramShowEndLabelsFigureCommand >> defaultMenuIconFormSet [

^ 'Show association end labels'
^ FormSet form: OPCoreIcons opShowLabelsIcon
]

{ #category : 'accessing' }
OPUmlDiagramShowEndLabelsFigureCommand >> description [

^ 'Show association end labels even where the text is just name of the class'
^ 'Show all association end labels'
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Class {
#name : 'OPUmlDiagramUnsetEndLabelsFigureCommand',
#superclass : 'OPUmlDiagramEndLabelsFigureCommand',
#category : 'OpenPonk-ClassEditor-Commands',
#package : 'OpenPonk-ClassEditor',
#tag : 'Commands'
}

{ #category : 'testing' }
OPUmlDiagramUnsetEndLabelsFigureCommand class >> canBeExecutedInContext: aToolContext [

^ (super canBeExecutedInContext: aToolContext) and: [
aToolContext diagramElements anySatisfy: [ :any |
any owningElement exists ] ]
]

{ #category : 'accessing' }
OPUmlDiagramUnsetEndLabelsFigureCommand >> basicMenuItemName [

^ 'Use diagram-level setting'
]

{ #category : 'execution' }
OPUmlDiagramUnsetEndLabelsFigureCommand >> execute [

diagramElements
select: [ :each | each owningElement exists ]
thenDo: [ :each | each unsetAssociationEndLabels ]
]

{ #category : 'testing' }
OPUmlDiagramUnsetEndLabelsFigureCommand >> isCurrentStyle: aStyle [

aStyle ifNil: [ ^ true ].
^ (aStyle includesKey:
OPUmlAssociationEndLabel showAssociationEndLabelsKey) not
]

0 comments on commit c2e2235

Please sign in to comment.