下面列出了怎么用com.google.gwt.core.client.Scheduler的API类实例代码及写法,或者点击链接到github查看源代码。
public void showPopup() {
popup.setWidth(640);
popup.setHeight(480);
popup.setModal(true);
popup.setGlassEnabled(true);
popup.center();
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
if (index.isEmpty()) {
popup.index();
} else {
popup.showSearchPage();
}
}
});
}
/**
* Animate any element with specific animation. Animation is done by CSS and runs multiple times.
*
* Animation is started when element is appended to the DOM or new (not same) animation is added
* to already displayed element. Animation runs on hidden elements too and is not paused/stopped
* when element is set as hidden.
*
* @param widget Widget to apply animation to.
* @param animation Custom CSS class name used as animation.
* @param count Number of animation repeats. 0 disables animation, any negative value set repeats to infinite.
* @param duration Animation duration in ms. 0 disables animation, any negative value keeps default of original animation.
* @param delay Delay before starting the animation loop in ms. Value <= 0 means no delay.
* @param <T> Any object extending UIObject class (typically Widget).
* @return Animation's CSS class name, which can be removed to stop animation.
*/
public static <T extends UIObject> String animate(final T widget, final String animation, final int count, final int duration, final int delay) {
if (widget != null && animation != null) {
// on valid input
if (widget.getStyleName().contains(animation)) {
// animation is present, remove it and run again.
stopAnimation(widget, animation);
Scheduler.get().scheduleFixedDelay(new Scheduler.RepeatingCommand() {
@Override
public boolean execute() {
styleElement(widget.getElement(), animation, count, duration, delay);
return false;
}
}, 200);
return animation + " " + getStyleNameFromAnimation(animation,count,duration,delay);
} else {
// animation was not present, run immediately
return styleElement(widget.getElement(), animation, count, duration, delay);
}
} else {
return null;
}
}
@Override
protected void onAttach() {
super.onAttach();
/*
* When this window gets reattached, set the tabstop to the previous
* state.
*/
setTabStopEnabled(doTabStop);
// Fix for #14413. Any pseudo elements inside these elements are not
// visible on initial render unless we shake the DOM.
if (BrowserInfo.get().isIE8()) {
closeBox.getStyle().setDisplay(Style.Display.NONE);
Scheduler.get().scheduleFinally(new Command() {
@Override
public void execute() {
closeBox.getStyle().clearDisplay();
}
});
}
}
public void checkEligibility(boolean online, boolean sectioning, Long sessionId, Long studentId, PinCallback callback, AcademicSessionInfo session) {
iOnline = online;
iSectioning = sectioning;
iSessionId = sessionId;
iStudentId = studentId;
iCallback = callback;
if (session != null) {
setText(MESSAGES.dialogPinForSession(session.getTerm(), session.getYear()));
iPinLabel.setText(MESSAGES.pinForSession(session.getTerm(), session.getYear()));
} else {
setText(MESSAGES.dialogPin());
iPinLabel.setText(MESSAGES.pin());
}
iPin.setText("");
center();
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
iPin.setFocus(true);
}
});
}
@Override
public void onFocus(FocusEvent event) {
super.onFocus(event);
if (!this.focused) {
this.focused = true;
if (!isReadOnly() && isEnabled()) {
if (mask != null && nullRepresentation != null && nullRepresentation.equals(super.getText())) {
addStyleName("c-focus-move");
Scheduler.get().scheduleDeferred(() -> {
if (!isReadOnly() && isEnabled() && focused) {
setSelectionRange(getPreviousPos(0), 0);
}
removeStyleName("c-focus-move");
});
}
}
}
}
private void initOnEdit() {
// LOG.info("initOnEdit");
originChildren = null;
lastClicked = null;
updateReorderUi(false);
attachListResultSet();
// select first
if (!childrenListGrid.getOriginalResultSet().isEmpty()) {
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
// defer the select as it is ignored after refresh in onDataArrived
selectChildFromHistory();
}
});
}
}
private void prepareSecurityContext(Scheduler.ScheduledCommand andThen) {
// creates an empty (always true) security context for the bootstrap steps
/*securityFramework.createSecurityContext(null, Collections.<String>emptySet(), false,
new AsyncCallback<SecurityContext>() {
@Override
public void onFailure(Throwable caught) {
andThen.execute();
}
@Override
public void onSuccess(SecurityContext result) {
andThen.execute();
}
});*/
andThen.execute();
}
@Override
public void setPreview(final SafeHtml html) {
Scheduler.get().scheduleDeferred(() -> {
contentCanvas.clear();
contentCanvas.add(new ScrollPanel(new HTML(html)));
});
}
public void verifyConnection(final DataSource dataSource, boolean xa, boolean existing,
Scheduler.ScheduledCommand onCreated) {
VerifyConnectionOp vop = new VerifyConnectionOp(dataSourceStore, dispatcher, beanFactory,
currentProfileSelection.getName());
vop.execute(dataSource, xa, existing, new SimpleCallback<VerifyConnectionOp.VerifyResult>() {
@Override
public void onSuccess(final VerifyConnectionOp.VerifyResult result) {
getView().showVerifyConncectionResult(dataSource.getName(), result);
if (result.wasCreated() && onCreated != null) {
Scheduler.get().scheduleDeferred(onCreated);
}
}
});
}
@Override
public void setPreview(final SafeHtml html) {
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
previewCanvas.clear();
previewCanvas.add(new ScrollPanel(new HTML(html)));
}
});
}
public Widget asWidget() {
filter.setMaxLength(30);
filter.setVisibleLength(20);
filter.getElement().setAttribute("style", "width:120px;");
filter.addKeyUpHandler(new KeyUpHandler() {
@Override
public void onKeyUp(KeyUpEvent keyUpEvent) {
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
String prefix = filter.getText();
if (prefix != null && !prefix.equals("")) {
// filter by prefix
filterByPrefix(prefix);
} else {
clearFilter();
}
}
});
}
});
HorizontalPanel panel = new HorizontalPanel();
Label label = new Label(Console.CONSTANTS.common_label_filter() + ": ");
panel.add(label);
panel.add(filter);
label.getElement().setAttribute("style", "padding-top:8px;margin-right:8px");
return panel;
}
void showSearchPage() {
deck.showWidget(1);
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
textBox.setFocus(true);
}
});
}
private void callLoadProject() {
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
if (!readyToLoadProject()) { // wait till project is processed
Scheduler.get().scheduleDeferred(this);
} else {
loadProject();
}
}
});
}
public void setPasteZone(final Widget pasteZone) {
if (pasteZone != null) {
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
fileUpload.setPasteZone(pasteZone.getElement());
}
});
} else {
fileUpload.setPasteZone(null);
}
}
public void onResize() {
Scheduler.get().scheduleDeferred(() -> {
int panelHeight = panel.getElement().getParentElement().getOffsetHeight();
int editorHeight = panelHeight - HEADER_HEIGHT - TOOLS_HEIGHT - MARGIN_BOTTOM;
if (panelHeight > 0) {
editor.setHeight(editorHeight + "px");
}
});
}
protected void showTooltip(boolean forceShow) {
// Schedule timer for showing the tooltip according to if it
// was recently closed or not.
int timeout = 0;
if (!forceShow) {
timeout = justClosed ? getQuickOpenDelay() : getOpenDelay();
}
if (timeout == 0) {
Scheduler.get().scheduleDeferred(this::showTooltip);
} else {
showTimer.schedule(timeout);
opening = true;
}
}
@Override
public void setPreview(final SafeHtml html) {
Scheduler.get().scheduleDeferred(() -> {
previewCanvas.clear();
previewCanvas.add(new ScrollPanel(new HTML(html)));
});
}
protected void showSuggestions(boolean userOriginated) {
Scheduler.get().scheduleDeferred(() -> {
suggestionsContainer.clearItems();
for (Suggestion suggestion : suggestions) {
SuggestionItem menuItem = new SuggestionItem(suggestion);
menuItem.setScheduledCommand(this::selectSuggestion);
String styleName = suggestion.getStyleName();
if (styleName != null && !styleName.isEmpty()) {
menuItem.addStyleName(suggestion.getStyleName());
}
suggestionsContainer.addItem(menuItem);
}
suggestionsContainer.selectItem(0);
suggestionsPopup.removeAutoHidePartner(getElement());
suggestionsPopup.addAutoHidePartner(getElement());
if ((isFocused() || !userOriginated)
&& (!suggestionsPopup.isAttached() || !suggestionsPopup.isVisible())) {
suggestionsPopup.showPopup();
}
suggestionsPopup.updateWidth();
});
}
@Override
public void onElementResize(ElementResizeEvent e) {
final int height = e.getElement().getClientHeight();
final int width = e.getElement().getClientWidth();
if (previousHeight != height) {
previousHeight = height;
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
getWidget().notifyHeightChanged(height);
updateDelegateTargetHeight();
}
});
}
if (previousWidth != width) {
previousWidth = width;
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
getWidget().notifyWidthChanged(width);
updateAllStepsPredecessors();
updateDelegateTargetHeight();
}
});
}
}
@Override
protected void onAction(Action action) {
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
loadEndpoints(false);
}
}); }
@Override
public void setPreview(SafeHtml html) {
Scheduler.get().scheduleDeferred(() -> {
previewCanvas.clear();
previewCanvas.add(new ScrollPanel(new HTML(html)));
});
}
private void setSpannedRowWidthAfterDOMFullyInited() {
// Defer setting width on spanned columns to make sure that
// they are added to the DOM before trying to calculate
// widths.
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
calcAndSetWidthForSpannedCell();
}
});
}
@Override
protected void onPreviewNativeEvent(Event.NativePreviewEvent event) {
super.onPreviewNativeEvent(event);
NativeEvent nativeEvent = event.getNativeEvent();
Element target = Element.as(nativeEvent.getEventTarget());
if (Event.ONCLICK == event.getTypeInt()) {
if (getElement().isOrHasChild(target)) {
Scheduler.get().scheduleDeferred(this::hide);
}
}
previewTableContextMenuEvent(event);
}
@JsIgnore
@Override
public void onModuleLoad() {
// Model factory is used in remote Waves
ModelFactory.instance = null;
ServiceConfig.configProvider = getConfigProvider();
getEditorConfigProvider();
GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() {
@Override
public void onUncaughtException(Throwable e) {
Console.log("Uncaught Exception: " + e.getMessage());
String string = "";
for (StackTraceElement element : e.getStackTrace()) {
string += element + "\n";
}
Console.log("Trace: ");
Console.log(string);
}
});
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
service = new ServerlessFrontend();
notifyOnLoadHandlers(service);
}
});
}
public void doCollapse(final boolean collapse) {
if (collapse != this.collapsed) {
EventBus.get().fireEventFromSource(new CollapseEvent(CollapseHelper.this, collapse), CollapseHelper.this);
this.collapsableElement.getStyle().setHeight(this.collapsableElement.getOffsetHeight(), Unit.PX);
StyleUtils.removeStyle(this.collapsableElement, CollapseHelper.STYLE_COLLAPSE);
StyleUtils.removeStyle(this.collapsableElement, CollapseHelper.STYLE_VISIBLE);
StyleUtils.addStyle(this.collapsableElement, CollapseHelper.STYLE_COLLAPSING);
final int endHeight = collapse ? 0 : this.collapsableElement.getScrollHeight();
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
CollapseHelper.this.collapsableElement.getStyle().setHeight(endHeight, Unit.PX);
}
});
Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
@Override
public boolean execute() {
CollapseHelper.this.collapsableElement.getStyle().clearHeight();
StyleUtils.removeStyle(CollapseHelper.this.collapsableElement, CollapseHelper.STYLE_COLLAPSING);
StyleUtils.addStyle(CollapseHelper.this.collapsableElement, CollapseHelper.STYLE_COLLAPSE);
StyleUtils.toggleStyle(CollapseHelper.this.collapsableElement, CollapseHelper.STYLE_VISIBLE, !collapse);
return false;
}
}, 350);
this.collapsed = collapse;
}
}
@Override
protected void onAction(Action action) {
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
refresh(true);
}
});
}
@Override
public void postLayout() {
// Have to re-layout after parent layout expand hack applied
// to avoid split position glitch.
if (updateLayout) {
Scheduler.get().scheduleFinally(this::layout);
updateLayout = false;
}
}
protected Scheduler.ScheduledCommand getSelectAllCommand() {
return () -> {
for (Column column : getColumns()) {
if (column.isHidden()) {
column.setHidden(false);
}
}
};
}
@Override
public void setPreview(final SafeHtml html) {
Scheduler.get().scheduleDeferred(() -> {
contentCanvas.clear();
contentCanvas.add(new ScrollPanel(new HTML(html)));
});
}
@Override
public void setFullScreen(final boolean fullscreen) {
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
layout.setWidgetHidden(nav, fullscreen);
editor.updateEditorConstraints();
}
});
}