File extensions

I would have expected the following dialog component to add the selected file extension to the filename entered using the keyboard - this is the 'standard microsoft behaviour'.


DialogComponentFileChooser c_save = new DialogComponentFileChooser(
new SettingsModelString (
SaveNodeModel.DEFAULT_SAVE ),
"Save file", JFileChooser.SAVE_DIALOG, "smi", "csv", "smiles", "pdb", "sdf" );
addDialogComponent(c_save );
c_save.setToolTipText("The molecules are written to this file");

With some other GUI toolkits (eg from FORTRAN) I have found it necessary to fetch the file type/extension and check that it is present. However, this method doesn't appear to be exposed.

This problem is also apparent with OPEN_DIALOG, but is less likely to cause user complaints because the file with its extension will be on the list and need only be clicked!

How should I workaround this issue?

Hi Think,

the file chooser component actually does what you expect. At least since version 1.3.3 (and from the history I can see that it is in there since 1.3 already).
It only adds the extensions if you enter the filename through the file chooser dialog (via the "Browse..." button) and not in the textfield of the combobox directly. But I believe that is what you were expecting, right?

Did you use the DialogComponentFileChooser from the org.knime.core.node.defaultnodesettings package? I did not test the deprecated one from the package org.knime.core.node.defaultnodedialog. Don't use any of the components from this package. They are obsolete, deprecated and not maintained anymore. It is unfortunate that they are named very closely - and the deprecated package defaultnodedialog will be gone with one of the next releases.

- Peter.

Sorry, I should have stated that I was using 1.2.1

However, I believe the Windows convention is that keyboard entries into the combobox should also have the selected extension added if not already present. I will check 1.3.3 next week.

Using 1.3.3:

After clicking browse and typing a name into the "File name" string entry field then clicking Save adds the specified file type to the text unless this already ends with that string. It does not insert a "." after the text entered and the file extension.

I suspect the underlying problem relates to the fact that file extensions and file types are two separate concepts under windows.

Incidentally, users would also expect the node to remember the folder/path that it last used rather than revert to some obscure default.


file extensions are just appended as specified - I believe you can solve your problem by simply specifying the extensions with the dot.

The browse dialog starts from the path currently entered in the text field. If that's empty it uses the first entry from the history as starting point (which is bad behavior, I agree, and must be changed). If both items are empty, is starts at the user's home.

- Peter.

If I use eg ".sdf" in place of "sdf" it continues to work as a filter but no extension is added to the filename when "save" is pushed! :(

Oh no! Why not?!?
But it does work with the table writer for example. That node uses the default component and an extension (".table") gets added if not specified by the user.
If it is of enough importance for you to debug it Class DialogComponentFileChooser, line 233 is where we start examining the selected file and add an extension if needed.
Or let me know how I can be of more help.
- Peter.