KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.File JavaDoc;
8 import org.exoplatform.faces.application.ExoFacesMessage;
9 import org.exoplatform.faces.core.component.InformationProvider;
10 import org.exoplatform.faces.core.component.UIGrid;
11 import org.exoplatform.faces.core.component.model.*;
12 import org.exoplatform.faces.core.event.ExoActionEvent;
13 import org.exoplatform.faces.core.event.ExoActionListener;
14 import org.exoplatform.portlets.content.explorer.component.model.NodeDescriptor;
15 /**
16  * @email: tuan08@users.sourceforge.net
17  * @version: $Id: UIContentDisplayer.java,v 1.2 2004/08/07 18:11:26 tuan08 Exp $
18  */

19 public class UIFileNodeInfo extends UIGrid implements ExplorerListener {
20   private static Parameter[] DELETE_PARAMS = {new Parameter(ACTION, DELETE_ACTION)} ;
21   
22   private Cell parentURI_ = new Cell("") ;
23   private Cell name_ = new Cell("") ;
24   private Cell type_ = new Cell("") ;
25   private Cell owner_ = new Cell("") ;
26   
27   public UIFileNodeInfo() {
28     add(new HeaderRow().
29         add(new LabelCell("#{UIFileNodeInfo.header.property}")).
30         add(new LabelCell("#{UIFileNodeInfo.header.value}")));
31     add(new Row().
32         add(new LabelCell("#{UIFileNodeInfo.label.parent-uri}")).add(parentURI_).setClazz("even"));
33     add(new Row().
34         add(new LabelCell("#{UIFileNodeInfo.label.local-name}")).add(name_).setClazz("odd"));
35     add(new Row().
36         add(new LabelCell("#{UIFileNodeInfo.label.type}")).add(type_).setClazz("even"));
37     add(new Row().
38         add(new LabelCell("#{UIFileNodeInfo.label.owner}")).add(owner_).setClazz("odd"));
39     add(new Row().
40         add(new ActionCell().
41             add(new Button("#{UIFileNodeInfo.button.delete}", DELETE_PARAMS)).
42             addColspan("2")));
43     addActionListener(RemoveNodeActionListener.class, DELETE_ACTION) ;
44   }
45   
46   public void onChange(UIExplorer uiExplorer, NodeDescriptor node) {
47     parentURI_.setValue(node.getParentUri()) ;
48     name_.setValue(node.getName()) ;
49     type_.setValue(node.getNodeType()) ;
50     owner_.setValue(node.getOwner()) ;
51   }
52   
53   public void onRemove(UIExplorer uiExplorer, NodeDescriptor node) {
54     
55   }
56   
57   public void onModify(UIExplorer uiExplorer, NodeDescriptor node) {}
58   
59   public void onAddChild(UIExplorer uiExplorer, NodeDescriptor node) {
60     
61   }
62   
63   static public class RemoveNodeActionListener extends ExoActionListener {
64     public void execute(ExoActionEvent event) throws Exception JavaDoc {
65       UIFileNodeInfo uiInfo = (UIFileNodeInfo) event.getComponent() ;
66       UIFileExplorer uiExplorer =
67         (UIFileExplorer) uiInfo.getAncestorOfType(UIFileExplorer.class) ;
68       NodeDescriptor node = uiExplorer.getSelectNode() ;
69       InformationProvider iprovider = findInformationProvider(uiInfo) ;
70       if("/".equals(node.getUri())) {
71         iprovider.addMessage(new ExoFacesMessage("#{UIFileNodeInfo.msg.remove-root-node}")) ;
72         return ;
73       }
74       String JavaDoc realPath = uiExplorer.getRealPathBaseDir() + node.getUri() ;
75       File JavaDoc file = new File JavaDoc(realPath) ;
76       if(delete(file)) {
77         uiExplorer.broadcastOnRemove(node);
78         uiExplorer.changeNode(node.getParentUri()) ;
79         iprovider.addMessage(new ExoFacesMessage("#{UIFileNodeInfo.msg.remove-node-ok}")) ;
80       } else {
81         iprovider.addMessage(new ExoFacesMessage("#{UIFileNodeInfo.msg.remove-node-fail}")) ;
82       }
83     }
84     
85     public static boolean delete(File JavaDoc file) {
86       if (file.isDirectory()) {
87         File JavaDoc[] children = file.listFiles();
88         for (int i=0; i<children.length; i++) {
89           if (delete(children[i])) return false;
90         }
91       }
92       return file.delete();
93     }
94   }
95 }
Popular Tags