View | Details | Raw Unified | Return to bug 198307
Collapse All | Expand All

(-)a/php.editor/src/org/netbeans/modules/php/editor/PHPCodeTemplateFilter.java (-19 / +25 lines)
 Lines 42-49    Link Here 
42
package org.netbeans.modules.php.editor;
42
package org.netbeans.modules.php.editor;
43
43
44
import java.util.Collections;
44
import java.util.Collections;
45
import java.util.concurrent.Callable;
46
import java.util.concurrent.ExecutionException;
47
import java.util.concurrent.Future;
48
import java.util.concurrent.FutureTask;
49
import java.util.concurrent.RunnableFuture;
50
import javax.swing.SwingUtilities;
45
import javax.swing.text.JTextComponent;
51
import javax.swing.text.JTextComponent;
46
import org.netbeans.editor.BaseDocument;
47
import org.netbeans.lib.editor.codetemplates.api.CodeTemplate;
52
import org.netbeans.lib.editor.codetemplates.api.CodeTemplate;
48
import org.netbeans.lib.editor.codetemplates.spi.CodeTemplateFilter;
53
import org.netbeans.lib.editor.codetemplates.spi.CodeTemplateFilter;
49
import org.netbeans.modules.csl.spi.ParserResult;
54
import org.netbeans.modules.csl.spi.ParserResult;
 Lines 57-63    Link Here 
57
import org.openide.util.Exceptions;
62
import org.openide.util.Exceptions;
58
import org.openide.util.RequestProcessor;
63
import org.openide.util.RequestProcessor;
59
import static org.netbeans.modules.php.editor.CompletionContextFinder.CompletionContext;
64
import static org.netbeans.modules.php.editor.CompletionContextFinder.CompletionContext;
60
import org.openide.util.RequestProcessor.Task;
61
65
62
/**
66
/**
63
 *
67
 *
 Lines 69-102    Link Here 
69
    private int caretOffset;
73
    private int caretOffset;
70
    private CompletionContext context;
74
    private CompletionContext context;
71
    private static final RequestProcessor requestProcessor = new RequestProcessor("PHPCodeTemplateFilter");//NOI18N
75
    private static final RequestProcessor requestProcessor = new RequestProcessor("PHPCodeTemplateFilter");//NOI18N
72
    private final Task postedTask;
76
    private final Future<Future<Void>> future;
73
77
74
    public PHPCodeTemplateFilter(final JTextComponent component, final int offset) {
78
    public PHPCodeTemplateFilter(final JTextComponent component, final int offset) {
75
        this.caretOffset = offset;
79
        this.caretOffset = offset;
76
        postedTask = requestProcessor.post(new Runnable() {
80
        future = requestProcessor.submit(new Callable<Future<Void>>() {
77
            public void run() {
81
            @Override
78
                parseDocument(component);
82
            public Future<Void> call() {
83
                try {
84
                    return parseDocument(component);
85
                } catch (ParseException ex) {
86
                    Exceptions.printStackTrace(ex);
87
                }
88
                return null;
79
            }
89
            }
80
        });
90
        });
81
    }
91
    }
82
92
83
    public boolean accept(CodeTemplate template) {
93
    public boolean accept(CodeTemplate template) {
84
        try {
94
        try {
85
            if (postedTask.waitFinished(300)) {
95
            future.get().get();
86
                if (context == CompletionContext.CLASS_CONTEXT_KEYWORDS) {
96
            if (context == CompletionContext.CLASS_CONTEXT_KEYWORDS) {
87
                    return template.getAbbreviation().equals("fnc"); //NOI18N
97
                return template.getAbbreviation().equals("fnc"); //NOI18N
88
                    }
89
                return accept;
90
            } else {
91
                postedTask.cancel();
92
            }
98
            }
99
            return accept;
100
            
93
        } catch (InterruptedException ex) {
101
        } catch (InterruptedException ex) {
102
        } catch (ExecutionException ee) {
94
        }
103
        }
95
        return false;
104
        return false;
96
    }
105
    }
97
106
98
    @Override
107
    @Override
99
    public  void run(ResultIterator resultIterator) throws Exception {
108
    public  void run(ResultIterator resultIterator) throws Exception {
109
        System.out.println("EXECUTED!!!!!");
100
        ParserResult parameter = null;
110
        ParserResult parameter = null;
101
        String mimeType = resultIterator.getSnapshot().getMimeType();
111
        String mimeType = resultIterator.getSnapshot().getMimeType();
102
        if (!mimeType.equals(FileUtils.PHP_MIME_TYPE)) {
112
        if (!mimeType.equals(FileUtils.PHP_MIME_TYPE)) {
 Lines 131-141    Link Here 
131
        }
141
        }
132
    }
142
    }
133
143
134
    private void parseDocument(final JTextComponent component) {
144
    private Future<Void> parseDocument(final JTextComponent component) throws ParseException {
135
        try {
145
        return ParserManager.parseWhenScanFinished(Collections.singleton(Source.create(component.getDocument())), this);
136
            ParserManager.parseWhenScanFinished(Collections.singleton(Source.create(component.getDocument())), this);
137
        } catch (ParseException ex) {
138
            Exceptions.printStackTrace(ex);
139
        }
140
    }
146
    }
141
}
147
}

Return to bug 198307
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo