KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > piagetproject > treestructure > UserNode


1 /*
2  * UserNode.java
3  *
4  * Created on June 25, 2005, 12:05 PM
5  *
6  * To change this template, choose Tools | Options and locate the template under
7  * the Source Creation and Management node. Right-click the template and choose
8  * Open. You can then make changes to the template in the Source Editor.
9  */

10
11 package org.netbeans.modules.piagetproject.treestructure;
12
13 import java.awt.Image JavaDoc;
14 import java.util.ArrayList JavaDoc;
15 import javax.swing.AbstractAction JavaDoc;
16 import javax.swing.Action JavaDoc;
17 import org.openide.nodes.AbstractNode;
18 import org.openide.nodes.Children;
19 import org.openide.nodes.Node;
20 import org.openide.util.Utilities;
21
22 /**
23  *
24  * @author loicsegapelli
25  */

26 public class UserNode extends AbstractNode implements PiagetTreeNode{
27     
28     private String JavaDoc filepath;
29     private AbstractAction JavaDoc layoutAction;
30     
31     private String JavaDoc username;
32     private String JavaDoc level;
33     
34     /** Creates a new instance of UserNode */
35     public UserNode(String JavaDoc filepath, String JavaDoc username, String JavaDoc level) {
36         super(NodeRetriever.getSessions(filepath, username, level));
37         this.filepath = filepath;
38         this.level = level;
39         this.username = username;
40         super.setName(username);
41         setShortDescription("User node: "+username);
42         Children c = this.getChildren();
43         try{
44             LayoutNode layout = (LayoutNode)c.findChild("layout");
45             layoutAction = layout.getLayoutAction();
46         }catch(Exception JavaDoc e){
47             layoutAction = null;
48         }
49     }
50     
51     public Action JavaDoc[] getActions(boolean context) {
52         
53         if(layoutAction != null)
54             return new Action JavaDoc[] {
55                 StatsAction.getInstance(),
56                         layoutAction,
57                         new DeleteAction((AbstractNode)this, filepath)
58             };
59         else
60             return new Action JavaDoc[] {
61                 StatsAction.getInstance(),
62                         new DeleteAction((AbstractNode)this, filepath)
63             };
64     }
65     
66     public Image JavaDoc getIcon(int type) {
67         return Utilities.loadImage("org/netbeans/modules/piagetproject/resources/user.png");
68     }
69     
70     public Image JavaDoc getOpenedIcon(int type) {
71         return getIcon(type);
72     }
73     
74     public Info [] getInfos() {
75         Children c = this.getChildren();
76         Node n [] = c.getNodes();
77         ArrayList JavaDoc infos = new ArrayList JavaDoc();
78         
79         for(int i=0; i<c.getNodesCount(); i++){
80             Info infoNode [] = ((PiagetTreeNode)n[i]).getInfos();
81             for(int j=0; j<infoNode.length; j++){
82                 infos.add(infoNode[j]);
83             }
84         }
85         
86         Info [] out = new Info [infos.size()];
87         for(int i=0; i<out.length; i++){
88             out [i] = (Info)infos.get(i);
89         }
90         
91         return out;
92     }
93 }
94
Popular Tags