use of com.haulmont.cuba.gui.components.Timer in project cuba by cuba-platform.
the class WindowLoader method addInitTimerMethodTask.
protected void addInitTimerMethodTask(Timer timer, String timerMethodName) {
context.addPostInitTask((windowContext, window) -> {
Method timerMethod;
try {
timerMethod = window.getClass().getMethod(timerMethodName, Timer.class);
} catch (NoSuchMethodException e) {
throw new GuiDevelopmentException("Unable to find invoke method for timer", windowContext.getFullFrameId(), ParamsMap.of("Timer Id", timer.getId(), "Method name", timerMethodName));
}
timer.addActionListener(t -> {
try {
timerMethod.invoke(window, t);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException("Unable to invoke onTimer", e);
}
});
});
}
use of com.haulmont.cuba.gui.components.Timer in project cuba by cuba-platform.
the class WebWindow method stopTimers.
/**
* Completely stop and remove timers of the window.
*/
public void stopTimers() {
AppUI appUI = AppUI.getCurrent();
if (timers != null) {
for (Timer timer : timers) {
timer.stop();
WebTimer webTimer = (WebTimer) timer;
appUI.removeTimer(webTimer.getTimerImpl());
}
timers.clear();
}
}
use of com.haulmont.cuba.gui.components.Timer in project cuba by cuba-platform.
the class WindowLoader method loadTimer.
protected void loadTimer(ComponentsFactory factory, final Window component, Element element) {
Timer timer = factory.createTimer();
timer.setXmlDescriptor(element);
timer.setId(element.attributeValue("id"));
String delay = element.attributeValue("delay");
if (StringUtils.isEmpty(delay)) {
throw new GuiDevelopmentException("Timer 'delay' can't be empty", context.getCurrentFrameId(), "Timer ID", timer.getId());
}
int value;
try {
value = Integer.parseInt(delay);
} catch (NumberFormatException e) {
throw new GuiDevelopmentException("Timer 'delay' must be numeric", context.getFullFrameId(), ParamsMap.of("Timer delay", delay, "Timer ID", timer.getId()));
}
if (value <= 0) {
throw new GuiDevelopmentException("Timer 'delay' must be greater than 0", context.getFullFrameId(), "Timer ID", timer.getId());
}
timer.setDelay(value);
timer.setRepeating(Boolean.parseBoolean(element.attributeValue("repeating")));
String onTimer = element.attributeValue("onTimer");
if (StringUtils.isNotEmpty(onTimer)) {
String timerMethodName = onTimer;
if (StringUtils.startsWith(onTimer, "invoke:")) {
timerMethodName = StringUtils.substring(onTimer, "invoke:".length());
}
timerMethodName = StringUtils.trim(timerMethodName);
addInitTimerMethodTask(timer, timerMethodName);
}
String autostart = element.attributeValue("autostart");
if (StringUtils.isNotEmpty(autostart) && Boolean.parseBoolean(autostart)) {
addAutoStartTimerTask(timer);
}
timer.setFrame(context.getFrame());
component.addTimer(timer);
}
use of com.haulmont.cuba.gui.components.Timer in project cuba by cuba-platform.
the class TimerFacetProvider method addInitTimerMethodTask.
// for compatibility only
@Deprecated
protected void addInitTimerMethodTask(Timer timer, String timerMethodName, ComponentContext context) {
FrameOwner controller = context.getFrame().getFrameOwner();
if (controller instanceof LegacyFragmentAdapter) {
controller = ((LegacyFragmentAdapter) controller).getRealScreen();
}
Class<? extends FrameOwner> windowClass = controller.getClass();
Method timerMethod;
try {
timerMethod = windowClass.getMethod(timerMethodName, Timer.class);
} catch (NoSuchMethodException e) {
throw new GuiDevelopmentException("Unable to find invoke method for timer", context, ParamsMap.of("Timer Id", timer.getId(), "Method name", timerMethodName));
}
timer.addTimerActionListener(new DeclarativeTimerActionHandler(timerMethod, controller));
}
Aggregations