Example usage for com.google.gwt.user.client Timer scheduleRepeating

List of usage examples for com.google.gwt.user.client Timer scheduleRepeating

Introduction

In this page you can find the example usage for com.google.gwt.user.client Timer scheduleRepeating.

Prototype

public synchronized void scheduleRepeating(final int periodMs) 

Source Link

Document

Schedules a timer that elapses repeatedly.

Usage

From source file:fr.loria.score.client.ClientJupiterAlg.java

License:Open Source License

/**
 * Simulate the server-push via simple polling
 *//*from w w  w .j  av  a 2 s.c  o  m*/
private void serverPushForClient() {

    final Timer timer = new Timer() {
        @Override
        public void run() {
            comService.clientReceive(getSiteId(), new AsyncCallback<Message[]>() {
                public void onSuccess(Message[] messages) {
                    if (messages.length > 0) {
                        for (int i = 0; i < messages.length; i++) {
                            Message message = messages[i];
                            receive(message);
                        }
                    }
                }

                public void onFailure(Throwable caught) {
                    logger.severe("Error: " + caught);
                    if (caught instanceof StatusCodeException
                            && ((StatusCodeException) caught).getStatusCode() == 0) {
                        // timer.cancel();
                    }
                }
            });
        }
    };
    timer.scheduleRepeating(REFRESH_INTERVAL);
}

From source file:gov.nist.spectrumbrowser.admin.ServiceControl.java

License:Open Source License

private void setStatusBox() {

    final Timer timer = new Timer() {
        @Override//  w  w  w .  j  a v a  2  s.com
        public void run() {
            Admin.getAdminService().getServicesStatus(new SpectrumBrowserCallback<String>() {
                @Override
                public void onSuccess(String result) {
                    try {
                        JSONObject jsonObj = JSONParser.parseLenient(result).isObject();
                        JSONObject status = jsonObj.get("serviceStatus").isObject();

                        for (String serviceName : SERVICE_NAMES) {
                            String serviceStatus = status.get(serviceName).isString().stringValue();
                            statusBoxMap.get(serviceName).setText(serviceStatus);
                            if (stopButtonMap.get(serviceName) != null)
                                stopButtonMap.get(serviceName).setEnabled(true);
                            if (restartButtonMap.get(serviceName) != null) {
                                restartButtonMap.get(serviceName).setEnabled(true);
                            }
                        }
                    } catch (Throwable th) {
                        logger.log(Level.SEVERE, "Error parsing json ", th);
                        admin.logoff();
                    }

                }

                @Override
                public void onFailure(Throwable throwable) {
                    // Window.alert("Error communicating with server -- check servicecontrol service status.");
                    cancel();
                    admin.logoff();
                }
            });

        }
    };
    timer.scheduleRepeating(STATUS_CHECK_TIME_SEC * 1000);
}

From source file:gov.nist.spectrumbrowser.client.SpectrumBrowserShowDatasets.java

License:Open Source License

public SpectrumBrowserShowDatasets(SpectrumBrowser browser, VerticalPanel verticalPanel) {
    this.spectrumBrowser = browser;
    this.verticalPanel = verticalPanel;
    ImagePreloader.load(SpectrumBrowser.getIconsPath() + "mm_20_red.png", null);
    ImagePreloader.load(SpectrumBrowser.getIconsPath() + "mm_20_yellow.png", null);

    LoadApi.go(new Runnable() {
        @Override/*from w  w w. ja  v  a 2s . c o m*/
        public void run() {
            draw();
        }
    }, false);

    Timer timer = new Timer() {

        @Override
        public void run() {

            spectrumBrowser.getSpectrumBrowserService()
                    .checkSessionTimeout(new SpectrumBrowserCallback<String>() {
                        @Override
                        public void onSuccess(String result) {
                            JSONObject retval = JSONParser.parseLenient(result).isObject();
                            String status = retval.get("status").isString().stringValue();
                            if (status.equals("NOK")) {
                                cancel();
                                if (spectrumBrowser.isUserLoggedIn()) {
                                    spectrumBrowser.logoff();
                                } else {
                                    Window.alert("Your session has expired.");
                                    spectrumBrowser.logoff();
                                }
                            }

                        }

                        @Override
                        public void onFailure(Throwable throwable) {
                            cancel();
                            logger.finer("Session Timer: Error communicating with server -- logging off.");
                            if (spectrumBrowser.isUserLoggedIn()) {
                                spectrumBrowser.logoff();
                            } else {
                                spectrumBrowser.logoff();
                            }
                        }
                    });

        }
    };

    // Check for session timeout every second.
    timer.scheduleRepeating(60 * 1000);

}

