Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a demo page for component list presenter #1462

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/Spec2-Examples/SpDemoComponentListPage.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"
Demo page for component list.

"
Class {
#name : 'SpDemoComponentListPage',
#superclass : 'SpDemoPage',
#category : 'Spec2-Examples-Demo-Labeled',
#package : 'Spec2-Examples',
#tag : 'Demo-Labeled'
}

{ #category : 'initialization' }
SpDemoComponentListPage class >> pageName [

^ 'Component List'
]

{ #category : 'initialization' }
SpDemoComponentListPage class >> priority [

^ 1310
]

{ #category : 'initialization' }
SpDemoComponentListPage >> pageClass [
^ SpTransmissionComponentListExample
]
39 changes: 39 additions & 0 deletions src/Spec2-Examples/SpTransmissionComponentItemExample.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"
Represents an item example to display a class name and its comment in a Spec component list.
"
Class {
#name : 'SpTransmissionComponentItemExample',
#superclass : 'SpPresenter',
#instVars : [
'classNamePresenter',
'classCommentPresenter'
],
#category : 'Spec2-Examples-Demo-ComponentList',
#package : 'Spec2-Examples',
#tag : 'Demo-ComponentList'
}

{ #category : 'layout' }
SpTransmissionComponentItemExample >> defaultLayout [

^ SpBoxLayout newTopToBottom
add: classNamePresenter expand: false fill: false padding: 5;
add: classCommentPresenter expand: true fill: true padding: 5;
yourself.
]

{ #category : 'initialization' }
SpTransmissionComponentItemExample >> initializePresenters [

classNamePresenter := self newLabel
label: owner className;
addStyle: 'gray';
yourself.
classCommentPresenter := self newText text: owner comment.
]

{ #category : 'accessing - model' }
SpTransmissionComponentItemExample >> setModelBeforeInitialization: aClass [

owner := aClass
]
110 changes: 110 additions & 0 deletions src/Spec2-Examples/SpTransmissionComponentListExample.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
"
This class defines the main entry point for running a Spec example of a two-pane ""browser"", however, it display the class comments on classes of the selected package. It defines a component list (`newComponentList`) to hold a list of presenters, instances of `SpTransmissionComponentItemExample`.

- In the left side there are a list of system's pacakges.
- When a package is clicked, in the right side will appear a list of presenters.
- Each presenter is an instance of `SpTransmissionComponentItemExample`.
- The ""glue"" between this main container and the presenter-items is implemented in `SpTransmissionComponentPageExample >> #setModel:`

"
Class {
#name : 'SpTransmissionComponentListExample',
#superclass : 'SpPresenter',
#instVars : [
'classesPresenter',
'packagesPresenter'
],
#category : 'Spec2-Examples-Demo-ComponentList',
#package : 'Spec2-Examples',
#tag : 'Demo-ComponentList'
}

{ #category : 'showing' }
SpTransmissionComponentListExample class >> open [
<script>

^ self new open
]

{ #category : 'initialization' }
SpTransmissionComponentListExample >> connectPresenters [

packagesPresenter
transmitTo: classesPresenter
transform: [ :aPackage |
aPackage
ifNotNil: [
aPackage definedClasses asArray collect: [ : packageClass |
self
instantiate: SpTransmissionComponentItemExample
on: packageClass ] ]
ifNil: [ #( ) ] ].

]

{ #category : 'transmission' }
SpTransmissionComponentListExample >> defaultInputPort [

^ SpListItemsPort newPresenter: classesPresenter

]

{ #category : 'layout' }
SpTransmissionComponentListExample >> defaultLayout [

| packagesLayout classesLayout |
packagesLayout := SpBoxLayout newTopToBottom
add: 'Packages' expand: false;
add: packagesPresenter;
yourself.

classesLayout := SpBoxLayout newTopToBottom
add: 'Classes' expand: false;
add: classesPresenter;
yourself.

^ SpBoxLayout newTopToBottom
spacing: 5;
add: (SpPanedLayout newLeftToRight
add: packagesLayout;
add: classesLayout;
yourself);
yourself
]

{ #category : 'ports' }
SpTransmissionComponentListExample >> defaultOutputPort [

^ packagesPresenter
]

{ #category : 'initialization' }
SpTransmissionComponentListExample >> initialize [

super initialize.
self application addStyleSheetFromString: '.application [
.gray [ Draw { #backgroundColor: #veryLightGray } ],
.red [ Draw { #backgroundColor: #red } ]
]'.
]

{ #category : 'initialization' }
SpTransmissionComponentListExample >> initializePresenters [

packagesPresenter := self newList.
packagesPresenter
display: [ :package | package name ];
displayIcon: [ self iconNamed: #package ];
sortingBlock: [ :a :b | a name < b name ];
items: RPackageOrganizer default packages.

classesPresenter := self newComponentList.
]

{ #category : 'initialization' }
SpTransmissionComponentListExample >> initializeWindow: aWindowPresenter [

aWindowPresenter
title: 'Transmission example with component list example';
initialExtent: 800 @ 600
]