private void permanentFocusOwnerChanged() { if (!isEditing()) { return; } myFocusManager.doWhenFocusSettlesDown(new ExpirableRunnable() { @Override public boolean isExpired() { return !isEditing(); } @Override public void run() { Component c = myFocusManager.getFocusOwner(); if (UIUtil.isMeaninglessFocusOwner(c)) { // this allows using popup menus and menu bar without stopping cell editing return; } while (c != null) { if (c instanceof JPopupMenu) { c = ((JPopupMenu)c).getInvoker(); } if (c == JBTable.this) { // focus remains inside the table return; } else if (c instanceof Window) { if (c == SwingUtilities.getWindowAncestor(JBTable.this)) { removeCellEditor(); } break; } c = c.getParent(); } } }); }
private void permanentFocusOwnerChanged() { if (!isEditing()) { return; } final IdeFocusManager focusManager = IdeFocusManager.findInstanceByComponent(JBTable.this); focusManager.doWhenFocusSettlesDown(new ExpirableRunnable() { @Override public boolean isExpired() { return !isEditing(); } @Override public void run() { Component c = focusManager.getFocusOwner(); if (UIUtil.isMeaninglessFocusOwner(c)) { // this allows using popup menus and menu bar without stopping cell editing return; } while (c != null) { if (c instanceof JPopupMenu) { c = ((JPopupMenu)c).getInvoker(); } if (c == JBTable.this) { // focus remains inside the table return; } else if (c instanceof Window) { if (c == SwingUtilities.getWindowAncestor(JBTable.this)) { removeCellEditor(); } break; } c = c.getParent(); } } }); }
@Override public void doWhenFocusSettlesDown(@NotNull ExpirableRunnable runnable) { if (!runnable.isExpired()) { runnable.run(); } }
@Override public void revalidateFocus(@NotNull ExpirableRunnable runnable) { }
@Override public void doWhenFocusSettlesDown(@NotNull ExpirableRunnable runnable) { getGlobalInstance().doWhenFocusSettlesDown(runnable); }
@Override public void revalidateFocus(@NotNull ExpirableRunnable runnable) { getGlobalInstance().revalidateFocus(runnable); }
public void restoreFocus() { final Application app = ApplicationManager.getApplication(); if (app == null || wrongOS() || myConsumed || isSheduledForRestore()) return; Project project = null; DataManager dataManager = DataManager.getInstance(); if (dataManager != null) { DataContext context = myParentWindow == null ? dataManager.getDataContext() : dataManager.getDataContext(myParentWindow); if (context != null) { project = CommonDataKeys.PROJECT.getData(context); } } mySheduledForRestore = true; final List<FocusTrackback> stack = getCleanStackForRoot(); final int index = stack.indexOf(this); for (int i = index - 1; i >=0; i--) { if (stack.get(i).isSheduledForRestore()) { dispose(); return; } } if (project != null && !project.isDisposed()) { final IdeFocusManager focusManager = IdeFocusManager.getInstance(project); cleanParentWindow(); final Project finalProject = project; focusManager.requestFocus(new MyFocusCommand(), myForcedRestore).doWhenProcessed(new Runnable() { public void run() { dispose(); } }).doWhenRejected(new Runnable() { @Override public void run() { focusManager.revalidateFocus(new ExpirableRunnable.ForProject(finalProject) { @Override public void run() { if (UIUtil.isMeaninglessFocusOwner(focusManager.getFocusOwner())) { focusManager.requestDefaultFocus(false); } } }); } }); } else { // no ide focus manager, so no way -- do just later //noinspection SSBasedInspection SwingUtilities.invokeLater(new Runnable() { public void run() { _restoreFocus(); dispose(); } }); } }
public void restoreFocus() { final Application app = ApplicationManager.getApplication(); if (app == null || wrongOS() || myConsumed || isSheduledForRestore()) return; Project project = null; DataContext context = myParentWindow == null ? DataManager.getInstance().getDataContext() : DataManager.getInstance().getDataContext(myParentWindow); if (context != null) { project = PlatformDataKeys.PROJECT.getData(context); } mySheduledForRestore = true; final List<FocusTrackback> stack = getCleanStackForRoot(); final int index = stack.indexOf(this); for (int i = index - 1; i >=0; i--) { if (stack.get(i).isSheduledForRestore()) { dispose(); return; } } if (project != null && !project.isDisposed()) { final IdeFocusManager focusManager = IdeFocusManager.getInstance(project); cleanParentWindow(); final Project finalProject = project; focusManager.requestFocus(new MyFocusCommand(), myForcedRestore).doWhenProcessed(new Runnable() { public void run() { dispose(); } }).doWhenRejected(new Runnable() { @Override public void run() { focusManager.revalidateFocus(new ExpirableRunnable.ForProject(finalProject) { @Override public void run() { if (UIUtil.isMeaninglessFocusOwner(focusManager.getFocusOwner())) { focusManager.requestDefaultFocus(false); } } }); } }); } else { // no ide focus manager, so no way -- do just later //noinspection SSBasedInspection SwingUtilities.invokeLater(new Runnable() { public void run() { _restoreFocus(); dispose(); } }); } }
@Override public void doWhenFocusSettlesDown(@Nonnull ExpirableRunnable runnable) { if (!runnable.isExpired()) { runnable.run(); } }
@Override public void doWhenFocusSettlesDown(@Nonnull ExpirableRunnable runnable) { getGlobalInstance().doWhenFocusSettlesDown(runnable); }
/** * Executes given runnable after all focus activities are finished */ public abstract void doWhenFocusSettlesDown(@NotNull ExpirableRunnable runnable);
/** * Injects some procedure that will maybe do something with focus after all focus requests are fulfilled and * before focus transfer is reported ready. */ public abstract void revalidateFocus(@NotNull ExpirableRunnable runnable);
/** * Executes given runnable after all focus activities are finished * @param runnable */ public abstract void doWhenFocusSettlesDown(@NotNull ExpirableRunnable runnable);
/** * Injects some procedure that will maybe do something with focus after all focus requests are fulfilled and * before focus transfer is reported ready. * @param runnable */ public abstract void revalidateFocus(@NotNull ExpirableRunnable runnable);
/** * Executes given runnable after all focus activities are finished */ public abstract void doWhenFocusSettlesDown(@Nonnull ExpirableRunnable runnable);