From source file:gov.nist.spectrumbrowser.client.SpectrumBrowserShowDatasets.java

License:Open Source License

public void draw() {
    try {/*from w  w  w.  j a v  a 2  s .  c om*/
        spectrumBrowser.showWaitImage();
        Window.setTitle("MSOD:Home");
        SpectrumBrowser.clearSensorInformation();
        sensorMarkers.clear();
        SensorGroupMarker.clear();
        verticalPanel.clear();
        navigationBar = new MenuBar();
        navigationBar.clearItems();

        verticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        verticalPanel.add(navigationBar);

        HorizontalPanel mapAndSensorInfoPanel = new HorizontalPanel();
        mapAndSensorInfoPanel.setStyleName("mapAndSensorInfoPanel");

        HTML html = new HTML("<h2>" + END_LABEL + "</h2> ", true);

        verticalPanel.add(html);
        String help = "Click on a sensor marker to select it. "
                + "Then select start date and and duration of interest.";
        helpLabel = new Label();
        helpLabel.setText(help);
        verticalPanel.add(helpLabel);

        ScrollPanel scrollPanel = new ScrollPanel();
        scrollPanel.setHeight(SpectrumBrowser.MAP_WIDTH + "px");
        scrollPanel.setStyleName("sensorInformationScrollPanel");

        sensorInfoPanel = new VerticalPanel();
        sensorInfoPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        scrollPanel.add(sensorInfoPanel);
        sensorInfoPanel.setStyleName("sensorInfoPanel");

        mapAndSensorInfoPanel.add(scrollPanel);

        selectionGrid = new Grid(1, 10);
        selectionGrid.setStyleName("selectionGrid");
        selectionGrid.setVisible(false);

        for (int i = 0; i < selectionGrid.getRowCount(); i++) {
            for (int j = 0; j < selectionGrid.getColumnCount(); j++) {
                selectionGrid.getCellFormatter().setHorizontalAlignment(i, j,
                        HasHorizontalAlignment.ALIGN_CENTER);
                selectionGrid.getCellFormatter().setVerticalAlignment(i, j, HasVerticalAlignment.ALIGN_MIDDLE);
            }
        }

        verticalPanel.add(selectionGrid);

        sensorInfoPanel.clear();
        //sensorInfoPanel.setTitle("Click on marker to select sensors.");
        Label selectedMarkersLabel = new Label();
        selectedMarkersLabel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        selectedMarkersLabel.setText("Sensor Information Display");
        selectedMarkersLabel.getElement().getStyle().setCursor(Cursor.TEXT);
        selectedMarkersLabel.setStyleName("selectedMarkersLabel");
        sensorInfoPanel.add(selectedMarkersLabel);

        if (map == null) {
            MapOptions mapOptions = MapOptions.newInstance(true);
            mapOptions.setMaxZoom(15);
            mapOptions.setMinZoom(3);
            mapOptions.setStreetViewControl(false);
            map = new MapWidget(mapOptions);
            //map.setTitle("Click on a marker to display information about a sensor.");
            map.setSize(SpectrumBrowser.MAP_WIDTH + "px", SpectrumBrowser.MAP_HEIGHT + "px");
        } else if (map.getParent() != null) {
            map.removeFromParent();
        }
        mapAndSensorInfoPanel.add(map);
        verticalPanel.add(mapAndSensorInfoPanel);
        logger.finer("getLocationInfo");

        spectrumBrowser.getSpectrumBrowserService().getLocationInfo(SpectrumBrowser.getSessionToken(),
                new SpectrumBrowserCallback<String>() {
                    @Override
                    public void onFailure(Throwable caught) {
                        logger.log(Level.SEVERE, "Error in processing request", caught);
                        verticalPanel.clear();

                        if (spectrumBrowser.isUserLoggedIn()) {
                            Window.alert("The system is down for maintenance. Please try again later.\n"
                                    + caught.getMessage());
                            spectrumBrowser.logoff();
                        } else {
                            HTML error = new HTML(
                                    "<h1>The System is down for maintenance. Please try later.</h1>");
                            verticalPanel.add(error);
                            HTML errorMsg = new HTML("<h2>" + caught.getMessage() + "</h2>");
                            verticalPanel.add(errorMsg);
                        }
                    }

                    @Override
                    public void onSuccess(String jsonString) {

                        try {
                            logger.finer(jsonString);
                            JSONObject jsonObj = (JSONObject) JSONParser.parseLenient(jsonString);

                            String baseUrl = SpectrumBrowser.getBaseUrlAuthority();
                            addSensor(jsonObj, baseUrl);

                            logger.finer("Added returned sensors. Dealing with peers");
                            // Now deal with the peers.
                            final JSONObject peers = jsonObj.get("peers").isObject();
                            // By definition, peers do not need login but we need a session
                            // Key to talk to the peer so go get one.
                            for (String url : peers.keySet()) {
                                logger.finer("Showing sensors for Peer " + url);
                                final String peerUrl = url;
                                spectrumBrowser.getSpectrumBrowserService().isAuthenticationRequired(url,
                                        new SpectrumBrowserCallback<String>() {

                                            @Override
                                            public void onSuccess(String result) {
                                                JSONObject jobj = JSONParser.parseLenient(result).isObject();
                                                boolean authRequired = jobj.get("AuthenticationRequired")
                                                        .isBoolean().booleanValue();
                                                if (!authRequired) {
                                                    String sessionToken = jobj.get("SessionToken").isString()
                                                            .stringValue();
                                                    SpectrumBrowser.setSessionToken(peerUrl, sessionToken);
                                                    JSONObject peerObj = peers.get(peerUrl).isObject();
                                                    addSensor(peerObj, peerUrl);
                                                }
                                            }

                                            @Override
                                            public void onFailure(Throwable throwable) {
                                                logger.log(Level.SEVERE, "Could not contact peer at " + peerUrl,
                                                        throwable);
                                            }
                                        });
                            }
                            final Timer timer = new Timer() {
                                @Override
                                public void run() {
                                    if (getMap().isAttached()) {
                                        spectrumBrowser.hideWaitImage();
                                        showMarkers();
                                        cancel();
                                    }
                                }
                            };
                            timer.scheduleRepeating(500);
                            populateMenuItems();

                            map.addZoomChangeHandler(new ZoomChangeMapHandler() {

                                @Override
                                public void onEvent(ZoomChangeMapEvent event) {
                                    SensorGroupMarker.showMarkers();
                                }
                            });

                        } catch (Exception ex) {
                            logger.log(Level.SEVERE, "Error ", ex);
                            spectrumBrowser.displayError("Error parsing json response");

                        }

                    }
                }

        );

    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Error in displaying data sets", ex);
    }
}

