1 10 11 package org.netbeans.modules.piagetproject.treestructure; 12 import java.util.ArrayList ; 13 import java.util.HashSet ; 14 import javax.swing.AbstractAction ; 15 import javax.swing.Action ; 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 28 public class StatsAction extends AbstractAction { 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 e) { 42 Node[] n = WindowManager.getDefault().getRegistry().getActivatedNodes(); 43 if(n==null || n.length<1) return; 44 45 ArrayList list = new ArrayList (); 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 set = new HashSet (list.size()); 57 SessionTopComponent tc = new SessionTopComponent(); 58 Property.reset(); 59 String name = null; 60 for(int i=0; i<list.size(); i++){ 61 Info inf = (Info)list.get(i); 62 String path = inf.path; 63 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 doTopComponent = new Runnable () { 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(); } 83 }; 84 85 doTopComponent.run(); 86 87 } 88 89 public Object clone() throws CloneNotSupportedException { 90 throw new CloneNotSupportedException (); 91 } 92 93 94 95 } 96 | Popular Tags |