Prevent from choosing a folder in SWT DirectoryDialog - java

I'm using the DirectoryDialog component in my application to let the user select a folder.
Now I want to have the possibility to prevent the user from choosing a specific folder. Is there a handler or listener or something like that?

This can't be done.
DirectoryDialog is just a thin wrapper around the native open directory dialog (for example on macOS it uses NSOpenPanel). The native dialog is very different on the various platforms supported by SWT making it not practical to allow this.
You could craft your own directory dialog using a TreeViewer and the native file APIs.

Related

How can I select multiple folders with JavaFX using DirectoryChooser?

I'm using the latest version of JavaFX and I'm trying to open a user dialog to select multiple folders at once. I know you can do it in Swing but I'm trying to do it in JavaFX. I tried using DirectoryChooser but as far as I can see there is no method that allows you to choose multiple directories. Does anyone know how I can go about this or should I just use Swing?

Highlighting the same explorer windows on explorer /select command

We use explorer /select command with the file path to open the file in windows explorer. https://support.microsoft.com/en-us/kb/152457 But on multiple invocations it opens a new window everytime. I am invoking the command from a java application using the process runtime APIs.
is it possible to have one window being opened ?. For e.g. if an explorer with c:/A is being opened ,repeated invocation of the same command must open the same window which is opened. ?
cheers
Saurav
It seems that your problem does not have a simple solution.
According to my understanding the "window sharing" of expplorer is not the explorer's feature. Please take a look on the following article: https://support.microsoft.com/en-us/kb/241911
(Although this article is talking about Internet Explorer I guess it is relevant for file exploerer as well).
According to my user experience the window sharing happens only when you are getting to directory via some kind of shortcut and does not happen when you are running explorer explicitly. For example if you type in "run" window "explorer" the new window is always created, however if you type "c:\" the window will be re-used.
You want to execute explorer with specific option, so you have to run it explicitly, therefore no window re-use can be achieved.
But I can suggest you 2 workarounds.
Do not use /select option. "Run" the base directory of the file you want to select. This will guarantee the window reuse. Then "select" file using java.awt.Robot by "typing" its name.
Manage the opened Explorer windows yourself into your java application. You can store map of file-to-exploerer window handler. When application wants to run open explorer for file that is already selected in other explorer window, activate it. To do this you need some JNI/JNA code. Take a look on the following discussions for details.
In Java Swing how do you get a Win32 window handle (hwnd) reference to a window?
Find out what application (window) is in focus in Java

JFilechooser appearance

In my swing application, I have set the UI Look and Feel as:
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
And it works well on Windows. Inside, the application, the user has to select files using the JFileChooser. The JFileChooser appearance on windows is again the native one. But not on Mac.
The screenshot of the JFileChooser Panel:
But instead, I prefer something like this: (This one is taken from upload option in gmail)
What should I change the UIManager to or anything else??
Several alternatives include these:
java.awt.FileDialog, illustrated here.
A custom ChooserUI, shown here.
A completely custom implementation; several variations are shown here.
On MacOS, you can use the FileDialog which looks like what you are describing. The drawback is that it is a lot less configurable.
I have experienced a lot of troubles when migrating from Java 6 to Java 8 since with my Java application I have to open some proprietary file bundles.
FileDialog still gives the better LookAndFeel, but treats the bundled files as if it were directories. A first fix to this is to set FileDialog to select directories, which still allows to navigate inside the file-bundle, but as well allows to select the bundle as a whole.
System.setProperty("apple.awt.fileDialogForDirectories", "true");
Not quite happy by the solution I tried other options, including the VAqua LookAndFeel for macOS which looked really great but sometimes didn't display me all the UI Elements (some JTree were hidden at startup, and JFileChooser did look great, but still didn't show me the Network drives in the sidebar).
Finally I found a simple property that - when set - allows to use FileDialog as it was under Java 6. Of course, if we want to select files and not directories, the line above must be deleted.
System.setProperty("apple.awt.use-file-dialog-packages", "true");
Found this one in an old example project about Dialog personalization
The file chooser implementation for Windows, Linux and Mac is not 100% right for any OS
Unfortunately if you really want this you need to look for a replacement for JFileChooser or you need to write your own look and fee.
Java has trouble keeping up with the OS changes.

Explorer Panel in Java

does anyone know a free windows explorer type of project written in java?
Basically i just want to implement a simple windows explorer but dont want to start from scratch with all the drag and drops, icon arrangements and so on.
Thanks
See File Browser GUI.
You can explore common navigator framework for eclipse, it would use swt, jface, draw2d. It provides with drag and drop options.

How to write a Icon Handlers for explorer.exe in Java

First of all, I'm a java developer and I am currently working on a small application for Windows only.
In my application, I wish to do as dropbox or tortoise do : add an overlay icon in windows explorer to show the user some state of files managed by my application. (I want the icon of the file change depending on some data stored in the file)
Is it possible to do so in Java ? Do you have examples ?
If it is doable but not efficient, how would you do instead ?
Thanks in advance
Fluminis
It would be possible to do this via JNI - you would need to hook into the Windows registry and from there into the Explorer shell, probably into the various file classes held there.
However, unless you have at least some familiarity with C++ and the windows API, you are unlikely to be able to achieve this.
Java is not the ideal language for what you want to do.

Categories

Resources