Skip to content

Commit

Permalink
Merge pull request #26 from Joshua-Dias-Barreto/master
Browse files Browse the repository at this point in the history
Interactive functionality to add / delete rows
  • Loading branch information
jecisc authored Oct 2, 2023
2 parents 5520411 + b22226b commit b586a00
Show file tree
Hide file tree
Showing 2 changed files with 250 additions and 10 deletions.
192 changes: 192 additions & 0 deletions src/AI-DataFrameInspector/AISpAddRowPresenter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
"
Class for handling the window which allows users to add rows.
It provides a user friendly way to add rows to DataFrames.
This window has these fields:
- **Position** : The position at which the new row should be added.
- **Row Name** : The row name of the new row to be added.
- **New Row** : The user can type the new row by adding the necessary items under each column.
- **Add button** : Adds the row to the DataFrame.
- **Reset button** : Clears the items entered under each column of the new row.
After entering each item under the specific column, the 'enter' key must be hit.
"
Class {
#name : #AISpAddRowPresenter,
#superclass : #AISpDataFramePresenter,
#instVars : [
'sortType',
'columnName',
'emptyRow',
'resetButton',
'newRowName',
'newRow',
'oneRowPresenter',
'block',
'rowInputTable',
'newRowInputTable',
'positionInput',
'addButton',
'tablePresenter',
'applyButton',
'cancelButton',
'dataRows'
],
#category : #'AI-DataFrameInspector-sub presenters'
}

