Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make JFace Window blink in taskbar or get users attention?

I wonder someone has any idea how to solve this:

In my Java Eclipse plugin there are some processes which take some time. Therefore the user might minimize the window and let the process run in the background.
Now, when the process is finished, I can force the window to come to the top again, but that is a no-no in usability. I'd rather want the process to blink in the taskbar instead. Is there any way to achieve this?

I had a look at the org.eclipse.jface.window but could'nt find anything like that, same goes for the SWT documentation...

Another thing which came to my mind - as people are using this app on mac os x and linux as well, is there a platform independant solution, which will inform the user that the process has finished but without bringing the window to the top?

Any ideas are highly welcome!

Edit:
I found out that on windows the user can adjust whether he would like to enable a force to foreground or not. If that option is disabled, the task will just blink in the taskbar...
Here's a good read on that...

If anyone maybe knows about some platform independant way of achieving this kind of behaviour, please share your knowledge with me!

like image 517
Gnark Avatar asked May 05 '10 12:05

Gnark


3 Answers

I don't think there's a platform independent way of doing this. You will have to take a look at the platform-specific API calls and implement them via JNI or JNA.

For Windows, here's a snippet from one of my own applications:

public static void flashWindow(final Shell shell, boolean flashTray,
        boolean flashWindow) {
    try {
        if (isActiveWindow(shell)) {
            flashWindow = false;
            flashTray = false;
        }
        User32 lib = (User32) getLibrary("user32", User32.class);
        User32.FLASHWINFO flash = new User32.FLASHWINFO();
        flash.hWnd = new W32API.HANDLE(new W32API.UINT_PTR(shell.handle)
                .toPointer());
        flash.uCount = 2;
        flash.dwTimeout = 1000;
        if (flashTray || flashWindow) {
            flash.dwFlags = (flashTray ? User32.FLASHW_TRAY : 0)
                    | (flashWindow ? User32.FLASHW_CAPTION : 0);
        } else {
            flash.dwFlags = User32.FLASHW_STOP;
        }
        flash.cbSize = flash.size();
        if (lib.FlashWindowEx(flash) && !flashWindow) {
            final FocusListener focusListener = new FocusListener() {
                public void focusGained(FocusEvent arg0) {
                    flashWindow(shell, false, false);
                    shell.removeFocusListener(this);
                }

                public void focusLost(FocusEvent arg0) {
                }
            };
            shell.addFocusListener(focusListener);
        }
    } catch (UnsatisfiedLinkError e) {
    }
}

Here's a simplified version of getLibrary():

protected static StdCallLibrary getLibrary(String libraryName,
        Class<?> interfaceClass) throws UnsatisfiedLinkError {
    try {
        StdCallLibrary lib = (StdCallLibrary) Native.loadLibrary(libraryName,
                interfaceClass);
        return lib;
    } catch (UnsatisfiedLinkError e) {
        Logger.out.error("Could not load " + libraryName + " library.");
        throw e;
    }
}

Take care to dispose() the library when you're done with it.

like image 113
Paul Lammertsma Avatar answered Oct 02 '22 00:10

Paul Lammertsma


Well, that's not exactly blinking, but since Eclipse 3.6 M6, you can overlay text, image or progress bar to the TaskItem in a platform-independent way with SWT. See the New and Noteworthy and the SWT snippet.

like image 35
thSoft Avatar answered Oct 02 '22 01:10

thSoft


What you could do to get the users attention without being annoying is to change the windows text this is protable with a simple:

shellName.setText("task 20% complete")

this would allow the user to get an update while having the window minimized and then add a focus listener to return the window to its normal text when focus is regained. This would allow for minimal intrusiveness while informing the user.

like image 32
user187457 Avatar answered Oct 02 '22 01:10

user187457