Get rid of java.awt.Desktop to open file browser/alternatives.
Hello, RapidMiners!
According to my findings motivated by this conversation with @kayman: RapidMiner relies upon the java.awt.Desktop class to execute the Open in file browser action. That works on Windows, Mac and older some Linux/Gnome machines, leaving out other desktop environments. There is a feature that could benefit all other desktop environments that aren't quite compatible. (e.g. Ubuntu 18, as we found out).
It would be a good thing to add a default file manager as part of the RapidMiner Studio configuration (most users don't adjust these unless they are advanced users), and stick to (default) if none is configured.
if .isDesktopSupported() is true and (default) is chosen as file manager, open the files in the default file manager as reported by the java.awt.Desktop class. Otherwise, if .isDesktopSupported() is false and default is selected, try to open anyway or present users with a message that says that they need to configure a file manager; else, open files with the file manager chosen by the user.
RapidMiner users on various Linux platforms will benefit from this, as desktop integration has always been incomplete there, and will give a workaround whenever things change, like it happened with Ubuntu.
What do you think?
Comments
@rfuentealba,
for reference, this is the source code of the action:
https://github.com/rapidminer/rapidminer-studio/blob/master/src/main/java/com/rapidminer/repository/gui/actions/OpenInFileBrowserAction.java
what would you do if isDesktopSupported() is false?
BR,
Martin
Dortmund, Germany
Hello @mschmitz,
First, on the RapidMiner Studio Preferences, on the System tab, add a section to specify a file manager that is different from the default one offered by the operating system. There I can specify that I want to use gmc (Gnome Midnight Commander) instead of nautilus (the default one in Gnome, AFAIK).
On the OpenFileInBrowserAction.java file, do this:
if (RapidMinerStudioPreferences.defaultFileBrowser.isEmpty() && (!Desktop.isDesktopSupported() || !Desktop.getDesktop().isSupported(Desktop.Action.OPEN))) {
alert_that_no_browser_can_open_stuff();
return;
}
// try to open if it exists and is a directory
File file = new File(pathBuilder.toString());
if (file.exists() && file.isDirectory())
{
// Try to open with default if the default file browser is empty.
// Otherwise, execute the default file browser passing the file as a
// parameter.
if (RapidMinerStudioPreferences.defaultFileBrowser.isEmpty()) {
Desktop.getDesktop().open(file);
} else {
Runtime.getRuntime().exec(String.format("sh -c %s %s", RapidMinerStudioPreferences.defaultFileBrowser, file);
}
}
If the method chosen for launching a process can return the result of the operation, read it and if it's different from 0, throw an exception that will be captured by the catch statement on lines 97-99.
For what is worth, there are more ways to launch UNIX processes, I just cited a simple one that might or might not be appropriate.
Is this detailed enough? Thank you!
reported to dev team and tagged @mschmitz on the ticket.
@rfuentealba,
just as an idea: I could provide an extension on github which has a new action called "Open File (Ubuntu)". This would have basically the same class i referenced here. Would you be able to edit the class so that the extension does it?
BR,
Martin
Dortmund, Germany
Hi @mschmitz,
What is your idea, keeping that as a plugin to not put that kind of logic on the core, or once the plugin works you want to merge that there?
All the best,
@rfuentealba,
good question. I got another functionality lying around which allows you to write ExampleSets to Excel by just right clicking on it. So this extension would have 2 new options. I personally would like to either:
- Have an open source extension with more then 1 "Custom Action" to make it useful
- Merge it into core
One nice part of the open soruce part would be, that other people can learn from this.
But i am not the person who decides on this.
Best,
Martin
Dortmund, Germany
@mschmitz, I have no problems with any choice, actually, and I can do part of it. From the usability point of view, it can be confusing to have two menu items for the same action, though.
There are two things I don't know how to do: one is adding a new tab in the Preferences menu so that I can configure the default file browser there, and the other is retrieving the value to use it elsewhere. If you can point me to the pieces of code for that, I can help you with either choice.
All the best,
This little feature will come at one point in the future. I already implemented it while working on something else, but it will probably not be released for some time.
It will be done pretty much exactly like your pseudo code above
Regards,
Marco
All the best,
Rodrigo.