KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > javacore > RescanAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.javacore;
21
22 import java.net.URL JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.Set JavaDoc;
25 import javax.swing.SwingUtilities JavaDoc;
26 import org.netbeans.api.java.queries.SourceLevelQuery;
27 import org.netbeans.jmi.javamodel.Codebase;
28 import org.netbeans.jmi.javamodel.CodebaseClass;
29 import org.netbeans.jmi.javamodel.JavaModelPackage;
30 import org.netbeans.modules.javacore.classpath.MergedClassPathImplementation;
31 import org.netbeans.modules.javacore.internalapi.JavaMetamodel;
32 import org.netbeans.modules.javacore.scanning.FileScanner;
33 import org.openide.ErrorManager;
34 import org.openide.awt.StatusDisplayer;
35 import org.openide.filesystems.FileObject;
36 import org.openide.util.HelpCtx;
37 import org.openide.util.NbBundle;
38 import org.openide.util.RequestProcessor;
39 import org.openide.util.actions.CallableSystemAction;
40
41 public class RescanAction extends CallableSystemAction implements Runnable JavaDoc {
42     private RequestProcessor.Task scanningTask;
43     private Runnable JavaDoc start;
44     private Runnable JavaDoc stop;
45     
46     public String JavaDoc getName() {
47         return NbBundle.getMessage(RescanAction.class, "LBL_RescanAction"); // NOI18N
48
}
49     
50     public HelpCtx getHelpCtx() {
51         return new HelpCtx(RescanAction.class);
52     }
53     
54     public void performAction() {
55         postRequest();
56     }
57     
58     private void postRequest() {
59         init();
60         scanningTask.schedule(0);
61     }
62     
63     private void init() {
64         if (scanningTask == null) {
65             scanningTask = new RequestProcessor("Rescanning RP").create(this);
66             start = new Runnable JavaDoc() {
67                 public void run() {
68                     StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(RescanAction.class, "LBL_Rescanning"));
69                 }
70             };
71             stop = new Runnable JavaDoc() {
72                 public void run() {
73                     StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(RescanAction.class, "LBL_RescanningFinished"));
74                 }
75             };
76         }
77     }
78     
79     protected boolean asynchronous() {
80         return false;
81     }
82     
83     public void run() {
84         Set JavaDoc roots = MergedClassPathImplementation.getDefault().getRoots();
85         SwingUtilities.invokeLater(start);
86         try {
87             for (Iterator JavaDoc it = roots.iterator(); it.hasNext();) {
88                 FileObject root = (FileObject) it.next();
89
90                 JMManager.getDefaultRepository().beginTrans(false);
91                 try {
92                     JavaModelPackage extent = JavaMetamodel.getManager().getJavaExtent(root);
93                     if (extent != null) {
94                         CodebaseClass cbClass = extent.getCodebase();
95                         Codebase cb = (Codebase) cbClass.refAllOfClass().iterator().next();
96                         try {
97                             URL JavaDoc url = root.getURL();
98                             String JavaDoc sourceLevel = SourceLevelQuery.getSourceLevel(root);
99                             new FileScanner(url, sourceLevel, cb, true).scan();
100                         } catch (Exception JavaDoc ex) {
101                             ErrorManager.getDefault().notify(ex);
102                         }
103                     }
104                 } finally {
105                     JavaMetamodel.getDefaultRepository().endTrans();
106                 }
107             }
108         } finally {
109             SwingUtilities.invokeLater(stop);
110         }
111     }
112 }
113
Popular Tags