Example usage for com.vaadin.ui Component getUI

List of usage examples for com.vaadin.ui Component getUI

Introduction

In this page you can find the example usage for com.vaadin.ui Component getUI.

Prototype

@Override
public UI getUI();

Source Link

Document

Gets the UI the component is attached to.

Usage

From source file:com.cavisson.gui.dashboard.components.charts.model.AbstractVaadinChartExample.java

/**
 * Runs given task repeatedly until the reference component is attached
 *
 * @param component//ww  w .  j ava  2s. c  o m
 * @param task
 * @param interval
 * @param initialPause
 *            a timeout after tas is started
 */
public static void runWhileAttached(final Component component, final Runnable task, final int interval,
        final int initialPause) {
    // Until reliable push available in our demo servers
    UI.getCurrent().setPollInterval(interval);

    final Thread thread = new Thread() {
        public void run() {
            try {
                Thread.sleep(initialPause);
                while (true) {
                    Future<Void> future = component.getUI().access(task);
                    future.get();
                    Thread.sleep(interval);
                }
            } catch (InterruptedException e) {
            } catch (ExecutionException e) {
                Logger.getLogger(getClass().getName()).log(Level.WARNING,
                        "Stopping repeating command due to an exception", e);
            } catch (com.vaadin.ui.UIDetachedException e) {
            } catch (Exception e) {
                Logger.getLogger(getClass().getName()).log(Level.WARNING,
                        "Unexpected exception while running scheduled update", e);
            }
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Thread stopped");
        };
    };
    thread.start();
}

From source file:com.jain.addon.i18N.handlers.I18NComponentHandler.java

License:Apache License

public I18NComponentHandler(final Component component) {
    this(component.getCaption());
    provider = ((I18NUI) component.getUI()).getI18nProvider();
}

From source file:com.jain.addon.i18N.handlers.I18NComponentHandler.java

License:Apache License

public void applyI18N(Component component, Locale locale) {
    if (provider == null)
        provider = ((I18NUI) component.getUI()).getI18nProvider();

    if (component instanceof Label) {
        ((Label) component).setValue(getCaption(locale));
    } else {//from w w  w.  ja  v  a2 s .  c o m
        component.setCaption(getCaption(locale));
    }
}

From source file:com.jain.addon.i18N.I18NChangeListener.java

License:Apache License

public void localeChanged(Component component) {
    if (currentLocale != component.getUI().getLocale()) {
        currentLocale = component.getUI().getLocale();

        updateComponents(component);/*from  ww w. j  ava 2  s  .  co m*/
    }
}

From source file:com.jain.addon.i18N.I18NHelper.java

License:Apache License

/**
 * Method to find I18NChangeListener or create an instance if this is not available
 * @param component//  w  ww  .  ja v a2  s  .c o m
 * @param create
 * @return {@link I18NChangeListener}
 */
public static I18NChangeListener findListener(Component component, boolean create) {
    I18NChangeListener listener = null;

    if (component instanceof I18NUI) {
        listener = ((I18NUI) component).getLocalChangeListener();
        if (listener != null)
            return listener;
    }

    if (component.getUI() instanceof I18NUI) {
        listener = ((I18NUI) component.getUI()).getLocalChangeListener();
        if (listener != null)
            return listener;
    }

    if (create) {
        listener = new I18NChangeListener();
        return listener;
    }

    return listener;
}

From source file:com.jain.addon.I18N.listners.JAttachDetachListner.java

License:Apache License

private void handleAddRemoveComponent(Component component, boolean remove) {
    if (remove) {
        components.remove(component);// www  . j ava2  s  . com
        if (component.getUI() != null) {
            I18NHelper.deRegistor(component.getUI(), component);

            if (component.getUI() instanceof I18NUI) {
                ((I18NUI) component.getUI()).getEventHandler().deRegistor(component);
            }
        } else
            System.out.println("Component root is null :: " + component);
    } else {
        components.add(component);
        I18NHelper.register(component.getUI(), component);

        if (component.getUI() instanceof I18NUI) {
            ((I18NUI) component.getUI()).getEventHandler().register(component);
        }
    }
}

From source file:de.metas.ui.web.vaadin.window.WindowPresenter.java

License:Open Source License

private final UI getUI() {
    final WindowView view = getView();
    if (view == null) {
        return null;
    }/* ww w  .java 2  s. c  om*/
    final Component viewComp = view.getComponent();
    if (viewComp == null) {
        return null;
    }

    final UI ui = viewComp.getUI();
    return ui;
}

From source file:info.magnolia.ui.framework.app.DefaultAppView.java

License:Open Source License

@Override
public void setTheme(String themeName) {
    String stylename = String.format("app-%s", themeName);
    final String themeUrl = String.format("../%s/styles.css", themeName);

    final Component vaadinComponent = asVaadinComponent();
    vaadinComponent.addStyleName(stylename);
    vaadinComponent.addAttachListener(new AttachListener() {

        @Override/*from  www  .j a  va 2 s .  co  m*/
        public void attach(AttachEvent event) {
            ThemeResource res = new ThemeResource(themeUrl);
            CSSInject cssInject = new CSSInject(vaadinComponent.getUI());
            cssInject.addStyleSheet(res);
        }
    });
}

From source file:org.eclipse.hawkbit.ui.components.HawkbitUIErrorHandler.java

License:Open Source License

private static Optional<Page> getPageOriginError(final ErrorEvent event) {

    final Component errorOrigin = findAbstractComponent(event);

    if (errorOrigin != null && errorOrigin.getUI() != null) {
        return Optional.ofNullable(errorOrigin.getUI().getPage());
    }// w  w w.ja  v  a  2  s . c o  m

    return Optional.empty();
}

From source file:org.jdal.vaadin.VaadinUtils.java

License:Apache License

/**
 * Close current window./*from  w  w  w .jav  a2  s .c  o m*/
 * @param panel a component in window to close.
 */
public static void closeWindow(Component panel) {
    panel.getUI().removeWindow(getWindow(panel));
}