Example usage for com.vaadin.ui Link setWidth

List of usage examples for com.vaadin.ui Link setWidth

Introduction

In this page you can find the example usage for com.vaadin.ui Link setWidth.

Prototype

@Override
    public void setWidth(float width, Unit unit) 

Source Link

Usage

From source file:org.vaadin.addons.sitekit.viewlet.user.ProfileImageViewlet.java

License:Apache License

@Override
public void enter(final String parameters) {
    final String user = getSite().getSecurityProvider().getUser();
    if (user == null) {
        final VerticalLayout layout = new VerticalLayout();
        layout.setMargin(false);/*from w w w .  j a v  a2s.  c  om*/
        final Link link = new Link(null, new ExternalResource("#!login"));
        link.setStyleName("gravatar");
        link.setIcon(getSite().getIcon("view-icon-login"));
        link.setWidth(32, UNITS_PIXELS);
        link.setHeight(32, UNITS_PIXELS);
        layout.addComponent(link);
        layout.setComponentAlignment(link, Alignment.MIDDLE_CENTER);
        this.setCompositionRoot(layout);
        return;
    }
    try {
        final VerticalLayout layout = new VerticalLayout();
        layout.setMargin(false);
        if (getSite().getSiteContext().getObject("gravatar-url") == null) {
            getSite().getSiteContext().putObject("gravatar-url", getGravatarUrl(user));
        }
        final URL gravatarUrl = new URL((String) getSite().getSiteContext().getObject("gravatar-url"));
        //final Embedded embedded = new Embedded(null, new ExternalResource(gravatarUrl));
        final Link link = new Link(null, new ExternalResource("http://www.gravatar.com/"));
        link.setStyleName("gravatar");
        link.setIcon(new ExternalResource(gravatarUrl));
        link.setWidth(32, UNITS_PIXELS);
        link.setHeight(32, UNITS_PIXELS);
        layout.addComponent(link);
        layout.setComponentAlignment(link, Alignment.MIDDLE_CENTER);
        this.setCompositionRoot(layout);
    } catch (final Exception e) {
        LOGGER.warn("Error reading gravatar image for user: " + user, e);
    }
}