KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > content > explorer > component > UIChildrenInfo


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.portlets.content.explorer.component;
6
7 import java.util.List JavaDoc;
8 import org.exoplatform.faces.core.component.UIGrid;
9 import org.exoplatform.faces.core.component.model.*;
10 import org.exoplatform.faces.core.event.ExoActionEvent;
11 import org.exoplatform.faces.core.event.ExoActionListener;
12 import org.exoplatform.portlets.content.explorer.component.model.NodeDescriptor;
13 import org.exoplatform.commons.utils.Formater;
14 /**
15  * @email: tuan08@users.sourceforge.net
16  * @version: $Id: UIContentDisplayer.java,v 1.2 2004/08/07 18:11:26 tuan08 Exp $
17  */

18 abstract public class UIChildrenInfo extends UIGrid implements ExplorerListener {
19   private static Formater ft_ = Formater.getDefaultFormater() ;
20   
21   private NodeDescriptorDataHandler dataHandler_ ;
22   
23   public UIChildrenInfo() {
24     setClazz("UIChildrenInfo") ;
25     dataHandler_ = new NodeDescriptorDataHandler() ;
26     add(new Rows(dataHandler_, "even", "odd").
27         add(new Column("#{UIChildrenInfo.header.icon}", "icon")).
28         add(new LinkColumn("#{UIChildrenInfo.header.locale-name}", "localName", "uri").
29             addParameter(UIExplorer.CHANGE_NODE).
30             setHeaderClass("left-indent").setCellClass("left-indent")).
31         add(new Column("#{UIChildrenInfo.header.modified-date}", "modifiedDate")).
32         add(new Column("#{UIChildrenInfo.header.created-date}", "createdDate")).
33         add(new Column("#{UIChildrenInfo.header.owner}", "owner")).
34         add(new Column("#{UIChildrenInfo.header.versioning}", "versioning"))) ;
35     addActionListener(ChangeNodeActionListener.class, UIExplorer.CHANGE_NODE_ACTION) ;
36   }
37   
38   static public class NodeDescriptorDataHandler extends ListDataHandler {
39     private NodeDescriptor node ;
40     
41     public String JavaDoc getData(String JavaDoc fieldName) {
42       if("localName".equals(fieldName)) return node.getName() ;
43       if("owner".equals(fieldName)) return node.getOwner() ;
44       if("createdDate".equals(fieldName)) return ft_.format(node.getCreatedDate()) ;
45       if("modifiedDate".equals(fieldName)) return ft_.format(node.getModifiedDate()) ;
46       if("versioning".equals(fieldName)) return Boolean.toString(node.isVersioning()) ;
47       if("uri".equals(fieldName)) return node.getUri() ;
48       if("icon".equals(fieldName)) return node.getIcon() ;
49       return null ;
50     }
51     
52     public void setCurrentObject(Object JavaDoc o) { node = (NodeDescriptor) o; }
53   }
54   
55   public void onChange(UIExplorer uiExplorer, NodeDescriptor node) {
56     if(node.isLeafNode()) {
57       setRendered(false) ;
58       return ;
59     }
60     List JavaDoc children = getChildren(uiExplorer, node) ;
61     dataHandler_.setDatas(children) ;
62     node.setChildren(children) ;
63     setRendered(true) ;
64   }
65   
66   public void onModify(UIExplorer uiExplorer, NodeDescriptor node) {
67     
68   }
69   
70   public void onAddChild(UIExplorer uiExplorer, NodeDescriptor node) {
71     
72   }
73   
74   abstract protected List JavaDoc getChildren(UIExplorer uiExplorer, NodeDescriptor node) ;
75   
76   
77   static public class ChangeNodeActionListener extends ExoActionListener {
78     public void execute(ExoActionEvent event) throws Exception JavaDoc {
79       UIChildrenInfo uicomp = (UIChildrenInfo) event.getComponent() ;
80       UIExplorer uiExplorer =
81         (UIExplorer) uicomp.getAncestorOfType(UIExplorer.class) ;
82       String JavaDoc uri = event.getParameter(OBJECTID) ;
83       if("../".equals(uri)) uri = uiExplorer.getSelectNode().getParentUri() ;
84       uiExplorer.changeNode(uri);
85     }
86   }
87 }
Popular Tags