From source file:gwt.material.design.components.client.utils.helper.TimerHelper.java

License:Apache License

public static Timer scheduleRepeating(final int schedule, final Runnable runnable) {
    final Timer timer = new Timer() {
        @Override/*from   w w  w. j a v  a  2  s  .c  o  m*/
        public void run() {
            runnable.run();
        }
    };
    timer.scheduleRepeating(schedule);
    return timer;
}

From source file:gwt.material.design.demo.client.ui.charts.MaterialAreaChart.java

License:Apache License

private void setLoop() {
    Timer timer = new Timer() {
        public void run() {
            if (isLoop) {
                drawChart(values);//from w w  w .  j a  v a 2  s .  com
                isLoop = false;
            } else {
                drawChart(valuesInitial);
                isLoop = true;
            }
        }
    };
    timer.scheduleRepeating(1000);
}

From source file:gwt.material.design.demo.client.ui.charts.MaterialBarChart.java

License:Apache License

private void setLoop() {

    Timer timer = new Timer() {

        public void run() {
            if (isLoop) {
                drawChart(values);/*from w w w . j a va2  s .  c o m*/
                isLoop = false;
            } else {
                drawChart(valuesInitial);
                isLoop = true;
            }

        }
    };
    timer.scheduleRepeating(1000);
}

