uh, for some reason my mail client eat the formatting... but you get the idea ;)
On Mar 20 2022, at 3:14 pm, Esteban Lorenzano <esteba...@netc.eu> wrote: > Hi, > > well, the incomplete documentation of Spec states clearly that you will be > receiving two parameters: > onAcceptEdition: aBlock > "Set the block to execute when cell edition is accepted. > `aBlock` receives two arguments: > - the element of the table (See `SpAbstractListPresenter>>#items:` > - the string entered while editing" > acceptAction := aBlock > > So, when you set beEditable to your column, you can do something like this: > items := { #one -> 'one'. #two -> 'two' }. > table := SpTablePresenter new > addColumn: (SpStringTableColumn title: 'Key' evaluated: #key); > addColumn: (SpStringTableColumn new > title: 'Value'; > evaluated: #value; > beEditable; > onAcceptEdition: [ :item :newValue | item value: newValue ]; > yourself); > items: items; > open. > and then you can edit whatever you want and update your item. > > Now, since this is a mechanism that has not been used a lot yet in morphic > backend, I just discovered and fixed a bug (not in editable tables, but that > affects it: https://github.com/pharo-spec/Spec/issues/1263), so if you want > to actually use the functionality, you will need to wait until is merged > (tomorrow). > Esteban > > On Mar 20 2022, at 10:26 am, Mark O'Donoghue <mark.odonoghue.2...@gmail.com> > wrote: > > Howdy all > > > > > > I am making progress with quite a large application which relies heavily on > > Spec2 > > ( but Spec2 is such a big learning curve for me – especially given the > > incomplete documentation… 😊) > > > > I am currently struggling with the following issue: > > I have a SpTablePresenter which shows a collection of domain objects > > (subclassed from Model). > > The domain object are instances of ‘Asset’ which is a relatively simple > > class. > > The table works fine. > > > > Now, I need to be able to update some columns , but I don’t think I want to > > build a separate form for doing classic CRUD operations. > > (There is no need for create or delete functionality – so an in-situ update > > seems desirable…). > > > > I’ve made a start using SpStringTableColumn >> beEditable and > > #onAcceptEdition: > > > > But I can’t see how to work out what row and column has changed, and how I > > can update the corresponding Asset instance(s). > > It thought it would be handled using #whenModelChanged: but there are > > models in many places (and at several levels in the Spec hierarchy)… > > I’ve tried following it all the way down to the adapters and morphs but I > > can’t see how the freshly edited cell interacts with the model or > > announcements. > > > > (BTW - It doesn’t look like the ‘selected item’ features are appropriate > > since you can do edits in other rows regardless of what row is/isn’t > > selected.) > > > > Is there a correct and/or elegant way to detect these cell changes in a > > SpTablePresenter and apply them to my domain objects…? > > > > Cheers > > Mark > > > > > > > > > > From: Mark O'Donoghue <mark.odonoghue.2...@gmail.com> > > Sent: Sunday, 4 July 2021 5:26 PM > > To: pharo-users@lists.pharo.org > > Subject: Question about Spec2 and SpTablePresenter > > > > > > > > > > > > Howdy all > > > > I’ve got stuck trying to manage Tables – over 12 hours now and I’m out of > > ideas!. ☹ > > > > Any observations / suggestions are most welcome… > > > > I’ve been loading small external files of transactions using NeoCSV into > > Spec2 tables. > > I am trying to use Fuel to persist the table contents so that my > > application will re-load the working state from where I finished in the > > last session. > > (I’ve opted for Fuel as a simple alternative to having to do the whole > > object relational mapping thing.) > > > > The idea is that transactions (and potentially some manual adjustments) > > will be processed over time. > > (This is preferable to having to reload all files from the beginning evert > > time I run the application…) > > > > The Spec2 tables have been working well until I tried to persist them. > > I can’t seem to fully re-load them to a previously saved state. > > > > For example - I can restore the essential contents of my table in most > > circumstances using: > > > > restoreObjects > > > > “filePresenter1 is a SpTablePresenter” > > > > | objects savedEntry | > > > > objects := CpPersist restoreObjectsFromFileNamed: > > 'E:\Me\zzzST-Test\demo.fuel'. > > > > recentFileList := objects at: 1. > > currFileFilter := objects at: 2. > > savedEntry := objects at: 3. > > > > self updateFilterButton: currFileFilter. > > > > filteredFileList := self filterFilesUsing: currFileFilter. > > > > filePresenter1 items: filteredFileList. > > > > savedEntry > > ifNotNil: [filePresenter1 selectItem: savedEntry ]. > > > > > > However, if any of the table columns are re-sorted , the re-load operation > > gets confused and I can’t get the saved a saved selected item to become > > selected again. > > > > (It seems to be confusing the index numbers of the sorted and unsorted > > lists – even when I match by contents rather than index.) > > (I also created an equality test to ensure equivalent entries are > > recognised by the #= operation in the list of the underlying model ). > > > > This all works fine - unless I sort a column! > > > > Since this approach was going to be used on several screens I’d really like > > to find a solution. > > > > Cheers > > Mark > > Perth, Western Australia