Java Code Examples for org.eclipse.swt.widgets.Shell#forceActive()
The following examples show how to use
org.eclipse.swt.widgets.Shell#forceActive() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwtAppleCommander.java From AppleCommander with GNU General Public License v2.0 | 5 votes |
/** * Launch SwtAppleCommander with a given display. * Primary motivation is getting S-Leak to work! */ public void launch(Display display) { imageManager = new ImageManager(display); SwtAppleCommander application = new SwtAppleCommander(); Shell shell = application.open(display); shell.forceActive(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } UserPreferences.getInstance().save(); }
Example 2
Source File: ShellFactory.java From BiglyBT with GNU General Public License v2.0 | 5 votes |
@Override public void open() { UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT(); if (uiFunctions != null) { Boolean bringToFront = (Boolean)getData( "bringToFront" ); if ( bringToFront == null || bringToFront ){ Shell mainShell = uiFunctions.getMainShell(); if (mainShell != null && mainShell.getMinimized()) { uiFunctions.bringToFront(); } } } Shell firstShellWithStyle = Utils.findFirstShellWithStyle(SWT.APPLICATION_MODAL); if (firstShellWithStyle != null && firstShellWithStyle != this) { // ok, there's a window with application_modal set, which on OSX will mean // that if we open our window, it will be on top, but users won't be able // to interact with it. So, wait until the modal window goes away.. firstShellWithStyle.addDisposeListener(new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { // wait for dispose to complete, then run open again to check for // any new application modal shells to wait for Utils.execSWTThreadLater(0, new AERunnable() { @Override public void runSupport() { AEShell.this.open(); } }); } }); firstShellWithStyle.setVisible(true); firstShellWithStyle.forceActive(); } else { if (!isDisposed()) { super.open(); } } }
Example 3
Source File: DebugEarlyStartup.java From Pydev with Eclipse Public License 1.0 | 4 votes |
/** * There are some issues with just forceActive as it doesn't actually bring it to the front on windows on some situations. * * - https://bugs.eclipse.org/bugs/show_bug.cgi?id=192036: outlines the win32 solution implemented in here (using reflection to avoid issues compiling on other platforms). * * Some possible alternatives: * - we could change the text/icon in the taskbar (http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet336.java) * - Creating our own windows-dependent dll (but this is probably too much for the build process too) http://stackoverflow.com/questions/2773364/make-jface-window-blink-in-taskbar-or-get-users-attention * - https://github.com/jnr/jnr-ffi using the approach commented on http://stackoverflow.com/questions/2315560/how-do-you-force-a-java-swt-program-to-move-itself-to-the-foreground seems a possible acceptable workaround */ public void forceActive(final Shell shell, int forceOption) { //First, make sure it's not minimized shell.setMinimized(false); if (forceOption == DebugPluginPrefsInitializer.FORCE_SHOW_SHELL_ON_BREAKPOINT_MAKE_ACTIVE) { if (PlatformUtils.isWindowsPlatform()) { try { Class<?> OSClass = Class.forName("org.eclipse.swt.internal.win32.OS"); Method hFromMethod = OSClass.getMethod("GetForegroundWindow"); Method SetForegroundWindowMethod = OSClass.getMethod("SetForegroundWindow", int.class); Method GetWindowThreadProcessIdMethod = OSClass.getMethod("GetWindowThreadProcessId", int.class, int[].class); int hFrom = (int) hFromMethod.invoke(OSClass); //int hFrom = OS.GetForegroundWindow(); // on Mac it's not available, so, use reflection to compile on it. Field handleField = shell.getClass().getDeclaredField("handle"); int shellHandle = (Integer) handleField.get(shell); if (hFrom <= 0) { //OS.SetForegroundWindow(shell.handle); SetForegroundWindowMethod.invoke(OSClass, shellHandle); return; } if (shellHandle == hFrom) { return; } //int pid = OS.GetWindowThreadProcessId(hFrom, null); int pid = (int) GetWindowThreadProcessIdMethod.invoke(OSClass, hFrom, null); //int _threadid = OS.GetWindowThreadProcessId(shell.handle, null); int _threadid = (int) GetWindowThreadProcessIdMethod.invoke(OSClass, shellHandle, null); if (_threadid == pid) { //OS.SetForegroundWindow(shell.handle); SetForegroundWindowMethod.invoke(OSClass, shellHandle); return; } if (pid > 0) { Method AttachThreadInputMethod = OSClass.getMethod("AttachThreadInput", int.class, int.class, boolean.class); //if (!OS.AttachThreadInput(_threadid, pid, true)) { if (!((boolean) AttachThreadInputMethod.invoke(OSClass, _threadid, pid, true))) { return; } //OS.SetForegroundWindow(shell.handle); SetForegroundWindowMethod.invoke(OSClass, shellHandle); //OS.AttachThreadInput(_threadid, pid, false); AttachThreadInputMethod.invoke(OSClass, _threadid, pid, false); } //OS.BringWindowToTop(shell.handle); //OS.UpdateWindow(shell.handle); //OS.SetActiveWindow(shell.handle); for (String s : new String[] { "BringWindowToTop", "UpdateWindow", "SetActiveWindow" }) { Method method = OSClass.getMethod(s, int.class); method.invoke(OSClass, shellHandle); } return; //ok, workaround on win32 worked. } catch (Throwable e) { // Log and go the usual platform-independent route... Log.log(e); } //As specified from http://www.eclipsezone.com/eclipse/forums/t28413.html: shell.forceActive(); shell.setActive(); } } if (forceOption == DebugPluginPrefsInitializer.FORCE_SHOW_SHELL_ON_BREAKPOINT_SHOW_INDETERMINATE_PROGRESS) { final TaskBar taskBar = shell.getDisplay().getSystemTaskBar(); if (taskBar != null) { TaskItem item = taskBar.getItem(shell); if (item == null) { item = taskBar.getItem(null); } RunInUiThread.async(new ShowIndeterminateProgressRunnable(shell, item, System.currentTimeMillis() + 5000)); } } }