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

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

Introduction

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

Prototype

public synchronized void schedule(int delayMs) 

Source Link

Document

Schedules a timer to elapse in the future.

Usage

From source file:ch.eaternity.client.Search.java

License:Apache License

private void selectRowMealsYours(final int row) {

    if (FoundRezepteYours.size() < row) {
        return;/*from  w w  w .  j  a va2 s  .  co m*/
    }
    Recipe item = FoundRezepteYours.get(row);
    if (item == null) {
        return;
    }

    styleRowMealsYours(selectedRow, false);
    styleRowMealsYours(row, true);

    Timer t = new Timer() {
        public void run() {
            styleRowMealsYours(row, false);
        }
    };

    superDisplay.cloneRecipe(item);
    t.schedule(200);

    selectedRow = row;
    if (listenerMeals != null) {
        listenerMeals.onItemSelected(item);
    }

}

From source file:ch.eaternity.client.Search.java

License:Apache License

private void selectRow(final int row) {

    // get the grams from the input
    // if 2 valid numbers exist, take the first valid one
    int grams = 0;

    searchString = SearchInput.getText().trim();
    String[] searches = searchString.split(" ");

    for (String search : searches) {
        try {//from  w  w w.j av a 2s.  c  o  m
            int x = Integer.parseInt(search);
            grams = x;
            break;
        } catch (NumberFormatException nFE) {
        }
    }

    if (FoundIngredient.size() + FoundAlternativeIngredients.size() < row) {
        return;
    }

    Ingredient item;
    if (row >= 0 && row < FoundIngredient.size()) {
        item = FoundIngredient.get(row);
    } else if (row >= FoundIngredient.size()
            && row < FoundIngredient.size() + FoundAlternativeIngredients.size()) {
        item = FoundAlternativeIngredients.get(row - FoundIngredient.size());
    } else
        return;

    if (item == null) {
        return;
    }

    styleRow(selectedRow, false);
    styleRow(row, true);

    //TODO uncomment this: idea is to animate some effects
    //infoZutat.setZutat(item);

    //      leftSplitPanel.setHeight("500px");
    //      leftSplitPanel.addSouth( new InfoZutat(), 500);

    //      leftSplitPanel.setWidgetTopHeight(infoZutat, 0, PX, 0, PX);
    //      leftSplitPanel.forceLayout();
    //      leftSplitPanel.setWidgetTopHeight(infoZutat, 0, PX, 2, EM);
    //      leftSplitPanel.animate(500);

    //TODO uncomment this: idea is to provide a tooltip with more informations

    //infoZutat.stylePanel(true);

    // infotext ber angeklickte zutat
    // Gro:Name, Foto, Liste:Labels: Text:Beschreibung Wikipedia klein:Alternativen
    //

    Timer t = new Timer() {
        public void run() {
            styleRow(row, false);
        }
    };

    final RecipeView rezeptView;
    int selectedRecipe = superDisplay.getSelectedRecipeNumber();
    if (selectedRecipe != -1) {
        rezeptView = superDisplay.getSelectedRecipeView();
    } else {
        rezeptView = superDisplay.createNewRecipeView();
    }
    superDisplay.addOneIngredientToMenu(item, rezeptView, grams);
    rezeptView.showRezept(rezeptView.recipe);
    superDisplay.displayRecipeEditView(rezeptView);

    superDisplay.adjustStickyEditLayout();

    t.schedule(200);
    selectedRow = row;
    markedRow = 0;

    if (listener != null) {
        listener.onItemSelected(item);
    }
}

From source file:ch.heftix.mailxel.client.StatusItem.java

License:Open Source License

public void done(final String message, final int autoHideAfterMs) {
    working.setUrl("img/tick.png");
    // working.setVisible(false);
    lDone.setText(message);// w w w  .  j  a v  a2 s  .  c  om
    isDone = true;
    if (autoHideAfterMs > 0) {
        Timer timer = new Timer() {

            public void run() {
                statusInfoBar.removeDones();
            }
        };
        timer.schedule(autoHideAfterMs);
    }
}

From source file:ch.unifr.pai.twice.comm.serverPush.client.RemoteEventing.java

License:Apache License

/**
 * Fires the event to the local event bus after a specific delay
 * //from w  w w .j  av a2  s  .  com
 * @param event
 * @param source
 * @param localEvent
 */
