com.google.gwt.user.client.ui.Focusable Java Examples

The following examples show how to use com.google.gwt.user.client.ui.Focusable. 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: MockComponent.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a tree item for the component which will be displayed in the
 * source structure explorer.
 *
 * @return  tree item for this component
 */
protected TreeItem buildTree() {
  // Instantiate new tree item for this component
  // Note: We create a ClippedImagePrototype because we need something that can be
  // used to get HTML for the iconImage. AbstractImagePrototype requires
  // an ImageResource, which we don't necessarily have.
  TreeItem itemNode = new TreeItem(
      new HTML("<span>" + iconImage.getElement().getString() + SafeHtmlUtils.htmlEscapeAllowEntities(getName()) + "</span>")) {
    @Override
    protected Focusable getFocusable() {
      return nullFocusable;
    }
  };
  itemNode.setUserObject(sourceStructureExplorerItem);
  return itemNode;
}
 
Example #2
Source File: VPopupButton.java    From cuba with Apache License 2.0 6 votes vote down vote up
/**
 * Try to sync all known active child widgets to server
 */
private void syncChildren() {
    // Notify children with focus
    if ((getWidget() instanceof Focusable)) {
        ((Focusable) getWidget()).setFocus(false);
    } else {
        checkForRTE(getWidget());
    }

    // Notify children that have used the keyboard
    for (Element e : activeChildren) {
        try {
            nativeBlur(e);
        } catch (Exception ignored) {
        }
    }
    activeChildren.clear();
}
 
Example #3
Source File: UniTimeTable.java    From unitime with Apache License 2.0 6 votes vote down vote up
private boolean focus(int row, int col) {
	if (!getRowFormatter().isVisible(row) || col >= getCellCount(row)) return false;
	Widget w = super.getWidget(row, col);
	if (w == null || !w.isVisible()) return false;
	if (w instanceof SmartTableCell) {
		return ((SmartTableCell)w).focus();
	} else if (w instanceof HasFocus) {
		return ((HasFocus)w).focus();
	} else if (w instanceof Focusable) {
		((Focusable)w).setFocus(true);
		if (w instanceof TextBoxBase)
			((TextBoxBase)w).selectAll();
		return true;
	}
	return false;
}
 
Example #4
Source File: AutoSizingBase.java    From gwt-traction with Apache License 2.0 6 votes vote down vote up
public AutoSizingBase(T box, S shadow) {
this.box = box;
this.shadow = shadow;

	box.addKeyDownHandler(this);
	box.addKeyUpHandler(this);
box.addValueChangeHandler(this);

div.setStyleName("gwt-traction-input-autosize");
shadow.setStyleName("gwt-traction-input-shadow");

// make sure the shadow isn't in the tab order
if (shadow instanceof Focusable) {
    // we can't use -1 because FocusWidget.onAttach looks for
    // that and sets it to 0. any negative value will remove
    // it from the tab order.
    ((Focusable) shadow).setTabIndex(-2);
}

// note this has to be in a FlowPanel to work
div.add(box);
div.add(shadow);

initWidget(div);	
   }
 
Example #5
Source File: SimpleEditPage.java    From unitime with Apache License 2.0 5 votes vote down vote up
public boolean focus() { 
	Widget w = getWidget();
	if (w instanceof UniTimeWidget<?>)
		w = ((UniTimeWidget<?>)w).getWidget();
	if (w instanceof Focusable) {
		((Focusable)w).setFocus(true);
		if (w instanceof TextBox)
			((TextBox)w).selectAll();
		return true;
	}
	return false;
}
 
Example #6
Source File: UniTimeTable.java    From unitime with Apache License 2.0 5 votes vote down vote up
public boolean focus() {
	if (getWidget() instanceof HasFocus) {
		return ((HasFocus)getWidget()).focus();
	} else if (getWidget() instanceof Focusable) {
		((Focusable)getWidget()).setFocus(true);
		if (getWidget() instanceof TextBoxBase)
			((TextBoxBase)getWidget()).selectAll();
		return true;
	}
	return false;
}
 
Example #7
Source File: InputList.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void resetFocusHandler() {
	this.registrationCollection.removeHandler();
	boolean hasError = this.hasErrors();
	if (!hasError && !this.focused) {
		this.setTabIndex(0);
		this.registrationCollection.add(this.addFocusHandler(this));
	} else if (hasError && !this.focused) {
		this.setTabIndex(-1);
		if (this.input instanceof HasFocusHandlers) {
			this.registrationCollection.add(((HasFocusHandlers) this.input).addFocusHandler(this));
		}
	} else {
		this.setTabIndex(-1);
		if (this.input instanceof HasBlurHandlers) {
			this.registrationCollection.add(((HasBlurHandlers) this.input).addBlurHandler(this));
		}
		Scheduler.get().scheduleDeferred(new ScheduledCommand() {

			@Override
			public void execute() {
				if (InternalListItem.this.input instanceof Focusable) {
					((Focusable) InternalListItem.this.input).setFocus(true);
				}
			}
		});
	}
}
 
