This page provides information for editing (EMF) data stored in a file. It covers:
- Selecting the file
The data can be in a fixed file, or can be in any file selected by the user. - Handling the file (EMF specific)
The mechanism provided by EMF is not in line with the normal ‘new’, ‘open’ and ‘save’ operations. Therefore we provide theEMFResourceclass.
File selection
There are the following situations:
- Information stored in a single, fixed file
For example, information on all travels stored in a single file. - File to open or save to be specified per usage
For example, each photoshow is stored in its own file.
Common:
- Filename
The user should always see on which file he’s working - Changes
The application has to know whether there are changes in the data since the data was last saved. This is known as the file being ‘dirty’.
This should also be visible to the user.
Information stored in a single, fixed file
Some types of information are typically stored in a single file. Examples of this (in the MyWorld applications) are:
- Your family address book (Rolodex)
- Your personal media information (Media)
In this case the filename is typically specified in a configuration file and the file is opened on application startup. There is only a File/Save menu option.
Application start:
- Check that the filename is specified
Define the filename via the properties mechanism, which takes care that the filename is e.g. available via SomeRegistry.dataFilename. - If the filename isn’t specified, inform the user about this and inform him how to specify the filename. Or, even better, offer him the option to open an editor to set this value. This is done in the MyWorld applications.
Settings are handled at startup, so typically the user has to restart the application after updating the settings. - If the filename is specified, the next check is to see whether the file exists.
If the file doesn’t exist, inform the user about this and ask him whether the file should be created or not. Typically the application can’t do anything if the file isn’t created. - Open the file
- When the user selects File/Save, save the file and clear the ‘dirty’ indication.
- If the user wants to exit the application, check whether the file is ‘dirty’. If so, ask the user whether he want so save changes before exiting.
File to open or save to be specified per usage
Some types of information are typically stored per file. For example, each photoshow is stored in its own file.
Let the user select the file via a FileChooser.
File handling
Use an EMFResource to handle the file.
First create the EMFResource.
Next call load() to read the data from the file. A FileNotFoundException occurs if the file doesn’t exist yet. Catch this exception and if it occurs show the user a dialog asking whether the file should be created or not.

