This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

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

(-)a/editor.lib2/apichanges.xml (+14 lines)
Lines 105-110 Link Here
105
105
106
    <changes>
106
    <changes>
107
107
108
        <change id="added-dialogbinding">
109
            <summary>DialogBinding added</summary>
110
            <version major="1" minor="11"/>
111
            <date day="15" month="5" year="2009"/>
112
            <author login="dbalek"/>
113
            <compatibility binary="compatible" source="compatible" semantic="compatible" addition="yes"/>
114
            <description>DialogBinding allows for content of some text component to be virtually placed
115
                to the given offset inside of a file or document. This way, the necessary context is
116
                provided for code completion and similar features to work in any text component.
117
            </description>
118
            <class package="org.netbeans.api.editor" name="DialogBinding"/>
119
            <issue number="150875"/>
120
        </change>
121
108
        <change id="added-editoractionregistration">
122
        <change id="added-editoractionregistration">
109
            <summary>EditorActionRegistration annotation added</summary>
123
            <summary>EditorActionRegistration annotation added</summary>
110
            <version major="1" minor="10"/>
124
            <version major="1" minor="10"/>
(-)a/editor.lib2/nbproject/project.properties (-1 / +1 lines)
Lines 40-46 Link Here
40
is.autoload=true
40
is.autoload=true
41
javac.source=1.5
41
javac.source=1.5
42
javac.compilerargs=-Xlint:unchecked
42
javac.compilerargs=-Xlint:unchecked
43
spec.version.base=1.10.0
43
spec.version.base=1.11.0
44
cp.extra=${nb_all}/apisupport.harness/external/openjdk-javac-6-b12.jar
44
cp.extra=${nb_all}/apisupport.harness/external/openjdk-javac-6-b12.jar
45
45
46
javadoc.arch=${basedir}/arch.xml
46
javadoc.arch=${basedir}/arch.xml
(-)a/editor.lib2/src/org/netbeans/api/editor/DialogBinding.java (-1 / +19 lines)
Lines 55-66 Link Here
55
        Parameters.notNull("component", component); //NOI18N
55
        Parameters.notNull("component", component); //NOI18N
56
        if (!fileObject.isValid() || !fileObject.isData())
56
        if (!fileObject.isValid() || !fileObject.isData())
57
            return;
57
            return;
58
        bind(component, null, fileObject, offset, length, fileObject.getMIMEType());
59
    }
60
61
    /**
62
     * Bind given component and given document together.
63
     * @param document to bind
64
     * @param offset position at which content of the component will be virtually placed
65
     * @param length how many characters replace from the original document
66
     * @param component component to bind
67
     */
68
    public static void bindComponentToDocument(final Document document, int offset, int length, final JTextComponent component) {
69
        Parameters.notNull("document", document); //NOI18N
70
        Parameters.notNull("component", component); //NOI18N
71
        bind(component, document, null, offset, length, (String)document.getProperty("mimeType")); //NOI18N
72
    }
