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

The following examples show how to use com.google.gwt.core.client.Scheduler.RepeatingCommand. 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: HtmlScheduler.java    From realtime-channel with Apache License 2.0 6 votes vote down vote up
@Override
public int schedulePeriodic(int delayMs, final Handler<Void> handler) {
  final String key = "" + (++timerId);
  RepeatingCommand cmd = new RepeatingCommand() {
    @Override
    public boolean execute() {
      if (timers.has(key)) {
        handler.handle(null);
        return true;
      }
      return false;
    }
  };
  timers.set(key, cmd);
  com.google.gwt.core.client.Scheduler.get().scheduleFixedPeriod(cmd, delayMs);
  return timerId;
}
 
Example #2
Source File: HtmlScheduler.java    From realtime-channel with Apache License 2.0 6 votes vote down vote up
@Override
public int scheduleDelay(int delayMs, final Handler<Void> handler) {
  final String key = "" + (++timerId);
  RepeatingCommand cmd = new RepeatingCommand() {
    @Override
    public boolean execute() {
      if (timers.has(key)) {
        timers.remove(key);
        handler.handle(null);
      }
      return false;
    }
  };
  timers.set(key, cmd);
  com.google.gwt.core.client.Scheduler.get().scheduleFixedDelay(cmd, delayMs);
  return timerId;
}
 
Example #3
Source File: UndercurrentHarness.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * Populates the info box. Continuously reports which element has browser
 * focus, and reports timing information for the stage loading.
 *
 * @param timeline timeline to report
 */
private static void showInfo(Timeline timeline) {
  Element timeBox = Document.get().getElementById("timeline");
  timeline.dump(timeBox);

  Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
    private final Element activeBox = Document.get().getElementById("active");

    @Override
    public boolean execute() {
      Element e = getActiveElement();
      String text = (e != null ? e.getTagName() + " id:" + e.getId() : "none");
      activeBox.setInnerText(text);
      return true;
    }

    private native Element getActiveElement() /*-{
      return $doc.activeElement;
    }-*/;
  }, 1000);
}
 
Example #4
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 #5
Source File: UndercurrentHarness.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
/**
 * Populates the info box. Continuously reports which element has browser
 * focus, and reports timing information for the stage loading.
 *
 * @param timeline timeline to report
 */
private static void showInfo(Timeline timeline) {
  Element timeBox = Document.get().getElementById("timeline");
  timeline.dump(timeBox);

  Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
    private final Element activeBox = Document.get().getElementById("active");

    @Override
    public boolean execute() {
      Element e = getActiveElement();
      String text = (e != null ? e.getTagName() + " id:" + e.getId() : "none");
      activeBox.setInnerText(text);
      return true;
    }

    private native Element getActiveElement() /*-{
      return $doc.activeElement;
    }-*/;
  }, 1000);
}
 
Example #6
Source File: TabPanel.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void setActivePane(final TabPanelContent source) {
	for (TabPanelContent tabPane : this.tabPaneList) {
		if (!tabPane.equals(source)) {
			tabPane.setActive(false);
		}
	}
	source.getTabLink().setActive(true);
	Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

		@Override
		public boolean execute() {
			source.setActive(true);
			return false;
		}
	}, 150);
}
 
Example #7
Source File: Modal.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void hide() {
	final RootPanel rootPanel = RootPanel.get();

	this.visible = false;
	StyleUtils.removeStyle(Modal.this, Modal.STYLE_VISIBLE);
	StyleUtils.removeStyle(rootPanel, Modal.STYLE_MODAL_OPEN);

	Modal.MODAL_BACKDROP.hide();

	Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
		@Override
		public boolean execute() {
			Modal.this.getElement().getStyle().clearDisplay();
			rootPanel.remove(getContainerWidget());
			return false;
		}
	}, 150);
}
 
Example #8
Source File: TabPanelContent.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void setActive(final boolean active) {
	this.active = active;
	if (this.tabLink != null) {
		this.tabLink.setActive(active);
	}
	StyleUtils.toggleStyle(this, TabPanelContent.STYLE_IN, active);
	if (active) {
		StyleUtils.addStyle(this, TabPanelContent.STYLE_ACTIVE);
	} else {
		Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

			@Override
			public boolean execute() {
				StyleUtils.removeStyle(TabPanelContent.this, TabPanelContent.STYLE_ACTIVE);
				return false;
			}
		}, 150);
	}
}
 
