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:org.bioversityinternational.cisf.client.tools.Elements.java

License:Apache License

/**
 * Causes an element to "fade out" via opacity.
 * When onFadeComplete is called, the element will be entirely transparent.
 * @param target the UIObject to be faded out
 * @param milliseconds how long the fade effect should take to process
 * @param callback the callback to be invoked on fade progress
 */// w  w  w.  j av a  2s  .c o m
public static void fadeOut(final UIObject target, final int milliseconds, final FadeCallback callback) {
    final Element e = target.getElement();
    final int interval = milliseconds / 50;
    DeferredCommand.addCommand(new Command() {

        public void execute() {
            callback.onFadeStart();

            final Timer t = new Timer() {
                int pct = 100;

                @Override
                public void run() {
                    pct -= 2;
                    setOpacity(e, pct);
                    if (pct == 0) {
                        this.cancel();
                        callback.onFadeComplete();
                    }
                }
            };
            t.scheduleRepeating(interval);

        }
    });
}

From source file:org.catchwa.skeetstalker.client.SkeetStalker.java

License:Open Source License

/**
 * This is the entry point method./*from ww  w  .  ja v a2s .c om*/
 */
public void onModuleLoad() {
    final Grid table = new Grid(1, 1);
    final HTML lastOnlineLabel = new HTML();
    table.setHTML(0, 0, "<b>Questions they'll probably answer (unless you get there first!)</b>");

    RootPanel.get("lastOnlineContainer").add(lastOnlineLabel);
    RootPanel.get("questionsContainer").add(table);

    Grid g = new Grid(2, 3);
    g.setWidget(0, 0, new Label("User ID"));
    idTextBox.setText("" + org.catchwa.skeetstalker.shared.Constants.DEFAULT_ID);
    g.setWidget(0, 1, idTextBox);

    siteChoices.setVisibleItemCount(1);
    sites = new HashMap<String, String>();
    sites.put("Stack Overflow", "http://api.stackoverflow.com");
    siteChoices.addItem("Stack Overflow");
    populateSitesDropdown();
    g.setWidget(0, 2, siteChoices);

    Button stalkButton = new Button();
    stalkButton.setText("Stalk!");
    stalkButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            site = sites.get(siteChoices.getItemText(siteChoices.getSelectedIndex()));
            id = Integer.parseInt(idTextBox.getText());
            resetTable();
            refreshLastOnline();
            refreshAnswerThese();
            dp.setOpen(false);
        }
    });
    g.setWidget(1, 0, stalkButton);

    Button userIdButton = new Button();
    userIdButton.setText("Find User ID...");
    userIdButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            createDialogBox();
            db.show();
        }
    });
    g.setWidget(1, 1, userIdButton);

    dp.add(g);
    RootPanel.get().add(dp);

    refreshLastOnline();
    refreshAnswerThese();

    Timer t1 = new Timer() {
        @Override
        public void run() {
            refreshAnswerThese();
        }
    };

    Timer t2 = new Timer() {
        @Override
        public void run() {
            refreshLastOnline();
        }
    };

    t1.scheduleRepeating(org.catchwa.skeetstalker.shared.Constants.CLIENT_QUESTIONS_TABLE_REFRESH_INTERVAL);
    t2.scheduleRepeating(org.catchwa.skeetstalker.shared.Constants.CLIENT_LAST_ONLINE_REFRESH_INTERVAL);
}

From source file:org.catrobat.html5player.client.Stage.java

License:Open Source License

/**
 * Parses the project-XML, adds all StartScripts to the scheduler, loads
 * all images which where added to the ImageHandler and waits for them to
 * load. After the images got loaded, the scheduler gets started.
 * //from   w w  w  . j a va  2s.c om
 * @param projectXml
 */
public void start(String projectXml) {

    Parser parser = new Parser();

    long start = System.currentTimeMillis();

    parser.parseXML(spriteManager, projectXml);
    if (!parser.isParsingComplete()) {
        return;
    }

    CatrobatDebug.debug("XML got parsed");
    CatrobatDebug.debug("Parsing took " + (System.currentTimeMillis() - start) + " ms");

    ImageHandler.get().loadImages();

    CatrobatDebug.debug("Actual number of attached images: " + ImageHandler.get().getNumberOfAttachedImages());

    //add StartScripts to scheduler
    spriteManager.playCatroid();

    //      spriteManager.debugSpriteCostumes();

    CatrobatDebug.debug("Actual scripts waiting to run: " + CatScheduler.get().getThreadCount());

    //wait for the images to load, then start the scheduler
    Timer imagesLoadedTimer = new Timer() {

        @Override
        public void run() {

            if (ImageHandler.get().areImagesLoaded() || ImageHandler.get().hasNothingToDo()) {

                CatrobatDebug.debug(ImageHandler.get().getNumberImagesLoaded()
                        + " images are loaded, now starting scheduler...");

                ImageHandler.get().reset();

                //revive scheduler, so it can run again
                CatScheduler.get().reviveScheduler();

                //start CatScheduler
                Scheduler.get().scheduleFixedDelay(CatScheduler.get(), CatScheduler.SCHEDULE_DELAY);
                this.cancel();
            } else {
                CatrobatDebug.debug("ImageHandler not finished loading...");
                CatrobatDebug.debug(ImageHandler.get().getStatus());
                if (ImageHandler.get().hasLoadingFailed()) {
                    CatrobatDebug.error("ImageHandler couldn't load an image");
                    log("ImageHandler couldn't load an image");
                    this.cancel();

                    loadingFailure();
                }
            }
        }
    };

    imagesLoadedTimer.scheduleRepeating(50);
}

