KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > retouche > navigation > ClassMemberNavigatorSourceFactory


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 package org.netbeans.modules.retouche.navigation;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.Collections JavaDoc;
23 import java.util.List JavaDoc;
24 import org.netbeans.api.gsf.CancellableTask;
25 import org.netbeans.api.retouche.source.CompilationInfo;
26 import org.netbeans.api.retouche.source.Source.Priority;
27 import org.netbeans.modules.gsf.LanguageRegistry;
28 import org.openide.filesystems.FileObject;
29 import org.openide.filesystems.FileUtil;
30 import org.openide.util.Lookup;
31 import org.netbeans.api.retouche.source.Phase;
32 import org.netbeans.api.retouche.source.support.LookupBasedSourceTaskFactory;
33
34 /**
35  * This file is originally from Retouche, the Java Support
36  * infrastructure in NetBeans. I have modified the file as little
37  * as possible to make merging Retouche fixes back as simple as
38  * possible.
39  * <p>
40  *
41  * @author Jan Lahoda, Petr Hrebejk
42  */

43 public final class ClassMemberNavigatorSourceFactory extends LookupBasedSourceTaskFactory {
44             
45     private ClassMemberPanelUI ui;
46     private static final CancellableTask<CompilationInfo> EMPTY_TASK = new CancellableTask<CompilationInfo>() {
47
48         public void cancel() {}
49
50         public void run(CompilationInfo parameter) throws Exception JavaDoc {}
51     };
52     
53     static ClassMemberNavigatorSourceFactory getInstance() {
54         return Lookup.getDefault().lookup(ClassMemberNavigatorSourceFactory.class);
55     }
56     
57     public ClassMemberNavigatorSourceFactory() {
58         super(Phase.ELEMENTS_RESOLVED, Priority.NORMAL);
59     }
60
61     public synchronized CancellableTask<CompilationInfo> createTask(FileObject file) {
62         // System.out.println("CREATE TASK FOR " + file.getNameExt() );
63
if ( ui == null) {
64             return EMPTY_TASK;
65         }
66         else {
67             return ui.getTask();
68         }
69     }
70
71     public List JavaDoc<FileObject> getFileObjects() {
72         List JavaDoc<FileObject> result = new ArrayList JavaDoc<FileObject>();
73
74         // Filter uninteresting files from the lookup
75
LanguageRegistry registry = LanguageRegistry.getInstance();
76         for( FileObject fileObject : super.getFileObjects() ) {
77             if (!registry.isSupported(FileUtil.getMIMEType(fileObject))) {
78                 continue;
79             }
80             result.add(fileObject);
81         }
82         
83         if (result.size() == 1)
84             return result;
85
86         return Collections.emptyList();
87     }
88
89     public synchronized void setLookup(Lookup l, ClassMemberPanelUI ui) {
90         this.ui = ui;
91         super.setLookup(l);
92     }
93
94     @Override JavaDoc
95     protected void lookupContentChanged() {
96           // System.out.println("lookupContentChanged");
97
if ( ui != null ) {
98             ui.showWaitNode(); // Creating new task (file changed)
99
}
100     }
101     
102 }
103
Popular Tags