Issue Details (XML | Word | Printable)

Key: SWINGX-1304
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Won't Fix
Priority: Major Major
Assignee: kleopatra
Reporter: martinm1000
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
swingx

ColumnHighlightPredicate could take Enum as columns integers

Created: 15/Apr/10 07:19 AM   Updated: 31/Mar/11 01:32 AM   Resolved: 31/Mar/11 01:32 AM
Component/s: Highlighter
Affects Version/s: 1.6.1
Fix Version/s: 1.6.3

Time Tracking:
Not Specified

Environment:

Operating System: All
Platform: All


Issuezilla Id: 1,304
Tags:
Participants: Karl Schaefer, kleopatra and martinm1000


 Description  « Hide

From http://forums.java.net/jive/message.jspa?messageID=396995#396995

I know I'm not the only one to use Enums for the columns definition of a JXTable
(But I think there is another way to setup the columns in swingx - anyway).
Having to do ordinal() on each enum value is ugly;

Could ColumnHighlightPredicate take Enum... and call ordinal() on them
automatically ?
I think this could be a good enhancement. Also maybe elsewhere where
integers/columns are used in the package ?

Example:
Before : new ColumnHighlightPredicate(COLUMN_MILESTONE.ordinal(),
COLUMN_FINISHED.ordinal(), COLUMN_OPEN.ordinal());

After : new ColumnHighlightPredicate(COLUMN_MILESTONE, COLUMN_FINISHED,
COLUMN_OPEN);



kleopatra added a comment - 30/Mar/11 09:31 AM

well, after looking into this (had it added already it turned out that the addition is not possible without formally breaking existing code: with a second constructor taking varargs

new ColumnHighlightPredicate() wont compile

While very uncommon - no column highlighted, that is always false - it might stand in the way somewhere. Plus it doesn't look (to me like a big deal to use a convenience method like:

public static int[] createOrdinals(Enum<?>... values) {
int[] cols = new int[values.length];
for (int i = 0; i < values.length; i++) { cols[i] = values[i].ordinal(); }
return cols;
}

and then you enum-enthusiasts can use it in client code like:

new ColumnHighlightPredicate(createOrdinals(COLUMN_MILESTONE, COLUMN_FINISHED))

we could add the static method somewhere in utilities, maybe in TableUtilities?

Tend to close this issue as wontfix.

Comments please?

CU
Jeanette


Karl Schaefer added a comment - 30/Mar/11 10:13 AM

You could do:

ColumnHighlightPredicate()
ColumnHighlightPredicate(int, int...)
ColumnHighlightPredicate(Enum, Enum...)

It would break existing code for people that did not use varargs notation in constructing the ColumnHighlightPredicate, such as:
new ColumnHighlightPredicate(new int[] {1, 2, 3, 4,})

But who does that with ints?

Karl


kleopatra added a comment - 30/Mar/11 12:46 PM

Without actually trying looks like: each and every code which constructs the array of ints somehow, such as

int[] columnsToHighlight = lookupColumnsFor(myTable)
new ColumnHighlightPredicate(columnsToHighlight);

Don't think your suggestion is an option - it changes existing signature in a backward breaking manner. Nothing I want to do, especially not if it doesn't buy very much.

Thanks anyway - always good to see your brain chunk out approaches I didn't think of

Cheers
Jeanette


kleopatra added a comment - 31/Mar/11 01:31 AM

closing as wontfix. Added convenience method to TableUtilities