From source file:org.catrobat.html5player.client.Stage.java

License:Open Source License

/**
 * /*  ww w  .ja  v  a2  s.com*/
 */
public void displayLoadingImage() {

    CatrobatDebug.debug("displayLoadingImage...");

    //ImageHandler.get().addImage("loadgif", "images/ajax-loader.gif");
    Image i = new Image("images/ajax-loader.gif");
    ImageHandler.get().newImage("loadgif", i);
    ImageHandler.get().loadImages();

    //wait for the image to load, then draw it
    Timer imageLoadedTimer = new Timer() {

        @Override
        public void run() {

            if (ImageHandler.get().areImagesLoaded()) {

                CatrobatDebug.debug("Loading gif ready to display");

                Image image = ImageHandler.get().getImage("loadgif");

                ImageHandler.get().reset();

                Scene.get().clearCanvas();

                Scene.get().drawImage(image, getStageMiddleX(), getStageMiddleY(), image.getWidth(),
                        image.getHeight(), 1);
                //               Scene.get().update();
                this.cancel();
            }
        }
    };

    imageLoadedTimer.scheduleRepeating(10);
}

From source file:org.cruxframework.crux.widgets.client.rss.feed.Loader.java

License:Apache License

static void startTimer() {
    Timer t = new Timer() {
        public void run() {
            if (apiReady()) {
                cancel();/*w w  w. j a va2 s . c om*/
                closeDocument(getDocument(SANDBOX));
                callback.onLoad();
            }
        }
    };
    t.scheduleRepeating(10);
}

From source file:org.dataconservancy.dcs.access.client.ui.WfEventRefresherPanel.java

License:Apache License

public WfEventRefresherPanel(final String submitterId, final String wfInstanceId) {
    super(false);
    grid = new Grid(4, 2);
    grid.getRowFormatter().setStyleName(0, "statusPopupPanelText");
    grid.setStyleName("statusPopupPanel");
    setWidget(grid);/*from  w  ww.java 2s .c  om*/
    setStyleName("statusPopupPanelContainer");
    grid.setText(0, 1, "Starting");

    image = new Image("images/wait.gif");
    grid.setWidget(0, 0, image);

    final Timer timer = new Timer() {
        @Override
        public void run() {
            if (doneFlag == 1) {
                grid.setText(0, 1, "Ingest Workflow for " + dTitle + " completed");
                image = new Image("images/done.png");
                grid.setWidget(0, 0, image);
                cancel();
                doneFlag = 0;
            }
            dbService.getProv(submitterId, wfInstanceId, latestDate,
                    new AsyncCallback<List<ProvenaceDataset>>() {
                        public void onSuccess(List<ProvenaceDataset> result) {
                            String events = "<ul>";
                            for (final ProvenaceDataset dataset : result) {
                                for (Map.Entry<String, List<ProvenanceRecord>> entry : dataset.provRecordbyWf
                                        .entrySet()) {
                                    for (final ProvenanceRecord provRecord : entry.getValue()) {
                                        int i = 0;
                                        for (Event event : provRecord.getEvents()) {

                                            if (event.getEventType().contains("match"))
                                                events += "<li>"
                                                        + Constants.eventMessages.get(event.getEventType())
                                                        + ": Completed(" + event.getEventDetail() + ")"
                                                        + "</li>";
                                            else
                                                events += "<li>"
                                                        + Constants.eventMessages.get(event.getEventType())
                                                        + ": Completed</li>";
                                            if (i == provRecord.getEvents().size() - 1) {
                                                events += "</ul>";
                                                final String temp = events;
                                                dbService.getDate(event.getEventDate(),
                                                        new AsyncCallback<String>() {

                                                            @Override
                                                            public void onFailure(Throwable caught) {
                                                                // TODO Auto-generated method stub

                                                            }

                                                            @Override
                                                            public void onSuccess(String result) {
                                                                latestDate = result;
                                                                if (provRecord
                                                                        .getStatus() == org.dataconservancy.dcs.access.shared.Status.Completed) {
                                                                    doneFlag = 1;
                                                                    dTitle = dataset.datasetTitle;
                                                                }

                                                                grid.setWidget(0, 1, new HTML(temp));
                                                                image = new Image("images/wait.gif");
                                                                grid.setWidget(0, 0, image);

                                                            }

                                                        });
                                            }

                                            i++;
                                        }
                                    }
                                }

                                //are the dates sorted? looks like it at a glance - please confirm
                            }
                        }

                        @Override
                        public void onFailure(Throwable caught) {
                            // TODO Auto-generated method stub

                        }
                    });
        }

    };
    timer.scheduleRepeating(4 * 1000);//every 20 seconds

    close = new Button("Close");
    close.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            hidePanel();
            timer.cancel();
        }
    });

    //close button
    grid.setWidget(3, 1, close);
    Panel progressPanel = new FlowPanel();
    progressPanel.setStyleName("progressBarContainer");
    insideProgressPanel.setWidth("0%");
    insideProgressPanel.setStyleName("Gradient");
    progressPanel.add(insideProgressPanel);

}