{ #category : #'instance creation' }
AISpAddRowPresenter class >> openOn: aDataFrame [

^ (self on: aDataFrame) open
]

{ #category : #adding }
AISpAddRowPresenter >> addButtonAction [

newRow name: newRowName text.
dataFrame addRow: newRow atPosition: positionInput number.
self window close
]

{ #category : #initialization }
AISpAddRowPresenter >> connectPresenters [

addButton action: [ self addButtonAction ].
resetButton action: [ self resetButtonAction ]
]

{ #category : #layout }
AISpAddRowPresenter >> defaultLayout [

| topLayout bottomLayout |
topLayout := SpBoxLayout newLeftToRight
spacing: 70;
add: (SpGridLayout new
add: 'Position' at: 1 @ 1;
add: positionInput at: 2 @ 1;
yourself);
add: (SpGridLayout new
add: 'Row Name' at: 1 @ 1;
add: newRowName at: 2 @ 1;
yourself);
yourself.

bottomLayout := SpBoxLayout newLeftToRight
spacing: 5;
add: addButton width: 65;
add: resetButton width: 65;
yourself.

^ SpBoxLayout newTopToBottom
spacing: 15;
add: topLayout height: 40;
add: rowInputTable height: 70;
add: bottomLayout height: 30;
yourself
]

{ #category : #initialization }
AISpAddRowPresenter >> initializeAddResetButtons [

addButton := self newButton
label: 'Add';
icon: (self iconNamed: #smallAdd).
resetButton := self newButton
label: 'Reset';
icon: (self iconNamed: #refreshIcon)
]

{ #category : #initialization }
AISpAddRowPresenter >> initializeNewRowInputTable [

emptyRow := dataFrame rowsFrom: 1 to: 1.
1 to: emptyRow numberOfColumns do: [ :columnIndex |
1 to: emptyRow numberOfRows do: [ :rowIndex |
emptyRow at: rowIndex at: columnIndex put: '' ] ].
newRow := DataSeries
withKeys: dataFrame columnNames
values: (emptyRow at: 1) asArray.
newRowInputTable := self newTable.
dataFrame columnNames doWithIndex: [ :headerName :columnIndex |
| column |
column := SpStringTableColumn
title: headerName
evaluated: [ :rowWithName |
(rowWithName at: columnIndex + 1) asString ].
column beEditable.
column onAcceptEdition: [ :row :newValue |
newRow at: headerName put: newValue ].
newRowInputTable addColumn: column ].
newRowInputTable beResizable.
newRowInputTable items: emptyRow asArrayOfRowsWithName
]

{ #category : #'as yet unclassified' }
AISpAddRowPresenter >> initializeNewRowName [

newRowName := self newTextInput
placeholder: 'row name';
text: '';
yourself
]

{ #category : #initialization }
AISpAddRowPresenter >> initializePositionInput [

positionInput := self newNumberInput
number: dataFrame numberOfRows + 1;
beInteger;
yourself
]

{ #category : #initialization }
AISpAddRowPresenter >> initializePresenters [

self initializeNewRowName.
self initializeRowInputTable.
self initializePositionInput.
self initializeAddResetButtons
]

{ #category : #'as yet unclassified' }
AISpAddRowPresenter >> initializeRowInputTable [

emptyRow := dataFrame rowsFrom: 1 to: 1.
1 to: emptyRow numberOfColumns do: [ :columnIndex |
1 to: emptyRow numberOfRows do: [ :rowIndex |
emptyRow at: rowIndex at: columnIndex put: '' ] ].
newRow := DataSeries
withKeys: dataFrame columnNames
values: (emptyRow at: 1) asArray.
rowInputTable := self newTable.
dataFrame columnNames doWithIndex: [ :headerName :columnIndex |
| column |
column := SpStringTableColumn
title: headerName
evaluated: [ :rowWithName |
(rowWithName at: columnIndex + 1) asString ].
column beEditable.
column onAcceptEdition: [ :row :newValue |
newRow at: headerName put: newValue ].
rowInputTable addColumn: column ].
rowInputTable beResizable.
rowInputTable items: emptyRow asArrayOfRowsWithName
]

{ #category : #initialization }
AISpAddRowPresenter >> initializeWindow: aWindowPresenter [

aWindowPresenter
initialExtent: 500 @ 250;
title: 'Add Row';
whenClosedDo: [
newRowName text: ''.
positionInput number: dataFrame numberOfRows + 1 ]
]

{ #category : #initialization }
AISpAddRowPresenter >> resetButtonAction [

self initializeNewRowInputTable.
self layout replace: rowInputTable with: newRowInputTable.
rowInputTable := newRowInputTable
]
68 changes: 58 additions & 10 deletions src/AI-DataFrameInspector/AISpDataFramePresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ Class {
'editButton',
'searchBar',
'sortButton',
'addRowButton',
'newdataFramePresenter',
'sortPresenter',
'addRowPresenter',
'windowPresenter'
],
#category : #'AI-DataFrameInspector-Main presenters'
Expand All @@ -30,12 +32,32 @@ AISpDataFramePresenter class >> openOn: aDataFrame [
^ (self on: aDataFrame) open
]

{ #category : #adding }
AISpDataFramePresenter >> addRowButtonAction [

windowPresenter := addRowPresenter open.
windowPresenter whenClosedDo: [ self refreshLayout ]
]

{ #category : #initialization }
AISpDataFramePresenter >> connectPresenters [

editButton action: [ self editButtonAction ].
searchBar whenTextChangedDo: [ self searchBarAction ].
sortButton action: [ self sortButtonAction ]
sortButton action: [ self sortButtonAction ].
addRowButton action: [ self addRowButtonAction ]
]

{ #category : #'as yet unclassified' }
AISpDataFramePresenter >> dataFrameContextMenu [

^ self newMenu addItem: [ :item |
item
name: 'delete row';
icon: (self iconNamed: #remove);
action: [
dataFrame removeRow: (dataFramePresenter selectedItem at: 1).
self refreshLayout ] ]
]

{ #category : #layout }
Expand All @@ -48,6 +70,7 @@ AISpDataFramePresenter >> defaultLayout [
add: editButton width: 60;
add: sortButton width: 50;
add: searchBar width: 100;
add: addRowButton width: 80;
yourself)
height: 20;
add: dataFramePresenter;
Expand Down Expand Up @@ -120,7 +143,9 @@ AISpDataFramePresenter >> editDataFrame [
newdataFramePresenter addColumn: column ] ].
newdataFramePresenter beResizable.

newdataFramePresenter items: dataFrame asArrayOfRowsWithName
newdataFramePresenter
items: dataFrame asArrayOfRowsWithName;
contextMenu: self dataFrameContextMenu
]

{ #category : #searching }
Expand All @@ -144,6 +169,15 @@ AISpDataFramePresenter >> initialize [
super initialize
]

{ #category : #'as yet unclassified' }
AISpDataFramePresenter >> initializeAddRowPresenter [

windowPresenter := SpWindowPresenter new.
addRowPresenter := self
instantiate: AISpAddRowPresenter
on: dataFrame
]

{ #category : #initialization }
AISpDataFramePresenter >> initializeDataFramePresenter [

Expand All @@ -167,7 +201,9 @@ AISpDataFramePresenter >> initializeDataFramePresenter [
evaluated: [ :rowWithName | rowWithName at: columnIndex + 1 ]) ].
dataFramePresenter beResizable.

dataFramePresenter items: dataFrame asArrayOfRowsWithName
dataFramePresenter
items: dataFrame asArrayOfRowsWithName;
contextMenu: self dataFrameContextMenu
]

{ #category : #initialization }
Expand All @@ -191,15 +227,18 @@ AISpDataFramePresenter >> initializeNewDataFramePresenter [
evaluated: [ :rowWithName | rowWithName at: columnIndex + 1 ]) ].
newdataFramePresenter beResizable.

newdataFramePresenter items: dataFrame asArrayOfRowsWithName
newdataFramePresenter
items: dataFrame asArrayOfRowsWithName;
contextMenu: self dataFrameContextMenu
]

{ #category : #initialization }
AISpDataFramePresenter >> initializePresenters [

self initializeDataFramePresenter.
self initializeToolbarPresenter.
self initializeSortPresenter
self initializeSortPresenter.
self initializeAddRowPresenter
]

{ #category : #initialization }
Expand All @@ -222,7 +261,19 @@ AISpDataFramePresenter >> initializeToolbarPresenter [
sortButton := self newButton
label: 'sort';
icon: (self iconNamed: #smallOpen);
yourself
yourself.
addRowButton := self newButton
label: 'Add Row';
icon: (self iconNamed: #smallAdd);
yourself
]

{ #category : #'as yet unclassified' }
AISpDataFramePresenter >> refreshLayout [

self initializeNewDataFramePresenter.
self layout replace: dataFramePresenter with: newdataFramePresenter.
dataFramePresenter := newdataFramePresenter
]

{ #category : #searching }
Expand All @@ -248,8 +299,5 @@ AISpDataFramePresenter >> setModelBeforeInitialization: aModel [
AISpDataFramePresenter >> sortButtonAction [

windowPresenter := sortPresenter open.
windowPresenter whenClosedDo: [
self initializeNewDataFramePresenter.
self layout replace: dataFramePresenter with: newdataFramePresenter.
dataFramePresenter := newdataFramePresenter ]
windowPresenter whenClosedDo: [ self refreshLayout ]
]

0 comments on commit b586a00

Please sign in to comment.