Search in sources :

Example 1 with JSCallWithReturnValue

use of au.com.vaadinutils.js.JSCallWithReturnValue in project VaadinUtils by rlsutton1.

the class DashBoardView method enter.

@Override
public void enter(ViewChangeEvent event) {
    setMargin(new MarginInfo(false, false, false, false));
    setSizeFull();
    final Label preparing = new Label("Preparing your dashboard...");
    preparing.setStyleName(ValoTheme.LABEL_H1);
    addComponent(preparing);
    // defer the load of the dashboard to a separate request, otherwise on a
    // refresh(F5) it will be blank. I think this is due to the DashBoard
    // widget needing to be initialized (client side) first
    new JSCallWithReturnValue("true").callBoolean(new JavaScriptCallback<Boolean>() {

        @Override
        public void callback(Boolean value) {
            final UI ui = UI.getCurrent();
            new Thread(getLoadRunner(preparing, ui), "Dash Board Delayed Loader").start();
        }

        private Runnable getLoadRunner(final Label preparing, final UI ui) {
            return new Runnable() {

                @Override
                public void run() {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e1) {
                        logger.error(e1);
                    }
                    ui.access(new Runnable() {

                        @Override
                        public void run() {
                            try (AutoCloseable closer = EntityManagerProvider.setThreadLocalEntityManagerTryWithResources()) {
                                removeComponent(preparing);
                                postLoad();
                            } catch (Exception e) {
                                logger.error(e, e);
                            }
                        }
                    });
                }
            };
        }
    });
}
Also used : UI(com.vaadin.ui.UI) MarginInfo(com.vaadin.shared.ui.MarginInfo) Label(com.vaadin.ui.Label) JSCallWithReturnValue(au.com.vaadinutils.js.JSCallWithReturnValue)

Aggregations

JSCallWithReturnValue (au.com.vaadinutils.js.JSCallWithReturnValue)1 MarginInfo (com.vaadin.shared.ui.MarginInfo)1 Label (com.vaadin.ui.Label)1 UI (com.vaadin.ui.UI)1