com.google.gwt.core.client.Scheduler.ScheduledCommand Java Examples

The following examples show how to use com.google.gwt.core.client.Scheduler.ScheduledCommand. 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: UniTimeConfirmationDialog.java    From unitime with Apache License 2.0 6 votes vote down vote up
public void center(final boolean defaultIsYes) {
	super.center();
	iDefaultIsYes = defaultIsYes;
	if (iMessage != null && !iMessage.isEmpty())
		AriaStatus.getInstance().setText(ARIA.dialogOpened(getText()) + " " + iMessage + (iNo == null ? "" : " " + ARIA.confirmationEnterToAcceptEscapeToReject()));
	Scheduler.get().scheduleDeferred(new ScheduledCommand() {
		@Override
		public void execute() {
			if (iTextBox != null) {
				iTextBox.setFocus(true);
				iTextBox.selectAll();
			} else {
				(iDefaultIsYes ? iYes : iNo).setFocus(true);
			}
		}
	});
}
 
Example #2
Source File: DocumentationDisplay.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
public DocumentationDisplay() {
	this.initWidget(Binder.BINDER.createAndBindUi(this));

	Window.addResizeHandler(new ResizeHandler() {

		@Override
		public void onResize(ResizeEvent event) {
			DocumentationDisplay.this.redraw(false);
		}
	});

	Scheduler.get().scheduleDeferred(new ScheduledCommand() {

		@Override
		public void execute() {
			DocumentationDisplay.this.redraw(true);
		}
	});
}
 
Example #3
Source File: AddressBookPage.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
@UiHandler("searchBox")
void onSearchBox(KeyPressEvent event) {
	final InputText source = (InputText) event.getSource();
	Scheduler.get().scheduleDeferred(new ScheduledCommand() {

		@Override
		public void execute() {
			String query = source.flush();
			if (query == null || query.length() == 0) {
				AddressBookPage.this.displayList(AddressBookPage.this.displayedList);
			} else {
				final String queryToCompare = query.toLowerCase().trim();
				Iterable<Contact> filteredIteable =
					Iterables.filter(AddressBookPage.this.displayedList, new Predicate<Contact>() {

						@Override
						public boolean apply(Contact contact) {
							return contact.getName() != null
								&& contact.getName().toLowerCase().contains(queryToCompare);
						}
					});
				AddressBookPage.this.displayList(Lists.newArrayList(filteredIteable));
			}
		}
	});
}
 
Example #4
Source File: PinDialog.java    From unitime with Apache License 2.0 6 votes vote down vote up
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);
		}
	});
}
 
Example #5
Source File: UserAuthentication.java    From unitime with Apache License 2.0 6 votes vote down vote up
public void authenticate() {
	if (!CONSTANTS.allowUserLogin()) {
		if (isAllowLookup())
			doLookup();
		else
			ToolBox.open(GWT.getHostPageBaseURL() + "login.do?target=" + URL.encodeQueryString(Window.Location.getHref()));
		return;
	}
	AriaStatus.getInstance().setText(ARIA.authenticationDialogOpened());
	iError.setVisible(false);
	iDialog.center();
	Scheduler.get().scheduleDeferred(new ScheduledCommand() {
		@Override
		public void execute() {
			iUserName.selectAll();
			iUserName.setFocus(true);
		}
	});
}
 
Example #6
Source File: JTSWebAppEntry.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void onModuleLoad() {
	sLogger.info("Module loading");

	if (GWT.isScript()) {
		GWT.setUncaughtExceptionHandler(this);

		Scheduler.get().scheduleDeferred(new ScheduledCommand() {
			
			@Override
			public void execute() {
				onLoad();
			}
		});
	} else {
		onLoad();
	}
}
 