Example #9
Source File: PopupMessage.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
public PopupMessage(String title, String messageText) {
	setHeaderControls(HeaderControls.HEADER_LABEL, HeaderControls.CLOSE_BUTTON);
	setTitle(title);
	setAlign(Alignment.CENTER);
	setAutoSize(true);
	centerInPage();
	
	Label label=new Label(messageText);
	label.setMinWidth(350);
	
	VLayout layout= new VLayout();
	layout.setMembersMargin(2);
	layout.setMembers(label);
	
	addItem(layout);
	
	Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

		@Override
		public boolean execute() {
			PopupMessage.this.destroy();
			return false;
		}
	}, Session.get().getConfigAsInt("gui.popup.timeout") * 1000);
}
 
Example #10
Source File: Modal.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void show() {
	this.ensureDismissButton();
	this.redraw();
	this.visible = true;

	Widget modal = getContainerWidget();

	if (modal.isAttached()) {
		modal.removeFromParent();
	}

	Modal.MODAL_BACKDROP.show();
	this.getElement().getStyle().setDisplay(Display.BLOCK);
	RootPanel rootPanel = RootPanel.get();
	rootPanel.add(modal);
	StyleUtils.addStyle(rootPanel, Modal.STYLE_MODAL_OPEN);

	Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
		@Override
		public boolean execute() {
			StyleUtils.addStyle(Modal.this, Modal.STYLE_VISIBLE);
			return false;
		}
	}, 150);
}
 
Example #11
Source File: InputFile.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void handleCompleteJson(String reponseData) {
	if (Strings.isNullOrEmpty(reponseData)) {
		handleError("500", "Unable to post data");
	}

	JSONObject jsObject = JSONParser.parseLenient(reponseData).isObject();

	final FileDto file = new FileDto();
	file.setName(jsObject.get("name").isString().stringValue());
	file.setExtension(jsObject.get("extension").isString().stringValue());
	file.setMime(jsObject.get("mime").isString().stringValue());
	file.setToken(jsObject.get("token").isString().stringValue());
	file.setContentLength((long) jsObject.get("contentLength").isNumber().doubleValue());

	if (this.uploadForm != null) {
		this.uploadForm = this.uploadForm.destroy();
	}
	this.sendRequest = null;
	this.fileId = null;

	this.progressBar.edit(this.progressBar.getMax());

	Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

		@Override
		public boolean execute() {
			InputFile.this.edit(file);
			return false;
		}
	}, this.params.inputFileProgressHideDelay());
}
 
Example #12
Source File: ServerProxy.java    From gwteventbinder with Apache License 2.0 5 votes vote down vote up
@EventHandler
void onContactsScreenOpened(ContactScreenOpenedEvent event) {
  // Pretend to make a server request
  Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
    @Override
    public boolean execute() {
      LinkedList<String> results = new LinkedList<String>();
      results.add("John Doe");
      results.add("Jane Doe");
      eventBus.fireEvent(new ContactsLoadedEvent(results));
      return false;
    }
  }, 1000);
}
 
Example #13
Source File: Alert.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void hide() {
	StyleUtils.removeStyle(this, Alert.STYLE_VISIBLE);
	Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

		@Override
		public boolean execute() {
			Alert.this.removeFromParent();
			Alert.this.fireEvent(new AlertDismissEvent(Alert.this));
			return false;
		}
	}, 150);
}
 
Example #14
Source File: Modal.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void hide() {
	StyleUtils.removeStyle(ModalBackdrop.this, Modal.STYLE_VISIBLE);
	Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

		@Override
		public boolean execute() {
			RootPanel.get().remove(ModalBackdrop.this);
			return false;
		}
	}, 100);
}
 
Example #15
Source File: CollapseHelper.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
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;
	}
}
 
Example #16
Source File: AbstractHover.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void schedule(int delay, final Visibility visibility) {
	if (delay > 0) {
		Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

			@Override
			public boolean execute() {
				AbstractHover.this.changeVisibility(visibility);
				return false;
			}
		}, delay);
	} else {
		this.changeVisibility(visibility);
	}
}
 
