Hi Etienne,
thanks for the quick answer. I've tried to implement my TreeModel
as shown in your sample, but it won't work. The problem is, that
if the getRoot()or getChild() method returns a string instead of
original object the Tree won't be built. In the getChildCount
method I need the parent as original object to return number of
childs.
Any suggestions?
Kind Regards
Florian
public class DecoratedTreeModel extends AbstractTreeModel {
private ITreeModel fDecoratee;
private IValueRenderer fRenderer;
public DecoratedTreeModel(ITreeModel decoratee,
IValueRenderer renderer) {
fDecoratee = decoratee;
fRenderer = renderer;
}
public Object getRoot() {
Object rawValue = fDecoratee.getRoot();
Object renderedValue = fRenderer.render(rawValue);
return renderedValue;
}
public Object getChild(Object parent, int index) {
Object rawValue = fDecoratee.getChild(parent,index);
Object renderedValue = fRenderer.render(rawValue);
return renderedValue;
}
public int getChildCount(Object parent) {
return fDecoratee.getChildCount(parent);
}
public boolean isLeaf(Object node) {
return fDecoratee.isLeaf(node);
}
public int getIndexOfChild(Object parent, Object child) {
return fDecoratee.getIndexOfChild(parent,child);
}
public ITreeModel getDecoratee() {
return fDecoratee;
}
public static interface IValueRenderer {
Object render(Object inRawValue);
}
}
private ULCTree getTrvStructure() {
if (trvStructure == null) {
trvStructure = new ULCTree();
trvStructure.setShowsRootHandles(true);
trvStructure.setModel(new DecoratedTreeModel
(getPackageDetailModel(),
new TreeValueRenderer()));
}
return trvStructure;
}
public static class TreeValueRenderer
implements DecoratedTreeModel.IValueRenderer {
public Object render(Object inRawValue) {
String valueString = "";
if (inRawValue instanceof GeneralPackageBean){
valueString = "Package";
System.out.println(valueString);
}else{ if(inRawValue instanceof HeadRecordDK){
valueString = "DK Headrecord";
System.out.println(valueString);
}}
return valueString;
}
}
Hi Florian
This might help...
http://www.jroller.com/page/ulc/?anchor=renderer_limitations
Etienne
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
Sent: Wednesday, November 15, 2006 6:18 AM
To: [email protected]
Subject: [ULC-developer] ITreeCellRenderer: setText()
Hi,
I'm trying to implement a ITreeCellRenderer for my ULCTree, but i
cannot set the text for the items.
The displayed text near every node seems to be the result of
object.toString()...
Here is the code:
private ITreeCellRenderer createTreeCellRenderer() {
DefaultTreeCellRenderer treeCellRenderer =
new DefaultTreeCellRenderer() {
public IRendererComponent
getTreeCellRendererComponent(
ULCTree tree, Object value, boolean selected,
boolean expanded, boolean leaf, boolean
hasFocus){
if (value instanceof GeneralPackageBean){
setClosedIcon(closedPackage);
setLeafIcon(closedPackage);
setOpenIcon(openPackage);
setText("package");
}else{ if(value instanceof HeadRecordDK){
setClosedIcon(headRecordDK);
setLeafIcon(headRecordDK);
setOpenIcon(headRecordDK);
setText("head record");
}}
return super.getTreeCellRendererComponent(tree,
value, selected, expanded, leaf, hasFocus);
}
};
return treeCellRenderer;
}
However, in the mailing list archive I found a post from June
2005 concerning this issue.
http://lists.canoo.com/mailman/private/ulc-developer/2005/002383.html
But the posted workaround won't work with my TreeModel.
Is there any other solution since ULC 6.1?
Freundliche Grüße /Best Regards
Florian Mair
DACHSER GmbH & Co. KG
Hauptniederlassung / Head Office
IT, Finance, Administration and Personnel (IFAP) Team EDI
Memminger Str. 140
87439 Kempten
mailto:[EMAIL PROTECTED]
http://www.dachser.com
_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer
_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer
_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer