List of usage examples for com.google.gwt.user.client Timer Timer
Timer
From source file:com.gwtpro.html5.fileapi.client.upload.UploadRequest.java
License:Apache License
public UploadRequest(XMLHttpRequest2 xmlHttpRequest, int timeoutMillis, final UploadRequestCallback callback) { this.timeoutMillis = timeoutMillis; this.xmlHttpRequest = xmlHttpRequest; if (timeoutMillis > 0) { this.timer = new Timer() { @Override/*from ww w . j av a 2 s. c om*/ public void run() { fireOnTimeout(callback); } }; this.timer.schedule(timeoutMillis); } else { this.timer = null; } }
From source file:com.gwttest.client.Demo.java
License:Open Source License
public void onModuleLoad() { final ChartWidget chart = new ChartWidget(); HorizontalPanel hp = new HorizontalPanel(); hp.setSpacing(10);/*from w ww . j a va2s . c om*/ VerticalPanel vp = new VerticalPanel(); vp.setSpacing(20); // add home page HTML homeText = new HTML("<h2>Welcome to OFCGWT</h2>" + "<i>....the OpenFlashChart GWT Library</i></br></br>" + "This demonstration site will showcase the many different types of charts that can be inserted into a GWT application."); vp.add(homeText); vp.setCellHeight(homeText, "100"); createPopupDialog(); Button popup = new Button("Show 2nd Chart in Dialog"); popup.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { popupDb.center(); popupDb.show(); } }); vp.add(popup); Button image = new Button("Show Image of Chart"); image.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { ImageServiceAsync imgService = (ImageServiceAsync) GWT.create(ImageService.class); ServiceDefTarget target = (ServiceDefTarget) imgService; target.setServiceEntryPoint(GWT.getHostPageBaseURL() + "ImageService"); imgService.getImageToken(chart.getImageData(), new AsyncCallback<String>() { public void onFailure(Throwable caught) { } public void onSuccess(String result) { createImageDialog(GWT.getHostPageBaseURL() + "image?var=img_" + result); } }); } }); vp.add(image); vp.add(new HTML("Update Speed <i>(0-off, 4-max)</i>")); final SliderBar slider = new SliderBar(0.0, 4.0); slider.setStepSize(1.0); slider.setCurrentValue(1.0); slider.setNumTicks(4); slider.setNumLabels(4); slider.setWidth("100%"); vp.add(slider); hp.add(vp); hp.setCellWidth(vp, "300"); // add chart VerticalPanel vp2 = new VerticalPanel(); DecoratorPanel dp = new DecoratorPanel(); SimplePanel chartPanel = new SimplePanel(); chartPanel.setStylePrimaryName("chartPanel"); chart.setSize("500", "400"); chart.setChartData(getPieChartData()); chartPanel.add(chart); dp.add(chartPanel); vp2.add(dp); vp2.add(new HTML("Chart's JSON data:")); ta = new TextArea(); ta.setWidth("400"); ta.setHeight("100"); ta.setText(chart.getJsonData()); vp2.add(ta); hp.add(vp2); VerticalPanel chartlist = new VerticalPanel(); chartlist.setSpacing(5); Command cmd = new Command() { public void execute() { chart.setChartData(getPieChartData()); ta.setText(chart.getJsonData()); } }; RadioButton rb = createRadioButton("PieChart - No Labels", cmd); updateCmd = cmd; rb.setValue(true); chartlist.add(rb); chartlist.add(createRadioButton("PieChart - Animate", new Command() { public void execute() { chart.setChartData(getAniPieChartData()); ta.setText(chart.getJsonData()); } })); chartlist.add(createRadioButton("BarChart - Transparent", new Command() { public void execute() { chart.setChartData(getBarChartTransparentData()); ta.setText(chart.getJsonData()); } })); chartlist.add(createRadioButton("BarChart - Glass", new Command() { public void execute() { chart.setChartData(getBarChartGlassData()); ta.setText(chart.getJsonData()); } })); chartlist.add(createRadioButton("3DBarChart + Line", new Command() { public void execute() { chart.setChartData(get3DBarLineChartData()); ta.setText(chart.getJsonData()); } })); chartlist.add(createRadioButton("CylinderChart", new Command() { public void execute() { chart.setChartData(getCylinderChartData()); ta.setText(chart.getJsonData()); } })); chartlist.add(createRadioButton("CylinderChart - RoundGlass", new Command() { public void execute() { chart.setChartData(getCylinderChartGlassData()); ta.setText(chart.getJsonData()); } })); chartlist.add(createRadioButton("LineChart - 3 Dot Types", new Command() { public void execute() { chart.setChartData(getLineChartData()); ta.setText(chart.getJsonData()); } })); chartlist.add(createRadioButton("ScatterChart - Star Dot", new Command() { public void execute() { chart.setChartData(getScatterPointChartData()); ta.setText(chart.getJsonData()); } })); chartlist.add(createRadioButton("ScatterChart - Line", new Command() { public void execute() { chart.setChartData(getScatterLineChartData()); ta.setText(chart.getJsonData()); } })); chartlist.add(createRadioButton("RadarChart", new Command() { public void execute() { chart.setChartData(getRadarChartData()); ta.setText(chart.getJsonData()); } })); chartlist.add(createRadioButton("Horizontal-BarChart", new Command() { public void execute() { chart.setChartData(getHorizBarChartData()); ta.setText(chart.getJsonData()); } })); chartlist.add(createRadioButton("AreaChart - Hollow", new Command() { public void execute() { chart.setChartData(getAreaHollowChartData()); ta.setText(chart.getJsonData()); } })); chartlist.add(createRadioButton("AreaChart - Line", new Command() { public void execute() { chart.setChartData(getAreaLineChartData()); ta.setText(chart.getJsonData()); } })); chartlist.add(createRadioButton("SketchChart", new Command() { public void execute() { chart.setChartData(getSketchChartData()); ta.setText(chart.getJsonData()); } })); chartlist.add(createRadioButton("StackChart", new Command() { public void execute() { chart.setChartData(getStackChartData()); ta.setText(chart.getJsonData()); } })); chartlist.add(createRadioButton("HorizontalStackChart", new Command() { public void execute() { chart.setChartData(getHorizontalStackChartData()); ta.setText(chart.getJsonData()); } })); hp.add(chartlist); hp.setCellWidth(chartlist, "300"); RootPanel.get().add(hp); final Timer updater = new Timer() { public void run() { updateCmd.execute(); } }; updater.scheduleRepeating(3000); slider.addChangeListener(new ChangeListener() { public void onChange(Widget sender) { switch ((int) (slider.getCurrentValue())) { case 0: updater.cancel(); break; case 1: updater.scheduleRepeating(3000); break; case 2: updater.scheduleRepeating(1000); break; case 3: updater.scheduleRepeating(200); break; case 4: updater.scheduleRepeating(50); break; } } }); }
From source file:com.haulmont.cuba.web.toolkit.ui.client.downloader.CubaFileDownloaderConnector.java
License:Apache License
public void downloadFileById(String resourceId) { final String url = getResourceUrl(resourceId); if (url != null && !url.isEmpty()) { final IFrameElement iframe = Document.get().createIFrameElement(); Style style = iframe.getStyle(); style.setVisibility(Style.Visibility.HIDDEN); style.setHeight(0, Style.Unit.PX); style.setWidth(0, Style.Unit.PX); iframe.setFrameBorder(0);//from w w w .j av a 2s . c om iframe.setTabIndex(-1); iframe.setSrc(url); RootPanel.getBodyElement().appendChild(iframe); Timer removeTimer = new Timer() { @Override public void run() { iframe.removeFromParent(); } }; removeTimer.schedule(60 * 1000); } }
From source file:com.haulmont.cuba.web.toolkit.ui.client.jqueryfileupload.JQueryFileUploadOverlay.java
License:Apache License
protected static void hideDropZones() { if (dragStopTimer != null) { dragStopTimer.cancel();/*from ww w . j av a 2 s . co m*/ } dragStopTimer = new Timer() { @Override public void run() { forceHideDropZones(); } }; dragStopTimer.schedule(300); }
From source file:com.haulmont.cuba.web.toolkit.ui.client.orderedactionslayout.CubaOrderedLayoutSlot.java
License:Apache License
public void setCaption(String captionText, boolean contextHelpIconEnabled, Icon icon, List<String> styles, String error, boolean showError, boolean required, boolean enabled, boolean captionAsHtml) { // CAUTION copied from super // Caption wrappers Widget widget = getWidget();//from ww w . java 2 s . c o m final Element focusedElement = WidgetUtil.getFocusedElement(); // By default focus will not be lost boolean focusLost = false; if (captionText != null || icon != null || error != null || required || contextHelpIconEnabled) { 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"); if (caption != null) { 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) { if (caption != 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); } if (caption != null) { caption.appendChild(requiredIcon); } } else if (requiredIcon != null) { requiredIcon.removeFromParent(); requiredIcon = null; } // Context Help // Haulmont API if (contextHelpIconEnabled) { if (contextHelpIcon == null) { contextHelpIcon = DOM.createSpan(); // TODO decide something better (e.g. use CSS to insert the character) contextHelpIcon.setInnerHTML("?"); contextHelpIcon.setClassName(CONTEXT_HELP_CLASSNAME); // The question mark 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(contextHelpIcon, true); } if (caption != null) { caption.appendChild(contextHelpIcon); if (clickHandlerRegistration == null) { clickHandlerRegistration = addDomHandler(this, ClickEvent.getType()); } } } else { if (this.contextHelpIcon != null) { this.contextHelpIcon.removeFromParent(); this.contextHelpIcon = null; } if (clickHandlerRegistration != null) { clickHandlerRegistration.removeHandler(); clickHandlerRegistration = null; } } // Error if (error != null && showError) { if (errorIcon == null) { errorIcon = DOM.createSpan(); errorIcon.setClassName("v-errorindicator"); } if (caption != null) { 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.haulmont.cuba.web.widgets.client.orderedactionslayout.CubaOrderedLayoutSlot.java
License:Apache License
public void setCaption(String captionText, boolean contextHelpIconEnabled, Icon icon, List<String> styles, String error, boolean showError, boolean required, boolean enabled, boolean captionAsHtml) { // CAUTION copied from super // Caption wrappers Widget widget = getWidget();//from w w w. j a va 2 s . c o m final Element focusedElement = WidgetUtil.getFocusedElement(); // By default focus will not be lost boolean focusLost = false; if (captionText != null || icon != null || error != null || required || contextHelpIconEnabled) { 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"); if (caption != null) { 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) { if (caption != 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); } if (caption != null) { caption.appendChild(requiredIcon); } } else if (requiredIcon != null) { requiredIcon.removeFromParent(); requiredIcon = null; } // Context Help // Haulmont API if (contextHelpIconEnabled) { if (contextHelpIcon == null) { contextHelpIcon = DOM.createSpan(); // TODO decide something better (e.g. use CSS to insert the character) contextHelpIcon.setInnerHTML("?"); contextHelpIcon.setClassName(CONTEXT_HELP_CLASSNAME); ComponentConnector componentConnector = Util.findConnectorFor(widget); if (hasContextHelpIconListeners(componentConnector.getState())) { contextHelpIcon.addClassName(CONTEXT_HELP_CLICKABLE_CLASSNAME); } // The question mark 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(contextHelpIcon, true); } if (caption != null) { caption.appendChild(contextHelpIcon); if (clickHandlerRegistration == null) { clickHandlerRegistration = addDomHandler(this, ClickEvent.getType()); } } } else { if (this.contextHelpIcon != null) { this.contextHelpIcon.removeFromParent(); this.contextHelpIcon = null; } if (clickHandlerRegistration != null) { clickHandlerRegistration.removeHandler(); clickHandlerRegistration = null; } } // Error if (error != null && showError) { if (errorIcon == null) { errorIcon = DOM.createSpan(); errorIcon.setClassName("v-errorindicator"); } if (caption != null) { 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.hazelcast.monitor.client.ToolTip.java
License:Open Source License
public ToolTip(String message, int x, int y) { super(true);/* w w w. j ava2 s. c om*/ this.setPopupPosition(x, y); this.add(new Label(message)); removeDelay = new Timer() { public void run() { ToolTip.this.setVisible(false); ToolTip.this.hide(); } }; removeDelay.schedule(VISIBLE_DELAY); this.addCloseHandler(new CloseHandler() { public void onClose(CloseEvent closeEvent) { removeDelay.cancel(); } }); this.setStyleName("toolTip"); this.show(); }
From source file:com.ikon.frontend.client.panel.bottom.BottomPanel.java
License:Open Source License
/** * Sets the status//w w w. j a va 2s.co m * * @param key The status value * @param error Is error or not */ public void setStatus(String key, boolean error) { this.key = key; aditionalErrorMsg = ""; // Always we ensure remove status here might be disabled to prevent removing new status data if (removeStatus != null) { removeStatus.cancel(); removeStatus = null; } if (error) { statusMsg.addStyleName("okm-Input-Error"); DateTimeFormat dtf = DateTimeFormat.getFormat(Main.i18n("general.hour.pattern")); aditionalErrorMsg = " - " + dtf.format(new Date()); // On error case we reset status at 2 minutes removeStatus = new Timer() { public void run() { resetStatus(); } }; removeStatus.schedule(120 * 1000); // 2 min } else { statusMsg.removeStyleName("okm-Input-Error"); } statusMsg.setText(" " + Main.i18n(key) + aditionalErrorMsg); }
From source file:com.ikon.frontend.client.panel.bottom.BottomPanel.java
License:Open Source License
/** * Sets the status code//from w ww .j av a2 s.co m * * @param key The status code key * @param error Is error or not * @param errorCode The code error */ public void setStatus(String key, boolean error, int errorCode) { this.key = key; aditionalErrorMsg = ""; // Always we ensure remove status here might be disabled to prevent removing new status data if (removeStatus != null) { removeStatus.cancel(); removeStatus = null; } if (error) { statusMsg.addStyleName("okm-Input-Error"); DateTimeFormat dtf = DateTimeFormat.getFormat(Main.i18n("general.hour.pattern")); aditionalErrorMsg = " (" + errorCode + ") - " + dtf.format(new Date()); // On error case we reset status at 2 minutes removeStatus = new Timer() { public void run() { resetStatus(); } }; removeStatus.schedule(120 * 1000); // 2 min } else { statusMsg.removeStyleName("okm-Input-Error"); } statusMsg.setText(" " + Main.i18n(key) + aditionalErrorMsg); }
From source file:com.ikon.frontend.client.panel.center.Browser.java
License:Open Source License
/** * onSplitResize/*from w ww . j av a 2 s . c om*/ */ public void onSplitResize() { final int resizeUpdatePeriod = 20; // ms ( Internally splitter is refreshing each 20 ms ) if (isResizeInProgress) { new Timer() { @Override public void run() { resizePanels(); // Always making resize if (isResizeInProgress) { onSplitResize(); } else if (Util.getUserAgent().equals("chrome")) { resizePanels(); } } }.schedule(resizeUpdatePeriod); } }