Java 类com.google.gwt.user.client.ui.impl.FocusImpl 实例源码

项目:calendar-component    文件:FocusableComplexPanel.java   
/**
 * Sets/Removes the keyboard focus to the panel.
 *
 * @param focus
 *            If set to true then the focus is moved to the panel, if set to
 *            false the focus is removed
 */
public void setFocus(boolean focus) {
    if (focus) {
        FocusImpl.getFocusImplForPanel().focus(getElement());
    } else {
        FocusImpl.getFocusImplForPanel().blur(getElement());
    }
}
项目:calendar-component    文件:FocusableGrid.java   
/**
 * Sets/Removes the keyboard focus to the panel.
 *
 * @param focus
 *            If set to true then the focus is moved to the panel, if set to
 *            false the focus is removed
 */
public void setFocus(boolean focus) {
    if (focus) {
        FocusImpl.getFocusImplForPanel().focus(getElement());
    } else {
        FocusImpl.getFocusImplForPanel().blur(getElement());
    }
}
项目:calendar-component    文件:FocusableHTML.java   
/**
 * Sets/Removes the keyboard focus to the panel.
 *
 * @param focus
 *            If set to true then the focus is moved to the panel, if set to
 *            false the focus is removed
 */
public void setFocus(boolean focus) {
    if (focus) {
        FocusImpl.getFocusImplForPanel().focus(getElement());
    } else {
        FocusImpl.getFocusImplForPanel().blur(getElement());
    }
}
项目:cuba    文件:SuggestionsContainer.java   
public SuggestionsContainer(CubaSuggestionFieldWidget suggestionFieldWidget) {
    this.suggestionFieldWidget = suggestionFieldWidget;
    container = DOM.createDiv();

    final Element outer = FocusImpl.getFocusImplForPanel().createFocusable();
    DOM.appendChild(outer, container);
    setElement(outer);

    sinkEvents(Event.ONCLICK | Event.ONMOUSEDOWN | Event.ONMOUSEOVER | Event.ONMOUSEOUT | Event.ONFOCUS | Event.ONKEYDOWN);
    addDomHandler(event ->
            selectItem(null), BlurEvent.getType());

    setStylePrimaryName(STYLENAME);
}
项目:cuba    文件:SuggestionsContainer.java   
protected void performItemCommand(final SuggestionItem item) {
    selectedSuggestion = item;

    Scheduler.ScheduledCommand cmd = item.getScheduledCommand();
    if (cmd != null) {
        FocusImpl.getFocusImplForPanel().blur(getElement());

        Scheduler.get().scheduleFinally(cmd);
    }
}
项目:cuba    文件:FocusableFlowPanel.java   
protected void setFocus(boolean focus) {
    if (focus) {
        FocusImpl.getFocusImplForPanel().focus(getElement());
    } else {
        FocusImpl.getFocusImplForPanel().blur(getElement());
    }
}
项目:Wiab.pro    文件:DomHelper.java   
/**
 * Focus the element, if possible
 * @param element
 */
