List of usage examples for com.google.gwt.user.client Timer scheduleRepeating
public synchronized void scheduleRepeating(final int periodMs)
From source file:org.eclipse.kapua.app.console.client.device.DeviceConfigSnapshots.java
License:Open Source License
public void refreshWhenOnline() { final int PERIOD_MILLIS = 1000; Timer timer = new Timer() { private int TIMEOUT_MILLIS = 30000; private int countdownMillis = TIMEOUT_MILLIS; public void run() { if (m_selectedDevice != null) { countdownMillis -= PERIOD_MILLIS; // // Poll the current status of the device until is online again or timeout. gwtDeviceService.findDevice(m_selectedDevice.getScopeId(), m_selectedDevice.getClientId(), new AsyncCallback<GwtDevice>() { @Override public void onFailure(Throwable t) { done();//from w w w . j a v a 2 s . c o m } @Override public void onSuccess(GwtDevice gwtDevice) { if (countdownMillis <= 0 || // Allow the device to disconnect before checking if it's online again. ((TIMEOUT_MILLIS - countdownMillis) > 5000 && gwtDevice.isOnline())) { done(); } } private void done() { cancel(); // force a dirty on both tabs m_tabConfig.setDevice(m_selectedDevice); refresh(); } }); } } }; m_grid.mask(MSGS.waiting()); timer.scheduleRepeating(PERIOD_MILLIS); }
From source file:org.gatein.management.gadget.client.Application.java
License:Open Source License
/** * Create and return the dialog box for the site upload. * * @return a {@code DialogBox}//from w w w. ja v a 2 s . c o m */ private DialogBox createDialogBox() { // Create a dialog box final DialogBox dialogBox = new DialogBox(); dialogBox.setText("Import site"); dialogBox.setAnimationEnabled(true); dialogBox.setModal(true); dialogBox.setGlassEnabled(true); final AbsolutePanel absolutePanel = new AbsolutePanel(); dialogBox.setWidget(absolutePanel); absolutePanel.setStyleName("status-panel"); absolutePanel.setSize("400px", "220px"); final Button importButton = new Button("Import"); final CheckBox overwriteBox = new CheckBox("Overwrite the existing site"); final HTML statusImg = new HTML(" ", true); final Label statusLabel = new Label("status label"); final Label headerLabel = new Label("Select file to import :"); final AbsolutePanel statusPanel = new AbsolutePanel(); headerLabel.setSize("380px", "39px"); headerLabel.setStyleName("header-style"); absolutePanel.add(headerLabel, 10, 10); final MultiUploader uploader = new GTNMultiUploader(); uploader.setAvoidRepeatFiles(false); absolutePanel.add(uploader, 10, 46); uploader.setSize("380px", "32px"); uploader.addOnChangeUploadHandler(new IUploader.OnChangeUploaderHandler() { @Override public void onChange(IUploader uploader) { // Nothing to do if (uploader.getFileName() != null) { importButton.setEnabled(true); } } }); // Add a finish handler which will notify user once the upload finishes uploader.addOnFinishUploadHandler(new IUploader.OnFinishUploaderHandler() { public void onFinish(IUploader uploader) { switch (uploader.getStatus()) { case SUCCESS: statusLabel.setText("File uploaded with success"); statusLabel.setStyleName("success-style"); statusImg.setStyleName("success-style-icon"); break; case ERROR: statusLabel.setText("File upload error"); statusLabel.setStyleName("error-style"); statusImg.setStyleName("error-style-icon"); break; case CANCELED: statusLabel.setText("File upload canceled"); statusLabel.setStyleName("warn-style"); statusImg.setStyleName("warn-style-icon"); break; default: statusLabel.setText(""); statusLabel.setStyleName("blank-style"); statusImg.setStyleName("blank-style"); break; } overwriteBox.setEnabled(true); importButton.setEnabled(true); } }); // Add a start handler which will disable the UI until the upload finishes uploader.addOnStartUploadHandler(new IUploader.OnStartUploaderHandler() { boolean isShwon = false; public void onStart(IUploader uploader) { statusLabel.setText("Process in progress..."); statusLabel.setStyleName("progress-style"); statusImg.setStyleName("progress-style-icon"); overwriteBox.setEnabled(false); importButton.setEnabled(false); if (!isShwon) { statusPanel.setStyleName("status-panel"); statusPanel.setSize("380px", "0px"); absolutePanel.add(statusPanel, 10, 120); Timer t = new Timer() { int dx = 5; int height = 0; public void run() { height += dx; statusPanel.setHeight(height + "px"); if (height >= 45) { cancel(); // Stop the timer } } }; // Schedule the timer to run once in 100 milliseconds. t.scheduleRepeating(100); isShwon = true; } } }); // accept only zip files uploader.setValidExtensions(new String[] { "zip" }); // You can add customized parameters to servlet call uploader.setServletPath(UPLOAD_ACTION_URL + "?pc=" + getPortalContainerName()); overwriteBox.setTitle("If you want to force overwriting an existing site, check this checkbox"); overwriteBox.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { String url = UPLOAD_ACTION_URL + "?pc=" + getPortalContainerName() + "&overwrite=" + overwriteBox.getValue(); uploader.setServletPath(url); } }); absolutePanel.add(overwriteBox, 10, 84); Button closeButton = new Button("Close", new ClickHandler() { public void onClick(ClickEvent event) { dialogBox.hide(); } }); absolutePanel.add(closeButton, 343, 188); statusImg.setStyleName("progress-style-icon"); statusPanel.add(statusImg, 10, 10); statusImg.setSize("50px", "30px"); statusPanel.add(statusLabel, 60, 15); statusLabel.setSize("300px", "25px"); importButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { uploader.submit(); } }); importButton.setEnabled(false); absolutePanel.add(importButton, 10, 188); return dialogBox; }
From source file:org.gatein.management.gadget.mop.exportimport.client.Application.java
License:Open Source License
/** * Create and return the dialog box for the site upload. * * @return a {@code DialogBox}//w ww.j a v a2 s. c om */ private DialogBox createDialogBox() { // Create a dialog box final DialogBox dialogBox = new DialogBox(); dialogBox.setText("Import site"); dialogBox.setAnimationEnabled(true); dialogBox.setModal(true); dialogBox.setGlassEnabled(true); final AbsolutePanel absolutePanel = new AbsolutePanel(); dialogBox.setWidget(absolutePanel); absolutePanel.setStyleName("status-panel"); absolutePanel.setSize("400px", "220px"); final Button importButton = new Button("Import"); final Label importModeLabel = new Label("Import Mode:"); final ListBox importModeListBox = new ListBox(false); importModeListBox.addItem("Conserve", "conserve"); importModeListBox.addItem("Insert", "insert"); importModeListBox.addItem("Merge", "merge"); importModeListBox.addItem("Overwrite", "overwrite"); importModeListBox.setSelectedIndex(2); // set default to 'merge' final HTML statusImg = new HTML(" ", true); final Label statusLabel = new Label("status label"); final Label headerLabel = new Label("Select file to import :"); final AbsolutePanel statusPanel = new AbsolutePanel(); headerLabel.setSize("380px", "39px"); headerLabel.setStyleName("header-style"); absolutePanel.add(headerLabel, 10, 10); final MultiUploader uploader = new GTNMultiUploader(); uploader.setAvoidRepeatFiles(false); absolutePanel.add(uploader, 10, 46); uploader.setSize("380px", "32px"); uploader.addOnChangeUploadHandler(new IUploader.OnChangeUploaderHandler() { @Override public void onChange(IUploader uploader) { // Nothing to do if (uploader.getFileName() != null) { importButton.setEnabled(true); } } }); // Add a finish handler which will notify user once the upload finishes uploader.addOnFinishUploadHandler(new IUploader.OnFinishUploaderHandler() { public void onFinish(IUploader uploader) { switch (uploader.getStatus()) { case SUCCESS: statusLabel.setText("File uploaded with success"); statusLabel.setStyleName("success-style"); statusImg.setStyleName("success-style-icon"); break; case ERROR: statusLabel.setText("File upload error"); statusLabel.setStyleName("error-style"); statusImg.setStyleName("error-style-icon"); break; case CANCELED: statusLabel.setText("File upload canceled"); statusLabel.setStyleName("warn-style"); statusImg.setStyleName("warn-style-icon"); break; default: statusLabel.setText(""); statusLabel.setStyleName("blank-style"); statusImg.setStyleName("blank-style"); break; } importModeListBox.setEnabled(true); importButton.setEnabled(true); } }); // Add a start handler which will disable the UI until the upload finishes uploader.addOnStartUploadHandler(new IUploader.OnStartUploaderHandler() { boolean isShwon = false; public void onStart(IUploader uploader) { if (uploader.getStatus() == IUploadStatus.Status.INPROGRESS) { statusLabel.setText("Process in progress..."); statusLabel.setStyleName("progress-style"); statusImg.setStyleName("progress-style-icon"); importModeListBox.setEnabled(false); importButton.setEnabled(false); if (!isShwon) { statusPanel.setStyleName("status-panel"); statusPanel.setSize("380px", "0px"); absolutePanel.add(statusPanel, 10, 120); Timer t = new Timer() { int dx = 5; int height = 0; public void run() { height += dx; statusPanel.setHeight(height + "px"); if (height >= 45) { cancel(); // Stop the timer } } }; // Schedule the timer to run once in 100 milliseconds. t.scheduleRepeating(100); isShwon = true; } } } }); // accept only zip files uploader.setValidExtensions("zip"); // You can add customized parameters to servlet call uploader.setServletPath(UPLOAD_ACTION_URL + "?pc=" + getPortalContainerName()); importModeListBox.setTitle("The import mode to use during import."); importModeListBox.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent changeEvent) { String url = UPLOAD_ACTION_URL + "?pc=" + getPortalContainerName() + "&importMode=" + importModeListBox.getValue(importModeListBox.getSelectedIndex()); uploader.setServletPath(url); } }); absolutePanel.add(importModeLabel, 10, 88); absolutePanel.add(importModeListBox, 95, 84); Button closeButton = new Button("Close", new ClickHandler() { public void onClick(ClickEvent event) { dialogBox.hide(); } }); absolutePanel.add(closeButton, 343, 188); statusImg.setStyleName("progress-style-icon"); statusPanel.add(statusImg, 10, 10); statusImg.setSize("50px", "30px"); statusPanel.add(statusLabel, 60, 15); statusLabel.setSize("300px", "25px"); importButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { uploader.submit(); } }); importButton.setEnabled(false); absolutePanel.add(importButton, 10, 188); return dialogBox; }
From source file:org.geosdi.maplite.client.model.LegendBuilder.java
private static DialogBox getRefreshDialogBox(final ClientRasterInfo raster, final Map map) { // Create a dialog box and set the caption text final DialogBox refreshDialogBox = new DialogBox(); refreshDialogBox.ensureDebugId("cwDialogBox"); refreshDialogBox.setText("REFRESH TIME"); // Create a table to layout the content VerticalPanel dialogContents = new VerticalPanel(); dialogContents.setSpacing(4);/*from w ww .j a v a 2 s. co m*/ refreshDialogBox.setWidget(dialogContents); // Add some text to the top of the dialog HTML details = new HTML("seconds"); dialogContents.add(details); dialogContents.setCellHorizontalAlignment(details, HasHorizontalAlignment.ALIGN_CENTER); final TextBox normalText = new TextBox(); normalText.ensureDebugId("cwBasicText-textbox"); // Set the normal text box to automatically adjust its direction according // to the input text. Use the Any-RTL heuristic, which sets an RTL direction // iff the text contains at least one RTL character. normalText.setDirectionEstimator(AnyRtlDirectionEstimator.get()); dialogContents.add(normalText); dialogContents.setCellHorizontalAlignment(normalText, HasHorizontalAlignment.ALIGN_CENTER); // Add a close button at the bottom of the dialog Button closeButton = new Button("Apply", new ClickHandler() { private java.util.Map<ClientRasterInfo, Timer> timerMap = Maps.<ClientRasterInfo, Timer>newHashMap(); @Override public void onClick(ClickEvent event) { String value = normalText.getValue(); try { int seconds = Integer.parseInt(value); if (seconds != 0 && seconds < 30) { Window.alert("The time must be greater or equal to 30 seconds"); } else { Layer layer = map.getLayer(raster.getWmsLayerId()); final WMS wms = WMS.narrowToLayer(layer.getJSObject()); Timer timer = timerMap.get(raster); if (timer == null) { timer = new Timer() { @Override public void run() { logger.info("Repeat scheduling"); wms.redraw(true); } }; timerMap.put(raster, timer); } if (seconds == 0) { timer.cancel(); } else { timer.scheduleRepeating(seconds * 1000); } refreshDialogBox.hide(); } } catch (NumberFormatException nfe) { Window.alert("The passed value is not a valid integer number"); } } }); dialogContents.add(closeButton); if (LocaleInfo.getCurrentLocale().isRTL()) { dialogContents.setCellHorizontalAlignment(closeButton, HasHorizontalAlignment.ALIGN_LEFT); } else { dialogContents.setCellHorizontalAlignment(closeButton, HasHorizontalAlignment.ALIGN_RIGHT); } // Return the dialog box refreshDialogBox.setGlassEnabled(true); refreshDialogBox.setAnimationEnabled(true); refreshDialogBox.center(); return refreshDialogBox; }
From source file:org.gk.client.GKEngine.java
License:Open Source License
@Override public void start() { if (hasRenderPageFunction()) { RootPanel.get().add(viewport);/*from w ww . ja v a2 s . co m*/ } gk = Engine.get(); Timer timer = new Timer() { @Override public void run() { if (gk.isReady()) { cancel(); registry(GKEngine.this, gk); } } }; timer.scheduleRepeating(200); }
From source file:org.gk.ui.client.com.tree.dir.gkTreeDirPanelIC.java
License:Open Source License
public void expandNode(final List expandNode) { Timer timer = new Timer() { gkTreeDirPanelIC tree = gkTreeDirPanelIC.this; @Override/* w ww . j a v a2 s . c om*/ public void run() { try { if (expandNode.size() == 0) { cancel(); } ModelData targetNode = tree.getStore().findModel(expandNode.get(expandNode.size() - 1) + ""); for (Iterator it = expandNode.iterator(); it.hasNext();) { String nodeId = it.next() + ""; ModelData md = tree.getStore().findModel(nodeId); if (md == null) { cancel(); break; } else if (md.equals(targetNode)) { tree.setExpanded(md, true); TreePanelSelectionModel sm = tree.getSelectionModel(); sm.select(targetNode, false); tree.setSelectionModel(sm); cancel(); } else if (!tree.isExpanded(md)) { tree.setExpanded(md, true); break; } } } catch (Exception e) { cancel(); } } }; timer.scheduleRepeating(200); }
From source file:org.jboss.errai.bus.client.api.base.ClientTaskManager.java
License:Apache License
public AsyncTask scheduleRepeating(TimeUnit unit, int interval, final Runnable task) { final Timer timer = new Timer() { @Override/*from ww w. jav a 2s . c o m*/ public void run() { task.run(); } }; AsyncTask asyncTask = createAsyncTask(task, timer); timer.scheduleRepeating((int) unit.convert(interval, TimeUnit.MILLISECONDS)); return asyncTask; }
From source file:org.jboss.errai.otec.client.atomizer.Atomizer.java
License:Apache License
public static AtomizerSession syncWidgetWith(final OTEngine engine, final OTEntity entity, final ValueBoxBase widget) { LogUtil.log("NEW ATOMIZER SESSION (engine:" + engine.getId() + ", widget=" + widget + ")"); final Multimap<Object, HandlerRegistration> HANDLER_REGISTRATION_MAP = HashMultimap.create(); final EntityChangeStreamImpl entityChangeStream = new EntityChangeStreamImpl(engine, entity); final EntityStreamRegistration entityStreamRegistration = engine.getPeerState() .addEntityStream(entityChangeStream); widget.setValue(entity.getState().get()); HANDLER_REGISTRATION_MAP.put(widget, widget.addKeyDownHandler(new KeyDownHandler() { @Override/*www .ja va2s . c om*/ public void onKeyDown(final KeyDownEvent event) { if (shouldIgnoreKeyPress(event)) { return; } if (widget.getSelectedText().length() > 0) { stopEvents(); entityChangeStream.notifyDelete(widget.getCursorPos(), widget.getSelectedText()); startEvents(); } else if (event.getNativeKeyCode() == KeyCodes.KEY_BACKSPACE) { stopEvents(); final int index = widget.getCursorPos() - 1; entityChangeStream.notifyDelete(index, " "); startEvents(); } else if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { stopEvents(); entityChangeStream.notifyInsert(widget.getCursorPos(), "\n"); startEvents(); } } })); HANDLER_REGISTRATION_MAP.put(widget, widget.addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(final KeyPressEvent event) { if (event.getUnicodeCharCode() != 13 && event.getUnicodeCharCode() != 0) { stopEvents(); entityChangeStream.notifyInsert(widget.getCursorPos(), String.valueOf(event.getCharCode())); startEvents(); } } })); DOM.setEventListener(widget.getElement(), new EventListener() { @Override public void onBrowserEvent(Event event) { if (event.getTypeInt() == Event.ONPASTE) { final String before = (String) entity.getState().get(); new Timer() { @Override public void run() { final String after = (String) widget.getValue(); final DiffUtil.Delta diff = DiffUtil.diff(before, after); stopEvents(); entityChangeStream.notifyInsert(diff.getCursor(), diff.getDeltaText()); startEvents(); } }.schedule(1); } widget.onBrowserEvent(event); } }); attachCutHandler(widget.getElement(), new Runnable() { @Override public void run() { stopEvents(); entityChangeStream.notifyDelete(widget.getCursorPos(), widget.getSelectedText()); startEvents(); } }); attachTextDragHandler(widget.getElement(), new Runnable() { @Override public void run() { stopEvents(); entityChangeStream.notifyDelete(widget.getCursorPos(), widget.getSelectedText()); entityChangeStream.flush(); startEvents(); } }, new Runnable() { @Override public void run() { final String old = (String) entity.getState().get(); new Timer() { @Override public void run() { final DiffUtil.Delta diff = DiffUtil.diff(old, (String) widget.getValue()); if (diff.getDeltaText().length() > 0) { stopEvents(); entityChangeStream.notifyInsert(diff.getCursor(), diff.getDeltaText()); startEvents(); } } }.schedule(1); } }); final ListenerRegistration listenerRegistration = entity.getState() .addStateChangeListener(new StateChangeListener() { @Override public int getCursorPos() { return widget.getCursorPos(); } @Override public void onStateChange(final int newCursorPos, final Object newValue) { if (NO_PROPAGATE_STATE_CHANGE) { return; } widget.setValue(newValue, false); widget.setCursorPos(newCursorPos); } }); DOM.sinkEvents(widget.getElement(), DOM.getEventsSunk(widget.getElement()) | Event.ONPASTE); final Timer timer = new Timer() { @Override public void run() { entityChangeStream.flush(); } }; timer.scheduleRepeating(500); return new AtomizerSession() { @Override public void end() { entityChangeStream.close(); timer.cancel(); LogUtil.log("END ATOMIZER SESSION"); entityStreamRegistration.remove(); listenerRegistration.remove(); final Collection<HandlerRegistration> values = HANDLER_REGISTRATION_MAP.values(); for (final HandlerRegistration value : values) { value.removeHandler(); } } }; }
From source file:org.jboss.errai.widgets.client.effects.effectimpl.IEEffectImpl.java
License:Apache License
public Timer doFade(final Element el, double duration, final int start, final int end) { Timer t = start < end ? new Timer() { int step = start; public void run() { step += 5;/*from ww w .ja va2 s . c o m*/ if (step < end) { setOpacity(el, step); } else { setOpacity(el, end); cancel(); } } } : new Timer() { int step = end; public void run() { step -= 5; if (step > end) { setOpacity(el, step); } else { setOpacity(el, end); cancel(); } } }; t.scheduleRepeating(1); return t; }
From source file:org.jboss.errai.widgets.client.effects.effectimpl.KHTMLEffectImpl.java
License:Apache License
public Timer doFade(final Element el, double duration, final int start, final int end) { // final Style s = el.getStyle(); Timer t = start < end ? new Timer() { int step = start; public void run() { step += 5;/*from w w w. j av a2 s. c o m*/ if (step < end) { _setOpacity(el, step); } else { _setOpacity(el, end); cancel(); } } } : new Timer() { int step = end; public void run() { step -= 5; if (step > end) { _setOpacity(el, step); } else { _setOpacity(el, end); cancel(); } } }; t.scheduleRepeating(1); return t; }