Code completion that works on Standard Netbeans Platform Application but fail when the project is built using Maven

"edgnets" <[email protected]>
Newsgroups gmane.comp.java.netbeans.modules.openide.devel
Message-ID <[email protected]>
Hi. I´d like to ask for help of this community to understand the diference between a code running in a 'Standard Netbeans Platform project' and fails when run on 'NetBeans Platform-based application built using Maven'.

I downloaded the source code from Geertjan's Blog that explain how to implement a code completion on JEditorPane:

https://blogs.oracle.com/geertjan/entry/jtextfield_code_completion
https://blogs.oracle.com/geertjan/entry/jeditorpane_code_completion_part_2
https://blogs.oracle.com/geertjan/entry/jeditorpane_code_completion_part_3

When I run the source code in a project using a Standard Netbeans Platform project the example works fine however the same code in a new project using NetBeans Platform-based application built using Maven throws an exception when is called DialogBinding.bindComponentToDocument(...). ps. both projects is attached here. 

The problematic piece of code is below:

Code:
EditorKit kit = CloneableEditorSupport.getEditorKit("text/plain");
countryField.setEditorKit(kit);
DialogBinding.bindComponentToDocument(countryField.getDocument(), 0, 0, countryField);




Debugging the code I noticed the following behavior when comparing the two projects:

When I run a Standard Netbeans Project (works well)

*CloneableEditorSupport.getEditorKit("text/plain") return a instance of org.openide.text.CloneableEditorSupport$PlainEditorKit
*Within .setEditorKit(kit) is called kit.createDefaultDocument() that return an instance of org.netbeans.modules.editor.NbEditorDocument
*Within .bindComponentToDocument(..) is called document.getProperty("mimeType")  that returns (java.lang.String) "text/plain"

When I run on Maven Netbeans Project (Fail)

*CloneableEditorSupport.getEditorKit("text/plain") return a instance of org.netbeans.modules.editor.plain.PlainKit
*Within .setEditorKit(kit) is called kit.createDefaultDocument() that return an instance of javax.swing.text.PlainDocument
*Within .bindComponentToDocument(..) is called document.getProperty("mimeType")  that returns null
*In some point within .bindComponentToDocument(..) the MimeLookup.getLookup(mimeType).lookup(EditorKit.class) throws a NullpointerException because MimeLookup.getLookup(mimeType) returns null.


I think the main reason is that on  my Maven project there is no implementation for the EditorKit.class within the MimeLookup what makes the CloneableEditorSupport.getEditorKit("text/plain") return a default instance of PlainEditorKit rather than NbEditorDocument.


Code:
   public static EditorKit getEditorKit(String mimePath) {
        Lookup lookup = MimeLookup.getLookup(MimePath.parse(mimePath));
        EditorKit kit = lookup.lookup(EditorKit.class);
        if (kit == null) {
            // Try 'text/plain'
            lookup = MimeLookup.getLookup(MimePath.parse("text/plain"));
            kit = lookup.lookup(EditorKit.class);
        }
        // Don't use the prototype instance straightaway
        return kit != null ? (EditorKit) kit.clone() : new PlainEditorKit();
    }



I do not fully understood how the MimeLookup works nor why the same code on two project have different behaviors. 

I appreciate any help to make this Code completion example works in a NetBeans Platform-based application built using Maven.


Thank you




Attachments: 
http://forums.netbeans.org//files/codecompletationmavenapp_201.zip
http://forums.netbeans.org//files/codecompletatationapp_857.zip
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.