Example #7
Source File: SessionDatesSelector.java    From unitime with Apache License 2.0 6 votes vote down vote up
public SessionDatesSelector(AcademicSessionProvider session) {
	iAcademicSession = session;
	
	iPanel = new UniTimeWidget<DatesPanel>(new DatesPanel());
	
	initWidget(iPanel);
	
	iAcademicSession.addAcademicSessionChangeHandler(new AcademicSessionChangeHandler() {
		@Override
		public void onAcademicSessionChange(AcademicSessionChangeEvent event) {
			if (event.isChanged()) init(event.getNewAcademicSessionId());
		}
	});
	
	Scheduler.get().scheduleDeferred(new ScheduledCommand() {
		@Override
		public void execute() {
			init(iAcademicSession.getAcademicSessionId());
		}
	});
}
 
Example #8
Source File: ContextFieldSet.java    From bitcoin-transaction-explorer with MIT License 6 votes vote down vote up
private void displayContextPopup(final Widget target, final Widget popupContent) {
  if (!popupPanel.isShowing()) {
    popupContent.getElement().getStyle().setVisibility(Visibility.HIDDEN);
  }

  popupPanel.setWidget(popupContent);
  popupPanel.show();
  attachRegistration = target.addAttachHandler(attachHandler);

  // Defer the attach event because we don't have the element's width/height at this point
  Scheduler.get().scheduleDeferred(new ScheduledCommand() {
    @Override
    public void execute() {
      popupPanel.attachToWidget(target);
      popupContent.getElement().getStyle().clearVisibility();
    }
  });
}
 
Example #9
Source File: NavSpy.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
NavWidget(NavWidget parentNav, final Element heading) {
	super(heading.getInnerHTML(), new ScheduledCommand() {
		@Override
		public void execute() {
			int top = NavSpy.this.getElementTop(heading) - NavSpy.this.spyOffset;
			if (NavSpy.this.isBodyScrollWidget()) {
				Window.scrollTo(Document.get().getScrollLeft(), top);
			} else {
				NavSpy.this.scrollWidget.getElement().setScrollTop(top);
			}
		}
	});

	this.parentNav = parentNav;
	this.level = NavSpy.this.getLevel(heading);
}
 
Example #10
Source File: SuggestionsSelectList.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Adds suggestions to the suggestion menu bar.
 * 
 * @param suggestions
 *            the suggestions to be added
 * @param textFieldWidget
 *            the text field which the suggestion is attached to to bring
 *            back the focus after selection
 * @param popupPanel
 *            pop-up panel where the menu bar is shown to hide it after
 *            selection
 * @param suggestionServerRpc
 *            server RPC to ask for new suggestion after a selection
 */
public void addItems(final List<SuggestTokenDto> suggestions, final VTextField textFieldWidget,
        final PopupPanel popupPanel, final TextFieldSuggestionBoxServerRpc suggestionServerRpc) {
    for (int index = 0; index < suggestions.size(); index++) {
        final SuggestTokenDto suggestToken = suggestions.get(index);
        final MenuItem mi = new MenuItem(suggestToken.getSuggestion(), true, new ScheduledCommand() {
            @Override
            public void execute() {
                final String tmpSuggestion = suggestToken.getSuggestion();
                final TokenStartEnd tokenStartEnd = tokenMap.get(tmpSuggestion);
                final String text = textFieldWidget.getValue();
                final StringBuilder builder = new StringBuilder(text);
                builder.replace(tokenStartEnd.getStart(), tokenStartEnd.getEnd() + 1, tmpSuggestion);
                textFieldWidget.setValue(builder.toString(), true);
                popupPanel.hide();
                textFieldWidget.setFocus(true);
                suggestionServerRpc.suggest(builder.toString(), textFieldWidget.getCursorPos());
            }
        });
        tokenMap.put(suggestToken.getSuggestion(),
                new TokenStartEnd(suggestToken.getStart(), suggestToken.getEnd()));
        Roles.getListitemRole().set(mi.getElement());
        WidgetUtil.sinkOnloadForImages(mi.getElement());
        addItem(mi);
    }
}
 
