X

Geertjan's Blog

  • November 23, 2010

Play in NetBeans IDE (Part 1)

Geertjan Wielenga
Product Manager
One of the nice people I met at Devoxx 2010 was Nicolas Leroux from the Play Framework. That's another web framework out there. The cool thing about the Play Framework, from a NetBeans point of view, is its built-in support for NetBeans IDE.

Once you have downloaded Play, you can go to the command prompt and create a new Play-based web application by typing "play new MyDemoApp". Then a new Play application is created. Then, once you have that, you can type the following very cool command line statement:

play netbeansify MyDemoApp

With that, a new "nbproject" folder is created, with content, which enables you to simply open the application into the IDE:

That's pretty cool. At Devoxx, I tried to figure out a way for the IDE to recognize the "routes" file that you see in the screenshot above. That file is always called "routes" and it never has a file extension. If anyone knows how NetBeans can recognize this file (i.e., how to create a file type for a file without a file extension?) please let me know.

Here's my solution, in the MIME type resolver:

<MIME-resolver>
<file>
<ext name=""/>
<resolver mime="text/x-routes"/>
</file>
</MIME-resolver>

I.e., above we have a MIME type resolver for a file without an extension.

Then, in the DataObject, only create the Node if the name of the underlying file is "routes". Otherwise, create a Node with a name, but nothing else.

@Override
protected Node createNodeDelegate() {
DataNode dataNode = new DataNode(this, Children.LEAF, getLookup());
if (dataNode.getDisplayName().equals("routes")) {
return dataNode;
} else {
AbstractNode nonRoutesNode = new AbstractNode(Children.LEAF);
nonRoutesNode.setDisplayName(getName());
return nonRoutesNode;
}
}

Works fine... except that all files without extensions that are NOT named "routes", i.e., those handled by the "else" above, now no longer have a data editor, i.e., they have no text file support that they used to have by virtue of not being recognized. So those default text features need to be reintroduced to all files with no extensions that are not named "routes".


Join the discussion

Comments ( 7 )
  • JZeitgeist Wednesday, November 24, 2010

    To your MIME-Resolver Problem:

    As far as I remember, there already is a "name"-Element in the MIME-Resolver DTD, which already does, what you did in the DataObject.

    However I did not use it yet, but it should work like this:

    <MIME-resolver>

    <file>

    <name name="routes" ignorecase="false"/>

    <resolver mime="text/x-routes"/>

    </file>

    </MIME-resolver>

    So only files named exactly "routes" are recognized.

    Source: http://bits.nbextras.org/dev/javadoc/org-openide-filesystems/org/openide/filesystems/doc-files/resolverDocumentation.html#name

    Kind regards,

    JZeitgeist


  • Geertjan Wielenga Wednesday, November 24, 2010

    Brilliant. That works perfectly, thanks a lot.


  • Jesse Glick Wednesday, November 24, 2010

    As a last resort, you can also always implement MIMEResolver directly and add to global lookup. Not recommended for scalability reasons if you can avoid it.


  • Jesse Glick Wednesday, November 24, 2010

    Adding a nbproject folder to make it look like a freeform project may be OK for a quick hack but this is not what IDE support should look like. A framework with such a distinctive project layout (not to mention what appears to be its own module/repository system written from scratch) deserves its own specialized project type, just like we have for Rails etc.

    (Then you would not need a hacked-up DataNode for "routes", since this would be presented with a custom node in the logical view. Sounds like you would still want it to have its own MIME type, for special editor features.)


  • Jesse Glick Wednesday, November 24, 2010

    BTW another interesting point:

    http://www.playframework.org/documentation/1.1/i18n#utf8

    It means that conf/messages should be treated as text/x-properties but must have a FileEncodingQueryImplementation (before org.netbeans.modules.openide.loaders.DataObjectEncodingQueryImplementation) marking it as UTF-8. Probably harmless if the IDE serializes international characters as escapes, so long as it can read unescaped UTF-8 characters.


  • Ehi Saturday, May 7, 2011
    See example of how its been done with Eclipse.
    http://vimeo.com/8926899
    What would be required for a deeper level integration with netbeans?
    Are there some examples anywhere ?
  • jlm Wednesday, August 1, 2012

    Thanks for the post, Geertjan.

    I have tried using the netbeansify command on a windows platform with no success. The eclipse equivalent seems to work in this case.


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.