How to Extend the Open File Dialog

You've included the "User Utilities" module (by right-clicking your NetBeans Platform application, choosing Properties, clicking Libraries, and checking the box next to "User Utilities" in the "ide" cluster) and so now you magically have "File | Open File" in the menu bar. When you invoke the Action that has magically been provided, you see the Open dialog, as shown below:


Look at the "Files of Type" filter above. And now look at it again, after I've added the "Image" module to the application (also in the "ide" cluster, as described for the "User Utilities" module above):

The "Image" module adds a new "Files of Type" filter. Now let's say you're creating your own file types, as I did a few days ago for working with ZIP files. I tweaked the @MIMEResolver annotation slightly, which is automatically available at the top of a DataObject created via the New File Type dialog:

@MIMEResolver.ExtensionRegistration(
        displayName = "#LBL_ZIP_LOADER",
        mimeType = "application/x-zip",
        showInFileChooser = {"ZIP Files", "ZIP archives"},
        extension = {"zip", "ZIP"})

And now I see this, i.e., all thanks to the "showInFileChooser" annotation attribute above:


In other words, use "showInFileChooser" if you want a new filter added to the Open File dialog, to enable the user to filter for files conforming to your custom file type. The value is a String Array, which defines the text to be displayed to the left of the file extension, while the file extension is shown automatically when the "showInFileChooser" attribute is defined. Multiple Strings in the Array is useful, maybe as in the above, in cases where the user might have different understandings of what a ZIP is, i.e., a file or an archive. Fine, provide texts for both understandings. An empty String simply means that nothing will appear to the left of "[.zip]".

Comments:

Is there something similar for file types that are recognized by XML root element? "showInFileChooser" is not defined in @MIMEResolver.NamespaceRegistration.

Posted by Bert on June 20, 2013 at 06:43 AM PDT #

Is it just me, or are the scrollbars in this look and feel horribly broken (too big for their allocated space)? I've seen this in a number of examples you've shown (as well as in other Java applications running on Windows).

Posted by Rogan Dawes on June 20, 2013 at 11:37 PM PDT #

Hi Geertjan,
very thanks for that great hint. 10min and 20 lines of code and a great new feature in my app.
best regards
Oliver

Posted by Oliver Rettig on June 22, 2013 at 12:51 PM 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
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today