List of usage examples for com.google.gwt.user.client Timer run
public abstract void run();
From source file:com.vaadin.client.ui.orderedlayout.Slot.java
License:Apache License
/** * Set the caption of the slot/*from www .j av a 2s . com*/ * * @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:cz.mzk.editor.client.presenter.CreateStructurePresenter.java
License:Open Source License
private void setSectionCreateLayout() { if (DigitalObjectModel.parseString(model).getTopLevelType() == TopLevelObjectModel.PERIODICAL) { leftPresenter.getView().getCreationModeItem().show(); final VLayout atOnceCreateLayout = new VLayout(2); HTMLFlow createFlow = new HTMLFlow(lang.markingLabel()); createAtOnceButton = new ButtonItem("createAtOnceButton", lang.create()); createAtOnceButton.setAlign(Alignment.RIGHT); DynamicForm createDynForm = new DynamicForm(); createDynForm.setItems(createAtOnceButton); firstNumber = new TextItem("firstNumber", lang.firstNumber()); firstNumber.setWidth(50);/*from w w w . ja v a 2 s.c o m*/ firstNumber.setDefaultValue(1); DynamicForm firstNumberDynForm = new DynamicForm(); firstNumberDynForm.setItems(firstNumber); firstNumberDynForm.setWidth(150); baseDate = new EditorDateItem("baseDate", lang.baseDate(), lang); afterDivisionRenumber = new CheckboxItem("afterDivisionRenumber", lang.afterDivRen()); afterDivisionRenumber.setValue(true); DynamicForm baseDateDynForm = new DynamicForm(); baseDateDynForm.setItems(baseDate, afterDivisionRenumber); HLayout buttonItem = new HLayout(2); buttonItem.addMember(createDynForm); buttonItem.addMember(firstNumberDynForm); atOnceCreateLayout.addMember(createFlow); atOnceCreateLayout.addMember(buttonItem); atOnceCreateLayout.addMember(baseDateDynForm); atOnceCreateLayout.setAlign(Alignment.CENTER); atOnceCreateLayout.setWidth(250); atOnceCreateLayout.setHeight(70); leftPresenter.getView().setSectionCreateLayout(atOnceCreateLayout); leftPresenter.getView().getCreationModeItem().setValue(lang.atOnce()); leftPresenter.getView().getCreationModeItem().addChangedHandler(new ChangedHandler() { @Override public void onChanged(ChangedEvent event) { if (lang.atOnce().equals(leftPresenter.getView().getCreationModeItem().getValue())) { leftPresenter.getView().setSectionCreateLayout(atOnceCreateLayout); } else { leftPresenter.getView().setSectionCreateLayout(leftPresenter.getSequentialCreateLayout()); } if (markedRecords.size() > 0) { Record[] selection = getView().getTileGrid().getSelection(); Record[] toUpdate = new Record[markedRecords.size()]; markedRecords.toArray(toUpdate); getView().updateRecordsInTileGrid(toUpdate, true); getView().getTileGrid().selectRecords(selection); } } }); createAtOnceButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (firstNumber.getValueAsString() == null || "".equals(firstNumber.getValueAsString()) || firstNumber.getValueAsString().matches(Constants.ONLY_NUMBERS)) { final ModalWindow mw = new ModalWindow(leftPresenter.getView().getSectionStack()); mw.setLoadingIcon("loadingAnimation.gif"); mw.show(true); Timer timer = new Timer() { @Override public void run() { createAtOnceProcess(); mw.hide(); } }; timer.run(); } else { SC.warn(lang.textBox() + " " + lang.firstNumber() + " " + lang.onlyNum()); } } }); } else { leftPresenter.getView().getCreationModeItem().hide(); leftPresenter.getView().setSectionCreateLayout(leftPresenter.getSequentialCreateLayout()); leftPresenter.getView().getCreationModeItem().setValue(lang.sequential()); } }
From source file:org.freemedsoftware.gwt.client.Util.java
License:Open Source License
/** * Set Focus on the Widget after a time delay of 500ms * /*from w ww .j av a 2 s.c o m*/ * @param Widget * - The widget to be focused. * */ public static void setFocus(final Widget widget) { Timer timer = new Timer() { public void run() { if (widget instanceof AsyncPicklistWidgetBase) { ((AsyncPicklistWidgetBase) widget).setFocus(true); } if (widget instanceof FocusWidget) { ((FocusWidget) widget).setFocus(true); } if (widget instanceof CustomRadioButtonGroup) { ((CustomRadioButtonGroup) widget).setFocus(true); } if (widget instanceof UserMultipleChoiceWidget) { ((UserMultipleChoiceWidget) widget).setFocus(); } if (widget instanceof PatientTagWidget) { ((PatientTagWidget) widget).setFocus(true); } } }; // Run initial polling ... timer.schedule(500); timer.run(); }
From source file:org.metawidget.gwt.client.ui.GwtMetawidget.java
License:LGPL
/** * Builds the widgets./*from ww w. ja va 2 s . co m*/ * <p> * Unlike <code>buildWidgets</code> in other Metawidget implementations, this method may be * asynchronous. If the <code>GwtMetawidget</code> is using an <code>GwtInspectorAsync</code> * Inspector (which it does by default), clients should not expect the widgets to be built by * the time this method returns. */ protected void buildWidgets() { // No need to build? if (mNeedToBuildWidgets != BUILDING_NEEDED) { // For unit tests: if buildWidgets is already underway, rely on // mExecuteAfterBuildWidgets being injected into it. This is preferrable to running // buildWidgets() twice without calling invalidateWidgets() if (mNeedToBuildWidgets == BUILDING_COMPLETE && mExecuteAfterBuildWidgets != null) { Timer executeAfterBuildWidgets = mExecuteAfterBuildWidgets; mExecuteAfterBuildWidgets = null; executeAfterBuildWidgets.run(); } return; } mNeedToBuildWidgets = BUILDING_IN_PROGRESS; // TODO: test configureOnce mPipeline.configureOnce(); if (mToInspect != null) { Inspector inspector = mPipeline.getInspector(); if (mLastInspection == null) { // Special support for GwtRemoteInspectorProxy if (inspector instanceof GwtRemoteInspectorProxy) { TypeAndNames typeAndNames = PathUtils.parsePath(mPath); ((GwtRemoteInspectorProxy) inspector).inspect(mToInspect, typeAndNames.getType(), typeAndNames.getNamesAsArray(), new AsyncCallback<String>() { public void onFailure(Throwable caught) { GwtUtils.alert(caught); mNeedToBuildWidgets = BUILDING_COMPLETE; } public void onSuccess(String inspectionResult) { mLastInspection = mPipeline.stringToElement(inspectionResult); try { mIgnoreAddRemove = true; mPipeline.buildWidgets(mLastInspection); } catch (Exception e) { GwtUtils.alert(e); } finally { mIgnoreAddRemove = false; } mNeedToBuildWidgets = BUILDING_COMPLETE; // For unit tests if (mExecuteAfterBuildWidgets != null) { Timer executeAfterBuildWidgets = mExecuteAfterBuildWidgets; mExecuteAfterBuildWidgets = null; executeAfterBuildWidgets.run(); } } }); return; } } // Regular GwtInspectors try { mIgnoreAddRemove = true; if (mLastInspection == null) { TypeAndNames typeAndNames = PathUtils.parsePath(mPath); mLastInspection = mPipeline.inspectAsDom(mToInspect, typeAndNames.getType(), typeAndNames.getNamesAsArray()); } mPipeline.buildWidgets(mLastInspection); } catch (Exception e) { GwtUtils.alert(e); } finally { mIgnoreAddRemove = false; } mNeedToBuildWidgets = BUILDING_COMPLETE; // For unit tests if (mExecuteAfterBuildWidgets != null) { mExecuteAfterBuildWidgets.run(); mExecuteAfterBuildWidgets = null; } } }
From source file:org.openremote.web.console.unit.ConsoleUnit.java
License:Open Source License
private boolean setPanel(Panel result) { boolean success = false; if (result != null) { // Unload current panel unloadPanel();/*from w w w . ja va 2 s . c om*/ // Set new panel and prefetch image resources panelService.setCurrentPanel(result); BrowserUtils.showLoadingMsg("Retrieving Resources.."); try { // List<String> imageUrls = panelService.getImageResourceUrls(); // for(String imageUrl : imageUrls ) { // addImageToCache(imageUrl); // Thread.sleep(100); // } Timer imageCacher = new Timer() { int i = 0; String[] imageUrls = panelService.getPanelImageUrls(); @Override public void run() { if (i < imageUrls.length) { addImageToCache(imageUrls[i]); i++; this.schedule(100); } else { // Prefetch All Images Resources before proceeding loadCache(new AsyncControllerCallback() { @Override public void onSuccess(Object result) { initialisePanel(); } @Override public void onFailure(Throwable e) { initialisePanel(); } }); } } }; imageCacher.run(); } catch (Exception e) { return false; } } return true; }
From source file:org.openremote.web.console.unit.ConsoleUnit.java
License:Open Source License
private void loadCache(final AsyncControllerCallback callback) { Timer imageLoader = new Timer() { private int secondCount = 0; private boolean allImagesLoaded = false; public void run() { boolean allImagesLoaded = true; for (Iterator<String> it = imageCache.keySet().iterator(); it.hasNext();) { String url = it.next(); ImageContainer image = imageCache.get(url); if (!image.getLoadAttempted()) { allImagesLoaded = false; break; }/*from w ww . ja va2 s.c o m*/ } if (secondCount > IMAGE_CACHE_LOAD_TIMEOUT_SECONDS) { callback.onFailure(new Exception("Timeout during image loading")); } else if (allImagesLoaded) { callback.onSuccess(null); } else { secondCount++; this.schedule(1000); } } }; imageLoader.run(); }
From source file:org.openremote.web.console.unit.ConsoleUnit.java
License:Open Source License
public void onAdd() { // Set Position setPosition();//from w w w.ja va 2 s. c o m // Configure display consoleDisplay.onAdd(width, height); show(); // Initialise the system panel // String systemPanelStr = dataService.getObjectString(EnumDataMap.SYSTEM_PANEL.getDataName()); // if (systemPanelStr == null) { // Load from Server BrowserUtils.showLoadingMsg("Retreiving System Panel Definition"); try { int displayDensity = BrowserUtils.getDisplayDensityValue(); new RequestBuilder(RequestBuilder.GET, "resources/systempanel" + displayDensity + ".json") .sendRequest("", new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { String systemPanelStr = response.getText(); systemPanel = AutoBeanService.getInstance().fromJsonString(Panel.class, systemPanelStr) .as(); // Initialise the system panel panelService.setCurrentPanel(systemPanel); BrowserUtils.showLoadingMsg("Retrieving Resources.."); try { // List<String> imageUrls = panelService.getImageResourceUrls(); // for(String imageUrl : imageUrls ) { // addImageToCache(imageUrl); // Thread.sleep(100); // } Timer imageCacher = new Timer() { int i = 0; String[] imageUrls = panelService.getPanelImageUrls(); @Override public void run() { if (i < imageUrls.length) { addImageToCache(imageUrls[i]); i++; this.schedule(100); } } }; imageCacher.run(); // Prefetch All Images Resources before proceeding loadCache(new AsyncControllerCallback() { @Override public void onSuccess(Object result) { initialiseConsole(); } @Override public void onFailure(Throwable e) { BrowserUtils.hideLoadingMsg(); BrowserUtils.showAlert( "FATAL Error: Failed to retrieve System Panel Definition."); } }); } catch (Exception e) { BrowserUtils.hideLoadingMsg(); BrowserUtils.showAlert("FATAL Error: Failed to retrieve System Panel Definition."); } } @Override public void onError(Request request, Throwable exception) { BrowserUtils.hideLoadingMsg(); BrowserUtils.showAlert("FATAL Error: Failed to retrieve System Panel Definition."); } }); } catch (RequestException e) { BrowserUtils.hideLoadingMsg(); BrowserUtils.showAlert("FATAL Error: Failed to retrieve System Panel Definition."); } // } // else { // systemPanel = AutoBeanService.getInstance().fromJsonString(Panel.class, systemPanelStr).as(); // initialiseConsole(); // } }
From source file:org.pepstock.jem.gwt.client.security.CurrentUser.java
License:Open Source License
private CurrentUser() { Timer preferencesStoreTimer = new Timer() { @Override/*from w ww . j av a 2s. co m*/ public void run() { if (user != null) { storePreferences(); } } }; preferencesStoreTimer.run(); preferencesStoreTimer.scheduleRepeating(PREFERENCES_STORE_INTERVAL); }
From source file:org.ssgwt.client.ui.SSFileSelector.java
License:Apache License
/** * Class constructor//from w w w. j av a2s .c o m * * @param label The label to display on the button */ public SSFileSelector(String label) { FlowPanel mainContainer = new FlowPanel(); fileUpload = new FileUpload(); fileUpload.setWidth("0px"); fileUpload.setHeight("0px"); mainContainer.add(fileUpload); button = new Button(label); button.addClickHandler(new ClickHandler() { /** * The event that fires once you click on the button * * @param event - The event that fires */ @Override public void onClick(ClickEvent event) { SSFileSelector.clickOnInputFile(fileUpload.getElement()); if (isForm) { /** * Timer to delay */ Timer timer = new Timer() { /** * This method will be called when a timer fires. */ public void run() { if (!getFileSelectedComplete()) { this.schedule(500); } else { if (isValidation) { error = null; int x = getFileName().lastIndexOf("."); if (x == -1) { setError(); } else { String extension = getFileName().substring(x + 1); if (allowedFiles.contains(extension)) { form.submit(); } else { setError(); } } } else { form.submit(); } } } }; timer.run(); } } }); mainContainer.add(button); initWidget(mainContainer); }
From source file:test.client.ResizableMapLayout.java
License:Open Source License
/** * Create a resizable map layout for the given map. The map will be added to this layout. * //from w w w .ja va 2 s .com * @param mapPresenter * The map to add. */ public ResizableMapLayout(final MapPresenter mapPresenter) { this.mapPresenter = mapPresenter; mapPresenter.getEventBus().addHandler(MapInitializationHandler.TYPE, new RedrawMapInitializationHandler()); layout = new ResizeLayoutPanel(); layout.setSize("100%", "100%"); layout.add(mapPresenter.asWidget()); // Add an automatic resize handler to set the correct size when the window resizes: Window.addResizeHandler(new ResizeHandler() { public void onResize(ResizeEvent event) { applySize(); } }); // Calculate the correct size on load: layout.addAttachHandler(new AttachEvent.Handler() { public void onAttachOrDetach(AttachEvent event) { Timer timer = new Timer() { @Override public void run() { if (!applySize()) { schedule(50); } } }; timer.run(); } }); }