Play in NetBeans IDE (Part 1)

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".

 

Comments:

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

Posted by JZeitgeist on November 23, 2010 at 08:28 PM PST #

Brilliant. That works perfectly, thanks a lot.

Posted by Geertjan Wielenga on November 23, 2010 at 08:42 PM PST #

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.

Posted by Jesse Glick on November 23, 2010 at 10:45 PM PST #

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.)

Posted by Jesse Glick on November 23, 2010 at 10:59 PM PST #

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.

Posted by Jesse Glick on November 23, 2010 at 11:10 PM PST #

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 ?

Posted by Ehi on May 06, 2011 at 11:49 PM PDT #

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.

Posted by jlm on August 01, 2012 at 06:47 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
24
25
26
27
28
29
30
   
       
Today