I have a project that i have to tackle for the company I'm working for and it basically means I have to handle and display files without any file extension. I'm not able to change the way they produce these files so I need some advice on the best way to deal with these kinds of files. The DataSystems API seems to only take care of files with extensions, so does that mean I have to make use of the FileSystems API only? If so I would appreciate some samples of Node and Children classes using the FileObject as what they actually represent.
Thanks a mil, really appreciate any help.
After spending some time reading through the material available from the Netbeans Platform website, I'm left with a few questions regarding my goal as mentioned above.
To clarify my objective: 1. I have a folder (outside of the application installation path) which contains files without extensions. Each file represent a point of interest, containing space-separated text data that will later be used to draw graphs by various graphing softwares. 2. I want to display these files as nodes in one module with perhaps a separate module for updating of these files. Updating will encompass a button that will cause the downloading of a compressed file, uncompressing this file, read its contents and interpret that contents to determine how the text data files will be updated. 3. Perhaps have content change listeners on the FileObjects represented by the nodes in order to display/indicate (perhaps via icon change?) the change of file contents. 4. I also want to be able to display the text data (read-only) contained in the FileObject represented by the clicked node in a text editor, but that is all I need to be able to do with these FileObjects and the nodes that represent them. 4. Have another module displaying all the compressed files downloaded to date (assuming that again I will want to display all the files in a 'download' folder) with the help of the Nodes and ExplorerView API. Here I might want to add 'semantic meaning' to these files since they are not average zip/Jar files, thus perhaps using the DataSystems API for this module.
The most dominant question in my mind at this point is what the correct way would be to represent all the files in this folder as nodes, and what this node's subclass and the corresponding Children class would look like. In the examples the "APIObject" is used, I want to set about replacing that object with FileObject if it is not necessary to use the DataSystems API in the first module?
Again I want to thank you for any help, it really is appreciated.
Ok, read your update. So, I'd say that definitely at some point you need DataObjects. The key points:
To "link" DataObjects to FileObjetcs you need a DataLoader. It's a factory of DataObjects, that gets activated only for some kind of files. Basically:
DataObject dataObject = DataObject.find(fileObject);
While it's common for a DataLoader to use a file extension to ack a file type, it's not the only way to go. Indeed, DataLoaders use MIME types and a MIMEResolver class can be used to assign a MIME type to a given file. Again, the easiest thing is to look at the extension, but your code can also look at contents to guess (http://wiki.netbeans.org/DevFaqFileRecognition). Basically you have to implement your MIMEResolver with a single method:
public String findMIMEType (FileObject fileObject);
that can do whatever it wants, then you register the MIMEResolver into the system (see http://bits.netbeans.org/dev/javadoc/org-openide-filesystems/org/openide/filesystems/doc-files/HOWTO-MIME.html for details).
At this point, DataObject.find() will be able to instantiate your own subclass of DataObject.
DataObject has got a createNodeDelegate() which can be used to create a Node to put into an view for rendering. It will automaticaly render with the name of the DataObject, which by default is the name of the FileObject. If I recall correctly (but at the moment I'm unsure), the Platform on its own should be able to create the proper DataObject for a directory, which would automatically create a Node with children for each contained file.
For looking at contents, you might have a look at the Editor API. Unfortunately I'm not acquainted with it, but generically speaking it should be activatable again by using MIME types, that its associating the MIME type you've previously defined to a "plain text" style. Look here http://bits.netbeans.org/dev/javadoc/org-openide-text/org/openide/text/doc-files/api.html and don't be worried by the lenght of the document, as it also explains stuff such as changing the contents, that you're not interested to.
Once you are able to render a tree of files, by using FilterNode to hide some children from view (see http://wiki.netbeans.org/DevFaqNodesDecorating).