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

How to Extend the Open File Dialog

$
0
0

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


Viewing all articles
Browse latest Browse all 19780

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>