Skip to content

Commit

Permalink
Add a comparison view to LeDuplicatePageIdError
Browse files Browse the repository at this point in the history
  • Loading branch information
chisandrei committed Mar 26, 2024
1 parent 30319bd commit 140f8b3
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/Lepiter-Core/LeDatabase.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ LeDatabase >> setPage: aLePage [
duplicate := (pages includesKey: aLePage databaseKey)
ifTrue: [ LeDuplicatePageIdError new
database: self;
pageInDB: (pages at: aLePage databaseKey);
pageInCurrentDatabase: (pages at: aLePage databaseKey);
pageToAdd: aLePage;
signal.
true]
Expand Down
169 changes: 140 additions & 29 deletions src/Lepiter-Core/LeDuplicatePageIdError.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,114 @@ Class {
#name : #LeDuplicatePageIdError,
#superclass : #Error,
#instVars : [
'page',
'file',
'pageInDB',
'database'
'database',
'newPage',
'existingPage'
],
#category : #'Lepiter-Core-Exceptions'
}

{ #category : #'gt - extensions' }
LeDuplicatePageIdError >> createAnnotatedPagesElement [
| pagesContainer headerElement rightContainer |
pagesContainer := BrHorizontalPane new
matchParent.

headerElement := BrHorizontalPane new
"padding: (BlInsets all: 0);"
hMatchParent;
vFitContent.

headerElement
addChild: self createExistingPageLabel;
addChild: self createNewPageLabel.

pagesContainer addChild: (LePageToolContentTreeElement new
withTitleOnly;
pageViewModel: existingPage asContentUIModel;
geometry: (BlRoundedRectangleGeometry cornerRadius: 4);
border: (BlBorder paint: (Color gray alpha: 0.2) width: 1);
margin: (BlInsets all: 5);
matchParent).

rightContainer := BrHorizontalPane new
margin: (BlInsets all: 5);
"addAptitude: (BrGlamorousWithHorizontalResizerAptitude new beLeft);"
matchParent.

"rightContainer addChild: (BrFrame new
constraintsDo: [ :c |
c vertical matchParent.
c horizontal exact: 10 ]
yourself)."

rightContainer addChild: (LePageToolContentTreeElement new
withTitleOnly;
pageViewModel: newPage asContentUIModel;
geometry: (BlRoundedRectangleGeometry cornerRadius: 4);
border: (BlBorder paint: (Color gray alpha: 0.2) width: 1);
matchParent).

pagesContainer
addChild: rightContainer.

^ BrVerticalPane new
matchParent;
addChild: headerElement;
addChild: pagesContainer
]

{ #category : #'gt - extensions' }
LeDuplicatePageIdError >> createExistingPageLabel [
^ BrLabel new
aptitude: BrGlamorousLabelAptitude;
text: ('Existing page' asRopedText glamorousCodeSmallSize
foreground: BrGlamorousColors defaultButtonTextColor);
hMatchParent
]

{ #category : #'gt - extensions' }
LeDuplicatePageIdError >> createExplanationText [
^ self standardMessageText, ' To proceed choose which page to load.'
"'The Phlow view created by the method ' asRopedText
,(self viewMethod printString asRopedText italic)
,' returned the' asRopedText
, (self parameterName asRopedText glamorousExplanationFor: #viewParameter)
, ' argument. This is not allowed. Return 'asRopedText
, (self parameterName, ' empty') asRopedText italic,
' instead.' asRopedText"
]

{ #category : #'gt - extensions' }
LeDuplicatePageIdError >> createExplanationWithPagesElement [
| container |
container := BrVerticalPane new
matchParent;
padding: (BlInsets top: 0 bottom: 5 left: 5 right: 5).

"container addChild: (BrEditor new
aptitude: BrGlamorousRegularEditorAptitude;
text: self createExplanationText;
margin: (BlInsets all: 10);
hMatchParent;
vFitContent).
"
container addChild: self createAnnotatedPagesElement.
container explainer isExplanationHolder: true.

^ container
]

{ #category : #'gt - extensions' }
LeDuplicatePageIdError >> createNewPageLabel [
^ BrLabel new
aptitude: BrGlamorousLabelAptitude;
text: ('New page' asRopedText glamorousCodeSmallSize
foreground: BrGlamorousColors defaultButtonTextColor);
hMatchParent
]

{ #category : #'private - adding / removing' }
LeDuplicatePageIdError >> database: aDatabase [
database := aDatabase
Expand All @@ -25,16 +125,17 @@ LeDuplicatePageIdError >> file: anObject [
file := anObject
]

{ #category : #accessing }
{ #category : #'gt - extensions' }
LeDuplicatePageIdError >> gtDetailsFor: aView [
<gtView>
<gtExceptionDebuggingView>

^ aView columnedList
title: 'Details';
priority: 0;
priority: 0.1;
items: {
'Page already in DB' -> pageInDB .
'Page to add' -> page };
'Page already in DB' -> existingPage .
'Page to add' -> newPage };
column: 'Page' text: #key;
column: 'Title' text: [:each | each value title];
column: 'Uid' text: [:each | each value uidString ];
Expand All @@ -46,6 +147,28 @@ LeDuplicatePageIdError >> gtDetailsFor: aView [
send: #value
]

{ #category : #'gt - extensions' }
LeDuplicatePageIdError >> gtViewTwoPageComparisonFor: aView [
<gtView>
<gtExceptionDebuggingView>

^ aView explicit
title: 'Comparison';
priority: 0;
stencil: [ self createExplanationWithPagesElement ]";
in: [ :currentView |
self shouldTransform ifTrue: [.
currentView
actionDropdownButtonIcon: BrGlamorousVectorIcons repair
tooltip: 'Refactor view return'
content: [ self refactoringContentElement ] ].
currentView
actionButtonIcon: BrGlamorousVectorIcons browse
tooltip: 'Browse method'
action: [ self viewMethod gtBrowse ];
yourself ]"
]

{ #category : #private }
LeDuplicatePageIdError >> isResumable [
"Determine whether an exception is resumable."
Expand All @@ -59,35 +182,23 @@ LeDuplicatePageIdError >> messageText [
messageText := self standardMessageText ]
]

{ #category : #accessing }
LeDuplicatePageIdError >> page [
^ page
]

{ #category : #accessing }
LeDuplicatePageIdError >> page: anObject [
page := anObject
]

{ #category : #'private - adding / removing' }
LeDuplicatePageIdError >> pageInDB: aPage [
pageInDB := aPage
LeDuplicatePageIdError >> pageInCurrentDatabase: aPage [
existingPage := aPage
]

{ #category : #'private - adding / removing' }
LeDuplicatePageIdError >> pageToAdd: aLePage [
page := aLePage
newPage := aLePage
]

{ #category : #accessing }
LeDuplicatePageIdError >> standardMessageText [
^ self page
ifNil: [ 'DuplicatePageIdError for unknown page.' ]
ifNotNil: [ :aPage |
'Page "{1}" with id {2} has the same databaseKey {3} as the existing "{4}" with id {5}.'
format: {page gtDisplayString.
page uidString.
page databaseKey.
pageInDB gtDisplayString.
pageInDB uidString} ]
^ 'The existing page "{1}" with id "{2}" has the same databaseKey "{3}" as the new page "{4}" with id "{5}".' format: {
existingPage gtDisplayString.
existingPage uidString.
newPage databaseKey.
newPage gtDisplayString.
newPage uidString.
}
]

0 comments on commit 140f8b3

Please sign in to comment.