private void fireEventToTheLocalBusWithDelay(final Event<?> event, final Object source, boolean localEvent) {
    if (event instanceof RemoteEvent) {
        if (((RemoteEvent<?>) event).isFireLocally()) {
            int delay = localEvent ? Math.max(localEventDeliveryDelay, eventDeliveryDelay) : eventDeliveryDelay;
            if (delay == 0) {
                if (source == null)
                    fireEventLocally(event);
                else
                    fireEventFromSourceLocally(event, source);
            } else {
                Timer t = new Timer() {

                    @Override
                    public void run() {
                        if (source == null)
                            fireEventLocally(event);
                        else
                            fireEventFromSourceLocally(event, source);
                    }
                };
                t.schedule(delay);
            }
        }

    }

}

From source file:ch.unifr.pai.twice.dragndrop.client.MPDragNDrop.java

License:Apache License

/**
 * @see ch.unifr.pai.twice.dragndrop.client.DragNDrop.DragNDropIntf#makeDraggable(ch.unifr.pai.twice.dragndrop.client.intf.Draggable,
 *      ch.unifr.pai.twice.dragndrop.client.configuration.DragConfiguration, com.google.gwt.dom.client.Element)
 * /*  w w w .j a v  a2 s. c  o  m*/
 *      Make the widget draggable by attaching a drag handler to it. If the drag handler is invoked, the logic checks if the widget is currently draggable
 *      (e.g. not locked by another user) and starts the drag by the invocation of
 *      {@link MPDragNDrop#startDrag(Widget, String, int, int, DragConfiguration, Element)} after making sure, that the delay defined by
 *      {@link MPDragNDrop#getDragDelayInMs()} is exceeded and it therefore is a valid drag
 * 
 */
@Override
public void makeDraggable(final Draggable w, final DragConfiguration conf, final Element dragProxyTemplate) {
    if (w instanceof Widget) {
        ((Widget) w).addStyleName("draggable");
        addDragHandler(w, new Callback<NativeEvent>() {
            @Override
            public void onDone(NativeEvent event) {
                if (w.isDraggable()) {
                    final String deviceId = getDeviceId(event);
                    final ValueHolder<Boolean> drag = new ValueHolder<Boolean>();
                    drag.setValue(true);
                    final HandlerRegistration end = registerEndHandler(w, new Callback<NativeEvent>() {

                        @Override
                        public void onDone(NativeEvent event) {

                            if (getDeviceId(event).equals(deviceId))
                                drag.setValue(false);
                        }
                    });
                    final int offsetX = getX(event) - ((Widget) w).getElement().getAbsoluteLeft();
                    final int offsetY = getY(event) - ((Widget) w).getElement().getAbsoluteTop();
                    DOM.eventPreventDefault((Event) event);
                    Timer t = new Timer() {

                        @Override
                        public void run() {
                            end.removeHandler();
                            if (drag.getValue() && !((Widget) w).getStyleName().contains(DRAGGINGSTYLENAME))
                                startDrag((Widget) w, deviceId, offsetX, offsetY, conf, dragProxyTemplate);
                        }
                    };
                    t.schedule(getDragDelayInMs());
                }
            }
        });
    }
}

From source file:ch.unifr.pai.twice.mousecontrol.client.TouchPadNintendoDS.java

License:Apache License

@Override
public void start() {
    super.start();
    if (windowScrollHandler != null)
        windowScrollHandler.removeHandler();
    windowScrollHandler = Window.addWindowScrollHandler(new Window.ScrollHandler() {

        @Override/*from  www .  java 2s  . c o  m*/
        public void onWindowScroll(ScrollEvent event) {
            if (skipEvents > 0)
                skipEvents--;
            l.getElement().getStyle().setLeft(RootPanel.getBodyElement().getScrollLeft(), Unit.PX);
            l.getElement().getStyle().setTop(RootPanel.getBodyElement().getScrollTop(), Unit.PX);
        }
    });
    Timer t2 = new Timer() {

        @Override
        public void run() {
            skipEvents = eventsAfterReset;
            Window.scrollTo(1000, 1000);
            updater.scheduleRepeating(50);
        }
    };
    t2.schedule(1000);
}

From source file:ch.unifr.pai.twice.utils.experiment.workflow.client.ExperimentWorkflow.java

License:Apache License

/**
 * stops the current task, disables the "next" button (to prevent users skipping the current tasks) for a short moment and show the next task if available.
 * Also start the timer if the task has a specified timeout that interrupts the execution
 *///from ww  w . ja  v  a  2  s  .c o  m
private void switchToNextTask() {
    int nextTaskIndex;
    if (taskTimer != null) {
        taskTimer.cancel();
        taskTimer = null;
    }
    if (currentTaskIndex >= experiments.size() - 1) {
        if (loopExecution) {
            nextTaskIndex = 0;
        } else {
            stop();
            return;
        }
    } else {
        nextTaskIndex = currentTaskIndex + 1;
    }
    Task<?> newTask = experiments.get(nextTaskIndex);
    if (currentTask instanceof HasStartAndStop)
        ((HasStartAndStop) currentTask).stop();
    // if (currentTask instanceof HasLog)
    // service.log(((HasLog) currentTask).getLog(), false,
    // new DummyAsyncCallback<Void>());
    if (newTask != null) {
        currentTask = newTask;
        if (newTask instanceof Widget) {
            // taskContainerPanel.setWidget(((Widget) newTask));
        }
    }
    if (newTask.hasNextButton()) {
        nextButton.setVisible(true);
        nextButton.setEnabled(false);
        Timer t = new Timer() {
            @Override
            public void run() {
                nextButton.setEnabled(true);
            }
        };
        t.schedule(ENABLENEXTBUTTONINMS);
    } else {
        nextButton.setVisible(false);
    }
    //
    // if (newTask instanceof EnforceInputDevice)
    // changeInputDevice(((EnforceInputDevice) newTask).useInputDevice());
    if (newTask instanceof HasStartAndStop) {
        ((HasStartAndStop) newTask).start();
    }
    currentTaskIndex++;
    if (newTask.getTimeout() != null) {
        taskTimer = new Timer() {
            @Override
            public void run() {
                switchToNextTask();
            }
        };
        taskTimer.schedule(newTask.getTimeout().intValue());

    }
}

From source file:cimav.visorglass.client.widgets.PanelesLayout.java

License:Apache License

private void loadGoogleDoc() {

    reloadIcon.setSpin(true); //arranca el spin
    if (urlGoogleDoc == null || urlGoogleDoc.trim().isEmpty()) {
        Timer t = new Timer() {
            @Override/*from w  w  w .j  a  v  a2 s.c  o  m*/
            public void run() {
                // si no hay URL/Doc, gira 2 seg.
                reloadIcon.setSpin(false);
            }
        };
        t.schedule(2000);
    } else {
        frameDocViewer.setUrl(urlGoogleDoc);
    }
}

From source file:client.net.sf.saxon.ce.expr.instruct.ScheduleExecution.java

License:Mozilla Public License

public TailCall processLeavingTail(final XPathContext context) throws XPathException {
    IntegerValue time = (IntegerValue) wait.evaluateItem(context);
    final CallTemplate.CallTemplatePackage pack = (CallTemplate.CallTemplatePackage) call
            .processLeavingTail(context);
    Timer t = new Timer() {
        public void run() {
            //Window.setTitle("Timer fired " + serial++);
            boolean success = false;
            logger.fine("processing ixsl:schedule-action");
            if (LogConfiguration.loggingIsEnabled() && LogController.traceIsEnabled()) {
                LogController.openTraceListener();
            }/*from w  w w.  ja  va  2s. co  m*/
            try {
                TailCall tc = pack.processLeavingTail();
                while (tc != null) {
                    tc = tc.processLeavingTail();
                }
                context.getController().getPendingUpdateList().apply(context);
                success = true;
            } catch (Exception err) {
                logger.log(Level.SEVERE, "In delayed event: " + err.getMessage());
                if (SaxonceApi.doThrowJsExceptions()) {
                    throw new RuntimeException(err.getMessage());
                }
            }
            if (LogConfiguration.loggingIsEnabled() && LogController.traceIsEnabled()) {
                LogController.closeTraceListener(success);
            }
        }
    };
    //Window.setTitle("Timer started " + serial + " (time " + time + "ms)");
    t.schedule(time.getIntValue());
    return null;
}

From source file:com.ait.toolkit.cordova.client.splashscreen.SplashScreen.java

License:Open Source License

/**
 * Shows the splash screen for the given number of seconds.
 * /*from   ww w. j  a v a  2 s .c  om*/
 * @param seconds
 */
public void show(int seconds) {
    Timer t = new Timer() {
        @Override
        public void run() {
            hide();
        }
    };

    t.schedule(seconds * 1000);
}