Example #11
Source File: TimeSelector.java    From unitime with Apache License 2.0 6 votes vote down vote up
private TimeMenuItem(final int slot) {
	super(slot2time(slot, iStart == null || iStart.getValue() == null ? 0 : slot - iStart.getValue()),
		true,
		new ScheduledCommand() {
			@Override
			public void execute() {
				hideSuggestions();
				setValue(slot, true);
				iLastSelected = iText.getText();
				fireSuggestionEvent(slot);
			}
		}
	);
	setStyleName("item");
	getElement().setAttribute("whiteSpace", "nowrap");
	iSlot = slot;
}
 
Example #12
Source File: AddressBookView.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
@UiHandler("searchBox")
void onSearchBox(KeyPressEvent event) {
	final InputText source = (InputText) event.getSource();
	Scheduler.get().scheduleDeferred(new ScheduledCommand() {

		@Override
		public void execute() {
			String query = source.flush();
			if (query == null || query.length() == 0) {
				displayList(displayedList);
			} else {
				final String queryToCompare = query.toLowerCase().trim();
				Iterable<Contact> filteredIteable = Iterables.filter(displayedList, new Predicate<Contact>() {

					@Override
					public boolean apply(Contact contact) {
						return contact.getName() != null && contact.getName().toLowerCase().contains(queryToCompare);
					}
				});
				displayList(Lists.newArrayList(filteredIteable));
			}
		}
	});
}
 
Example #13
Source File: Auth.java    From requestor with Apache License 2.0 6 votes vote down vote up
/**
 * Request an access token from an OAuth 2.0 provider.
 * <p/>
 * <p> If it can be determined that the user has already granted access, and the token has not yet expired, and that
 * the token will not expire soon, the existing token will be passed to the callback. </p>
 * <p/>
 * <p> Otherwise, a popup window will be displayed which may prompt the user to grant access. If the user has
 * already granted access the popup will immediately close and the token will be passed to the callback. If access
 * hasn't been granted, the user will be prompted, and when they grant, the token will be passed to the callback.
 * </p>
 *
 * @param req      Request for authentication.
 * @param callback Callback to pass the token to when access has been granted.
 */
public void login(AuthRequest req, final Callback<TokenInfo, Throwable> callback) {
    lastRequest = req;
    lastCallback = callback;

    String authUrl = req.toUrl(urlCodex) + "&redirect_uri=" + urlCodex.encode(oauthWindowUrl);

    // Try to look up the token we have stored.
    final TokenInfo info = getToken(req);
    if (info == null || info.getExpires() == null || expiringSoon(info)) {
        // Token wasn't found, or doesn't have an expiration, or is expired or
        // expiring soon. Requesting access will refresh the token.
        doLogin(authUrl, callback);
    } else {
        // Token was found and is good, immediately execute the callback with the
        // access token.

        scheduler.scheduleDeferred(new ScheduledCommand() {
            @Override
            public void execute() {
                callback.onSuccess(info);
            }
        });
    }
}
 
Example #14
Source File: CurriculaCourses.java    From unitime with Apache License 2.0 6 votes vote down vote up
public void openNew() {
	setText(MESSAGES.dialogNewGroup());
	iGrOldName = null;
	iGrName.setText(String.valueOf((char)('A' + getGroups().size())));
	iGrType.setSelectedIndex(0);
	iGrAssign.setVisible(true);
	iGrDelete.setVisible(false);
	iGrUpdate.setVisible(false);
	Scheduler.get().scheduleDeferred(new ScheduledCommand() {
		@Override
		public void execute() {
			iGrName.setFocus(true);
			iGrName.selectAll();
		}
	});
	center();
}
 
Example #15
Source File: AuthTest.java    From requestor with Apache License 2.0 6 votes vote down vote up
/**
 * When the token is found in cookies and will not expire soon, neither popup
 * nor iframe is used, and the token is immediately passed to the callback.
 */