Example #17
Source File: AbstractHover.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void changeVisibility(Visibility visibilityChange) {
	Visibility order = visibilityChange;
	if (order == Visibility.TOGGLE) {
		order = this.visibilityChange == Visibility.HIDE ? Visibility.SHOW : Visibility.HIDE;
	}
	final Element toDisplayElement = this.getHoverWidget().getElement();
	final Element target = this.getWidget().getElement();
	final Element parent = target.getParentElement();
	if (parent == null) {
		return;
	}
	switch (order) {
		case SHOW:
			parent.insertAfter(toDisplayElement, target);
			toDisplayElement.getStyle().setDisplay(Display.BLOCK);
			this.resetPosition(toDisplayElement, this.getWidget(), this.placement);
			StyleUtils.addStyle(this.getHoverWidget(), this.placement);
			StyleUtils.addStyle(toDisplayElement, Visibility.SHOW);
			break;
		case HIDE:
			StyleUtils.removeStyle(toDisplayElement, Visibility.SHOW);
			Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

				@Override
				public boolean execute() {
					toDisplayElement.getStyle().clearDisplay();
					toDisplayElement.removeFromParent();
					return false;
				}
			}, 200);
			break;
		default:
			break;
	}
	this.visibilityChange = order;
}
 
Example #18
Source File: InputDatePicker.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void hide() {
	StyleUtils.removeStyle(this.getElement(), InputDatePicker.STYLE_SHOW);
	Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

		@Override
		public boolean execute() {
			InputDatePicker.this.setVisible(false);
			RootPanel.get().remove(InputDatePicker.this);
			return false;
		}
	}, 200);
}
 
Example #19
Source File: ToastNotification.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ToastNotification(String messageText) {
	setShowEdges(false);
	setShowHeader(false);
	setShowHeaderBackground(false);
	setShowHeaderIcon(false);
	setShowResizer(false);
	setShowFooter(false);
	setShowTitle(false);
	setAlign(Alignment.CENTER);
	setMargin(0);
	setMembersMargin(3);
	setPadding(0);
	setBodyColor("white");
	setBackgroundColor("white");
	setBorder("1px solid DarkBlue");
	setOverflow(Overflow.HIDDEN);
	setAutoSize(true);
	centerInPage();
	setVertical(true);

	HTMLFlow message = new HTMLFlow(AwesomeFactory.getIconHtml("info-circle", messageText));
	message.setAlign(Alignment.CENTER);
	message.setStyleName("contactingserver");
	message.setLayoutAlign(Alignment.CENTER);
	message.setLayoutAlign(VerticalAlignment.CENTER);
	message.setBackgroundColor("white");
	message.setHeight(50);

	addItem(message);

	Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

		@Override
		public boolean execute() {
			ToastNotification.this.destroy();
			return false;
		}
	}, Session.get().getConfigAsInt("gui.popup.timeout") * 1000);
}
 
Example #20
Source File: Carousel.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void goTo(int itemIndex) {
	if (itemIndex == this.currentIndex || this.sliding) {
		return;
	}
	this.sliding = true;
	final int newItemIndex;
	if (itemIndex < 0) {
		newItemIndex = this.carouselItems.size() - 1;
	} else if (itemIndex >= this.carouselItems.size()) {
		newItemIndex = 0;
	} else {
		newItemIndex = itemIndex;
	}

	StyleUtils.addStyle(this.carouselItemsIndicators.get(this.currentIndex), ItemType.DEFAULT);

	boolean goLeft = newItemIndex > this.currentIndex;
	final CarouselItem curentItem = this.carouselItems.get(this.currentIndex);
	final CarouselItem newItem = this.carouselItems.get(newItemIndex);

	StyleUtils.addStyle(newItem, goLeft ? ItemType.NEXT : ItemType.PREVIOUS);
	// hook to force width evaluation (cf original bootstrap JS file)
	this.carouselItems.get(newItemIndex).getOffsetWidth();
	StyleUtils.addStyle(newItem, goLeft ? LeftRightType.LEFT : LeftRightType.RIGHT);
	StyleUtils.addStyle(curentItem, goLeft ? LeftRightType.LEFT : LeftRightType.RIGHT);

	Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

		@Override
		public boolean execute() {
			StyleUtils.removeStyle(curentItem, ItemType.DEFAULT);
			StyleUtils.removeStyle(newItem, ItemType.ACTIVE);
			StyleUtils.addStyle(curentItem, ItemType.DEFAULT);
			StyleUtils.addStyle(newItem, ItemType.ACTIVE);
			StyleUtils.cleanEnumStyle(curentItem.getElement(), LeftRightType.class);
			StyleUtils.cleanEnumStyle(newItem.getElement(), LeftRightType.class);
			StyleUtils.addStyle(Carousel.this.carouselItemsIndicators.get(newItemIndex), ItemType.ACTIVE);
			Carousel.this.currentIndex = newItemIndex;
			Carousel.this.sliding = false;
			return false;
		}
	}, 600);
}
 