public static void focus(Element element) {
  // NOTE(user): This may not work for divs, rather use getFocusImplForPanel
  //               for divs.
  try {
    FocusImpl.getFocusImplForWidget().focus(castToOld(element));
  } catch (Exception e) {
    // Suppress null pointer condition
  }
}
项目:Wiab.pro    文件:InteractiveSuggestionsManager.java   
@Override
public void onShow(PopupEventSourcer source) {
  // NOTE(user): Clear selection so that it doesn't get forcibly restored
  // when applying operations. In Firefox, that would take focus away from the
  // suggestion menu.
  selectionHelper.clearSelection();
  FocusImpl.getFocusImplForPanel().focus(menu.getElement());
}
项目:suggestfield    文件:SuggestionMenuBar.java   
void doItemAction(final SuggestionMenuItem item, boolean fireCommand,
        boolean focus) {
    // Should not perform any action if the item is disabled
    if (!item.isEnabled()) {
        return;
    }

    // Ensure that the item is selected.
    selectItem(item);

    // if the command should be fired and the item has one, fire it
    if (fireCommand && item.getScheduledCommand() != null) {
        // Close this menu and all of its parents.
        selectItem(null);

        // Remove the focus from the menu
        // FocusPanel.impl.blur(getElement());
        FocusImpl.getFocusImplForPanel().blur(getElement());

        // Fire the item's command. The command must be fired in the same
        // event
        // loop or popup blockers will prevent popups from opening.
        final ScheduledCommand cmd = item.getScheduledCommand();
        Scheduler.get().scheduleFinally(new Scheduler.ScheduledCommand() {
            @Override
            public void execute() {
                cmd.execute();
            }
        });
    }

}
项目:suggestfield    文件:SuggestionMenuBar.java   
private void init() {
    Element table = DOM.createTable();
    body = DOM.createTBody();
    DOM.appendChild(table, body);

    Element outer = FocusImpl.getFocusImplForPanel().createFocusable();
    DOM.appendChild(outer, table);
    setElement(outer);

    Roles.getMenubarRole().set(getElement());

    sinkEvents(Event.ONCLICK | Event.ONMOUSEOVER | Event.ONMOUSEOUT
            | Event.ONFOCUS | Event.ONKEYDOWN);

    setStyleName(STYLENAME_DEFAULT);
    addStyleDependentName("vertical");

    // Hide focus outline in Mozilla/Webkit/Opera
    getElement().getStyle().setProperty("outline", "0px");

    // Hide focus outline in IE 6/7
    getElement().setAttribute("hideFocus", "true");

    // Deselect items when blurring without a child menu.
    addDomHandler(new BlurHandler() {
        @Override
        public void onBlur(BlurEvent event) {
            selectItem(null);
        }
    }, BlurEvent.getType());
}
项目:incubator-wave    文件:DomHelper.java   
/**
 * Focus the element, if possible
 * @param element
 */
public static void focus(Element element) {
  // NOTE(user): This may not work for divs, rather use getFocusImplForPanel
  //               for divs.
  try {
    FocusImpl.getFocusImplForWidget().focus(castToOld(element));
  } catch (Exception e) {
    // Suppress null pointer condition
  }
}
项目:incubator-wave    文件:InteractiveSuggestionsManager.java   
@Override
public void onShow(PopupEventSourcer source) {
  // NOTE(user): Clear selection so that it doesn't get forcibly restored
  // when applying operations. In Firefox, that would take focus away from the
  // suggestion menu.
  selectionHelper.clearSelection();
  FocusImpl.getFocusImplForPanel().focus(menu.getElement());
}
项目:consulo    文件:CellTreeNodeView.java   
/**
 * Select or deselect this node with the keyboard.
 *
 * @param selected   true if selected, false if not
 * @param stealFocus true to steal focus
 */
void setKeyboardSelected(boolean selected, boolean stealFocus) {
  if (tree.isKeyboardSelectionDisabled()) {
    return;
  }

  // Apply the selected style.
  if (!selected || tree.isFocused || stealFocus) {
    setKeyboardSelectedStyle(selected);
  }

  // Make the node focusable or not.
  Element cellParent = getCellParent();
  if (!selected) {
    // Chrome: Elements remain focusable after removing the tabIndex, so set
    // it to -1 first.
    cellParent.setTabIndex(-1);
    cellParent.removeAttribute("tabIndex");
    cellParent.removeAttribute("accessKey");
  }
  else {
    FocusImpl focusImpl = FocusImpl.getFocusImplForWidget();
    focusImpl.setTabIndex(cellParent, tree.getTabIndex());
    char accessKey = tree.getAccessKey();
    if (accessKey != 0) {
      focusImpl.setAccessKey(cellParent, accessKey);
    }
    if (stealFocus && !tree.cellIsEditing) {
      cellParent.focus();
    }
  }

  // Update the selection model.
  if (KeyboardSelectionPolicy.BOUND_TO_SELECTION == tree.getKeyboardSelectionPolicy()) {
    setSelected(selected);
  }
}
项目:unitimes    文件:ClickableHint.java   
@Override
public void setAccessKey(char key) {
    FocusImpl.getFocusImplForWidget().setAccessKey(getElement(), key);
}
项目:Wiab.pro    文件:EditorImpl.java   
/**
 * TODO(user): use content document to set caret, and issue operation
 *
 * TODO(danilatos): This stuff seems out of date...
 *
 * TODO(danilatos): Make this method trivially idempotent
 *
 * {@inheritDoc}
 */