public void testLogin_notExpiringSoon() {
  AuthRequest req = new AuthRequest("url", "clientId").withScopes("scope");

  // Storing a token that does not expire soon (in exactly 10 minutes)
  TokenInfo info = new TokenInfo();
  info.setTokenType("type");
  info.setAccessToken("notExpiringSoon");
  info.setExpires(String.valueOf(MockClock.now + 10 * 60 * 1000));
  auth.setToken(req, info);

  MockCallback callback = new MockCallback();
  auth.login(req, callback);

  // A deferred command will have been scheduled. Execute it.
  List<ScheduledCommand> deferred = ((StubScheduler) auth.scheduler).getScheduledCommands();
  assertEquals(1, deferred.size());
  deferred.get(0).execute();

  // The iframe was used and the popup wasn't.
  assertFalse(auth.loggedInViaPopup);

  // onSuccess() was called and onFailure() wasn't.
  assertEquals("notExpiringSoon", callback.token.getAccessToken());
  assertNull(callback.failure);
}
 
Example #16
Source File: Launcher.java    From gwt-jackson with Apache License 2.0 6 votes vote down vote up
public void launch() {
    if ( operations.isEmpty() ) {
        return;
    }

    final Operation operation = operations.remove( 0 );
    Scheduler.get().scheduleIncremental( new RepeatingCommand() {
        @Override
        public boolean execute() {
            boolean res = operation.execute();
            if ( !res ) {
                Scheduler.get().scheduleDeferred( new ScheduledCommand() {
                    @Override
                    public void execute() {
                        launch();
                    }
                } );
            }
            return res;
        }
    } );
}
 
Example #17
Source File: ImportBatchItemEditor.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
private void selectNextChildAndFocus(Record record) {
    int nextSelection = getNextSelection(record);
    if (nextSelection < 0) {
        return ;
    }
    final HandlerRegistration[] editorLoadHandler = new HandlerRegistration[1];
    editorLoadHandler[0] = childEditor.addEditorLoadHandler(new EditorLoadHandler() {

        @Override
        public void onEditorLoad(EditorLoadEvent evt) {
            editorLoadHandler[0].removeHandler();
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                @Override
                public void execute() {
                    childEditor.focus();
                }
            });
        }
    });
    batchItemGrid.selectSingleRecord(nextSelection);
    batchItemGrid.scrollToRow(nextSelection);
}
 
Example #18
Source File: DigitalObjectChildrenEditor.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
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();
                }
            });
        }
    }
 
Example #19
Source File: Operation.java    From gwt-jackson with Apache License 2.0 6 votes vote down vote up
@Override
public boolean execute() {
    long startTime = System.currentTimeMillis();
    doExecute();
    totalTime += System.currentTimeMillis() - startTime;
    if ( ++count == nbIterations ) {
        Scheduler.get().scheduleDeferred( new ScheduledCommand() {
            @Override
            public void execute() {
                result.setResult( new BigDecimal( totalTime ).divide( new BigDecimal( count ) ) );
            }
        } );
        return false;
    } else {
        result.setPercent( new BigDecimal( count ).divide( new BigDecimal( nbIterations ) ).movePointRight( 2 ).intValue() );
        return true;
    }
}
 
Example #20
Source File: ScrollPanel.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void onAttach() {
	super.onAttach();
	Scheduler.get().scheduleDeferred(new ScheduledCommand() {

		@Override
		public void execute() {
			Window.addResizeHandler(ScrollPanel.this.resizeHandler);
			ScrollPanel.this.reset();
		}
	});
}
 
Example #21
Source File: StepConnector.java    From gantt with Apache License 2.0 5 votes vote down vote up
@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
    super.onStateChanged(stateChangeEvent);

    if (!(getParent() instanceof GanttConnector)) {
        return;
    }

    if (gantt == null) {
        gantt = getGanttConnector().getWidget();
    }

    if (stateChangeEvent.hasPropertyChanged("step")) {
        updatePredecessorWidgetReference();// need to be called before
                                           // setStep
        getWidget().setStep(getState().step);
    }
    if (!getWidget().getElement().hasParentElement()) {
        gantt.addStep(getStepIndex(), getWidget(), true);
    }
    getWidget().updateWidth();

    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
        @Override
        public void execute() {
            getWidget().updatePredecessor();
            GanttConnector ganttConnector = getGanttConnector();
            for (StepWidget stepWidget : ganttConnector.findRelatedSteps(getState().step,
                    ganttConnector.getChildComponents())) {
                stepWidget.updatePredecessor();
            }
        }
    });
}
 
