DialogComponentFileChooser set valid file extension automatically due to another value

Hi,

I want to ask if there is a way to set the possible file extensions in DialogComponentFileChooser due to another changed value.

The situation at my side;
I have created one option to select the possible file extension before. If the file extension is changed, the possible extnsion for DialogComponentFileChooser should change automatically.

Regards
Kefang

Hi Kefang,

You need to hack a bit but that should be possible:
Your goal is to call the setSuffixes(String...) method in FileHistoryPanel

which is used by DialogComponentFileChooser, as the member variable m_filesPanel:

However, that class does not give you direct access to this member. To get to it, you can either try reflection (http://tutorials.jenkov.com/java-reflection/private-fields-and-methods.html) which can be tricky, or you try to get access to the FileHistoryPanel by calling getComponentPanel on the dialog component, enumerating the children of that panel and locating the FileHistoryPanel there. The second method should be easier to do.

Once you have the reference to the FileHistoryPanel you can use it to set the suffixes as desired.

best,
Gabriel
Gabriel

1 Like

Hi @gab1one,

I will choose the second way. Another idea I have is to recreate the DialogComponentFileChooser and assign different extensions at the constructor. However, wonder if it affects the saveSettings in Dialog, and FlowVariable panel. Do you have any experience in this way?

Regards
Kefang

Hi Kefang

You will also need to remove the old dialog component from the panel when you do that and as you said make sure the saving and restoring works correctly. This could also work but I think it will be more complicated to get right.

best,
Gabriel

1 Like