@Override
public void focus(boolean collapsed) {
  if (!isAttached()) {
    EditorStaticDeps.logger.error().log("Shouldn't focus a detached editor");
    return;
  }

  // focus document
  if (isEditing() && content != null) {
    // first, handle DOM focus
    FocusedPointRange<Node> htmlSelection = getHtmlSelection(); // save before focusing.

    // element causes webkit based browsers to automatically scroll the element into view
    // In wave, we want to be in charge of how things move, so we cancel this behaviour
    // here by first recording the scrollTops of all the editor's ancestors, and
    // then resetting them after calling focus.
    Element docElement = getDocumentHtmlElement();
    maybeSaveAncestorScrollPositions(docElement);
    FocusImpl.getFocusImplForWidget().focus(DomHelper.castToOld(docElement));
    maybeRestoreAncestorScrollPositions(docElement);

    // then, handle the case when selection already existed inside the element:
    if (htmlSelection != null) {
      // NOTE(patcoleman): we may have killed it with the DOM focusing above, so restore
      NativeSelectionUtil.set(htmlSelection);

      if (!collapsed) {
        // if we have selection, and we're not forcibly collapsing it, then nothing needs doing.
        return;
      } else {
        // Otherwise, we might need to adjust it if we're collapsing it. So we'll fall through to
        // the manual selection-restore-with-collapse, but first we save what we have anyway.
        EditorStaticDeps.logger.trace().log("Saving...");
        doSaveSelection();
      }
    }

    // finally, make sure selection is correct:
    safelyRestoreSelection(aggressiveSelectionHelper, collapsed);
    scheduleUpdateNotification(true, true, false, false);
  }
}
项目:che    文件:Tree.java   
public Tree(
    NodeStorage nodeStorage,
    NodeLoader nodeLoader,
    TreeStyles treeStyles,
    EmptyStatus<Tree> emptyStatus) {
  checkNotNull(nodeStorage);
  checkNotNull(nodeLoader);
  checkNotNull(treeStyles);

  this.treeStyles = treeStyles;
  this.treeStyles.styles().ensureInjected();
  this.nodesByDom = new HashMap<>();
  this.focusImpl = FocusImpl.getFocusImplForPanel();
  this.storeHandlers = new GroupingHandlerRegistration();

  ensureTreeElement();
  ensureFocusElement();

  setNodeStorage(nodeStorage);
  setNodeLoader(nodeLoader);
  setSelectionModel(new SelectionModel());
  setGoInto(new DefaultGoInto());
  setView(new TreeView());
  setAllowTextSelection(false);

  disableBrowserContextMenu(true);

  // use as default
  if (emptyStatus == null) {
    emptyStatus = new StatusText<>();
  }
  this.emptyStatus = emptyStatus;
  this.emptyStatus.init(
      this,
      new Predicate<Tree>() {
        @Override
        public boolean apply(@Nullable Tree tree) {
          return tree.getNodeStorage().getRootCount() == 0;
        }
      });
}
项目:unitime    文件:ClickableHint.java   
@Override
public void setAccessKey(char key) {
    FocusImpl.getFocusImplForWidget().setAccessKey(getElement(), key);
}
项目:suggestfield    文件:SuggestionMenuBar.java   
/**
 * Give this MenuBar focus.
 */