From source file:jetbrains.jetpad.base.edt.JsEventDispatchThread.java

License:Apache License

@Override
public Registration scheduleRepeating(final int period, final Runnable r) {
    Timer timer = new Timer() {
        private long myLastInvocation = 0L;

        @Override/*from  ww w . j av a2s  .  c o  m*/
        public void run() {
            long current = getCurrentTimeMillis();
            if (current - myLastInvocation < period)
                return;
            myLastInvocation = current;
            doExecute(r);
        }
    };
    timer.scheduleRepeating(period);
    return timerReg(timer);
}

From source file:jetbrains.jetpad.cell.toDom.DomPopupManager.java

License:Apache License

@Override
protected Registration setPopupUpdate() {
    final Timer timer = new Timer() {
        @Override/*from   w  ww  .  ja  va2 s  . c o  m*/
        public void run() {
            updatePopupPositions();
        }
    };
    timer.scheduleRepeating(POPUPS_REFRESH_MILLIS);
    return new Registration() {
        @Override
        protected void doRemove() {
            timer.cancel();
        }
    };
}

From source file:jetbrains.jetpad.cell.toDom.TextCellMapper.java

License:Apache License

@Override
public void refreshProperties() {
    super.refreshProperties();

    Boolean focused = getSource().get(Cell.FOCUSED);
    if (focused) {
        if (myFocusRegistration == null) {
            final Timer timer = new Timer() {
                @Override/*  www.  j  av a2 s.c o  m*/
                public void run() {
                    if (System.currentTimeMillis() - myLastChangeTime < CARET_BLINK_DELAY)
                        return;
                    myCaretVisible = !myCaretVisible;
                    updateCaretVisibility();
                }
            };
            timer.scheduleRepeating(500);
            myContainerFocused = getContext().focused.get();
            myFocusRegistration = new CompositeRegistration(
                    getContext().focused.addHandler(new EventHandler<PropertyChangeEvent<Boolean>>() {
                        @Override
                        public void onEvent(PropertyChangeEvent<Boolean> event) {
                            myContainerFocused = event.getNewValue();
                            updateCaretVisibility();
                        }
                    }), getSource().caretVisible().addHandler(new EventHandler<PropertyChangeEvent<Boolean>>() {
                        @Override
                        public void onEvent(PropertyChangeEvent<Boolean> event) {
                            if (event.getNewValue()) {
                                myLastChangeTime = System.currentTimeMillis();
                                myCaretVisible = true;
                            }
                        }
                    }), new Registration() {
                        @Override
                        protected void doRemove() {
                            timer.cancel();
                        }
                    });
        }
    } else {
        if (myFocusRegistration != null) {
            myFocusRegistration.remove();
            myFocusRegistration = null;
        }
    }

    myLastChangeTime = System.currentTimeMillis();

    myTextEditor.setText(getSource().text().get());
    myTextEditor.setCaretPosition(getSource().caretPosition().get());
    myTextEditor.setCaretVisible(getSource().caretVisible().get() && focused);
    myTextEditor.setTextColor(getSource().textColor().get());
    myTextEditor.setBold(getSource().bold().get());
    myTextEditor.setFontFamily(getSource().fontFamily().get());
    myTextEditor.setFontSize(getSource().fontSize().get());

    myTextEditor.setSelectionVisible(getSource().selectionVisible().get() && focused);
    myTextEditor.setSelectionStart(getSource().selectionStart().get());
}