com.google.gwt.user.client.ui.impl.FocusImpl Java Examples

The following examples show how to use com.google.gwt.user.client.ui.impl.FocusImpl. 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: SuggestionsContainer.java    From cuba with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #2
Source File: FocusableComplexPanel.java    From calendar-component with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
    }
}
 
Example #3
Source File: FocusableGrid.java    From calendar-component with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
    }
}
 
Example #4
Source File: FocusableHTML.java    From calendar-component with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
    }
}
 
Example #5
Source File: SuggestionsContainer.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void performItemCommand(final SuggestionItem item) {
    selectedItem = item;

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

        Scheduler.get().scheduleFinally(cmd);
    }
}
 
Example #6
Source File: FocusableFlowPanel.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void setFocus(boolean focus) {
    if (focus) {
        FocusImpl.getFocusImplForPanel().focus(getElement());
    } else {
        FocusImpl.getFocusImplForPanel().blur(getElement());
    }
}
 
Example #7
Source File: DomHelper.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * 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
  }
}
 
Example #8
Source File: InteractiveSuggestionsManager.java    From swellrt with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #9
Source File: DomHelper.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * 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
  }
}
 
Example #10
Source File: InteractiveSuggestionsManager.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #11
Source File: CellTreeNodeView.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
  }
}
 
Example #12
Source File: ClickableHint.java    From unitime with Apache License 2.0 4 votes vote down vote up
@Override
public void setAccessKey(char key) {
	FocusImpl.getFocusImplForWidget().setAccessKey(getElement(), key);
}
 
Example #13
Source File: EditorImpl.java    From swellrt with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
  }
}
 
Example #14
Source File: EditorImpl.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
  }
}
 
Example #15
Source File: DomHelper.java    From swellrt with Apache License 2.0 2 votes vote down vote up
/**
 * 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));
}
 
Example #16
Source File: DomHelper.java    From incubator-retired-wave with Apache License 2.0 2 votes vote down vote up
/**
 * 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));
}