1 19 20 package org.netbeans.modules.javacore; 21 22 import java.net.URL ; 23 import java.util.Iterator ; 24 import java.util.Set ; 25 import javax.swing.SwingUtilities ; 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 { 42 private RequestProcessor.Task scanningTask; 43 private Runnable start; 44 private Runnable stop; 45 46 public String getName() { 47 return NbBundle.getMessage(RescanAction.class, "LBL_RescanAction"); } 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 () { 67 public void run() { 68 StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(RescanAction.class, "LBL_Rescanning")); 69 } 70 }; 71 stop = new Runnable () { 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 roots = MergedClassPathImplementation.getDefault().getRoots(); 85 SwingUtilities.invokeLater(start); 86 try { 87 for (Iterator 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 url = root.getURL(); 98 String sourceLevel = SourceLevelQuery.getSourceLevel(root); 99 new FileScanner(url, sourceLevel, cb, true).scan(); 100 } catch (Exception 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 |