Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Riena » Binding own structure to TreeTable
Binding own structure to TreeTable [message #505659] Mon, 04 January 2010 09:17 Go to next message
Matthias is currently offline MatthiasFriend
Messages: 52
Registered: September 2009
Member
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 12:25 Go to previous messageGo to next message
Christian Campo is currently offline Christian CampoFriend
Messages: 597
Registered: July 2009
Senior Member
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 #506439 is a reply to message #506404] Thu, 07 January 2010 09:35 Go to previous messageGo to next message
Matthias is currently offline MatthiasFriend
Messages: 52
Registered: September 2009
Member
Hi Christian,

thanks for your reply.
The problem with your first approach is that with bindToModel() "It is assumed that the rootElement and all children are of the same type", but i have different properties for child, parents, etc. throughout my structure levels.
BTW: The bindToModel method with enablement and
visibilty accessors somehow doesn't allow me to set different columnheaders.

I tried to implement your second approach (wrapping). I extended TreeNode and added a reference property that holds the current structure level. It's not very elegant and i don't know if that's what you've meant. Is there a snippet/sample/documentation somewhere?

matthias
Re: Binding own structure to TreeTable [message #506561 is a reply to message #506439] Fri, 08 January 2010 00:35 Go to previous messageGo to next message
Elias Volanakis is currently offline Elias VolanakisFriend
Messages: 26
Registered: July 2009
Junior Member
Hi Matthias,

from the previous messages I understand that you have different types in your tree model, that don't share any common subclass.

In that case I would implement a ITreeNode wrapper that can deal with all the different types. The methods would use instanceof to determine the type and the act accordingly.

To be frank we don't have an example for this, since all our examples only use one type of element (i.e. WordNode, TreeNode, etc).

If you need more help, it would be useful to post some example code, so we can discuss this in more detail and maybe provide a snippet for your use case.

Kind regards,
Elias.


Elias Volanakis | http://eclipsesource.com
elias (AT) eclipsesource.com | @evolanakis
Re: Binding own structure to TreeTable [message #506600 is a reply to message #506561] Fri, 08 January 2010 09:46 Go to previous messageGo to next message
Matthias is currently offline MatthiasFriend
Messages: 52
Registered: September 2009
Member
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 #507092 is a reply to message #506600] Tue, 12 January 2010 07:01 Go to previous messageGo to next message
Elias Volanakis is currently offline Elias VolanakisFriend
Messages: 26
Registered: July 2009
Junior Member
Hi Matthias,

if possible, it would help a lot if you can post a standalone example (or a link to a .zip file containing all necessary files). Otherwise I will have to spend quite a bit of time recreating the missing pieces.

If you use a standalone news reader (i.e. thunderbird) you should be able to attach files to your post.

Thanks,
Elias.


Elias Volanakis | http://eclipsesource.com
elias (AT) eclipsesource.com | @evolanakis
Re: Binding own structure to TreeTable [message #507141 is a reply to message #507092] Tue, 12 January 2010 09:59 Go to previous messageGo to next message
Matthias is currently offline MatthiasFriend
Messages: 52
Registered: September 2009
Member
good morning, i created the standalone project. i can't use thunderbird here, due to proxy restrictions. is there another way to attach the file? can pm you the file? then you could post it here.

matthias
Re: Binding own structure to TreeTable [message #507277 is a reply to message #507141] Tue, 12 January 2010 17:41 Go to previous messageGo to next message
Elias Volanakis is currently offline Elias VolanakisFriend
Messages: 26
Registered: July 2009
Junior Member
Hi Matthias,

I suggesting making this available via a bugzilla attachment. Remember to paste your previous post into the description, so we remember what this was about.

https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Riena

Elias.


Elias Volanakis | http://eclipsesource.com
elias (AT) eclipsesource.com | @evolanakis
Re: Binding own structure to TreeTable [message #507365 is a reply to message #507277] Wed, 13 January 2010 07:12 Go to previous messageGo to next message
Matthias is currently offline MatthiasFriend
Messages: 52
Registered: September 2009
Member
ok, i hope i did everything fine

please see:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=299464
Re: Binding own structure to TreeTable [message #584479 is a reply to message #506404] Thu, 07 January 2010 09:35 Go to previous messageGo to next message
Matthias is currently offline MatthiasFriend
Messages: 52
Registered: September 2009
Member
Hi Christian,

thanks for your reply.
The problem with your first approach is that with bindToModel() "It is assumed that the rootElement and all children are of the same type", but i have different properties for child, parents, etc. throughout my structure levels.
BTW: The bindToModel method with enablement and
visibilty accessors somehow doesn't allow me to set different columnheaders.

I tried to implement your second approach (wrapping). I extended TreeNode and added a reference property that holds the current structure level. It's not very elegant and i don't know if that's what you've meant. Is there a snippet/sample/documentation somewhere?

matthias
Re: Binding own structure to TreeTable [message #584514 is a reply to message #584479] Fri, 08 January 2010 00:35 Go to previous messageGo to next message
Elias Volanakis is currently offline Elias VolanakisFriend
Messages: 26
Registered: July 2009
Junior Member
Hi Matthias,

from the previous messages I understand that you have different types in your tree model, that don't share any common subclass.

In that case I would implement a ITreeNode wrapper that can deal with all the different types. The methods would use instanceof to determine the type and the act accordingly.

To be frank we don't have an example for this, since all our examples only use one type of element (i.e. WordNode, TreeNode, etc).

If you need more help, it would be useful to post some example code, so we can discuss this in more detail and maybe provide a snippet for your use case.

Kind regards,
Elias.
--
--
Elias Volanakis | http://eclipsesource.com
elias (AT) eclipsesource.com | @evolanakis


Elias Volanakis | http://eclipsesource.com
elias (AT) eclipsesource.com | @evolanakis
Re: Binding own structure to TreeTable [message #584521 is a reply to message #584514] Fri, 08 January 2010 09:46 Go to previous messageGo to next message
Matthias is currently offline MatthiasFriend
Messages: 52
Registered: September 2009
Member
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
Re: Binding own structure to TreeTable [message #584567 is a reply to message #584521] Tue, 12 January 2010 07:01 Go to previous messageGo to next message
Elias Volanakis is currently offline Elias VolanakisFriend
Messages: 26
Registered: July 2009
Junior Member
Hi Matthias,

if possible, it would help a lot if you can post a standalone example (or a link to a .zip file containing all necessary files). Otherwise I will have to spend quite a bit of time recreating the missing pieces.

If you use a standalone news reader (i.e. thunderbird) you should be able to attach files to your post.

Thanks,
Elias.
--
Elias Volanakis | http://eclipsesource.com
elias (AT) eclipsesource.com | @evolanakis


Elias Volanakis | http://eclipsesource.com
elias (AT) eclipsesource.com | @evolanakis
Re: Binding own structure to TreeTable [message #584581 is a reply to message #584567] Tue, 12 January 2010 09:59 Go to previous messageGo to next message
Matthias is currently offline MatthiasFriend
Messages: 52
Registered: September 2009
Member
good morning, i created the standalone project. i can't use thunderbird here, due to proxy restrictions. is there another way to attach the file? can pm you the file? then you could post it here.

matthias
Re: Binding own structure to TreeTable [message #584597 is a reply to message #507141] Tue, 12 January 2010 17:41 Go to previous messageGo to next message
Elias Volanakis is currently offline Elias VolanakisFriend
Messages: 26
Registered: July 2009
Junior Member
Hi Matthias,

I suggesting making this available via a bugzilla attachment. Remember to paste your previous post into the description, so we remember what this was about.

https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Riena

Elias.

--
Elias Volanakis | http://eclipsesource.com
elias (AT) eclipsesource.com | @evolanakis


Elias Volanakis | http://eclipsesource.com
elias (AT) eclipsesource.com | @evolanakis
Re: Binding own structure to TreeTable [message #584613 is a reply to message #584597] Wed, 13 January 2010 07:12 Go to previous message
Matthias is currently offline MatthiasFriend
Messages: 52
Registered: September 2009
Member
ok, i hope i did everything fine

please see:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=299464
Previous Topic:Riena on Windows 7
Next Topic:Improved wiki pages
Goto Forum:
  


Current Time: Thu Apr 25 10:06:03 GMT 2024

Powered by FUDForum. Page generated in 0.04224 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top