Example #21
Source File: ResourceLoader.java    From flow with Apache License 2.0 4 votes vote down vote up
/**
 * Load a stylesheet and notify a listener when the stylesheet is loaded.
 * Calling this method when the stylesheet is currently loading or already
 * loaded doesn't cause the stylesheet to be loaded again, but the listener
 * will still be notified when appropriate.
 *
 * @param stylesheetUrl
 *            the url of the stylesheet to load
 * @param resourceLoadListener
 *            the listener that will get notified when the stylesheet is
 *            loaded
 */
public void loadStylesheet(final String stylesheetUrl,
        final ResourceLoadListener resourceLoadListener) {
    final String url = WidgetUtil.getAbsoluteUrl(stylesheetUrl);
    final ResourceLoadEvent event = new ResourceLoadEvent(this, url);
    if (loadedResources.has(url)) {
        if (resourceLoadListener != null) {
            resourceLoadListener.onLoad(event);
        }
        return;
    }

    if (addListener(url, resourceLoadListener, loadListeners)) {
        LinkElement linkElement = getDocument().createLinkElement();
        linkElement.setRel("stylesheet");
        linkElement.setType("text/css");
        linkElement.setHref(url);

        if (BrowserInfo.get().isSafariOrIOS()) {
            // Safari doesn't fire any events for link elements
            // See http://www.phpied.com/when-is-a-stylesheet-really-loaded/
            Scheduler.get().scheduleFixedPeriod(new RepeatingCommand() {
                private final Duration duration = new Duration();

                @Override
                public boolean execute() {
                    int styleSheetLength = getStyleSheetLength(url);
                    if (getStyleSheetLength(url) > 0) {
                        fireLoad(event);
                        return false; // Stop repeating
                    } else if (styleSheetLength == 0) {
                        // "Loaded" empty sheet -> most likely 404 error
                        fireError(event);
                        return true;
                    } else if (duration.elapsedMillis() > 60 * 1000) {
                        fireError(event);
                        return false;
                    } else {
                        return true; // Continue repeating
                    }
                }
            }, 10);
        } else {
            addOnloadHandler(linkElement, new StyleSheetLoadListener(url),
                    event);
            if (BrowserInfo.get().isOpera()) {
                // Opera onerror never fired, assume error if no onload in x
                // seconds
                new Timer() {
                    @Override
                    public void run() {
                        if (!loadedResources.has(url)) {
                            fireError(event);
                        }
                    }
                }.schedule(5 * 1000);
            }
        }

        getHead().appendChild(linkElement);
    }
}
 
Example #22
Source File: YaProjectEditor.java    From appinventor-extensions with Apache License 2.0 4 votes vote down vote up
private void addFormEditor(YoungAndroidFormNode formNode) {
  final YaFormEditor newFormEditor = new YaFormEditor(this, formNode);
  final String formName = formNode.getFormName();
  OdeLog.log("Adding form editor for " + formName);
  if (editorMap.containsKey(formName)) {
    // This happens if the blocks editor was already added.
    editorMap.get(formName).formEditor = newFormEditor;
  } else {
    EditorSet editors = new EditorSet();
    editors.formEditor = newFormEditor;
    editorMap.put(formName, editors);
  }
  final Command afterLoadCommand = new Command() {
    @Override
    public void execute() {
      int pos = Collections.binarySearch(fileIds, newFormEditor.getFileId(),
          getFileIdComparator());
      if (pos < 0) {
        pos = -pos - 1;
      }
      insertFileEditor(newFormEditor, pos);
      if (isScreen1(formName)) {
        screen1FormLoaded = true;
        if (readyToShowScreen1()) {
          OdeLog.log("YaProjectEditor.addFormEditor.loadFile.execute: switching to screen "
              + formName + " for project " + newFormEditor.getProjectId());
          Ode.getInstance().getDesignToolbar().switchToScreen(newFormEditor.getProjectId(),
              formName, DesignToolbar.View.FORM);
        }
      }
      loadBlocksEditor(formName);
    }
  };
  if (!isScreen1(formName) && !screen1FormLoaded) {
    // Defer loading other screens until Screen1 is loaded. Otherwise we can end up in an
    // inconsistent state during project upgrades with Screen1-only properties.
    Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
      @Override
      public boolean execute() {
        if (screen1FormLoaded) {
          newFormEditor.loadFile(afterLoadCommand);
          return false;
        } else {
          return true;
        }
      }
    }, 100);
  } else {
    newFormEditor.loadFile(afterLoadCommand);
  }
}