Skip to main content

Sorting and filtering my own DataModel

5 replies [Last post]
lorson
Offline
Joined: 2006-02-17

Hi,

I have constructed my own DataModel now (JdbcDatamodel - just experimental) and my own

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kleopatra
Offline
Joined: 2003-06-11

>
> > By the way:
> > I don't like TabularDataModel and
> TabularDataModelAdapter because the former is derived
> from Swing-TableModel. Imho TabularDataModel should
> be a real JDNC-DataModel. Vice-versa
> TabularDataModelAdapter should be a wrapper for the
> Swing-TableModel.
>
> I agree with you here entirely.

Gerhard, as you see, Richard is happy

> I think I even
> removed this class from my incubator code, though it
> may still be there. I'll definately be lobbying for
> its removal :).

don't throw out the baby with the bathwater.

A "DataModel" as seen from the perspective of a form/binding probably will turn out to be different from "DataModel" as seen from the perspective of the backend. While the former needs the "record-ness" the latter is interested in the "generalized table-ness" of arbitrary data (collections, rowsets, beans, maps...).

Now back to the TabularDataModel:

first, to me it looks like a misnomer - being a TableModel it shouldn't have the postfix "DataModel". It _is_ an enhanced TableModel, the enhancements consist in asynchronous loading and supporting metaData. Any ideas to rename? Anyway, this "enhanced" TableModel is a good candidate to make it into the core Swing layer (hint, hint ...)

second, the TabularDataModelAdapter is adapting a _single row_ of a TableModel to a "DataModel" - for the sake of the form/binding perspective. As such, it will have its place in the framework, IMO,

third, adapting is not a one-way street: there will be adapters from swing models to jdnc models and vice versa.

Jeanette

kleopatra
Offline
Joined: 2003-06-11

Gerhard,

>
> I have constructed my own DataModel now
> w (JdbcDatamodel - just experimental) and my own
> “DataForm“. That DataForm-class has no dependencies
> to Swing-TableModel neither to JNForm.

why use a framework class if you can roll your own ;-) No, no, I understand the desire to experiment, doing it myself all the time.

>
> How to use filter and sorting now? Can I attach the
> filter- and sorting-capacities of JDNC directly to my
> own DataModel now? Or is filtering/sorting closely
> tied to Swing-TableModel or Swing-ListModel? I am
> quite confused about the working of Filter and
> FilterPipeline. Do I have to use an instance of
> JNTable to filter/search/sort my own DataModel?
>

Basically, you need to implement a ComponentAdapter and assign it to the FilterPipeline. The Adapter is meant to be provided by a JComponent that has the notion of filtering/sorting on top of an arbitrary model - so the "normal" place to assign and handle the references would be inside your "Data-form" - but there is nothing that prevents you to implement it on top of whatever is able to reasonably return values in a 2D coordinate system.

That said, the only (explicit) coupling to a view is by the method getComponent(). (some methods like hasFocus() don't make much sense outside of the view realm) Probably the contract has to be tweaked slightly to allow null as return value. Or we could split-up the interface into a bare-bone dimensional adapter and the view part... Just thinking aloud :-)

> But critics aside: I am very enthusiasmated about
> that project. And take my critics as “constructive“.

You are welcome.

Jeanette

lorson
Offline
Joined: 2006-02-17

> Gerhard,
>
> >
> > I have constructed my own DataModel now
> > w (JdbcDatamodel - just experimental) and my own
> > “DataForm“. That DataForm-class has no
> dependencies
> > to Swing-TableModel neither to JNForm.
>
> why use a framework class if you can roll your own
> ;-) No, no, I understand the desire to experiment,
> doing it myself all the time.

;-) I trying to "recreate" or reinvent an already existing framework written in a legacy-4GL-language.

> >
> > How to use filter and sorting now? Can I attach

>
> Basically, you need to implement a ComponentAdapter
> and assign it to the FilterPipeline. The Adapter is
> meant to be provided by a JComponent that has the
> notion of filtering/sorting on top of an arbitrary
> model - so the "normal" place to assign and handle
> the references would be inside your "Data-form" - but
> there is nothing that prevents you to implement it on
> top of whatever is able to reasonably return values
> in a 2D coordinate system.

Thanks, Jeanette. That was a very helpful information.
Some JDNC-libraries could be better documented. Especially the Filter/FilterPipeline/Component-Adapter design-pattern. I guess we need a wiki or a technical FAQ and I guess we need some persons willing to write that stuff ;-)

--
Gerhard

rbair
Offline
Joined: 2003-07-08

Hey Gerhard,

I don't think you really want to filter or sort on the DataModel itself, but really on the TableModel. Suppose you have a JList and a JTable linked up to a DataModel. If the sorting/filtering occured on the DataModel itself, it would modify both controls. This *may* be what you want, but there are definately a bunch of apps that would rather have the sorting affect only the "view" of the data in the Table.

I'm not really up on the FilterPipeline (I just kind of hacked a demo to use it once, but I never really groked it), but I believe you'll want to use the JXTable or the JNTable to utilize it.

> By the way:
> I don't like TabularDataModel and TabularDataModelAdapter because the former is derived from Swing-TableModel. Imho TabularDataModel should be a real JDNC-DataModel. Vice-versa TabularDataModelAdapter should be a wrapper for the Swing-TableModel.

I agree with you here entirely. I think I even removed this class from my incubator code, though it may still be there. I'll definately be lobbying for its removal :). However, it has some cool code for reading tabular file data, so I'm thinking of moving it into a type of DataSource rather than as an adapter as it currently is.

>But critics aside: I am very enthusiasmated about that project. And take my critics as “constructive“.

Always :)

Richard

dhall
Offline
Joined: 2006-02-17

>> I don't think you really want to filter or sort on the DataModel itself, but really on the TableModel. Suppose you have a JList and a JTable linked up to a DataModel. If the sorting/filtering occured on the DataModel itself, it would modify both controls. This may be what you want, but there are definately a bunch of apps that would rather have the sorting affect only the "view" of the data in the Table.

I think we should not limit sorting and filtering to only table models: sorting and filtering lists, based on information available in the metadata that describes the list would be useful. It isn't necessarily true that sorting a list in the datamodel would automagically sort all views of the list: a view can still have reference to the unsorted version, or two distinct sorter/filters could have the same common data reference, yielding two different views of the data.

Dave Hall
http://jga.sf.net/
http://jroller.com/page/dhall/

PS: Richard, I think I owe you feedback on the master/detail thread. I ducked out when the hurricanes started hitting and never really picked that one up again.