List of usage examples for com.google.gwt.user.client Timer schedule
public synchronized void schedule(int delayMs)
From source file:com.totsp.gwittir.client.fx.ui.SoftScrollbar.java
License:Open Source License
protected void onAttach() { super.onAttach(); target.addScrollListener(this.scrollListener); this.lowerTarget.addMouseListener(this.getLowerListener()); this.higherTarget.addMouseListener(this.getHigherListener()); this.barTarget.addMouseListener(this.getBarListener()); Window.addWindowResizeListener(this.windowListener); Timer t = new Timer() { public void run() { refresh();/*ww w . j av a 2s. co m*/ } }; t.schedule(10); }
From source file:com.vaadin.addon.spreadsheet.client.SpreadsheetWidget.java
/** * Checks if selected cell is locked, and sends an RPC to server if it is. *///from w ww.jav a 2 s .co m private void checkEditableAndNotify() { if (cellLocked) { if (!okToSendCellProtectRpc) { // don't send just yet return; } Timer timer = new Timer() { @Override public void run() { okToSendCellProtectRpc = true; } }; timer.schedule(1000); okToSendCellProtectRpc = false; ServerConnector connector = Util.findConnectorFor(this); SpreadsheetServerRpc rpc = RpcProxy.create(SpreadsheetServerRpc.class, connector); rpc.protectedCellWriteAttempted(); } }
From source file:com.vaadin.addon.timeline.gwt.client.VTimelineBrowser.java
@Override public void onTouchEnd(TouchEndEvent event) { event.preventDefault();/*from w w w .j a v a 2 s . co m*/ if (multitouching) { /* * Adding a timer to prevent single multitouch end events to mess up * rendering */ Timer t = new Timer() { @Override public void run() { multitouching = false; } }; t.schedule(500); } else if (!multitouching) { stopDrag(event.getNativeEvent()); } scroller.setLeftAdjustmentHandleVisible(true); scroller.setRightAdjustmentHandleVisible(true); }
From source file:com.vaadin.addon.timeline.gwt.client.VTimelineDisplay.java
public void onTouchEnd(TouchEndEvent event) { if (lastTouchFingerDistance > 0) { touchMove(event);/*from w w w. ja v a 2s . c o m*/ lastTouchFingerDistance = 0; /* * Adding a timer to prevent single multitouch end events to mess up * rendering */ Timer t = new Timer() { @Override public void run() { mouseOrTouchActive = false; multitouching = false; VConsole.log("VTimelineDisplay: Touch dragging ended (with a delay)"); } }; t.schedule(500); } else if (!multitouching) { stopDragging(event.getNativeEvent()); } }
From source file:com.vaadin.client.ui.orderedlayout.Slot.java
License:Apache License
/** * Set the caption of the slot/*w w w. ja va 2s . c o m*/ * * @param captionText * The text of the caption * @param icon * The icon * @param styles * The style names * @param error * The error message * @param showError * Should the error message be shown * @param required * Is the (field) required * @param enabled * Is the component enabled * @param captionAsHtml * true if the caption should be rendered as HTML, false * otherwise */ public void setCaption(String captionText, Icon icon, List<String> styles, String error, boolean showError, boolean required, boolean enabled, boolean captionAsHtml) { // TODO place for optimization: check if any of these have changed // since last time, and only run those changes // Caption wrappers Widget widget = getWidget(); final Element focusedElement = WidgetUtil.getFocusedElement(); // By default focus will not be lost boolean focusLost = false; if (captionText != null || icon != null || error != null || required) { if (caption == null) { caption = DOM.createDiv(); captionWrap = DOM.createDiv(); captionWrap.addClassName(StyleConstants.UI_WIDGET); captionWrap.addClassName("v-has-caption"); getElement().appendChild(captionWrap); orphan(widget); captionWrap.appendChild(widget.getElement()); adopt(widget); // Made changes to DOM. Focus can be lost if it was in the // widget. focusLost = (focusedElement == null ? false : widget.getElement().isOrHasChild(focusedElement)); } } else if (caption != null) { orphan(widget); getElement().appendChild(widget.getElement()); adopt(widget); captionWrap.removeFromParent(); caption = null; captionWrap = null; // Made changes to DOM. Focus can be lost if it was in the widget. focusLost = (focusedElement == null ? false : widget.getElement().isOrHasChild(focusedElement)); } // Caption text if (captionText != null) { if (this.captionText == null) { this.captionText = DOM.createSpan(); this.captionText.addClassName("v-captiontext"); caption.appendChild(this.captionText); } if (captionText.trim().equals("")) { this.captionText.setInnerHTML(" "); } else { if (captionAsHtml) { this.captionText.setInnerHTML(captionText); } else { this.captionText.setInnerText(captionText); } } } else if (this.captionText != null) { this.captionText.removeFromParent(); this.captionText = null; } // Icon if (this.icon != null) { this.icon.getElement().removeFromParent(); } if (icon != null) { caption.insertFirst(icon.getElement()); } this.icon = icon; // Required if (required) { if (requiredIcon == null) { requiredIcon = DOM.createSpan(); // TODO decide something better (e.g. use CSS to insert the // character) requiredIcon.setInnerHTML("*"); requiredIcon.setClassName("v-required-field-indicator"); // The star should not be read by the screen reader, as it is // purely visual. Required state is set at the element level for // the screen reader. Roles.getTextboxRole().setAriaHiddenState(requiredIcon, true); } caption.appendChild(requiredIcon); } else if (requiredIcon != null) { requiredIcon.removeFromParent(); requiredIcon = null; } // Error if (error != null && showError) { if (errorIcon == null) { errorIcon = DOM.createSpan(); errorIcon.setClassName("v-errorindicator"); } caption.appendChild(errorIcon); } else if (errorIcon != null) { errorIcon.removeFromParent(); errorIcon = null; } if (caption != null) { // Styles caption.setClassName("v-caption"); if (styles != null) { for (String style : styles) { caption.addClassName("v-caption-" + style); } } if (enabled) { caption.removeClassName("v-disabled"); } else { caption.addClassName("v-disabled"); } // Caption position if (captionText != null || icon != null) { setCaptionPosition(CaptionPosition.TOP); } else { setCaptionPosition(CaptionPosition.RIGHT); } } if (focusLost) { // Find out what element is currently focused. Element currentFocus = WidgetUtil.getFocusedElement(); if (currentFocus != null && currentFocus.equals(Document.get().getBody())) { // Focus has moved to BodyElement and should be moved back to // original location. This happened because of adding or // removing the captionWrap focusedElement.focus(); } else if (currentFocus != focusedElement) { // Focus is either moved somewhere else on purpose or IE has // lost it. Investigate further. Timer focusTimer = new Timer() { @Override public void run() { if (WidgetUtil.getFocusedElement() == null) { // This should never become an infinite loop and // even if it does it will be stopped once something // is done with the browser. schedule(25); } else if (WidgetUtil.getFocusedElement().equals(Document.get().getBody())) { // Focus found it's way to BodyElement. Now it can // be restored focusedElement.focus(); } } }; if (BrowserInfo.get().isIE8()) { // IE8 can't fix the focus immediately. It will fail. focusTimer.schedule(25); } else { // Newer IE versions can handle things immediately. focusTimer.run(); } } } }
From source file:com.vaadin.terminal.gwt.client.ui.VPopupCalendar.java
License:Open Source License
/** * Opens the calendar panel popup//from w ww . jav a 2 s. c o m */ public void openCalendarPanel() { if (!open && !readonly) { open = true; if (getCurrentDate() != null) { calendar.setDate((Date) getCurrentDate().clone()); } else { calendar.setDate(new Date()); } // clear previous values popup.setWidth(""); popup.setHeight(""); popup.setPopupPositionAndShow(new PositionCallback() { public void setPosition(int offsetWidth, int offsetHeight) { final int w = offsetWidth; final int h = offsetHeight; final int browserWindowWidth = Window.getClientWidth() + Window.getScrollLeft(); final int browserWindowHeight = Window.getClientHeight() + Window.getScrollTop(); int t = calendarToggle.getAbsoluteTop(); int l = calendarToggle.getAbsoluteLeft(); // Add a little extra space to the right to avoid // problems with IE7 scrollbars and to make it look // nicer. int extraSpace = 30; boolean overflowRight = false; if (l + +w + extraSpace > browserWindowWidth) { overflowRight = true; // Part of the popup is outside the browser window // (to the right) l = browserWindowWidth - w - extraSpace; } if (t + h + calendarToggle.getOffsetHeight() + 30 > browserWindowHeight) { // Part of the popup is outside the browser window // (below) t = browserWindowHeight - h - calendarToggle.getOffsetHeight() - 30; if (!overflowRight) { // Show to the right of the popup button unless we // are in the lower right corner of the screen l += calendarToggle.getOffsetWidth(); } } // fix size popup.setWidth(w + "px"); popup.setHeight(h + "px"); popup.setPopupPosition(l, t + calendarToggle.getOffsetHeight() + 2); /* * We have to wait a while before focusing since the popup * needs to be opened before we can focus */ Timer focusTimer = new Timer() { @Override public void run() { setFocus(true); } }; focusTimer.schedule(100); } }); } else { VConsole.error("Cannot reopen popup, it is already open!"); } }
From source file:com.vaadin.terminal.gwt.client.ui.VPopupCalendar.java
License:Open Source License
public void onClose(CloseEvent<PopupPanel> event) { if (event.getSource() == popup) { buildDate();//from w w w. j a v a 2 s .c o m if (!BrowserInfo.get().isTouchDevice()) { /* * Move focus to textbox, unless on touch device (avoids opening * virtual keyboard). */ focus(); } // TODO resolve what the "Sigh." is all about and document it here // Sigh. Timer t = new Timer() { @Override public void run() { open = false; } }; t.schedule(100); } }
From source file:cu.softel.integro.client.shared.tooltip.TooltipImpl.java
License:Apache License
private static void enter(Event e, TooltipOptions delegateOptions) { Element target = e.getCurrentEventTarget().cast(); final TooltipImpl impl = getImpl(target, delegateOptions); impl.cancelTimer();/*w w w . j a v a 2s. c o m*/ if (impl.options.getDelayShow() == 0) { impl.show(); return; } impl.setHover(true); Timer timer = new Timer() { @Override public void run() { if (impl.isHover()) { impl.show(); } } }; impl.setTimer(timer); timer.schedule(impl.options.getDelayShow()); }
From source file:cu.softel.integro.client.shared.tooltip.TooltipImpl.java
License:Apache License
private static void leave(Event e, TooltipOptions delegateOptions) { Element target = e.getCurrentEventTarget().cast(); final TooltipImpl impl = getImpl(target, delegateOptions); impl.cancelTimer();//from ww w. j ava 2 s .c o m if (impl.options.getDelayHide() == 0) { impl.hide(); return; } impl.setHover(false); Timer timer = new Timer() { @Override public void run() { if (!impl.isHover()) { impl.hide(); } } }; impl.setTimer(timer); timer.schedule(impl.options.getDelayHide()); }
From source file:cz.fi.muni.xkremser.editor.client.presenter.CreateStructurePresenter.java
License:Open Source License
/** * /*from ww w .ja va2s.c om*/ */ private void processImages() { String title = null; if (bundle != null && bundle.getDc() != null && bundle.getDc().getTitle() != null && bundle.getDc().getTitle().size() > 0) { title = bundle.getDc().getTitle().get(0); } final ScanFolderAction action = new ScanFolderAction(model, inputPath, title); final DispatchCallback<ScanFolderResult> callback = new DispatchCallback<ScanFolderResult>() { private volatile int done = 0; private int total = 0; private volatile boolean isDone = false; @Override public void callback(final ScanFolderResult result) { getEventBus().fireEvent(new RefreshTreeEvent(Constants.NAME_OF_TREE.INPUT_QUEUE)); ServerActionResult serverActionResult = result.getServerActionResult(); if (serverActionResult.getServerActionResult() == Constants.SERVER_ACTION_RESULT.OK) { convert(result); } else { if (serverActionResult .getServerActionResult() == Constants.SERVER_ACTION_RESULT.WRONG_FILE_NAME) { SC.ask(lang.wrongFileName() + serverActionResult.getMessage(), new BooleanCallback() { @Override public void execute(Boolean value) { if (value != null && value) { convert(result); } } }); } } } private void convert(ScanFolderResult result) { final List<ImageItem> itemList = result == null ? null : result.getItems(); final List<ImageItem> toAdd = result == null ? null : result.getToAdd(); if (toAdd != null && !toAdd.isEmpty()) { SetEnabledHotKeysEvent.fire(CreateStructurePresenter.this, false); int lastItem = toAdd.size(); boolean progressbar = lastItem > 5; final Progressbar hBar1 = progressbar ? new Progressbar() : null; if (progressbar) { done = 0; total = lastItem; hBar1.setHeight(24); hBar1.setVertical(false); hBar1.setPercentDone(0); getView().getPopupPanel().setAutoHideEnabled(false); getView().getPopupPanel().setWidget(hBar1); getView().getPopupPanel().setVisible(true); getView().getPopupPanel().center(); Timer timer = new Timer() { @Override public void run() { for (ImageItem item : toAdd) { convertItem(item, hBar1, itemList); } } }; timer.schedule(40); } else { for (ImageItem item : toAdd) { convertItem(item, hBar1, itemList); } } } else { doTheRest(itemList); } } @Override public void callbackError(final Throwable t) { if (t.getMessage() != null && t.getMessage().length() > 0 && t.getMessage().charAt(0) == Constants.SESSION_EXPIRED_FLAG) { SC.confirm(lang.sessionExpired(), new BooleanCallback() { @Override public void execute(Boolean value) { if (value != null && value) { MEditor.redirect(t.getMessage().substring(1)); } } }); } else { SC.ask(t.getMessage() + " " + lang.mesTryAgain(), new BooleanCallback() { @Override public void execute(Boolean value) { if (value != null && value) { processImages(); } } }); } getView().getPopupPanel().setAutoHideEnabled(true); getView().getPopupPanel().setVisible(false); getView().getPopupPanel().hide(); } private void doTheRest(List<ImageItem> itemList) { ScanRecord[] items = null; if (itemList != null && itemList.size() > 0) { items = new ScanRecord[itemList.size()]; for (int i = 0, total = itemList.size(); i < total; i++) { items[i] = new ScanRecord(i + 1, String.valueOf(i + 1), model, sysno, itemList.get(i).getIdentifier(), itemList.get(i).getJpgFsPath(), Constants.PAGE_TYPES.NP.toString()); } if (config.getHostname() == null || "".equals(config.getHostname().trim())) { EditorSC.compulsoryConfigFieldWarn(EditorClientConfiguration.Constants.HOSTNAME, EditorSC.ConfigFieldType.STRING, lang); } getView().onAddImages(DigitalObjectModel.PAGE.getValue(), items, config.getHostname(), false); getView().getTileGrid().addDropHandler(new DropHandler() { @Override public void onDrop(DropEvent event) { Object draggable = EventHandler.getDragTarget(); if (draggable instanceof TreeGrid) { ListGridRecord[] selection = leftPresenter.getView().getSubelementsGrid() .getSelectedRecords(); if (selection == null || selection.length == 0) { event.cancel(); return; } for (ListGridRecord rec : selection) { if (!DigitalObjectModel.PAGE.getValue() .equals(rec.getAttribute(Constants.ATTR_TYPE_ID))) { SC.say("TODO Sem muzete pretahovat jen objekty typu stranka."); event.cancel(); return; } } } } }); } getView().getPopupPanel().setAutoHideEnabled(true); getView().getPopupPanel().setWidget(null); getView().getPopupPanel().setVisible(false); getView().getPopupPanel().hide(); SetEnabledHotKeysEvent.fire(CreateStructurePresenter.this, true); } private void convertItem(ImageItem item, final Progressbar hBar1, final List<ImageItem> itemList) { ConvertToJPEG2000Action action = new ConvertToJPEG2000Action(item); final DispatchCallback<ConvertToJPEG2000Result> callback = new DispatchCallback<ConvertToJPEG2000Result>() { @Override public void callback(ConvertToJPEG2000Result result) { done++; if (hBar1 != null) { hBar1.setPercentDone(((100 * (done + 1)) / total)); } if (done >= total && !isDone) { synchronized (LOCK) { if (done >= total && !isDone) { doTheRest(itemList); isDone = true; } } } } @Override public void callbackError(Throwable t) { // unable to convert images to JPEG 2000 install the libraries bitch! if (!isDone) { synchronized (LOCK) { if (!isDone) { doTheRest(itemList); isDone = true; } } } } }; dispatcher.execute(action, callback); } }; Image loader = new Image("images/loadingAnimation3.gif"); getView().getPopupPanel().setWidget(loader); getView().getPopupPanel().setVisible(true); getView().getPopupPanel().center(); dispatcher.execute(action, callback); }