Quantcast
Channel: Oracle Bloggers
Viewing all articles
Browse latest Browse all 19780

"New File" Feature Without a Project Type?

$
0
0

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:

http://java.net/projects/nb-api-samples/sources/api-samples/show/versions/7.2/misc/SimpleApp

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!


Viewing all articles
Browse latest Browse all 19780

Trending Articles