Example #22
Source File: Affix.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void onLoad() {
	super.onLoad();
	Scheduler.get().scheduleDeferred(new ScheduledCommand() {

		@Override
		public void execute() {
			Affix.this.reset();
			Affix.this.handlerRegistrationCollection.add(Window.addWindowScrollHandler(Affix.this.scrollHandler));
			Affix.this.handlerRegistrationCollection.add(Window.addResizeHandler(Affix.this.resizeHandler));
		}
	});
}
 
Example #23
Source File: Modal.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void show() {
	RootPanel.get().add(this);
	Scheduler.get().scheduleDeferred(new ScheduledCommand() {
		@Override
		public void execute() {
			StyleUtils.addStyle(ModalBackdrop.this, Modal.STYLE_VISIBLE);
		}
	});
}
 
Example #24
Source File: CompositeFocusHelper.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onKeyDown(KeyDownEvent event) {
	if (event.getNativeKeyCode() == KeyCodes.KEY_TAB) {
		Scheduler.get().scheduleDeferred(new ScheduledCommand() {

			@Override
			public void execute() {
				Element activeElement = FocusUtils.getActiveElement();
				if (activeElement != null && !CompositeFocusHelper.this.isOrHasChildOfContainerOrPartner(activeElement)) {
					CompositeFocusHelper.this.blur();
				}
			}
		});
	}
}
 
Example #25
Source File: SampleDecorator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void addSources(Multimap<String, String> sources) {
	Panel panelToOpen = null;
	String sourceToOpen = null;
	this.sourceAccordion.clear();
	for (String panelName : sources.keySet()) {

		List sourceList = new List();
		sourceList.setType(Type.LIST);
		for (String source : sources.get(panelName)) {
			if (sourceToOpen == null) {
				sourceToOpen = source;
			}
			sourceList.add(new SourceItem(source));
		}
		Panel sourcePanel = new Panel();
		if (panelToOpen == null) {
			panelToOpen = sourcePanel;
		}
		sourcePanel.add(new Header(panelName));
		sourcePanel.add(sourceList);
		this.sourceAccordion.add(sourcePanel);
	}
	this.requestFile(sourceToOpen);
	final Panel toOpen = panelToOpen;

	Scheduler.get().scheduleDeferred(new ScheduledCommand() {

		@Override
		public void execute() {
			toOpen.setCollapse(false);
		}
	});
}
 
Example #26
Source File: AutoSizingBase.java    From gwt-traction with Apache License 2.0 5 votes vote down vote up
@Override
   public final void setFocus(boolean focus) {
if (focus) {
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
               @Override
               public void execute() {
                   box.setFocus(true);                      
               }
           });
}
else {
    box.setFocus(false);
}
   }
 
Example #27
Source File: GanttWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
private void deferredUpdateStepTop(int stepIndex, boolean updateAffectedSteps, DivElement bar, boolean insertDOM) {
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
        @Override
        public void execute() {
            updateStepTop(stepIndex, updateAffectedSteps, bar, insertDOM);
        }
    });
}
 
Example #28
Source File: GanttConnector.java    From gantt with Apache License 2.0 5 votes vote down vote up
@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

        @Override
        public void execute() {
            adjustDelegateTargetHeightLazily();
        }
    });
}
 
Example #29
Source File: GanttConnector.java    From gantt with Apache License 2.0 5 votes vote down vote up
@Override
public void onElementResize(ElementResizeEvent e) {
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

        @Override
        public void execute() {
            adjustDelegateTargetHeightLazily();
        }
    });
}
 
Example #30
Source File: GanttConnector.java    From gantt with Apache License 2.0 5 votes vote down vote up
@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();
            }
        });
    }
}