Skip to main content

JXTreeTable and sorting in subclasses

8 replies [Last post]
uvoigt
Offline
Joined: 2006-01-26
Points: 0

I started to try the sorting feature for a JXTreeTable implemented by user rturnbull (see .. cannot post ...).

rturnbull rewrote the whole component JXTreeTable which I don't like. I just want to create a subcomponent JXSortableTreeTable which overrides some methods to implement the sorting. The problem is that the setSortable, setRowSorter etc. methods in JXTreeTable are empty and I cannot call these methods of JXTable from my subclass.

Is it possible to apply the following patch so that subclasses of JXTreeTable are able to call the JXTable sort methods?

Thanks

Uli

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
Points: 0

Hi Uli,
very reluctant to do so ... though I see your problem ... hmm .... Most probably wouldn't support a per-clientProperty setting (developers need to be protected from themselves <g>), but might decide for a protected method with a hard-coded false which subclasses might override (at their own risk, and strongly documented against doing it, of course ;-)
Anyway, would you please file an issue so I'm forced to make up my mind? Please add a link to this thread
Thanks
Jeanette

kleopatra
Offline
Joined: 2003-06-11
Points: 0

decided against both clientProperty and some single method to turn on the sorting - both
are not safe enough, IMO. Instead, added protected methods to access respective super
methods. Thus subclasses have explicitly re-implement the respective no-ops implementations
in JXTreeTable. Hope that's repellent enough for any hobby adventurer ;-)

committed as of revision #3915, JXTreeTableUnitTest has a (fake! no real sorting) example
of how to override

Cheers
Jeanette

uvoigt
Offline
Joined: 2006-01-26
Points: 0

Thanks for the quick fix!
Uli

kschaefe
Offline
Joined: 2006-06-08
Points: 0

I opened this exact bug a long time ago. We went nowhere with it and I closed it, pending the results of Mustang integration.
https://swingx.dev.java.net/issues/show_bug.cgi?id=479
Karl

uvoigt
Offline
Joined: 2006-01-26
Points: 0

Thanks Karl!
I have reopened this bug. I am looking forward that we can make it easier to implement a special sorting behaviour for JXTreeTable.

Thanks!
Uli
P.S.: By the way: don't wonder if your posts are rejected if you use the word speciali-sed (withouth hyphen). It contains the blocked word ciali-s....

uvoigt
Offline
Joined: 2006-01-26
Points: 0

Here is the patch:

Index: swingx-core/src/main/java/org/jdesktop/swingx/JXTreeTable.java
===================================================================
--- swingx-core/src/main/java/org/jdesktop/swingx/JXTreeTable.java (revision 3908)
+++ swingx-core/src/main/java/org/jdesktop/swingx/JXTreeTable.java (working copy)
@@ -130,6 +130,9 @@
* Key for clientProperty to decide whether to apply hack around #766-swingx.
*/
public static final String DROP_HACK_FLAG_KEY = "treeTable.dropHackFlag";
+
+ public static final String SORT_HACK_FLAG_KEY = "treeTable.sortHackFlag";
+
/**
* Renderer used to render cells within the
* {@link #isHierarchical(int) hierarchical} column.
@@ -278,9 +281,14 @@
*/
@Override
public void setSortable(boolean sortable) {
- // no-op
+ if (shouldApplySortHack()) {
+ super.setSortable(sortable);
+ }
}

+ protected boolean shouldApplySortHack() {
+ return !Boolean.FALSE.equals(getClientProperty(SORT_HACK_FLAG_KEY));
+ }

/**
@@ -294,6 +302,9 @@
*/
@Override
public void setAutoCreateRowSorter(boolean autoCreateRowSorter) {
+ if (shouldApplySortHack()) {
+ super.setAutoCreateRowSorter(autoCreateRowSorter);
+ }
}

/**
@@ -307,6 +318,9 @@
*/
@Override
public void setRowSorter(RowSorter<? extends TableModel> sorter) {
+ if (shouldApplySortHack()) {
+ super.setRowSorter(sorter);
+ }
}

/**
@@ -2612,7 +2626,7 @@
protected boolean shouldApplyDropHack() {
return !Boolean.FALSE.equals(treeTable.getClientProperty(DROP_HACK_FLAG_KEY));
}
-
+

/**
* Hack around #297-swingx: tooltips shown at wrong row.

uvoigt
Offline
Joined: 2006-01-26
Points: 0
programmer_1
Offline
Joined: 2011-10-26
Points: 0

<And here is the missing URL: http://www.java.net/forum/topic/javadesktop/java-desktop-technologies/sw...>

"PAGE NOT FOUND"