Wednesday Jan 09, 2013

"New File" Feature Without a Project Type?

You're creating a NetBeans Platform application and discover that your "New File" menu item (and toolbar button) are always disabled. Why? Because you haven't implemented the Project API in your application. The "New File" feature is part of the Project UI module. You could include that module in your application and then you'd have the "New File" feature available but it will never be enabled, unless you've created a project already. You can see this in the New File dialog in the IDE: you need to specify the project for which you're creating a new file, until you have a project, you can't create a file. In short, "New File" is part of the project infrastructure.

So, what to do in applications that don't have a Project implementation but that do need to have "New File" feature? In this sample that I created today, two solutions are available out of the box:

Here are the two solutions:

  • An Action (same as the equivalent defined here in the PinkMatterPlatform) that creates a new file.
  • An Action that pops up a dialog where the user can select a file to be created.

In both cases, the "Templates" folder in the filesystem is queried, a file (or multiple files, in the second case) is found, and then the selected file is created.

Therefore, if you need a "New File" feature in your application, look no further than the prepackaged solutions above!


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.


« January 2013 »