nikiroo / jexer

Java Text User Interface
MIT License
0 stars 0 forks source link

Separate model and view #2

Open BenBE opened 6 years ago

BenBE commented 6 years ago

Would be nice if the view of the table and the data model for it could be separated. For an example of what I mean you might want to have a look at javax.swing.JTable and its use of TableModel and TableCellRenderer classes.

What this separation allows is for the TTable to be backed by a simple list of Model objects (e.g. each representing a file copy operation in progress) with one of the columns represented by some TProgressBar object instead of normal labels. The current design somewhat blocks this usecase for multiple reasons:

  1. I have to copy data from my program's model over to the TTable component
  2. I can only have plain strings (Labels) for the display, not progress bars, checkboxes or other widgets.

To make this change possible each access to the lines [sic] field should at least be wrapped by some "getObjectForCell" (JTableModel.getValueAt) call.

nikiroo commented 6 years ago

I will have a look at that.

nikiroo commented 6 years ago

Hello,

Sorry, I've been quite busy IRL... Still, would https://github.com/nikiroo/jexer/tree/ttable (far from done, it's still a WIP) looks more or less like what you were expecting that change to become?

Note, it's currently not usable: it is still not possible to select a row nor to add actions, and I still haven't added the jDoc (SHAME!).

But if you have any note to swap about the implementation (since it seems you gave some thought to it), I'm interested.

Thanks, Niki

BenBE commented 6 years ago

I know this feeling; not too different around here. :) I had a short look at the for patches and only noticed one minor wording issue bit skimming over the code. Will have to actually implement some bigger test case against the interface to tell for sure, but the direction looks good on first glance; probably some kinks here and there that will need some tweaking.

nikiroo commented 5 years ago

Ok, I finally had some time to work on this (I actually saw the message from the other thread before this one... shame on me).

I did indeed rename lines to rows, it seems better.

I also adopted a JModel approach, and allowed for a separate renderer.

It works well for text (with colours and such), and seems mostly OK for widgets (still have some problems when moving with the hscroller, the content is visible outside of the window).

I still need to implement 2 things though:

Both branches are up to date (ttable and ttable_pull) but the second one has 4 simple commits and is upstream-updated.

If you have notes regarding the current status, feel free to share!

(Sorry for the long delay, I was very busy IRL, though I have slightly moer time now -- my old eeePC is now back to work, so I can code when commuting to work.)