KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * SessionAction.java
3  *
4  * Created on July 11, 2005, 10:30 AM
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 import java.util.ArrayList JavaDoc;
13 import java.util.HashSet JavaDoc;
14 import javax.swing.AbstractAction JavaDoc;
15 import javax.swing.Action JavaDoc;
16 import org.netbeans.modules.piagetproject.property.Property;
17 import org.netbeans.modules.piagetproject.topcomponent.SessionFileWrapper;
18 import org.netbeans.modules.piagetproject.topcomponent.SessionTopComponent;
19 import org.openide.nodes.Node;
20 import org.openide.windows.Mode;
21 import org.openide.windows.TopComponent;
22 import org.openide.windows.WindowManager;
23
24 /**
25  *
26  * @author loicsegapelli
27  */

28 public class StatsAction extends AbstractAction JavaDoc {
29     
30     private static StatsAction instance;
31     
32     private StatsAction(){
33         putValue(Action.NAME, "stats");
34     }
35     
36     public static synchronized StatsAction getInstance(){
37         if(instance==null) instance = new StatsAction();
38         return instance;
39     }
40     
41     public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
42         Node[] n = WindowManager.getDefault().getRegistry().getActivatedNodes();
43         if(n==null || n.length<1) return;
44         
45         ArrayList JavaDoc list = new ArrayList JavaDoc();
46         for(int i=0; i<n.length; i++){
47             Info infos [] = ((PiagetTreeNode)n[i].getLookup().lookup(PiagetTreeNode.class)).getInfos();
48             for(int j=0; j<infos.length; j++){
49                 if(infos[j].path.endsWith(NodeRetriever.PARSED)){
50                     list.add(infos[j]);
51                 }
52             }
53         }
54         if(list.size() < 1) return;
55         
56         HashSet JavaDoc set = new HashSet JavaDoc(list.size());
57         SessionTopComponent tc = new SessionTopComponent();
58         Property.reset();
59         String JavaDoc name = null;
60         for(int i=0; i<list.size(); i++){
61             Info inf = (Info)list.get(i);
62             String JavaDoc path = inf.path;
63             //prevents double node analysis. Consider the following case: user
64
// has selected a session node and also its parent: because of recursion
65
// the node would be parsed twice
66
if(set.contains(path)) continue;
67             set.add(path);
68             name = SessionFileWrapper.wrapFile(path, inf.username, inf.level);
69         }
70         
71         tc.initComponents(list.size(), name);
72         
73         final TopComponent TC = tc;
74         Runnable JavaDoc doTopComponent = new Runnable JavaDoc() {
75             public void run() {
76                 Mode myMode = WindowManager.getDefault().findMode("editor");
77                 if (myMode != null){
78                     myMode.dockInto(TC);
79                 }
80                 TC.open();
81                 TC.requestActive(); //activate component, make it visible
82
}
83         };
84         
85         doTopComponent.run();
86         
87     }
88     
89     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
90         throw new CloneNotSupportedException JavaDoc();
91     }
92     
93     
94     
95 }
96
Popular Tags