public void focus() {
    FocusImpl.getFocusImplForPanel().focus(getElement());
}
项目:suggestfield    文件:SuggestionMenuBar.java   
@Override
public void onBrowserEvent(Event event) {
    SuggestionMenuItem item = findItem(DOM.eventGetTarget(event));
    switch (DOM.eventGetType(event)) {
    case Event.ONCLICK: {
        FocusImpl.getFocusImplForPanel().focus(getElement());
        // Fire an item's command when the user clicks on it.
        if (item != null) {
            doItemAction(item, true, true);
        }
        break;
    }

    case Event.ONMOUSEOVER: {
        if (item != null) {
            itemOver(item, true);
        }
        break;
    }

    case Event.ONMOUSEOUT: {
        if (item != null) {
            itemOver(null, false);
        }
        break;
    }

    case Event.ONFOCUS: {
        selectFirstItemIfNoneSelected();
        break;
    }

    case Event.ONKEYDOWN: {
        int keyCode = event.getKeyCode();
        boolean isRtl = LocaleInfo.getCurrentLocale().isRTL();
        keyCode = KeyCodes.maybeSwapArrowKeysForRtl(keyCode, isRtl);
        switch (keyCode) {
        case KeyCodes.KEY_UP:
            moveSelectionUp();
            eatEvent(event);
            break;
        case KeyCodes.KEY_DOWN:
            moveSelectionDown();
            eatEvent(event);
            break;
        case KeyCodes.KEY_ESCAPE:
            selectItem(null);
            eatEvent(event);
            break;
        case KeyCodes.KEY_TAB:
            selectItem(null);
            break;
        case KeyCodes.KEY_ENTER:
            if (!selectFirstItemIfNoneSelected()) {
                doItemAction(selectedItem, true, true);
                eatEvent(event);
            }
            break;
        } // end switch(keyCode)

        break;
    } // end case Event.ONKEYDOWN
    } // end switch (DOM.eventGetType(event))
    super.onBrowserEvent(event);
}
项目:incubator-wave    文件:EditorImpl.java   
/**
 * TODO(user): use content document to set caret, and issue operation
 *
 * TODO(danilatos): This stuff seems out of date...
 *
 * TODO(danilatos): Make this method trivially idempotent
 *
 * {@inheritDoc}
 */
@Override
public void focus(boolean collapsed) {
  if (!isAttached()) {
    EditorStaticDeps.logger.error().log("Shouldn't focus a detached editor");
    return;
  }

  // focus document
  if (isEditing() && content != null) {
    // first, handle DOM focus
    FocusedPointRange<Node> htmlSelection = getHtmlSelection(); // save before focusing.

    // element causes webkit based browsers to automatically scroll the element into view
    // In wave, we want to be in charge of how things move, so we cancel this behaviour
    // here by first recording the scrollTops of all the editor's ancestors, and
    // then resetting them after calling focus.
    Element docElement = getDocumentHtmlElement();
    maybeSaveAncestorScrollPositions(docElement);
    FocusImpl.getFocusImplForWidget().focus(DomHelper.castToOld(docElement));
    maybeRestoreAncestorScrollPositions(docElement);

    // then, handle the case when selection already existed inside the element:
    if (htmlSelection != null) {
      // NOTE(patcoleman): we may have killed it with the DOM focusing above, so restore
      NativeSelectionUtil.set(htmlSelection);

      if (!collapsed) {
        // if we have selection, and we're not forcibly collapsing it, then nothing needs doing.
        return;
      } else {
        // Otherwise, we might need to adjust it if we're collapsing it. So we'll fall through to
        // the manual selection-restore-with-collapse, but first we save what we have anyway.
        EditorStaticDeps.logger.trace().log("Saving...");
        doSaveSelection();
      }
    }

    // finally, make sure selection is correct:
    safelyRestoreSelection(aggressiveSelectionHelper, collapsed);
    scheduleUpdateNotification(true, true, false, false);
  }
}
项目:Wiab.pro    文件:DomHelper.java   
/**
 * Blur the element, if possible
 * @param element
 *
 * NOTE(user): Dan thinks this method should be deprecated, but is not
 *               sure why... Dan, please update once you remember.
 */
public static void blur(Element element) {
  FocusImpl.getFocusImplForWidget().blur(castToOld(element));
}
项目:incubator-wave    文件:DomHelper.java   
/**
 * Blur the element, if possible
 * @param element
 *
 * NOTE(user): Dan thinks this method should be deprecated, but is not
 *               sure why... Dan, please update once you remember.
 */
public static void blur(Element element) {
  FocusImpl.getFocusImplForWidget().blur(castToOld(element));
}