KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > gsf > tools > AstFactory


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.gsf.tools;
20
21 import java.io.IOException JavaDoc;
22 import java.util.logging.Level JavaDoc;
23 import java.util.logging.Logger JavaDoc;
24
25 import javax.swing.SwingUtilities JavaDoc;
26 import javax.swing.text.Document JavaDoc;
27
28 import org.netbeans.api.gsf.ParserResult;
29 import org.netbeans.api.gsf.CancellableTask;
30 import org.netbeans.api.retouche.source.CompilationInfo;
31 import org.netbeans.api.retouche.source.Phase;
32 import org.netbeans.api.retouche.source.RescheduleListener;
33 import org.netbeans.api.retouche.source.Source;
34 import org.netbeans.api.retouche.source.support.EditorAwareSourceTaskFactory;
35 import org.netbeans.modules.gsf.browser.AstViewer;
36 import org.openide.cookies.EditorCookie;
37 import org.openide.filesystems.FileObject;
38 import org.openide.filesystems.FileUtil;
39 import org.openide.loaders.DataObject;
40
41
42 /**
43  * Source factory for displaying the AST in the AST viewer when
44  * it has been parsed
45  *
46  * @author Tor Norbye
47  */

48 public class AstFactory extends EditorAwareSourceTaskFactory {
49     /**
50      * Creates a new instance of GsfHintsFactory
51      */

52     public AstFactory() {
53         super(Phase.RESOLVED, Source.Priority.BELOW_NORMAL);
54     }
55
56     public CancellableTask<CompilationInfo> createTask(FileObject file) {
57         return new AstProvider(file);
58     }
59
60     public final class AstProvider implements CancellableTask<CompilationInfo> {
61         private FileObject file;
62         private boolean cancel;
63
64         private AstProvider(FileObject file) {
65             this.file = file;
66         }
67
68         synchronized boolean isCanceled() {
69             return cancel;
70         }
71
72         public synchronized void cancel() {
73             cancel = true;
74         }
75
76         synchronized void resume() {
77             cancel = false;
78         }
79
80         public void run(CompilationInfo info) {
81             resume();
82
83             final ParserResult result = info.getParserResult();
84             SwingUtilities.invokeLater(new Runnable JavaDoc() {
85                     public void run() {
86                         AstViewer viewer = AstViewer.findInstance();
87                         if (viewer == null || !viewer.isShowing()) {
88                             return;
89                         }
90                         
91                         AstViewer.findInstance().refresh(file, result);
92                     }
93                 });
94         }
95     }
96 }
97
Popular Tags