[SWINGX-1304] ColumnHighlightPredicate could take Enum as columns integers Created: 15/Apr/10  Updated: 31/Mar/11  Resolved: 31/Mar/11

Status: Resolved
Project: swingx
Component/s: Highlighter
Affects Version/s: 1.6.1
Fix Version/s: 1.6.3

Type: Improvement Priority: Major
Reporter: martinm1000 Assignee: kleopatra
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: 0 minutes
Time Spent: Not Specified
Original Estimate: 0 minutes
Environment:

Operating System: All
Platform: All


Issuezilla Id: 1,304

 Description   

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);



 Comments   
Comment by kleopatra [ 30/Mar/11 ]

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

Comment by Karl Schaefer [ 30/Mar/11 ]

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

Comment by kleopatra [ 30/Mar/11 ]

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

Comment by kleopatra [ 31/Mar/11 ]

closing as wontfix. Added convenience method to TableUtilities

Generated at Mon Aug 31 14:36:01 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.