From 9935a77bfb62657dad26b1f565d0ee0243376514 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Fri, 13 Jun 2014 16:26:24 +0200 Subject: [PATCH] =?UTF-8?q?Zobrazovan=C3=AD=20st=C5=99edisek=20a=20pracovn?= =?UTF-8?q?=C3=ADch=20skupin=20ve=20stromov=C3=A9=20struktu=C5=99e.=20refs?= =?UTF-8?q?=20#97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../isspst/ui/workgroups/WorkgroupList.java | 19 ++++++++++ .../ui/workgroups/WorkgroupTreeFactory.java | 38 +++++++++++++++++++ .../ui/workgroups/WorkgroupTreeNode.java | 25 ++++++++++++ src/main/webapp/workgroups/workgroups.zul | 16 ++++++++ 4 files changed, 98 insertions(+) create mode 100644 src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupTreeFactory.java create mode 100644 src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupTreeNode.java diff --git a/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupList.java b/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupList.java index 30e21a54..6376aa95 100644 --- a/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupList.java +++ b/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupList.java @@ -1,8 +1,12 @@ package info.bukova.isspst.ui.workgroups; import org.zkoss.bind.annotation.Init; +import org.zkoss.bind.annotation.NotifyChange; import org.zkoss.zk.ui.select.annotation.WireVariable; +import org.zkoss.zul.TreeModel; +import org.zkoss.zul.TreeNode; +import info.bukova.isspst.data.Member; import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.services.workgroups.WorkgroupService; import info.bukova.isspst.ui.ListViewModel; @@ -11,12 +15,27 @@ public class WorkgroupList extends ListViewModel { @WireVariable private WorkgroupService workgroupService; + private WorkgroupTreeFactory treeFactory; @Init public void init() { service = workgroupService; dataClass = Workgroup.class; formZul = "workgroupForm.zul"; + treeFactory = new WorkgroupTreeFactory(); + } + + public TreeModel> getWorkgroupTreeModel() { + if (getDataBean() != null) { + return treeFactory.createTreeModel(getDataBean()); + } + + return null; + } + + @NotifyChange({"dataBean", "workgroupTreeModel"}) + public void setDataBean(Workgroup data) { + super.setDataBean(data); } } diff --git a/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupTreeFactory.java b/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupTreeFactory.java new file mode 100644 index 00000000..8538b8fd --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupTreeFactory.java @@ -0,0 +1,38 @@ +package info.bukova.isspst.ui.workgroups; + +import java.util.Collection; +import java.util.LinkedList; + +import info.bukova.isspst.Constants; +import info.bukova.isspst.data.JobMapping; +import info.bukova.isspst.data.Member; +import info.bukova.isspst.data.Workgroup; + +import org.zkoss.zul.DefaultTreeModel; +import org.zkoss.zul.TreeModel; +import org.zkoss.zul.TreeNode; + +public class WorkgroupTreeFactory { + + public TreeModel> createTreeModel(Workgroup workgroup) { + WorkgroupTreeNode root = new WorkgroupTreeNode(null, generateChildren(workgroup)); + + return new DefaultTreeModel(root); + } + + private Collection generateChildren(Member member) { + Collection children = new LinkedList(); + Workgroup workgroup = Workgroup.class.cast(member); + + for (JobMapping jm : workgroup.getMembers()) { + if (jm.getRole().getAuthority().equals(Constants.ROLE_USER) && jm.getMember().isHasJob()) { + children.add(new WorkgroupTreeNode(jm.getMember())); + } else if (jm.getRole().getAuthority().equals(Constants.ROLE_USER)) { + children.add(new WorkgroupTreeNode(jm.getMember(), generateChildren(jm.getMember()))); + } + } + + return children; + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupTreeNode.java b/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupTreeNode.java new file mode 100644 index 00000000..70278b6b --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupTreeNode.java @@ -0,0 +1,25 @@ +package info.bukova.isspst.ui.workgroups; + +import info.bukova.isspst.data.Member; + +import java.util.Collection; + +import org.zkoss.zul.DefaultTreeNode; + +public class WorkgroupTreeNode extends DefaultTreeNode { + + /** + * + */ + private static final long serialVersionUID = 465182942358883559L; + + public WorkgroupTreeNode(Member data, + Collection children) { + super(data, children); + } + + public WorkgroupTreeNode(Member data) { + super(data); + } + +} diff --git a/src/main/webapp/workgroups/workgroups.zul b/src/main/webapp/workgroups/workgroups.zul index fa085765..878bddd8 100644 --- a/src/main/webapp/workgroups/workgroups.zul +++ b/src/main/webapp/workgroups/workgroups.zul @@ -55,6 +55,22 @@ + + + + + + + + + +