com.vaadin.client.ui.label.LabelConnector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vaadin-client Show documentation
Show all versions of vaadin-client Show documentation
Vaadin is a web application framework for Rich Internet Applications (RIA).
Vaadin enables easy development and maintenance of fast and
secure rich web
applications with a stunning look and feel and a wide browser support.
It features a server-side architecture with the majority of the logic
running
on the server. Ajax technology is used at the browser-side to ensure a
rich
and interactive user experience.
The newest version!
/*
* Copyright (C) 2000-2024 Vaadin Ltd
*
* This program is available under Vaadin Commercial License and Service Terms.
*
* See for the full
* license.
*/
package com.vaadin.client.ui.label;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.PreElement;
import com.vaadin.client.Profiler;
import com.vaadin.client.WidgetUtil;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.client.ui.VLabel;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.Connect.LoadStyle;
import com.vaadin.shared.ui.label.LabelState;
import com.vaadin.ui.Label;
/**
* A connector class for the Label component. Eagerly loaded.
*
* @author Vaadin Ltd
*/
@Connect(value = Label.class, loadStyle = LoadStyle.EAGER)
public class LabelConnector extends AbstractComponentConnector {
@Override
public LabelState getState() {
return (LabelState) super.getState();
}
@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
super.onStateChanged(stateChangeEvent);
boolean sinkOnloads = false;
Profiler.enter("LabelConnector.onStateChanged update content");
VLabel widget = getWidget();
switch (getState().contentMode) {
case PREFORMATTED:
PreElement preElement = Document.get().createPreElement();
preElement.setInnerText(getState().text);
// clear existing content
widget.setHTML("");
// add preformatted text to dom
widget.getElement().appendChild(preElement);
break;
case TEXT:
widget.setText(getState().text);
break;
case HTML:
sinkOnloads = true;
widget.setHTML(getState().text);
break;
default:
throw new IllegalStateException(
"A new content mode has been added without configuring handling for it: "
+ getState().contentMode.name());
}
Profiler.leave("LabelConnector.onStateChanged update content");
if (sinkOnloads) {
Profiler.enter("LabelConnector.onStateChanged sinkOnloads");
WidgetUtil.sinkOnloadForImages(widget.getElement());
Profiler.leave("LabelConnector.onStateChanged sinkOnloads");
}
}
@Override
public VLabel getWidget() {
return (VLabel) super.getWidget();
}
}