Page 1 of 1

File Chooser That Understands oXygen Preferences

Posted: Thu Jul 17, 2014 2:45 am
by alolen
We have a lot of customizations in oXygen that require writers to choose files or directories, and our writers would like consistency with how the file browser works for default oXygen tools.

Right now we are just using a simple JFileChooser dialog for file/directory selection. Is there a way to call a file or directory chooser that is more 'oXygen aware'? In particular, one that will know whether the writer has set their preferences to open in the same directory as the current open file or to open in the last chose directory, and automatically do the right thing?

If not, is there some way to determine how the user has set this preference, so that my manually created JFileChooser can try to mimic it?

Re: File Chooser That Understands oXygen Preferences

Posted: Thu Jul 17, 2014 9:56 am
by alex_jitianu
Hello,

You could use one of the "choose" methods inside WorkspaceUtilities, like chooseFile. If you are working with plugin API, PluginWorkspace implements WorkspaceUtilities. If you are using framework level API, you can use AuthorAccess.getWorkspaceAccess.
Best regards,
Alex

Re: File Chooser That Understands oXygen Preferences

Posted: Thu Oct 23, 2014 1:37 am
by alolen
When I was initially asking for help with this, I was working on a plug-in. I was able to get the file browser working, with some experimentation. Now I am working in a framework, and I am having a problem I don't understand. I need to restrict the user to choosing a directory, not a file. I'm using AuthorAccess.getWorkspaceAccess() to get AuthorWorkspaceAccess, and that interface should have a chooseDirectory() method, according to the JavaDoc. But when I do this, all I can get are the chooseFile() methods. I really need a directory chooser. I can't figure out why, or what I am doing wrong, to onely get chooseFile and not chooseDirectory. Any ideas? Is it a bug in the API javadoc, or am I missing something?

Re: File Chooser That Understands oXygen Preferences

Posted: Thu Oct 23, 2014 10:24 am
by Radu
Hi,

The API ro.sync.exml.workspace.api.WorkspaceUtilities.chooseDirectory() was added in Oxygen 15.0 (the AuthorWorkspaceAccess interface extends the WorkspaceUtilities interface) so if you cannot find it you are probably using an older Oxygen version (or an older version of the Oxygen JARs to compile your plugin).
Anyway, even if you cannot upgrade and use the API you can create directly a Java Swing javax.swing.JFileChooser, set to it using the method javax.swing.JFileChooser.setFileSelectionMode(int) a mode in which only directories can be chosen and present it to the user.

Regards,
Radu