73
74
    private static void bind(final JTextComponent component, final Document document, final FileObject fileObject, int offset, int length, final String mimeType) {
58
        if (component instanceof JEditorPane)
75
        if (component instanceof JEditorPane)
59
            ((JEditorPane)component).setEditorKit(MimeLookup.getLookup(fileObject.getMIMEType()).lookup(EditorKit.class));
76
            ((JEditorPane) component).setEditorKit(MimeLookup.getLookup(mimeType).lookup(EditorKit.class));
60
        Document doc = component.getDocument();
77
        Document doc = component.getDocument();
61
        doc.putProperty("mimeType", "text/x-dialog-binding"); //NOI18N
78
        doc.putProperty("mimeType", "text/x-dialog-binding"); //NOI18N
62
        InputAttributes inputAttributes = new InputAttributes();
79
        InputAttributes inputAttributes = new InputAttributes();
63
        Language language = MimeLookup.getLookup("text/x-dialog-binding").lookup(Language.class); //NOI18N
80
        Language language = MimeLookup.getLookup("text/x-dialog-binding").lookup(Language.class); //NOI18N
81
        inputAttributes.setValue(language, "dialogBinding.document", document, true); //NOI18N
64
        inputAttributes.setValue(language, "dialogBinding.fileObject", fileObject, true); //NOI18N
82
        inputAttributes.setValue(language, "dialogBinding.fileObject", fileObject, true); //NOI18N
65
        inputAttributes.setValue(language, "dialogBinding.offset", offset, true); //NOI18N
83
        inputAttributes.setValue(language, "dialogBinding.offset", offset, true); //NOI18N
66
        inputAttributes.setValue(language, "dialogBinding.length", length, true); //NOI18N
84
        inputAttributes.setValue(language, "dialogBinding.length", length, true); //NOI18N
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/DialogBindingTokenId.java (-3 / +12 lines)
Lines 30-35 Link Here
30
import java.util.Collection;
30
import java.util.Collection;
31
import java.util.EnumSet;
31
import java.util.EnumSet;
32
import java.util.Map;
32
import java.util.Map;
33
import javax.swing.text.Document;
33
import org.netbeans.api.editor.mimelookup.MimeLookup;
34
import org.netbeans.api.editor.mimelookup.MimeLookup;
34
import org.netbeans.api.lexer.InputAttributes;
35
import org.netbeans.api.lexer.InputAttributes;
35
import org.netbeans.api.lexer.Language;
36
import org.netbeans.api.lexer.Language;
Lines 77-86 Link Here
77
        protected LanguageEmbedding<?> embedding(Token<DialogBindingTokenId> token, LanguagePath languagePath, InputAttributes inputAttributes) {
78
        protected LanguageEmbedding<?> embedding(Token<DialogBindingTokenId> token, LanguagePath languagePath, InputAttributes inputAttributes) {
78
            if (inputAttributes == null)
79
            if (inputAttributes == null)
79
                return null;
80
                return null;
80
            FileObject fo = (FileObject)inputAttributes.getValue(languagePath, "dialogBinding.fileObject"); //NOI18N
81
            String mimeType = null;
81
            if (fo == null)
82
            Document doc = (Document) inputAttributes.getValue(languagePath, "dialogBinding.document"); //NOI18N
83
            if (doc != null) {
84
                mimeType = (String)doc.getProperty("mimeType"); //NOI18N
85
            } else {
86
                FileObject fo = (FileObject)inputAttributes.getValue(languagePath, "dialogBinding.fileObject"); //NOI18N
87
                if (fo != null)
88
                    mimeType = fo.getMIMEType();
89
            }
90
            if (mimeType == null)
82
                return null;
91
                return null;
83
            Language<?> l = MimeLookup.getLookup(fo.getMIMEType()).lookup(Language.class);
92
            Language<?> l = MimeLookup.getLookup(mimeType).lookup(Language.class);
84
            return l != null ? LanguageEmbedding.create(l, 0, 0) : null;
93
            return l != null ? LanguageEmbedding.create(l, 0, 0) : null;
85
        }
94
        }
86
95
(-)a/java.editor/src/org/netbeans/modules/editor/java/Utilities.java (+4 lines)
Lines 81-86 Link Here
81
import org.netbeans.api.lexer.TokenHierarchy;
81
import org.netbeans.api.lexer.TokenHierarchy;
82
import org.netbeans.api.lexer.TokenSequence;
82
import org.netbeans.api.lexer.TokenSequence;
83
import org.netbeans.editor.ext.java.JavaTokenContext;
83
import org.netbeans.editor.ext.java.JavaTokenContext;
84
import org.netbeans.modules.editor.NbEditorUtilities;
84
import org.netbeans.modules.java.editor.options.CodeCompletionPanel;
85
import org.netbeans.modules.java.editor.options.CodeCompletionPanel;
85
import org.openide.filesystems.FileObject;
86
import org.openide.filesystems.FileObject;
86
import org.openide.util.WeakListeners;
87
import org.openide.util.WeakListeners;
Lines 350-355 Link Here
350
        if (doc.getLength() == 0 && "text/x-dialog-binding".equals(doc.getProperty("mimeType"))) { //NOI18N
351
        if (doc.getLength() == 0 && "text/x-dialog-binding".equals(doc.getProperty("mimeType"))) { //NOI18N
351
            InputAttributes attributes = (InputAttributes) doc.getProperty(InputAttributes.class);
352
            InputAttributes attributes = (InputAttributes) doc.getProperty(InputAttributes.class);
352
            LanguagePath path = LanguagePath.get(MimeLookup.getLookup("text/x-dialog-binding").lookup(Language.class)); //NOI18N
353
            LanguagePath path = LanguagePath.get(MimeLookup.getLookup("text/x-dialog-binding").lookup(Language.class)); //NOI18N
354
            Document d = (Document) attributes.getValue(path, "dialogBinding.document"); //NOI18N
355
            if (d != null)
356
                return "text/x-java".equals(NbEditorUtilities.getMimeType(d)); //NOI18N
353
            FileObject fo = (FileObject)attributes.getValue(path, "dialogBinding.fileObject"); //NOI18N
357
            FileObject fo = (FileObject)attributes.getValue(path, "dialogBinding.fileObject"); //NOI18N
354
            return "text/x-java".equals(fo.getMIMEType()); //NOI18N
358
            return "text/x-java".equals(fo.getMIMEType()); //NOI18N
355
        }
359
        }
(-)a/java.source/src/org/netbeans/api/java/source/ClasspathInfo.java (+8 lines)
Lines 227-232 Link Here
227
            if ("text/x-dialog-binding".equals(mimeType)) { //NOI18N
227
            if ("text/x-dialog-binding".equals(mimeType)) { //NOI18N
228
                InputAttributes attributes = (InputAttributes) doc.getProperty(InputAttributes.class);
228
                InputAttributes attributes = (InputAttributes) doc.getProperty(InputAttributes.class);
229
                LanguagePath path = LanguagePath.get(MimeLookup.getLookup(mimeType).lookup(Language.class));
229
                LanguagePath path = LanguagePath.get(MimeLookup.getLookup(mimeType).lookup(Language.class));
230
                Document d = (Document) attributes.getValue(path, "dialogBinding.document"); //NOI18N
231
                if (d != null) {
232
                    Object obj = d.getProperty(Document.StreamDescriptionProperty);
233
                    if (obj instanceof DataObject) {
234
                        DataObject dObj = (DataObject) obj;
235
                        return create(dObj.getPrimaryFile());
236
                    }
237
                }
230
                FileObject fileObject = (FileObject) attributes.getValue(path, "dialogBinding.fileObject"); //NOI18N
238
                FileObject fileObject = (FileObject) attributes.getValue(path, "dialogBinding.fileObject"); //NOI18N
231
                if (fileObject != null)
239
                if (fileObject != null)
232
                    return create(fileObject);
240
                    return create(fileObject);
(-)a/parsing.api/src/org/netbeans/modules/parsing/api/Source.java (-1 / +6 lines)
Lines 182-188 Link Here
182
                    if ("text/x-dialog-binding".equals(mimeType)) { //NOI18N
182
                    if ("text/x-dialog-binding".equals(mimeType)) { //NOI18N
183
                        InputAttributes attributes = (InputAttributes) document.getProperty(InputAttributes.class);
183
                        InputAttributes attributes = (InputAttributes) document.getProperty(InputAttributes.class);
184
                        LanguagePath path = LanguagePath.get(MimeLookup.getLookup(mimeType).lookup(Language.class));
184
                        LanguagePath path = LanguagePath.get(MimeLookup.getLookup(mimeType).lookup(Language.class));
185
                        fileObject = (FileObject) attributes.getValue(path, "dialogBinding.fileObject"); //NOI18N
185
                        Document doc = (Document) attributes.getValue(path, "dialogBinding.document"); //NOI18N
186
                        if (doc != null) {
187
                            fileObject = NbEditorUtilities.getFileObject(doc);
188
                        } else {
189
                            fileObject = (FileObject) attributes.getValue(path, "dialogBinding.fileObject"); //NOI18N
190
                        }
186
                    }
191
                    }
187
                    source = new Source(mimeType, document, fileObject);
192
                    source = new Source(mimeType, document, fileObject);
188
                }
193
                }
(-)a/parsing.api/src/org/netbeans/modules/parsing/impl/DialogBindingEmbeddingProvider.java (-21 / +31 lines)
Lines 41-50 Link Here
41
import org.netbeans.api.lexer.Language;
41
import org.netbeans.api.lexer.Language;
42
import org.netbeans.api.lexer.LanguagePath;
42
import org.netbeans.api.lexer.LanguagePath;
43
import org.netbeans.api.queries.FileEncodingQuery;
43
import org.netbeans.api.queries.FileEncodingQuery;
44
import org.netbeans.modules.editor.NbEditorUtilities;
44
import org.netbeans.modules.parsing.api.Embedding;
45
import org.netbeans.modules.parsing.api.Embedding;
45
import org.netbeans.modules.parsing.api.Snapshot;
46
import org.netbeans.modules.parsing.api.Snapshot;
46
import org.netbeans.modules.parsing.spi.EmbeddingProvider;
47
import org.netbeans.modules.parsing.spi.EmbeddingProvider;
47
import org.netbeans.modules.parsing.spi.Scheduler;
48
import org.netbeans.modules.parsing.spi.SchedulerTask;
48
import org.netbeans.modules.parsing.spi.SchedulerTask;
49
import org.netbeans.modules.parsing.spi.TaskFactory;
49
import org.netbeans.modules.parsing.spi.TaskFactory;
50
import org.openide.filesystems.FileObject;
50
import org.openide.filesystems.FileObject;
Lines 61-89 Link Here
61
        try {
61
        try {
62
            LanguagePath path = LanguagePath.get(MimeLookup.getLookup(snapshot.getMimeType()).lookup(Language.class));
62
            LanguagePath path = LanguagePath.get(MimeLookup.getLookup(snapshot.getMimeType()).lookup(Language.class));
63
            InputAttributes attributes = (InputAttributes) doc.getProperty(InputAttributes.class);
63
            InputAttributes attributes = (InputAttributes) doc.getProperty(InputAttributes.class);
64
            FileObject fileObject = (FileObject) attributes.getValue(path, "dialogBinding.fileObject"); //NOI18N
65
            int offset = (Integer)attributes.getValue(path, "dialogBinding.offset"); //NOI18N
64
            int offset = (Integer)attributes.getValue(path, "dialogBinding.offset"); //NOI18N
66
            int length = (Integer)attributes.getValue(path, "dialogBinding.length"); //NOI18N
65
            int length = (Integer)attributes.getValue(path, "dialogBinding.length"); //NOI18N
67
            String mimeType = fileObject.getMIMEType();
66
            Document d = (Document) attributes.getValue(path, "dialogBinding.document"); //NOI18N
68
            InputStream inputStream = fileObject.getInputStream();
67
            if (d != null) {
69
            try {
68
                String mimeType = NbEditorUtilities.getMimeType(d);
70
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, FileEncodingQuery.getEncoding(fileObject)));
69
                ArrayList<Embedding> ret = new ArrayList<Embedding>(3);
71
                CharBuffer charBuffer = CharBuffer.allocate(4096);
70
                ret.add(snapshot.create(d.getText(0, offset), mimeType));
72
                StringBuilder sb = new StringBuilder();
71
                ret.add(snapshot.create(0, snapshot.getText().length(), mimeType));
73
                int i = bufferedReader.read(charBuffer);
72
                ret.add(snapshot.create(d.getText(offset + length, d.getLength() - offset - length), mimeType));
74
                while (i > 0) {
73
                return Collections.singletonList(Embedding.create(ret));
75
                    charBuffer.flip();
74
            } else {
76
                    sb.append(charBuffer);
75
                FileObject fileObject = (FileObject) attributes.getValue(path, "dialogBinding.fileObject"); //NOI18N
77
                    charBuffer.clear();
76
                String mimeType = fileObject.getMIMEType();
78
                    i = bufferedReader.read(charBuffer);
77
                InputStream inputStream = fileObject.getInputStream();
78
                try {
79
                    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, FileEncodingQuery.getEncoding(fileObject)));
80
                    CharBuffer charBuffer = CharBuffer.allocate(4096);
81
                    StringBuilder sb = new StringBuilder();
82
                    int i = bufferedReader.read(charBuffer);
83
                    while (i > 0) {
84
                        charBuffer.flip();
85
                        sb.append(charBuffer);
86
                        charBuffer.clear();
87
                        i = bufferedReader.read(charBuffer);
88
                    }
89
                    ArrayList<Embedding> ret = new ArrayList<Embedding>(3);
90
                    ret.add(snapshot.create(sb.subSequence(0, offset), mimeType));
91
                    ret.add(snapshot.create(0, snapshot.getText().length(), mimeType));
92
                    ret.add(snapshot.create(sb.subSequence(offset + length, sb.length()), mimeType));
93
                    return Collections.singletonList(Embedding.create(ret));
94
                } finally {
95
                    inputStream.close();
79
                }
96
                }
80
                ArrayList<Embedding> ret = new ArrayList<Embedding>(3);
81
                ret.add(snapshot.create(sb.subSequence(0, offset), mimeType));
82
                ret.add(snapshot.create(0, snapshot.getText().length(), mimeType));
83
                ret.add(snapshot.create(sb.subSequence(offset + length, sb.length()), mimeType));
84
                return Collections.singletonList(Embedding.create(ret));
85
            } finally {
86
                inputStream.close();
87
            }
97
            }
88
        } catch (Exception e) {
98
        } catch (Exception e) {
89
            e.printStackTrace();
99
            e.printStackTrace();

Return to bug 163769