Home » Archived » Riena » Binding own structure to TreeTable
Binding own structure to TreeTable [message #505659] |
Mon, 04 January 2010 04:17  |
Eclipse User |
|
|
|
Hi there,
i'm new to Riena, i did the first steps using the tutorials and really liked it so far.
At the moment i'm trying to build a treetable that contains my own model structure (an hierarchy with 5-6 levels). I want to bind the data to the view, so that changes are updated to the model simultaneously. The "bindToModel()" method needs a certain treeElementClass, but i have a whole structure of classes to bind.
It works when i implement ITreeNode to each class of my structure and use ITreeNode.class in the bindToModel() method. But i don't like this approach since at the moment when i set up the structure i don't care if it's getting displayed or not.
Is there a better approach for that, maybe using special content providers? Are the examples somewhere?
thanks, matthias
|
|
|
Re: Binding own structure to TreeTable [message #506404 is a reply to message #505659] |
Thu, 07 January 2010 07:25   |
Eclipse User |
|
|
|
Am 04.01.10 10:17, schrieb matthias:
> Hi there,
> i'm new to Riena, i did the first steps using the tutorials and really
> liked it so far. At the moment i'm trying to build a treetable that
> contains my own model structure (an hierarchy with 5-6 levels). I want
> to bind the data to the view, so that changes are updated to the model
> simultaneously. The "bindToModel()" method needs a certain
> treeElementClass, but i have a whole structure of classes to bind.
> It works when i implement ITreeNode to each class of my structure and
> use ITreeNode.class in the bindToModel() method. But i don't like this
> approach since at the moment when i set up the structure i don't care if
> it's getting displayed or not. Is there a better approach for that,
> maybe using special content providers? Are the examples somewhere?
>
> thanks, matthias
Hi Matthias,
There are two ways I can see what you can do. Actually the bindToModel implementation does not require a ITreeNode in
its parameter list, it takes any object together with a list of properties for getting to the child node, the parent and
evaluating the visibilty etc. If you have this methods already in your own structure you could use just that.
i.e.
tree.bindToModel(treeRoot, MyStruct.class,"childred","parent","value",null,null) // the last two were enablement and
visibilty accessors that should work and create the desire effect shouldnt it ?
The second approach would be to create a TreeNode instance that wraps your own structure. You would then pass the
treeNode instance to bindToModel and subclass TreeNode to translate the methods into access to your own structure.
But I think the first approach should work for you much more better......
christian
|
|
| | |
Re: Binding own structure to TreeTable [message #506600 is a reply to message #506561] |
Fri, 08 January 2010 04:46   |
Eclipse User |
|
|
|
Hi Elias,
yes, i have different type in my model.
I reproduced my needs using a standard relation model (Teams - Players - Player's Kids).
I extended TreeNode to SampleTreeNode wrapping an object "reference" that holds the reference to the current node.
I can't attach the source file, so here's the code:
import java.util.ArrayList;
import java.util.List;
import org.eclipse.riena.beans.common.TypedComparator;
import org.eclipse.riena.navigation.ISubModuleNode;
import org.eclipse.riena.navigation.ui.controllers.SubModuleController;
import org.eclipse.riena.ui.ridgets.IActionListener;
import org.eclipse.riena.ui.ridgets.IActionRidget;
import org.eclipse.riena.ui.ridgets.IGroupedTreeTableRidget;
import org.eclipse.riena.ui.ridgets.ISelectableRidget;
import org.eclipse.riena.ui.ridgets.listener.ISelectionListener;
import org.eclipse.riena.ui.ridgets.listener.SelectionEvent;
public class SampleViewController extends SubModuleController {
private IGroupedTreeTableRidget tree;
public SampleViewController() {
}
public SampleViewController(ISubModuleNode navigationNode) {
super(navigationNode);
}
private Object[] input;
/**
* @see org.eclipse.riena.navigation.ui.controllers.SubModuleController#afterBind()
*/
@Override
public void afterBind() {
super.afterBind();
bindModel();
}
private void bindModel() {
input = createInput();
String[] columnPropertyNames = { SampleTreeNode.PROPERTY_VALUE, SampleTreeNode.PROPERTY_NOTE };
String[] columnHeaders = { "", "Note" };
tree.bindToModel(input, SampleTreeNode.class, SampleTreeNode.PROPERTY_CHILDREN, SampleTreeNode.PROPERTY_PARENT, columnPropertyNames, columnHeaders);
tree.expand(input[0]);
tree.setSelectionType(ISelectableRidget.SelectionType.SINGLE);
tree.setComparator(0, new TypedComparator<String>());
tree.setComparator(1, new TypedComparator<String>());
tree.setColumnSortable(0, false);
tree.setGroupingEnabled(false);
}
/**
* @see org.eclipse.riena.ui.ridgets.IRidgetContainer#configureRidgets()
*/
@Override
public void configureRidgets() {
tree = (IGroupedTreeTableRidget) getRidget("tree");
tree.addSelectionListener(new ISelectionListener() {
@Override
public void ridgetSelected(SelectionEvent event) {
SampleTreeNode node = (SampleTreeNode) tree.getSingleSelectionObservable().getValue();
if (node != null) {
System.out.println(node.getReference().getClass());
}
}
});
IActionRidget buttonProcessNode = ((IActionRidget) getRidget("buttonProcessNode"));
buttonProcessNode.addListener(new IActionListener() {
public void callback() {
System.out.println("ProcessNode");
}
});
}
private SampleTreeNode[] createInput() {
List<Team> teams = createTeams();
SampleTreeNode stnRoot = new SampleTreeNode("Sample Teams");
for (Team t : teams) {
SampleTreeNode stnTeam = new SampleTreeNode(stnRoot, t.getName() + " " + t.getYear());
stnTeam.setReference(t);
for (Player p : t.getPlayers()) {
SampleTreeNode stnPlayer = new SampleTreeNode(stnTeam, p.getFirstName() + " " + p.getLastName());
stnPlayer.setReference(p);
SampleTreeNode stnKids = new SampleTreeNode(stnPlayer, "Kids");
for (Kid k : p.getKids()) {
SampleTreeNode stnKid = new SampleTreeNode(stnKids, k.getName(), "Age: " + k.getAge());
stnKid.setReference(k);
}
}
}
return new SampleTreeNode[] { stnRoot };
}
private List<Team> createTeams() {
List<Team> teams = new ArrayList<Team>();
Team team = new Team("Celtics", "1985-86");
Player p = new Player("Kevin", "McHale", 21.3f, 8.1f, 2.7f);
p.add(new Kid("Kevin's Son", 4));
team.add(p);
p = new Player("Larry", "Bird", 25.8f, 9.8f, 6.8f);
p.add(new Kid("Larry's Son", 2));
team.add(p);
teams.add(team);
team = new Team("Bulls", "1995-96");
p = new Player("Michael", "Jordan", 21.3f, 8.1f, 2.7f);
team.add(p);
p = new Player("Scottie", "Pippen", 25.8f, 9.8f, 6.8f);
p.add(new Kid("Scottie's Son", 5));
p.add(new Kid("Scottie's Daughter", 7));
team.add(p);
teams.add(team);
return teams;
}
}
The model (Team - Player - Kid) isn't really bound, so when i would implement an EditingSupport e.g. to edit the Kid's name, i would need to access the reference, edit it, and rebuild my model again. That's not what i wanted to do.
thanks for your help, matthias
|
|
| | | | | | |
Re: Binding own structure to TreeTable [message #584521 is a reply to message #584514] |
Fri, 08 January 2010 04:46   |
Eclipse User |
|
|
|
Hi Elias,
yes, i have different type in my model.
I reproduced my needs using a standard relation model (Teams - Players - Player's Kids).
I extended TreeNode to SampleTreeNode wrapping an object "reference" that holds the reference to the current node.
I can't attach the source file, so here's the code:
import java.util.ArrayList;
import java.util.List;
import org.eclipse.riena.beans.common.TypedComparator;
import org.eclipse.riena.navigation.ISubModuleNode;
import org.eclipse.riena.navigation.ui.controllers.SubModuleControl ler;
import org.eclipse.riena.ui.ridgets.IActionListener;
import org.eclipse.riena.ui.ridgets.IActionRidget;
import org.eclipse.riena.ui.ridgets.IGroupedTreeTableRidget;
import org.eclipse.riena.ui.ridgets.ISelectableRidget;
import org.eclipse.riena.ui.ridgets.listener.ISelectionListener;
import org.eclipse.riena.ui.ridgets.listener.SelectionEvent;
public class SampleViewController extends SubModuleController {
private IGroupedTreeTableRidget tree;
public SampleViewController() {
}
public SampleViewController(ISubModuleNode navigationNode) {
super(navigationNode);
}
private Object[] input;
/**
* @see org.eclipse.riena.navigation.ui.controllers.SubModuleControl ler#afterBind()
*/
@Override
public void afterBind() {
super.afterBind();
bindModel();
}
private void bindModel() {
input = createInput();
String[] columnPropertyNames = { SampleTreeNode.PROPERTY_VALUE, SampleTreeNode.PROPERTY_NOTE };
String[] columnHeaders = { "", "Note" };
tree.bindToModel(input, SampleTreeNode.class, SampleTreeNode.PROPERTY_CHILDREN, SampleTreeNode.PROPERTY_PARENT, columnPropertyNames, columnHeaders);
tree.expand(input[0]);
tree.setSelectionType(ISelectableRidget.SelectionType.SINGLE );
tree.setComparator(0, new TypedComparator<String>());
tree.setComparator(1, new TypedComparator<String>());
tree.setColumnSortable(0, false);
tree.setGroupingEnabled(false);
}
/**
* @see org.eclipse.riena.ui.ridgets.IRidgetContainer#configureRidge ts()
*/
@Override
public void configureRidgets() {
tree = (IGroupedTreeTableRidget) getRidget("tree");
tree.addSelectionListener(new ISelectionListener() {
@Override
public void ridgetSelected(SelectionEvent event) {
SampleTreeNode node = (SampleTreeNode) tree.getSingleSelectionObservable().getValue();
if (node != null) {
System.out.println(node.getReference().getClass());
}
}
});
IActionRidget buttonProcessNode = ((IActionRidget) getRidget("buttonProcessNode"));
buttonProcessNode.addListener(new IActionListener() {
public void callback() {
System.out.println("ProcessNode");
}
});
}
private SampleTreeNode[] createInput() {
List<Team> teams = createTeams();
SampleTreeNode stnRoot = new SampleTreeNode("Sample Teams");
for (Team t : teams) {
SampleTreeNode stnTeam = new SampleTreeNode(stnRoot, t.getName() + " " + t.getYear());
stnTeam.setReference(t);
for (Player p : t.getPlayers()) {
SampleTreeNode stnPlayer = new SampleTreeNode(stnTeam, p.getFirstName() + " " + p.getLastName());
stnPlayer.setReference(p);
SampleTreeNode stnKids = new SampleTreeNode(stnPlayer, "Kids");
for (Kid k : p.getKids()) {
SampleTreeNode stnKid = new SampleTreeNode(stnKids, k.getName(), "Age: " + k.getAge());
stnKid.setReference(k);
}
}
}
return new SampleTreeNode[] { stnRoot };
}
private List<Team> createTeams() {
List<Team> teams = new ArrayList<Team>();
Team team = new Team("Celtics", "1985-86");
Player p = new Player("Kevin", "McHale", 21.3f, 8.1f, 2.7f);
p.add(new Kid("Kevin's Son", 4));
team.add(p);
p = new Player("Larry", "Bird", 25.8f, 9.8f, 6.8f);
p.add(new Kid("Larry's Son", 2));
team.add(p);
teams.add(team);
team = new Team("Bulls", "1995-96");
p = new Player("Michael", "Jordan", 21.3f, 8.1f, 2.7f);
team.add(p);
p = new Player("Scottie", "Pippen", 25.8f, 9.8f, 6.8f);
p.add(new Kid("Scottie's Son", 5));
p.add(new Kid("Scottie's Daughter", 7));
team.add(p);
teams.add(team);
return teams;
}
}
The model (Team - Player - Kid) isn't really bound, so when i would implement an EditingSupport e.g. to edit the Kid's name, i would need to access the reference, edit it, and rebuild my model again. That's not what i wanted to do.
thanks for your help, matthias
|
|
| | | | |
Goto Forum:
Current Time: Sun May 11 00:32:58 EDT 2025
Powered by FUDForum. Page generated in 0.07149 seconds
|