0

tree checkmark true and mutiple true

asked 2012-07-06 11:14:15 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Hi

The problem in the below code is even though i set checkmark = true and multiple = true, but still shows like radio button only. i,e single selection.
I want to make as per the demo
http://www.zkoss.org/zkdemo/tree/multiple_selection


Here is the code.

Zul File

<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>
<zk>
<div id="treeDiv" apply="mypack.TreeComposer">
  <label id="lbl" />
    <tree id="treeGrid" checkmark="true" multiple="true" width="550px" model="@{treeDiv$composer.treeModel}" treeitemRenderer="@{treeDiv$composer.treeRenderer}">
        <treecols>
            <treecol width="200px" label="Path" />
            <treecol width="350px" label="Description" />
        </treecols>
    </tree>
</div>
</zk>


composer

package mypack;

import java.util.ArrayList;
import java.util.List;

import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.DefaultTreeModel;
import org.zkoss.zul.DefaultTreeNode;
import org.zkoss.zul.Div;
import org.zkoss.zul.Label;
import org.zkoss.zul.Tree;
import org.zkoss.zul.Treecell;
import org.zkoss.zul.Treeitem;
import org.zkoss.zul.TreeitemRenderer;
import org.zkoss.zul.Treerow;
public class TreeComposer extends GenericForwardComposer<Div> {

  private Label lbl;
	public void doAfterCompose(Div comp) throws Exception {
		super.doAfterCompose(comp);
	}
	
	public void onInitModel$treeGrid() {
		lbl.setValue(lbl.getValue() + "onInitModel/");
	}

	public void onInitRender$treeGrid() {
		lbl.setValue(lbl.getValue() + "onInitRender/");
	}
	
	public DefaultTreeModel<FileInfo> getTreeModel() {
		return new DefaultTreeModel<FileInfo>(getFileInfoTreeData());
	}
	
	public FileInfoRenderer getTreeRenderer() {
		return new FileInfoRenderer();
	}
	
	private DefaultTreeNode<FileInfo> getFileInfoTreeData() {
		List<DefaultTreeNode<FileInfo>> inner3 = new ArrayList<DefaultTreeNode<FileInfo>>();
		inner3.add(new DefaultTreeNode<FileInfo>(new FileInfo("zcommon.jar", "ZK Common Library")));
		inner3.add(new DefaultTreeNode<FileInfo>(new FileInfo("zk.jar", "ZK Core Library")));
		
		List<DefaultTreeNode<FileInfo>> inner2 = new ArrayList<DefaultTreeNode<FileInfo>>();
		inner2.add(new DefaultTreeNode<FileInfo>(new FileInfo("/lib", "ZK Libraries"), inner3));
		inner2.add(new DefaultTreeNode<FileInfo>(new FileInfo("/src", "Source Code")));
		inner2.add(new DefaultTreeNode<FileInfo>(new FileInfo("/xsd", "XSD Files")));
		
		List<DefaultTreeNode<FileInfo>> inner1 = new ArrayList<DefaultTreeNode<FileInfo>>();
		inner1.add(new DefaultTreeNode<FileInfo>(new FileInfo("/doc", "Release and License Notes")));
		inner1.add(new DefaultTreeNode<FileInfo>(new FileInfo("/dist", "Distribution"), inner2));
		
		

		return new DefaultTreeNode<FileInfo>(null, inner1);
	}
	
	public class FileInfoRenderer implements TreeitemRenderer<DefaultTreeNode<FileInfo>> {

		public void render(final Treeitem item, DefaultTreeNode<FileInfo> data, int index) throws Exception {
			item.setValue(data);
			final FileInfo fi = data.getData();
			item.setOpen(true);
			//for update treeNode data
			Treerow tr = item.getTreerow();
			if(tr == null) {
				tr = new Treerow();
			} else {
				tr.getChildren().clear();
			}
			item.appendChild(tr);
			//render file path cell
			item.setCheckable(true);

			Treecell pathCell = new Treecell();
			pathCell.setLabel(fi.getPath());
			pathCell.setParent(tr);
			//render file description cell
			Treecell descriptionCell = new Treecell();
			descriptionCell.setLabel(fi.getDescription());
			descriptionCell.setParent(tr);
		}
	}
	
	public class FileInfo {
		private String path;
		private String description;

		public FileInfo() {}
		
		public FileInfo(String path, String description) {
			this.path = path;
			this.description = description;
		}

		public String getPath() {
			return path;
		}

		public void setPath(String path) {
			this.path = path;
		}

		public String getDescription() {
			return description;
		}

		public void setDescription(String description) {
			this.description = description;
		}
	}
}

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2012-07-07 17:35:04 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Please help

link publish delete flag offensive edit

answered 2012-07-23 16:28:13 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Can someone please help me in this......................

link publish delete flag offensive edit

answered 2012-07-23 16:33:36 +0800

gekkio gravatar image gekkio flag of Finland
899 1
http://gekkio.fi/blog

If you use DefaultTreeModel, you must set the multiple flag in the model, not in the tree component:

public DefaultTreeModel<FileInfo> getTreeModel() {
  DefaultTreeModel<FileInfo> model = new DefaultTreeModel<FileInfo>(getFileInfoTreeData());
  model.setMultiple(true);
  return model;
}

link publish delete flag offensive edit

answered 2012-07-23 17:14:02 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Thanks a lot.............. Do you have some example for the same in mvvm

link publish delete flag offensive edit

answered 2019-08-20 21:47:55 +0800

kellycasma gravatar image kellycasma
0

Muchas Gracias!

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2012-07-06 11:14:15 +0800

Seen: 208 times

Last updated: Aug 20 '19

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More