com.vaadin.flow.component.UI.getCurrent()

Here are the examples of the java api com.vaadin.flow.component.UI.getCurrent() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

16 Examples 7

19 Source : LoadingIndicatorView.java
with MIT License
from mcollovati

private LoadingIndicatorConfiguration getLoadingIndicatorConfiguration() {
    return UI.getCurrent().getLoadingIndicatorConfiguration();
}

19 Source : ExecJavaScriptView.java
with MIT License
from mcollovati

private NativeButton createJsButton(String text, String id, String script, Serializable... arguments) {
    return createButton(text, id, e -> UI.getCurrent().getPage().executeJs(script, arguments));
}

19 Source : AbstractDivView.java
with MIT License
from mcollovati

protected Page getPage() {
    // getUI not available in onLocationChange so leaving getCurrent here
    // for now
    return UI.getCurrent().getPage();
}

19 Source : UIAttributes.java
with Apache License 2.0
from appreciated

private static UIAttributes getSession() {
    if (UI.getCurrent().getSession().getAttribute(UIAttributes.clreplaced) == null) {
        UI.getCurrent().getSession().setAttribute(UIAttributes.clreplaced, new UIAttributes());
    }
    return UI.getCurrent().getSession().getAttribute(UIAttributes.clreplaced);
}

19 Source : AppLayoutNotification.java
with Apache License 2.0
from appreciated

public static <T extends Notification> void show(T notification) {
    getNotificationHolder().ifPresent(holder -> UI.getCurrent().access(() -> holder.add(notification)));
}

19 Source : MainLayout.java
with Apache License 2.0
from alejandro-du

private void tabsSelectionChanged(Tabs.SelectedChangeEvent event) {
    if (event.isFromClient()) {
        UI.getCurrent().navigate((Clreplaced<? extends Component>) tabToView.get(event.getSelectedTab()));
    }
}

18 Source : DateTimeResolver.java
with Apache License 2.0
from kochetkov-ma

public void retrieve() {
    UI.getCurrent().getPage().retrieveExtendedClientDetails(extendedClientDetails -> {
        if (extendedClientDetails == null) {
            log.warn("Cannot retrieve client details");
            return;
        }
        String timeZoneId = extendedClientDetails.getTimeZoneId();
        log.info("Client timezone = {}", timeZoneId);
        synchronized (lock) {
            try {
                var zoneId = ZoneId.of(timeZoneId);
                clientFormatter = serverFormatter.withZone(zoneId);
                fireReady();
            } catch (DateTimeException e) {
                if (log.isErrorEnabled()) {
                    log.error(format("Unknown timezone '%s'. Server timezone '%s' will be used", timeZoneId, serverFormatter.getZone()), e);
                }
                clientFormatter = serverFormatter;
            }
        }
    });
}

18 Source : MainLayout.java
with Apache License 2.0
from jreznot

private void callElectronUiApi(Serializable... args) {
    UI.getCurrent().getPage().executeJs("callElectronUiApi($0)", args);
}

18 Source : UIAttributes.java
with Apache License 2.0
from appreciated

/**
 *  Needs to be called from the UI Thread.
 * @param type
 * @param value
 * @param <T>
 */
public static <T extends Serializable> void set(Clreplaced<T> type, T value) {
    UIAttributes session = getSession();
    UI ui = UI.getCurrent();
    if (!session.map.containsKey(UI.getCurrent())) {
        session.map.put(ui, new HashMap<>());
    }
    session.map.get(ui).put(type, value);
}

18 Source : UIAttributes.java
with Apache License 2.0
from appreciated

/**
 * Needs to be called from the UI Thread.
 * @param type
 * @param <T>
 * @return
 */
public static <T extends Serializable> T get(Clreplaced<T> type) {
    UIAttributes session = getSession();
    UI ui = UI.getCurrent();
    if (!session.map.containsKey(UI.getCurrent())) {
        session.map.put(ui, new HashMap<>());
    }
    return (T) session.map.get(ui).get(type);
}

18 Source : UpNavigationHelper.java
with Apache License 2.0
from appreciated

public static void performUpNavigation(Clreplaced<? extends Component> currentNavigation) {
    getClosestRoute(RouteConfiguration.forSessionScope().getUrl(currentNavigation)).ifPresent(routeData -> UI.getCurrent().navigate(routeData.getUrl()));
}

17 Source : KeyboardEventView.java
with MIT License
from mcollovati

@Override
protected void onDetach(DetachEvent detachEvent) {
    UI.getCurrent().getSession().setErrorHandler(new DefaultErrorHandler());
}

17 Source : VertxStreamRequestHandler.java
with MIT License
from mcollovati

/**
 * Generates URI string for a dynamic resource using its {@code id} and
 * {@code name}. [0] UIid, [1] sec key, [2] name
 *
 * @param name file or attribute name to use in path
 * @param id   unique resource id
 * @return generated URI string
 */
public static String generateURI(String name, String id) {
    StringBuilder builder = new StringBuilder(DYN_RES_PREFIX);
    try {
        builder.append(UI.getCurrent().getUIId()).append(PATH_SEPARATOR);
        builder.append(id).append(PATH_SEPARATOR);
        builder.append(URLEncoder.encode(name, StandardCharsets.UTF_8.name()));
    } catch (UnsupportedEncodingException e) {
        // UTF8 has to be supported
        throw new RuntimeException(e);
    }
    return builder.toString();
}

17 Source : MainLayout.java
with Apache License 2.0
from alejandro-du

public void updatePagereplacedle() {
    Clreplaced<? extends HasComponents> viewClreplaced = tabToView.get(tabs.getSelectedTab());
    UI.getCurrent().getPage().setreplacedle(DemoUtils.getViewName(viewClreplaced) + " - " + "Crud UI add-on demo");
}

16 Source : ViewTestLayout.java
with MIT License
from mcollovati

@Override
public void beforeEnter(BeforeEnterEvent event) {
    // Defer value setting until all option elements have been attached
    UI.getCurrent().getPage().executeJs("setTimeout(function() {$0.value = $1}, 0)", viewSelect, event.getLocation().getPath());
}

15 Source : MenuTemplate.java
with MIT License
from netcore-jsa

@EventHandler
private void logout() {
    SecurityContextHolder.clearContext();
    UI ui = UI.getCurrent();
    ui.getSession().getSession().invalidate();
    ui.getSession().close();
    ui.getPage().reload();
}