Make JFace Window blink in taskbar or get users attention?
Asked Answered
V

4

9

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!

Vesuvianite answered 5/5, 2010 at 12:58 Comment(0)
D
2

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.

Disregard answered 5/5, 2010 at 18:39 Comment(2)
thanks for that snippet - but having several different versions for each OS is not really what I wanted to achieve...Vesuvianite
To my knowledge, there is no pure Java solution. JNA/JNI can be quite imposing, but you only need to have three implementations. Unfortunately, you'll have to ask somebody else for the other two. :)Disregard
I
2

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.

Incredible answered 18/5, 2010 at 7:57 Comment(2)
Thanks, I already had a look at that feature but the problem is that I cannot force my users to upgrade to 3.6 :-(Vesuvianite
Too bad. Maybe separate this functionality into a plugin with the proper version constraints and mark it optional?Incredible
S
1

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.

Swelter answered 17/5, 2010 at 21:15 Comment(0)
B
0

I had a similar problem with my plug-in.

What I ended up doing is creating a small icon for my program in the lower status dock (or whatever that thing at the bottom is called). Based on the completion of processes and other background events, my icon changes color and flashes (e.g., goes from grey to green when its initial setup is complete).

By making double clicks or right-clicks on this icon context-sensitive, I can then do things like open a corresponding window.

Burack answered 17/5, 2010 at 21:32 Comment(1)
are you talking about the taskbar in windows? or is this an OS idependant workaround?Vesuvianite

© 2022 - 2024 — McMap. All rights reserved.