Skip to main content

Ho to react on selection in Tree

4 replies [Last post]
are
Offline
Joined: 2008-05-13
Points: 0

Hi,

with the interpreter, I derived a class MyTreeCell from TreeCell, that held a bridge for the selection.

But now the compiler fails to accept anything else then a TreeCell, even if MyTreeCell extends TreeCell directly. I assume, it's just another bug.

But question now is: how I can work around to get the selection and it's change in Trees?

Best regards!
are

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alexsch
Offline
Joined: 2007-07-12
Points: 0

Could you post an example of MyTreeCell class usage?
It helps to find out an appropriate workaround.

are
Offline
Joined: 2008-05-13
Points: 0

[code]
class SelectModel {
attribute selectedTreeCell:MyTreeCell on replace {
doSomething();
}
}

class MyTreeCell extends TreeCell {
attribute selectModel:SelectModel;
override attribute selected on replace {
if (selected==true) {
selectModel.selectedTreeCell=this;
}
};
}

var selectModel=SelectModel{};
var rootTreeCell:MyTreeCell {
selectModel: selectModel
};
var tree=Tree {
root: bind rootTreeCell
};
[/code]

Thanks for your kind assistance!
are

alexsch
Offline
Joined: 2007-07-12
Points: 0

I think it is not the best idea, but you can use TreeCell value attribute to keep your model:

[code]
import javafx.ui.*;
import javafx.ui.canvas.*;
import java.lang.System;

class SelectModel {
public attribute value: java.lang.Object ;
public attribute action: function() ;

}

var selectModel=SelectModel{
action: function(){
System.out.println("Do something.");
}
};

var treeSelectedValue: java.lang.Object on replace{
System.out.println("tree cell: {treeSelectedValue.getClass().getName()}");
if(treeSelectedValue <> null){
var model = (treeSelectedValue as TreeCell).value;
if (model <> null and model instanceof SelectModel){
(model as SelectModel).action();
}
}
}

Frame{
title: "Hello World!"
content: Tree{
root: TreeCell{
text: "Root Node"
value: selectModel
cells: [
TreeCell {
text: "food"
value: selectModel
cells:
[TreeCell {
text: "hot dogs"
value: selectModel
},
TreeCell {
text: "pizza"
value: selectModel
},
TreeCell {
text: "ravioli"
value: selectModel
}]
}]
}
selectedValue: bind treeSelectedValue with inverse
}
visible: true
}
[/code]

are
Offline
Joined: 2008-05-13
Points: 0

this code is awfull! I thougt, JavaFX should make things easier, not even more complicated!

Nevermind! Alex, thank you so much! It works and I can use this example until a stable, full featured compiler arrives!

Best regards
are