Author: glandais Date: 2008-03-12 17:04:16 +0000 (Wed, 12 Mar 2008) New Revision: 1318 Modified: trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/GroupList.java trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/GroupList.tml Log: Display group hierarchy Modified: trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/GroupList.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/GroupList.java 2008-03-12 17:03:51 UTC (rev 1317) +++ trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/GroupList.java 2008-03-12 17:04:16 UTC (rev 1318) @@ -17,12 +17,19 @@ * ##% */ package fr.cemagref.simexplorer.is.ui.web.pages; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.apache.tapestry.ComponentResources; +import org.apache.tapestry.Link; import org.apache.tapestry.annotations.InjectPage; import org.apache.tapestry.annotations.Retain; import org.apache.tapestry.beaneditor.BeanModel; import org.apache.tapestry.ioc.annotations.Inject; import org.apache.tapestry.services.BeanModelSource; +import org.codelutin.tapestry.beans.TreeNode; import de.hsofttec.t5components.annotations.SetterGetter; import fr.cemagref.simexplorer.is.exceptions.SimExplorerException; @@ -76,7 +83,7 @@ * Gets the groups. * * @return the groups - * @throws SimExplorerException + * @throws SimExplorerException */ public Group[] getGroups() throws SimExplorerException { Group[] groups; @@ -96,7 +103,7 @@ * @param context the context * * @return the object - * @throws SimExplorerException + * @throws SimExplorerException */ public Object onActionFromDelete(Integer context) throws SimExplorerException { RemoteSecurityService.getAuthentificationService().deleteGroup(getToken(), context); @@ -117,10 +124,23 @@ } /** + * On edit. + * + * @param context the context + * + * @return the object + * + * @throws SimExplorerException the sim explorer exception + */ + public Object onEdit(Integer context) throws SimExplorerException { + return onActionFromEdit(context); + } + + /** * On action from add. * * @return the object - * @throws SimExplorerException + * @throws SimExplorerException */ public Object onActionFromAdd() throws SimExplorerException { groupEdit.setup(-1); @@ -154,4 +174,84 @@ this.groupEdit = groupEdit; } + /** + * Builds the node. + * + * @param group the group + * + * @return the tree node + */ + private TreeNode buildNode(Group group) { + TreeNode node = new TreeNode(); + + List<Group> children = group.getGroups(); + if (children.size() == 0) { + node.setType(TreeNode.TYPE_DOCUMENT); + } else { + node.setType(TreeNode.TYPE_FOLDER); + List<TreeNode> childrenNodes = new ArrayList<TreeNode>(); + for (Group child : children) { + childrenNodes.add(buildNode(child)); + } + node.setChildren(childrenNodes); + } + + Link link = getResources().createActionLink("edit", false, group.getId()); + StringBuffer sb = new StringBuffer(""); + sb.append("<a href=\""); + sb.append(link.toString()); + sb.append("\">"); + sb.append(getMessages().get("simexplorer.ui.web.modify")); + sb.append("</a>"); + + node.setColumns(new String[] { group.getName(), sb.toString() }); + + node.setObject(group); + + return node; + } + + /** + * Gets the group nodes. + * + * @return the group nodes + * + * @throws SimExplorerException the sim explorer exception + */ + public List<TreeNode> getGroupNodes() throws SimExplorerException { + List<TreeNode> nodes = new ArrayList<TreeNode>(); + + Map<Group, Integer> usage = new HashMap<Group, Integer>(); + Group[] groups = getGroups(); + for (Group group : groups) { + usage.put(group, 0); + } + for (Group group : groups) { + List<Group> children = group.getGroups(); + for (Group child : children) { + usage.put(child, usage.get(child) + 1); + } + } + + for (Group group : groups) { + if (usage.get(group).equals(0)) { + nodes.add(buildNode(group)); + } + } + + return nodes; + } + + /** + * Gets the group headers. + * + * @return the group headers + */ + public List<String> getGroupHeaders() { + List<String> result = new ArrayList<String>(); + result.add(getMessages().get("simexplorer.ui.web.name")); + result.add(getMessages().get("simexplorer.ui.web.title.groupedit")); + return result; + } + } Modified: trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/GroupList.tml =================================================================== --- trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/GroupList.tml 2008-03-12 17:03:51 UTC (rev 1317) +++ trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/GroupList.tml 2008-03-12 17:04:16 UTC (rev 1318) @@ -13,4 +13,10 @@ </p> <p><t:actionlink t:id="add">${message:simexplorer.ui.web.addgroup}</t:actionlink></p> + <p>${message:simexplorer.ui.web.groupHierarchy} :</p> + <table t:type="cl/TreeGrid" source="groupNodes" + columnHeaders="groupHeaders"> + </table> + + </t:layout>