Example #8
Source File: FormGroup.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void setFocus(boolean focused) {
	if (editor instanceof Focusable) {
		Focusable focusable = (Focusable) editor;
		focusable.setFocus(focused);
	}
}
 
Example #9
Source File: FormGroup.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void initFocusableEditor() {
	if (editor instanceof Focusable) {
		Focusable focusable = (Focusable) editor;
		if (accessKey != null) {
			focusable.setAccessKey(accessKey);
		}
		if (tabIndex != null) {
			focusable.setTabIndex(tabIndex);
		}
	}
}
 
Example #10
Source File: ErrorBinderVisitor.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public <A, B extends Editor> boolean visit(Context<B> context) {
	B editor = context.getEditor();

	if (editor instanceof EditorError) {
		Class<?> propertyType = ModelUtils.resolveType(this.model, context.getPath());

		Path path = context.getPath();
		EditorError editorError = (EditorError) editor;
		editorError.clearErrors();

		List<Error> toDisplay = Lists.newArrayList();
		for (Error error : this.errors) {
			if (path.equals(error.getPath()) && !error.isConsumed()) {
				String messageKey = error.getMessageKey();
				messageKey = this.fixMessageKey(messageKey);
				String message = messageHelper.getMessage(propertyType, path, messageKey);
				if (message == null) {
					message = messageHelper.findMessage(propertyType, messageKey);
				}
				if (error.getParameters() != null) {
					message = MessageHelper.replaceParams(message, error.getParameters());
				}
				if (message == null) {
					message = messageKey;
				}
				SimpleError errorToDisplay = new SimpleError(editorError, message, error.getValue(), error.getParameters());
				toDisplay.add(errorToDisplay);
				error.consume();
			}
		}
		if (!toDisplay.isEmpty() && editorError instanceof HasDrawable) {
			editorError.displayErrors(toDisplay);
			((HasDrawable) editorError).redraw();
			if (!focused && editorError instanceof Focusable) {
				focused = true;
				((Focusable) editorError).setFocus(true);
			}
		}
	}
	return true;
}
 
Example #11
Source File: ContentAssistAspect.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void showSuggestions(Oracle.Request request, final IsWidget textInput,
	Collection<? extends Suggestion<T>> suggestions, final SuggestionCallback<T> callback) {

	boolean anySuggestions = suggestions != null && !suggestions.isEmpty();
	if (!anySuggestions && this.hideWhenEmpty) {
		this.hideSuggestions();
		return;
	}

	if (this.suggestionPopup.isAttached()) {
		this.suggestionPopup.hide();
	}

	this.suggestionsContainer.clear();

	SuggestionItem<T> selected = null;
	for (final Oracle.Suggestion<T> currentSuggestion : suggestions) {
		String display = highlighter.highlight(currentSuggestion.getValue(), request.getQuery());
		final SuggestionItem<T> suggestionItem = new SuggestionItem<T>(currentSuggestion, display);
		if (selected == null) {
			selected = suggestionItem;
		}
		if (this.selectedItem != null && currentSuggestion.equals(this.selectedItem.suggestion)) {
			selected = suggestionItem;
		}

		suggestionItem.addDomHandler(new MouseUpHandler() {
			@Override
			public void onMouseUp(MouseUpEvent event) {
				if (textInput instanceof Focusable) {
					((Focusable) textInput).setFocus(true);
				}
				SuggestionDisplayImpl.this.setSuggestionItemSelected(suggestionItem);
				callback.onSuggestionSelected(suggestionItem.suggestion);
			}
		}, MouseUpEvent.getType());

		this.suggestionsContainer.append(suggestionItem);
	}

	this.setSuggestionItemSelected(selected);

	if (this.lastTextInput != textInput) {
		if (this.lastTextInput != null) {
			this.suggestionPopup.removeAutoHidePartner(this.lastTextInput.asWidget().getElement());
		}
		this.lastTextInput = textInput;
		this.suggestionPopup.addAutoHidePartner(this.lastTextInput.asWidget().getElement());
	}

	this.suggestionPopup.showRelativeTo(this.lastTextInput.asWidget());
	this.scrollToSelected();
}