From source file:org.drools.brms.client.LoggedInUserInfo.java

License:Apache License

public void setUserName(String userName) {
    StringBuffer content = new StringBuffer();

    content.append("<div id='user_info'>");
    content.append("Welcome: &nbsp;" + userName);
    content.append("&nbsp;&nbsp;&nbsp;<a href='logout.jsp'>[Sign Out]</a>");
    content.append("</div>");
    widgetcontent.setHTML(content.toString());

    //we have the timer to keep the session alive.
    Timer timer = new Timer() {

        public void run() {
            RepositoryServiceFactory.getSecurityService().getCurrentUser(new AsyncCallback() {

                public void onFailure(Throwable t) {
                }/*from w ww .j a va 2s . c o  m*/

                public void onSuccess(Object o) {
                    if (o == null) {
                        GenericCallback.showSessionExpiry();
                    }
                }

            });
        }

    };

    timer.scheduleRepeating(300000);

}

From source file:org.drools.guvnor.client.LoggedInUserInfo.java

License:Apache License

public void setUserName(String userName) {
    StringBuffer content = new StringBuffer();
    content.append("<div class='headerUserInfo'>");
    content.append("<small>Welcome: &nbsp;" + userName);
    content.append("&nbsp;&nbsp;&nbsp;<a href='logout.jsp'>[Sign Out]</a></small>");
    content.append("</div>");
    widgetcontent.setHTML(content.toString());

    //we have the timer to keep the session alive.
    Timer timer = new Timer() {

        public void run() {
            RepositoryServiceFactory.getSecurityService().getCurrentUser(new AsyncCallback() {

                public void onFailure(Throwable t) {
                }/*  w w  w. j ava2s.  c  o m*/

                public void onSuccess(Object o) {
                    UserSecurityContext ctx = (UserSecurityContext) o;
                    if (ctx.userName == null) {
                        GenericCallback.showSessionExpiry();
                    }
                }

            });
        }

    };

    timer.scheduleRepeating(300000);

}

From source file:org.drools.guvnor.client.rpc.PushClient.java

License:Apache License

private void connect() {
    connected = true;//from w  w w  . jav a2 s  . c  om

    System.err.println("Connecting" + System.currentTimeMillis());
    Timer timer = new Timer() {

        public void run() {
            RepositoryServiceAsync repositoryService = GWT.create(RepositoryService.class);
            repositoryService.subscribe(new AsyncCallback<List<PushResponse>>() {
                public void onFailure(Throwable caught) {
                    System.err.println("FAIL" + System.currentTimeMillis());
                }

                public void onSuccess(List<PushResponse> result) {
                    //System.err.println("Got response !" + System.currentTimeMillis());
                    processResult(result);
                }
            });
        }

    };

    timer.scheduleRepeating(60000);
    /*        
            RepositoryServiceAsync repositoryService = GWT.create(RepositoryService.class);
            repositoryService.subscribe(new AsyncCallback<List<PushResponse>>() {
    public void onFailure(Throwable caught) {
        System.err.println("FAIL" + System.currentTimeMillis());
                
        connect();
    }
            
    public void onSuccess(List<PushResponse> result) {
        System.err.println("Got response !" + System.currentTimeMillis());
        processResult(result);
        connect();
    }
            });*/

}

From source file:org.eclipse.kapua.app.console.client.device.DeviceConfigComponents.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.getUnescapedClientId(), new AsyncCallback<GwtDevice>() {

                            @Override
                            public void onFailure(Throwable t) {
                                done();// w  w w  .  jav  a  2  s .  c  om
                            }

                            @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();
                                refresh();
                                if (m_devConfPanel != null) {
                                    m_devConfPanel.unmask();
                                }
                            }
                        });
            }
        }
    };
    m_devConfPanel.mask(MSGS.waiting());
    timer.scheduleRepeating(PERIOD_MILLIS);
}